EmitVar() private method

private EmitVar ( CljILGen ilg, Var var ) : void
ilg CljILGen
var Var
return void
示例#1
0
 public void Emit(RHC rhc, ObjExpr objx, CljILGen ilg)
 {
     objx.EmitVar(ilg, _var);
     if (_isDynamic)
     {
         ilg.Emit(OpCodes.Call, Compiler.Method_Var_setDynamic0);
     }
     if (_meta != null)
     {
         if (_initProvided || true) //IncludesExplicitMetadata((MapExpr)_meta))
         {
             ilg.Emit(OpCodes.Dup);
             _meta.Emit(RHC.Expression, objx, ilg);
             ilg.Emit(OpCodes.Castclass, typeof(IPersistentMap));
             ilg.Emit(OpCodes.Call, Compiler.Method_Var_setMeta);
         }
     }
     if (_initProvided)
     {
         ilg.Emit(OpCodes.Dup);
         if (_init is FnExpr)
         {
             ((FnExpr)_init).EmitForDefn(objx, ilg);
         }
         else
         {
             _init.Emit(RHC.Expression, objx, ilg);
         }
         ilg.Emit(OpCodes.Call, Compiler.Method_Var_bindRoot);
     }
     if (rhc == RHC.Statement)
     {
         ilg.Emit(OpCodes.Pop);
     }
 }
示例#2
0
 public void Emit(RHC rhc, ObjExpr objx, CljILGen ilg)
 {
     objx.EmitVar(ilg, _var);
     if (_isDynamic)
     {
         ilg.Emit(OpCodes.Call, Compiler.Method_Var_setDynamic0);
     }
     if (_meta != null)
     {
         if (_initProvided || true) //IncludesExplicitMetadata((MapExpr)_meta))
         {
             ilg.Emit(OpCodes.Dup);
             _meta.Emit(RHC.Expression, objx, ilg);
             ilg.Emit(OpCodes.Castclass, typeof(IPersistentMap));
             ilg.Emit(OpCodes.Call, Compiler.Method_Var_setMeta);
         }
     }
     if (_initProvided)
     {
         ilg.Emit(OpCodes.Dup);
         if (_init is FnExpr)
             ((FnExpr)_init).EmitForDefn(objx, ilg);
         else
             _init.Emit(RHC.Expression, objx, ilg);
         ilg.Emit(OpCodes.Call,Compiler.Method_Var_bindRoot);
     }
     if (rhc == RHC.Statement)
         ilg.Emit(OpCodes.Pop);
 }
示例#3
0
 public void Emit(RHC rhc, ObjExpr objx, CljILGen ilg)
 {
     objx.EmitVar(ilg, _var);
     if (rhc == RHC.Statement)
     {
         ilg.Emit(OpCodes.Pop);
     }
 }
示例#4
0
 public void EmitAssign(RHC rhc, ObjExpr objx, CljILGen ilg, Expr val)
 {
     objx.EmitVar(ilg, _var);
     val.Emit(RHC.Expression, objx, ilg);
     ilg.Emit(OpCodes.Call, Compiler.Method_Var_set);
     if (rhc == RHC.Statement)
         ilg.Emit(OpCodes.Pop);
 }
示例#5
0
        public void Emit(RHC rhc, ObjExpr objx, CljILGen ilg)
        {
            objx.EmitVar(ilg, _var);

            if (_shadowsCoreMapping)
            {
                LocalBuilder locNs = ilg.DeclareLocal(typeof(Namespace));
                GenContext.SetLocalName(locNs, "ns");

                ilg.Emit(OpCodes.Dup);
                ilg.EmitFieldGet(VarNsFI);
                ilg.Emit(OpCodes.Stloc, locNs);

                LocalBuilder locSym = ilg.DeclareLocal(typeof(Symbol));
                GenContext.SetLocalName(locSym, "sym");

                ilg.Emit(OpCodes.Dup);
                ilg.EmitFieldGet(VarSymFI);
                ilg.Emit(OpCodes.Stloc, locSym);

                ilg.Emit(OpCodes.Ldloc, locNs);
                ilg.Emit(OpCodes.Ldloc, locSym);
                ilg.Emit(OpCodes.Call, NamespaceReferMI);
            }

            if (_isDynamic)
            {
                ilg.Emit(OpCodes.Call, Compiler.Method_Var_setDynamic0);
            }
            if (_meta != null)
            {
                if (_initProvided || true) //IncludesExplicitMetadata((MapExpr)_meta))
                {
                    ilg.Emit(OpCodes.Dup);
                    _meta.Emit(RHC.Expression, objx, ilg);
                    ilg.Emit(OpCodes.Castclass, typeof(IPersistentMap));
                    ilg.Emit(OpCodes.Call, Compiler.Method_Var_setMeta);
                }
            }
            if (_initProvided)
            {
                ilg.Emit(OpCodes.Dup);
                if (_init is FnExpr expr)
                {
                    expr.EmitForDefn(objx, ilg);
                }
                else
                {
                    _init.Emit(RHC.Expression, objx, ilg);
                }
                ilg.Emit(OpCodes.Call, Compiler.Method_Var_bindRoot);
            }
            if (rhc == RHC.Statement)
            {
                ilg.Emit(OpCodes.Pop);
            }
        }
