Beispiel #1
0
        internal static Operand Delegate(OPRTYPE ty, int addr, string moduleName)
        {
            Operand v = new Operand();

            v.ty    = ty;
            v.value = addr;
            v.mod   = moduleName;
            return(v);
        }
Beispiel #2
0
        bool s_func(OPRTYPE type)
        {
            bool isCFunc  = false;
            int  PARA_NUM = 1;

            vtab.NewFunction();
            vtab.NewLevel();

            lex.InSymbol();

            int L0 = 0;
            int L1 = 0;
            int L2 = 0;

            if (type == OPRTYPE.none)
            {
                if (lex.sy == SYMBOL.identsy)
                {
                    Operand x = Operand.Ident(lex.sym.id);
                    gen.emit(INSTYPE.MOV, x);
                    lex.InSymbol();
                    type    = OPRTYPE.funccon;
                    isCFunc = true;
                }
                else
                {
                    error.OnError(46);
                }
            }

            L0 = gen.emit(INSTYPE.MOV, Operand.Delegate(type, gen.IP + 2, module.moduleName));
            L1 = gen.emit(INSTYPE.JMP);
            L2 = gen.emit(INSTYPE.PROC, Operand.Delegate(type, gen.IP, module.moduleName));


            expect(SYMBOL.LP);


            do
            {
                if (lex.sy == SYMBOL.identsy)
                {
                    int addr = PARA_NUM + 1;             //+1 keep a return address

                    vtab.AddParameter(lex.sym.id, -addr);
                    lex.InSymbol();
                    PARA_NUM++;
                }
                else
                {
                    break;
                }

                if (lex.sy == SYMBOL.COMMA)
                {
                    lex.InSymbol();
                }
            } while (true);

            gen.IV[L2].operand.Addr = PARA_NUM;


            expect(SYMBOL.RP);
            emit_func1();

            if (type == OPRTYPE.classcon)
            {
                if (lex.sy == SYMBOL.COLON)
                {
                    gen.emit(INSTYPE.THIS);
                    gen.emit(INSTYPE.MOV, Operand.Ident(Expression.BASE_INSTANCE));
                    gen.emit(INSTYPE.OFS);
                    s_instance();
                    gen.emit(INSTYPE.STO1);
                }
            }

            expect(SYMBOL.LC);          //function body;
            while (s_sent() == 1)
            {
                ;
            }
            expect(SYMBOL.RC);
            //	Var.BackLevel();		// this has been excuted in (case RC of s_sent())

            vtab.BackFunction();

            gen.emit(INSTYPE.ENDP, (int)type);          //used for determining default RETURN statement

            if (type != OPRTYPE.none)
            {
                gen.remit(L1, gen.IP);
            }

            if (isCFunc)
            {
                gen.emit(INSTYPE.STO1);
            }


            if (lex.sy == SYMBOL.LP)
            {
                s_funcarg(false, L2);
                gen.remit(L0, INSTYPE.NOP);
                gen.IV[L0].operand = null;
            }

            return(true);
        }
Beispiel #3
0
 public bool e_func(OPRTYPE type)       //expression
 {
     return(s_func(type));
 }
Beispiel #4
0
 public Operand(int opr)
 {
     ty    = OPRTYPE.intcon;
     value = opr;
 }
Beispiel #5
0
 public Operand(Numeric opr)
 {
     ty    = OPRTYPE.numcon;
     value = opr;
 }
Beispiel #6
0
 public Operand()
 {
     ty    = OPRTYPE.none;
     value = null;
 }