Ejemplo n.º 1
0
 private void AddLocal(Token name)
 {
     if (_LocalCount >= MAX_LOCALS)
     {
         throw new CompilerException(name, "Too many local variables in scope.");
     }
     _LocalVarData[_LocalCount++] = new LoxCompilerLocal(name.Lexeme, SCOPE_NONE);
 }
Ejemplo n.º 2
0
 private LoxCompiler(TokenList tokens, ELoxFunctionType type, string name, LoxCompiler enclosing, LoxCompilerClass enclosingClass)
     : base(tokens, name)
 {
     _FunctionType      = type;
     Arity              = 0;
     _Chunk             = new GearsChunk(name);
     _Rules             = new List <Rule>();
     _EnclosingCompiler = enclosing;
     _CurrentClass      = enclosingClass;
     // stack slot zero is used for 'this' reference in methods, and is empty for script/functions:
     if (type != ELoxFunctionType.TYPE_FUNCTION)
     {
         _LocalVarData[_LocalCount++] = new LoxCompilerLocal("this", 0);
     }
     else
     {
         _LocalVarData[_LocalCount++] = new LoxCompilerLocal(string.Empty, 0);
     }
 }