示例#6
0
 public void EmitAssign(RHC rhc, ObjExpr objx, CljILGen ilg, Expr val)
 {
     objx.EmitVar(ilg, _var);
     val.Emit(RHC.Expression, objx, ilg);
     ilg.Emit(OpCodes.Call, Compiler.Method_Var_set);
     if (rhc == RHC.Statement)
     {
         ilg.Emit(OpCodes.Pop);
     }
 }
示例#7
0
        public void Emit(RHC rhc, ObjExpr objx, CljILGen ilg)
        {
            objx.EmitVar(ilg, _var);

            if ( _shadowsCoreMapping )
            {
                LocalBuilder locNs = ilg.DeclareLocal(typeof(Namespace));
                GenContext.SetLocalName(locNs, "ns");

                ilg.Emit(OpCodes.Dup);
                ilg.EmitFieldGet(VarNsFI);
                ilg.Emit(OpCodes.Stloc,locNs);

                LocalBuilder locSym = ilg.DeclareLocal(typeof(Symbol));
                GenContext.SetLocalName(locSym, "sym");

                ilg.Emit(OpCodes.Dup);
                ilg.EmitFieldGet(VarSymFI);
                ilg.Emit(OpCodes.Stloc, locSym);

                ilg.Emit(OpCodes.Ldloc, locNs);
                ilg.Emit(OpCodes.Ldloc, locSym);
                ilg.Emit(OpCodes.Call, NamespaceReferMI);
            }

            if (_isDynamic)
            {
                ilg.Emit(OpCodes.Call, Compiler.Method_Var_setDynamic0);
            }
            if (_meta != null)
            {
                if (_initProvided || true) //IncludesExplicitMetadata((MapExpr)_meta))
                {
                    ilg.Emit(OpCodes.Dup);
                    _meta.Emit(RHC.Expression, objx, ilg);
                    ilg.Emit(OpCodes.Castclass, typeof(IPersistentMap));
                    ilg.Emit(OpCodes.Call, Compiler.Method_Var_setMeta);
                }
            }
            if (_initProvided)
            {
                ilg.Emit(OpCodes.Dup);
                if (_init is FnExpr)
                    ((FnExpr)_init).EmitForDefn(objx, ilg);
                else
                    _init.Emit(RHC.Expression, objx, ilg);
                ilg.Emit(OpCodes.Call,Compiler.Method_Var_bindRoot);
            }
            if (rhc == RHC.Statement)
                ilg.Emit(OpCodes.Pop);
        }
示例#8
0
 public void Emit(RHC rhc, ObjExpr objx, CljILGen ilg)
 {
     objx.EmitVar(ilg, _var);
     if (rhc == RHC.Statement)
         ilg.Emit(OpCodes.Pop);
 }
