예제 #1
0
        public override void EmitSet(CodeGen cg)
        {
            Contract.RequiresNotNull(cg, "cg");

            Slot val = cg.GetLocalTmp(Type);

            val.EmitSet(cg);
            EmitSet(cg, val);
            cg.FreeLocalTmp(val);
        }
예제 #2
0
파일: Slot.cs 프로젝트: clorton/IDM-CMS
        // This override assumes that the IL stack already holds the value to be assigned from.
        public virtual void EmitSet(CodeGen cg)
        {
            Contract.RequiresNotNull(cg, "cg");

            // localTmpVal = <top of IL stack>
            Slot localTmpVal = cg.GetLocalTmp(typeof(object));

            localTmpVal.EmitSet(cg);

            // <slot> = localTmpVal
            EmitSet(cg, localTmpVal);

            cg.FreeLocalTmp(localTmpVal);
        }
예제 #3
0
        protected virtual Slot PrepareSlotForEmit(CodeGen cg)
        {
            // Emit globals from context and cast to tuple type

            // tmpLocal = ((tupleDictType)codeContext.Scope.GlobalScope.GetDictionary(context)).Tuple
            cg.EmitCodeContext();
            cg.EmitPropertyGet(typeof(CodeContext), "Scope");
            cg.EmitPropertyGet(typeof(Scope), "ModuleScope");
            cg.EmitCall(typeof(RuntimeHelpers).GetMethod("GetTupleDictionaryData").MakeGenericMethod(TupleType));

            Slot tmpLocal = cg.GetLocalTmp(TupleType);

            tmpLocal.EmitSet(cg);

            return(tmpLocal);
        }
예제 #4
0
        private CodeGen MakeRawKeysMethod(LanguageInfo li, Dictionary <SymbolId, Slot> fields)
        {
            Slot    rawKeysCache = li.TypeGen.AddStaticField(typeof(SymbolId[]), "ExtraKeysCache");
            CodeGen init         = li.TypeGen.TypeInitializer;

            init.EmitInt(0);
            init.Emit(OpCodes.Newarr, typeof(SymbolId));

            rawKeysCache.EmitSet(init);

            CodeGen cg = li.TypeGen.DefineMethodOverride(typeof(CustomSymbolDictionary).GetMethod("GetExtraKeys", BindingFlags.Public | BindingFlags.Instance));

            rawKeysCache.EmitGet(cg);
            cg.EmitReturn();
            cg.Finish();

            return(cg);
        }
예제 #5
0
        public override void EmitSet(CodeGen cg)
        {
            Contract.RequiresNotNull(cg, "cg");

            if (_instance.Type.IsAssignableFrom(_type))
            {
                if (_type.IsValueType)
                {
                    Debug.Assert(_instance.Type == typeof(object));
                    cg.Emit(OpCodes.Box, _type);
                }
                else
                {
                    cg.Emit(OpCodes.Castclass, _instance.Type);
                }
            }
            _instance.EmitSet(cg);
        }
        private static void EmitNestedTupleInit(CodeGen cg, Type storageType)
        {
            if (Tuple.GetSize(storageType) > Tuple.MaxSize)
            {
                Slot tmp = cg.GetLocalTmp(storageType);
                tmp.EmitSet(cg);

                Type[] nestedTuples = storageType.GetGenericArguments();
                for (int i = 0; i < nestedTuples.Length; i++)
                {
                    Type t = nestedTuples[i];
                    if (t.IsSubclassOf(typeof(Tuple)))
                    {
                        tmp.EmitGet(cg);

                        cg.EmitNew(t.GetConstructor(ArrayUtils.EmptyTypes));
                        cg.EmitPropertySet(storageType, String.Format("Item{0:D3}", i));

                        tmp.EmitGet(cg);
                        cg.EmitPropertyGet(storageType, String.Format("Item{0:D3}", i));

                        EmitNestedTupleInit(cg, t);
                    }
                }

                cg.FreeLocalTmp(tmp);
            }
            else
            {
                int capacity = 0;
                foreach (Type t in storageType.GetGenericArguments())
                {
                    if (t == typeof(None))
                    {
                        break;
                    }
                    capacity++;
                }
                cg.EmitInt(capacity);
                cg.EmitCall(typeof(RuntimeHelpers), "UninitializeEnvironmentTuple");
            }
        }
예제 #7
0
 public static ReturnFixer EmitArgument(CodeGen cg, Slot argSlot)
 {
     argSlot.EmitGet(cg);
     if (argSlot.Type.IsByRef)
     {
         Type elementType  = argSlot.Type.GetElementType();
         Type concreteType = typeof(StrongBox <>).MakeGenericType(elementType);
         Slot refSlot      = cg.GetLocalTmp(concreteType);
         cg.EmitLoadValueIndirect(elementType);
         cg.EmitNew(concreteType, new Type[] { elementType });
         refSlot.EmitSet(cg);
         refSlot.EmitGet(cg);
         return(new ReturnFixer(refSlot, argSlot));
     }
     else
     {
         cg.EmitBoxing(argSlot.Type);
         return(null);
     }
 }
        public override void EmitNewEnvironment(CodeGen cg)
        {
            ConstructorInfo ctor = EnvironmentType.GetConstructor(
                ScriptDomainManager.Options.DebugMode ?
                new Type[] {
                StorageType,
                typeof(SymbolId[]),
            } :
                new Type[] {
                StorageType,
            });

            // emit: dict.Tuple[.Item000...].Item000 = dict, and then leave dict on the stack

            cg.EmitNew(ctor);
            cg.Emit(OpCodes.Dup);

            Slot tmp = cg.GetLocalTmp(EnvironmentType);

            tmp.EmitSet(cg);

            cg.EmitPropertyGet(EnvironmentType, "TupleData");

            PropertyInfo last = null;

            foreach (PropertyInfo pi in Tuple.GetAccessPath(StorageType, 0))
            {
                if (last != null)
                {
                    cg.EmitPropertyGet(last);
                }
                last = pi;
            }

            tmp.EmitGet(cg);
            cg.EmitPropertySet(last);

            cg.FreeLocalTmp(tmp);
        }
        public override void EmitNewEnvironment(CodeGen cg)
        {
            ConstructorInfo ctor = EnvironmentType.GetConstructor(new Type[] { StorageType });

            // emit: dict.Tuple[.Item000...].Item000 = dict, and then leave dict on the stack

            cg.EmitNew(ctor);
            cg.Emit(OpCodes.Dup);

            Slot tmp = cg.GetLocalTmp(EnvironmentType);

            tmp.EmitSet(cg);

            cg.EmitPropertyGet(EnvironmentType, "Data");

            var fld = StorageType.GetField("$parent$");

            //cg.EmitFieldGet(fld);

            tmp.EmitGet(cg);
            cg.EmitFieldSet(fld);

            cg.FreeLocalTmp(tmp);
        }
예제 #10
0
 public override void EmitSet(CodeGen cg)
 {
     _storage.EmitSet(cg);
 }