示例#1
0
 void Scope::visit(VariablePattern& pattern, int dummy)
 {
   if (*pattern.name() != "_")
   {
     if (isTopLevel())
     {
       // It's a top-level module variable. Since these are forward declared,
       // they should already exist. Just look up the existing one.
       int module = resolver_.compiler_.getModuleIndex(resolver_.module_);
       int index = resolver_.module_.findVariable(pattern.name());
       
       if (index == -1)
       {
         resolver_.compiler_.reporter().error(pattern.pos(),
             "Variable '%s' is not defined.", pattern.name()->cString());
         
         // Put a fake index in so we can continue and report more errors.
         index = 0;
       }
       
       pattern.setResolved(new ResolvedName(module, index));
     }
     else
     {
       // Declaring a local variable, so create a slot for it.
       gc<ResolvedName> resolved = resolver_.makeLocal(pattern.pos(),
                                                       pattern.name());
       pattern.setResolved(resolved);
     }
   }
   
   if (!pattern.pattern().isNull())
   {
     pattern.pattern()->accept(*this, dummy);
   }
 }
示例#2
0
 void Resolver::makeParamSlot(gc<Pattern> param)
 {
   VariablePattern* variable = param->asVariablePattern();
   if (variable != NULL && *variable->name() != "_")
   {
     // It's a variable, so create a named local for it and resolve the
     // variable.
     variable->setResolved(makeLocal(param->pos(), variable->name()));
     
     // Note that we do *not* resolve the variable's inner pattern here. We
     // do that after all param slots are resolved so that we can ensure the
     // param slots are contiguous.
   }
   else
   {
     // We don't have a variable for this parameter, but the argument
     // will still be on the stack, so make an unnamed slot for it.
     makeLocal(param->pos(), String::format("(%d)", unnamedSlotId_++));
   }
 }