示例#9
0
        void EmitProto(RHC rhc, ObjExpr objx, CljILGen ilg)
        {
            Label onLabel   = ilg.DefineLabel();
            Label callLabel = ilg.DefineLabel();
            Label endLabel  = ilg.DefineLabel();

            Var v = ((VarExpr)_fexpr).Var;

            Expr e = (Expr)_args.nth(0);

            e.Emit(RHC.Expression, objx, ilg);               // target
            ilg.Emit(OpCodes.Dup);                           // target, target

            LocalBuilder targetTemp = ilg.DeclareLocal(typeof(Object));

            GenContext.SetLocalName(targetTemp, "target");
            ilg.Emit(OpCodes.Stloc, targetTemp);                  // target

            ilg.Emit(OpCodes.Call, Compiler.Method_Util_classOf); // class
            ilg.EmitLoadArg(0);                                   // class, this
            ilg.EmitFieldGet(objx.CachedTypeField(_siteIndex));   // class, cached-class
            ilg.Emit(OpCodes.Beq, callLabel);                     //
            if (_protocolOn != null)
            {
                ilg.Emit(OpCodes.Ldloc, targetTemp);             // target
                ilg.Emit(OpCodes.Isinst, _protocolOn);           // null or target
                ilg.Emit(OpCodes.Ldnull);                        // (null or target), null
                ilg.Emit(OpCodes.Cgt_Un);                        // (0 or 1)
                ilg.Emit(OpCodes.Brtrue, onLabel);
            }
            ilg.Emit(OpCodes.Ldloc, targetTemp);                  // target
            ilg.Emit(OpCodes.Call, Compiler.Method_Util_classOf); // class

            LocalBuilder typeTemp = ilg.DeclareLocal(typeof(Type));

            GenContext.SetLocalName(typeTemp, "type");
            ilg.Emit(OpCodes.Stloc, typeTemp);                   //    (typeType <= class)

            ilg.EmitLoadArg(0);                                  // this

            ilg.Emit(OpCodes.Ldloc, typeTemp);                   // this, class
            ilg.EmitFieldSet(objx.CachedTypeField(_siteIndex));  //

            ilg.MarkLabel(callLabel);

            objx.EmitVar(ilg, v);                                   // var
            ilg.Emit(OpCodes.Call, Compiler.Method_Var_getRawRoot); // proto-fn
            ilg.Emit(OpCodes.Castclass, typeof(AFunction));

            ilg.Emit(OpCodes.Ldloc, targetTemp);                  // proto-fn, target

            EmitArgsAndCall(1, rhc, objx, ilg);
            ilg.Emit(OpCodes.Br, endLabel);

            ilg.MarkLabel(onLabel);
            ilg.Emit(OpCodes.Ldloc, targetTemp);                  // target
            if (_protocolOn != null)
            {
                ilg.Emit(OpCodes.Castclass, _protocolOn);
                MethodExpr.EmitTypedArgs(objx, ilg, _onMethod.GetParameters(), RT.subvec(_args, 1, _args.count()));
                //if (rhc == RHC.Return)
                //{
                //    ObjMethod2 method = (ObjMethod)Compiler.MethodVar.deref();
                //    method.EmitClearLocals(context);
                //}
                ilg.Emit(OpCodes.Callvirt, _onMethod);
                HostExpr.EmitBoxReturn(objx, ilg, _onMethod.ReturnType);
            }
            ilg.MarkLabel(endLabel);
        }
示例#10
0
        void EmitProto(RHC rhc, ObjExpr objx, CljILGen ilg)
        {
            Label onLabel = ilg.DefineLabel();
            Label callLabel = ilg.DefineLabel();
            Label endLabel = ilg.DefineLabel();

            Var v = ((VarExpr)_fexpr).Var;

            Expr e = (Expr)_args.nth(0);
            e.Emit(RHC.Expression, objx, ilg);               // target
            ilg.Emit(OpCodes.Dup);                               // target, target

            LocalBuilder targetTemp = ilg.DeclareLocal(typeof(Object));
            GenContext.SetLocalName(targetTemp, "target");
            ilg.Emit(OpCodes.Stloc,targetTemp);                  // target

            ilg.Emit(OpCodes.Call,Compiler.Method_Util_classOf);          // class
            ilg.EmitLoadArg(0);                                  // class, this
            ilg.EmitFieldGet(objx.CachedTypeField(_siteIndex));  // class, cached-class
            ilg.Emit(OpCodes.Beq, callLabel);                    //
            if (_protocolOn != null)
            {
                ilg.Emit(OpCodes.Ldloc,targetTemp);              // target
                ilg.Emit(OpCodes.Isinst, _protocolOn);           // null or target
                ilg.Emit(OpCodes.Ldnull);                        // (null or target), null
                ilg.Emit(OpCodes.Cgt_Un);                        // (0 or 1)
                ilg.Emit(OpCodes.Brtrue, onLabel);
            }
            ilg.Emit(OpCodes.Ldloc,targetTemp);                  // target
            ilg.Emit(OpCodes.Call,Compiler.Method_Util_classOf);          // class

            LocalBuilder typeTemp = ilg.DeclareLocal(typeof(Type));
            GenContext.SetLocalName(typeTemp, "type");
            ilg.Emit(OpCodes.Stloc,typeTemp);                    //    (typeType <= class)

            ilg.EmitLoadArg(0);                                  // this

            ilg.Emit(OpCodes.Ldloc,typeTemp);                    // this, class
            ilg.EmitFieldSet(objx.CachedTypeField(_siteIndex));  //

            ilg.MarkLabel(callLabel);

            objx.EmitVar(ilg,v);                              // var
            ilg.Emit(OpCodes.Call,Compiler.Method_Var_getRawRoot);         // proto-fn
            ilg.Emit(OpCodes.Castclass, typeof(AFunction));

            ilg.Emit(OpCodes.Ldloc,targetTemp);                  // proto-fn, target

            EmitArgsAndCall(1,rhc,objx,ilg);
            ilg.Emit(OpCodes.Br,endLabel);

            ilg.MarkLabel(onLabel);
            ilg.Emit(OpCodes.Ldloc,targetTemp);                  // target
            if ( _protocolOn != null )
            {
                ilg.Emit(OpCodes.Castclass, _protocolOn);
                MethodExpr.EmitTypedArgs(objx, ilg, _onMethod.GetParameters(), RT.subvec(_args, 1, _args.count()));
                //if (rhc == RHC.Return)
                //{
                //    ObjMethod2 method = (ObjMethod)Compiler.MethodVar.deref();
                //    method.EmitClearLocals(context);
                //}
                ilg.Emit(OpCodes.Callvirt, _onMethod);
                HostExpr.EmitBoxReturn(objx, ilg, _onMethod.ReturnType);
            }
            ilg.MarkLabel(endLabel);
        }
