Beispiel #1
0
        protected virtual void emitInstanceInit(FMethod m)
        {
            hasInstanceInit = true;
            PERWAPI.CILInstructions code = ctor.CreateCodeBuffer();

            // initalize code to call super
            code.Inst(PERWAPI.Op.ldarg_0);

            // if closure, push FuncType static field
            if (funcType != null)
            {
                code.FieldInst(PERWAPI.FieldOp.ldsfld, typeField);
                PERWAPI.Method baseCtor = emitter.findMethod(baseClassName, ".ctor",
                                                             new string[] { "Fan.Sys.FuncType" }, "System.Void");
                baseCtor.AddCallConv(PERWAPI.CallConv.Instance); // if stub, make sure instance callconv
                code.MethInst(PERWAPI.MethodOp.call, baseCtor);
            }
            else
            {
                PERWAPI.Method baseCtor = emitter.findMethod(baseClassName, ".ctor",
                                                             new string[0], "System.Void");
                baseCtor.AddCallConv(PERWAPI.CallConv.Instance); // if stub, make sure instance callconv
                code.MethInst(PERWAPI.MethodOp.call, baseCtor);
            }

            // make peer
            if (isNative)
            {
                //code.op(ALOAD_0);  // for putfield
                //code.op(DUP);      // for arg to make
                //code.op2(INVOKESTATIC, method(selfName + "Peer.make(L" + className + ";)L" + className + "Peer;"));
                //code.op2(PUTFIELD, peerField.ref());

                code.Inst(PERWAPI.Op.ldarg_0);
                code.Inst(PERWAPI.Op.dup);
                PERWAPI.Method peerMake = emitter.findMethod(className + "Peer", "make",
                                                             new string[] { className }, className + "Peer");
                code.MethInst(PERWAPI.MethodOp.call, peerMake);
                code.FieldInst(PERWAPI.FieldOp.stfld, peerField);
            }

            if (m == null)
            {
                code.Inst(PERWAPI.Op.ret);
            }
            else
            {
                new FCodeEmit(this, m, code).emit();
            }
        }
Beispiel #2
0
        //////////////////////////////////////////////////////////////////////////
        // Overrides
        //////////////////////////////////////////////////////////////////////////

        protected override void emitInstanceInit(FMethod m)
        {
            hasInstanceInit = true;

            // make peer
            if (isNative)
            {
                throw new System.Exception("No native support for Err subclasses");
            }

            // stub ctor2
            PERWAPI.MethodDef ctor2 = emitter.findMethod(selfName, ".ctor",
                                                         new string[] { "Fan.Sys.Err/Val" }, "System.Void") as PERWAPI.MethodDef;
            ctor2.SetMethAttributes(
                PERWAPI.MethAttr.Public |
                PERWAPI.MethAttr.HideBySig |
                PERWAPI.MethAttr.SpecialRTSpecialName);
            ctor2.AddCallConv(PERWAPI.CallConv.Instance);

            // no arg constructor -> calls this(Err/Val)
            PERWAPI.CILInstructions code = ctor.CreateCodeBuffer();
            code.Inst(PERWAPI.Op.ldarg_0);
            PERWAPI.Method valctor = emitter.findMethod(className + "/Val", ".ctor", new string[0], "System.Void");
            code.MethInst(PERWAPI.MethodOp.newobj, valctor);
            code.MethInst(PERWAPI.MethodOp.call, ctor2);
            code.Inst(PERWAPI.Op.ret);

            // arg constructor with Err$Val (and init implementation)
            code = ctor2.CreateCodeBuffer();
            code.Inst(PERWAPI.Op.ldarg_0);
            code.Inst(PERWAPI.Op.ldarg_1);
            PERWAPI.Method baseCtor = emitter.findMethod(baseClassName, ".ctor",
                                                         new string[] { "Fan.Sys.Err/Val" }, "System.Void");
            baseCtor.AddCallConv(PERWAPI.CallConv.Instance); // if stub, make sure instance callconv
            code.MethInst(PERWAPI.MethodOp.call, baseCtor);
            if (m == null)
            {
                //code.maxLocals = 2;
                //code.maxStack  = 2;
                code.Inst(PERWAPI.Op.ret);
            }
            else
            {
                // e.code.maxLocals++;  // alloc room for Val extra argument
                new FCodeEmit(this, m, code).emit();
            }
        }
Beispiel #3
0
        private void emitCtor()
        {
            // no arg constructor
            ctor = emitter.findMethod(selfName, ".ctor", new string[0], "System.Void") as PERWAPI.MethodDef;
            ctor.SetMethAttributes(
                PERWAPI.MethAttr.Public |
                PERWAPI.MethAttr.HideBySig |
                PERWAPI.MethAttr.SpecialRTSpecialName);
            ctor.AddCallConv(PERWAPI.CallConv.Instance);

            PERWAPI.CILInstructions code = ctor.CreateCodeBuffer();
            code.Inst(PERWAPI.Op.ldarg_0);
            PERWAPI.Method baseCtor = emitter.findMethod(baseClassName, ".ctor", new string[0], "System.Void");
            baseCtor.AddCallConv(PERWAPI.CallConv.Instance); // if stub, make sure instance callconv
            code.MethInst(PERWAPI.MethodOp.call, baseCtor);
            code.Inst(PERWAPI.Op.ret);
        }
Beispiel #4
0
        /// <summary>
        /// Emit a native method
        /// <summary>
        public void emitNative()
        {
            // emit an empty method
            this.code = null;

            // emit code which calls the peer
            PERWAPI.CILInstructions code = doEmit();
            if (!emitter.stub)
            {
                if (isStatic)
                {
                    string[] parTypes = new string[paramLen];
                    for (int i = 0; i < paramLen; i++)
                    {
                        parTypes[i] = emit.nname(method.m_vars[i].type);
                    }

                    PERWAPI.Method peerMeth = emitter.findMethod(selfName + "Peer", name, parTypes, ret.nname());
                    pushArgs(code, false, paramLen);
                    code.MethInst(PERWAPI.MethodOp.call, peerMeth);
                }
                else
                {
                    string[] parTypes = new string[paramLen + 1];
                    parTypes[0] = selfName;
                    for (int i = 0; i < paramLen; i++)
                    {
                        parTypes[i + 1] = emit.nname(method.m_vars[i].type);
                    }

                    PERWAPI.Method peerMeth = emitter.findMethod(selfName + "Peer", name, parTypes, ret.nname());
                    peerMeth.AddCallConv(PERWAPI.CallConv.Instance);
                    code.Inst(PERWAPI.Op.ldarg_0);
                    code.FieldInst(PERWAPI.FieldOp.ldfld, emit.peerField);
                    pushArgs(code, true, paramLen);
                    code.MethInst(PERWAPI.MethodOp.call, peerMeth);
                }
            }
            code.Inst(PERWAPI.Op.ret);

            // emit default parameter wrappers
            emitWrappers();
        }