Пример #1
0
 public override void Accept(WithStatement withStmt)
 {
     symbolTable.NextScope();
     withStmt.Expression.Visit(this);
     methodBuilder.EmitInstruction(withStmt.Location, Opcode.BeginWith);
     withStmt.Body.Visit(this);
     methodBuilder.EmitInstruction(withStmt.Location, Opcode.EndWith);
     symbolTable.LeaveScope();
 }
Пример #2
0
        private IodineMethod CompileMethod(FunctionDeclaration funcDecl)
        {
            symbolTable.NextScope();
            IodineMethod methodBuilder = new IodineMethod(module, funcDecl.Name, funcDecl.InstanceMethod,
                                                          funcDecl.Parameters.Count,
                                                          symbolTable.CurrentScope.SymbolCount);
            FunctionCompiler compiler = new FunctionCompiler(symbolTable,
                                                             methodBuilder);

            methodBuilder.Variadic           = funcDecl.Variadic;
            methodBuilder.AcceptsKeywordArgs = funcDecl.AcceptsKeywordArgs;
            for (int i = 0; i < funcDecl.Parameters.Count; i++)
            {
                methodBuilder.Parameters [funcDecl.Parameters [i]] = symbolTable.GetSymbol
                                                                         (funcDecl.Parameters [i]).Index;
            }
            funcDecl.Children [0].Visit(compiler);
            AstNode lastNode = funcDecl.Children [0].LastOrDefault();

            if (lastNode != null)
            {
                methodBuilder.EmitInstruction(lastNode.Location, Opcode.LoadNull);
            }
            else
            {
                methodBuilder.EmitInstruction(funcDecl.Location, Opcode.LoadNull);
            }
            methodBuilder.FinalizeLabels();
            symbolTable.LeaveScope();
            return(methodBuilder);
        }