示例#11
0
        // TODO: Eliminate common code between EmitProtoLight and EmitProtoFull
        void EmitProtoLight(RHC rhc, ObjExpr objx, CljILGen ilg)
        {
            Label endLabel = ilg.DefineLabel();

            Var v = ((VarExpr)_fexpr).Var;

            Expr e = (Expr)_args.nth(0);
            e.Emit(RHC.Expression, objx, ilg);               // target

            LocalBuilder targetTemp = ilg.DeclareLocal(typeof(Object));
            GenContext.SetLocalName(targetTemp, "target");
            ilg.Emit(OpCodes.Stloc, targetTemp);             //   (targetTemp <= target)

            ilg.EmitString(String.Format("In Light Proto for {0}",v.Symbol.ToString()));
            ilg.Emit(OpCodes.Call,typeof(Console).GetMethod("WriteLine",new Type[] { typeof(string) }));

            //if (_protocolOn != null)
            //{
            //    ilg.Emit(OpCodes.Ldloc, targetTemp);              // target
            //    ilg.Emit(OpCodes.Isinst, _protocolOn);            // (target or null)
            //    ilg.Emit(OpCodes.Ldnull);                         // (target or null), null
            //    ilg.Emit(OpCodes.Cgt_Un);                         // (0 or 1)
            //    ilg.Emit(OpCodes.Brtrue, onLabel);
            //}

            objx.EmitVar(ilg, v);                                 // var
            ilg.Emit(OpCodes.Call, Compiler.Method_Var_getRawRoot);         // proto-fn

                ilg.Emit(OpCodes.Dup);
                ilg.Emit(OpCodes.Call, typeof(Object).GetMethod("GetType"));
                ilg.Emit(OpCodes.Callvirt, typeof(Object).GetMethod("ToString"));
                ilg.EmitString("Expected AFunction, got ");
                ilg.Emit(OpCodes.Call, typeof(Console).GetMethod("Write", new Type[] { typeof(String) }));
                ilg.Emit(OpCodes.Call, typeof(Console).GetMethod("WriteLine", new Type[] { typeof(String) }));

            ilg.Emit(OpCodes.Castclass, typeof(AFunction));

            ilg.EmitString("Castclass worked ");
            ilg.Emit(OpCodes.Call, typeof(Console).GetMethod("WriteLine", new Type[] { typeof(String) }));

            ilg.Emit(OpCodes.Ldloc, targetTemp);                  // proto-fn, target

            EmitArgsAndCall(1, rhc, objx, ilg);

            ilg.EmitString("gen'd args and called");
            ilg.Emit(OpCodes.Call, typeof(Console).GetMethod("WriteLine", new Type[] { typeof(String) }));

            ilg.Emit(OpCodes.Br, endLabel);

            //ilg.MarkLabel(onLabel);
            //ilg.Emit(OpCodes.Ldloc, targetTemp);                  // target
            //if (_protocolOn != null)
            //{
            //    ilg.Emit(OpCodes.Castclass, _protocolOn);
            //    MethodExpr.EmitTypedArgs(objx, ilg, _onMethod.GetParameters(), RT.subvec(_args, 1, _args.count()));
            //    //if (rhc == RHC.Return)
            //    //{
            //    //    ObjMethod2 method = (ObjMethod)Compiler.MethodVar.deref();
            //    //    method.EmitClearLocals(context);
            //    //}
            //    ilg.Emit(OpCodes.Callvirt,_onMethod);
            //    HostExpr.EmitBoxReturn(objx, ilg, _onMethod.ReturnType);
            //}
            ilg.MarkLabel(endLabel);
        }
