Beispiel #1
0
        public override void DoVisit(AST_VarDecl ast)
        {
            //checking of there are default args
            if (ast.is_func_arg && ast.children.Count > 0)
            {
                var fsymb    = func_decls.Peek();
                int symb_idx = (int)ast.symb_idx;
                //let's take into account 'this' special case, which is
                //stored at 0 idx and is not part of func args
                //(which are stored in the very beginning)
                if (fsymb.scope is ClassSymbol)
                {
                    --symb_idx;
                }
                var arg_op = Emit(Opcodes.DefArg, new int[] { symb_idx - fsymb.GetRequiredArgsNum(), 0 /*patched later*/ });
                VisitChildren(ast);
                AddOffsetFromTo(arg_op, Peek(), operand_idx: 1);
            }

            if (!ast.is_func_arg)
            {
                Emit(Opcodes.DeclVar, new int[] { (int)ast.symb_idx, AddConstant(ast.type) });
            }
            //check if it's not a module scope var (global)
            else if (func_decls.Count > 0)
            {
                if (ast.is_ref)
                {
                    Emit(Opcodes.ArgRef, new int[] { (int)ast.symb_idx });
                }
                else
                {
                    Emit(Opcodes.ArgVar, new int[] { (int)ast.symb_idx });
                }
            }
            else
            {
                Emit(Opcodes.DeclVar, new int[] { (int)ast.symb_idx, AddConstant(ast.type) });
            }
        }
Beispiel #2
0
 public abstract void DoVisit(AST_VarDecl ast);
Beispiel #3
0
 public override void DoVisit(AST_VarDecl node)
 {
     Console.Write("(VARDECL " + node.name);
     VisitChildren(node);
     Console.Write(")");
 }