Beispiel #1
0
  void ExprCompiler::compileParamField(PatternCompiler& compiler,
                                         gc<Pattern> param, int slot)
  {
    VariablePattern* variable = param->asVariablePattern();
    if (variable != NULL)
    {
      // It's a variable, so compile its inner pattern. We don't worry about
      // the variable itself because the calling convention ensures its value
      // is already in the right slot.
      compiler.compile(variable->pattern(), slot);

      // If we closed over the parameter, then we don't want in a local slot,
      // we want it in the upvar, so create it and copy the value up.
      if (*variable->name() != "_" &&
          variable->resolved()->scope() == NAME_CLOSURE)
      {
        write(variable->pos(),
              OP_SET_UPVAR, variable->resolved()->index(), slot, 1);
      }
    }
    else
    {
      // Not a variable, so just compile it normally.
      compiler.compile(param, slot);
    }
  }
Beispiel #2
0
  void PatternCompiler::visit(VariablePattern& pattern, int value)
  {
    // Assign to the variable if it isn't a throwaway.
    if (*pattern.name() != "_")
    {
      compiler_.compileAssignment(pattern.pos(), pattern.resolved(), value,
                                  true);
    }

    // Compile the inner pattern.
    if (!pattern.pattern().isNull())
    {
      pattern.pattern()->accept(*this, value);
    }
  }