示例#12
0
        // TODO: Eliminate common code between EmitProtoLight and EmitProtoFull

        void EmitProtoLight(RHC rhc, ObjExpr objx, CljILGen ilg)
        {
            Label endLabel = ilg.DefineLabel();

            Var v = ((VarExpr)_fexpr).Var;

            Expr e = (Expr)_args.nth(0);

            e.Emit(RHC.Expression, objx, ilg);               // target

            LocalBuilder targetTemp = ilg.DeclareLocal(typeof(Object));

            GenContext.SetLocalName(targetTemp, "target");
            ilg.Emit(OpCodes.Stloc, targetTemp);             //   (targetTemp <= target)

            ilg.EmitString(String.Format("In Light Proto for {0}", v.Symbol.ToString()));
            ilg.Emit(OpCodes.Call, typeof(Console).GetMethod("WriteLine", new Type[] { typeof(string) }));

            //if (_protocolOn != null)
            //{
            //    ilg.Emit(OpCodes.Ldloc, targetTemp);              // target
            //    ilg.Emit(OpCodes.Isinst, _protocolOn);            // (target or null)
            //    ilg.Emit(OpCodes.Ldnull);                         // (target or null), null
            //    ilg.Emit(OpCodes.Cgt_Un);                         // (0 or 1)
            //    ilg.Emit(OpCodes.Brtrue, onLabel);
            //}

            objx.EmitVar(ilg, v);                                   // var
            ilg.Emit(OpCodes.Call, Compiler.Method_Var_getRawRoot); // proto-fn


            ilg.Emit(OpCodes.Dup);
            ilg.Emit(OpCodes.Call, typeof(Object).GetMethod("GetType"));
            ilg.Emit(OpCodes.Callvirt, typeof(Object).GetMethod("ToString"));
            ilg.EmitString("Expected AFunction, got ");
            ilg.Emit(OpCodes.Call, typeof(Console).GetMethod("Write", new Type[] { typeof(String) }));
            ilg.Emit(OpCodes.Call, typeof(Console).GetMethod("WriteLine", new Type[] { typeof(String) }));


            ilg.Emit(OpCodes.Castclass, typeof(AFunction));

            ilg.EmitString("Castclass worked ");
            ilg.Emit(OpCodes.Call, typeof(Console).GetMethod("WriteLine", new Type[] { typeof(String) }));


            ilg.Emit(OpCodes.Ldloc, targetTemp);                  // proto-fn, target

            EmitArgsAndCall(1, rhc, objx, ilg);

            ilg.EmitString("gen'd args and called");
            ilg.Emit(OpCodes.Call, typeof(Console).GetMethod("WriteLine", new Type[] { typeof(String) }));

            ilg.Emit(OpCodes.Br, endLabel);

            //ilg.MarkLabel(onLabel);
            //ilg.Emit(OpCodes.Ldloc, targetTemp);                  // target
            //if (_protocolOn != null)
            //{
            //    ilg.Emit(OpCodes.Castclass, _protocolOn);
            //    MethodExpr.EmitTypedArgs(objx, ilg, _onMethod.GetParameters(), RT.subvec(_args, 1, _args.count()));
            //    //if (rhc == RHC.Return)
            //    //{
            //    //    ObjMethod2 method = (ObjMethod)Compiler.MethodVar.deref();
            //    //    method.EmitClearLocals(context);
            //    //}
            //    ilg.Emit(OpCodes.Callvirt,_onMethod);
            //    HostExpr.EmitBoxReturn(objx, ilg, _onMethod.ReturnType);
            //}
            ilg.MarkLabel(endLabel);
        }