Exemplo n.º 1
0
        public ModuleGlobalSlot(Slot builtinWrapper)
        {
            Debug.Assert(builtinWrapper.Type == typeof(ModuleGlobalWrapper));
            if (builtinWrapper.Type != typeof(ModuleGlobalWrapper)) throw new ArgumentException("builtinWrapper " + builtinWrapper.GetType().FullName);

            _wrapper = builtinWrapper;
        }
Exemplo n.º 2
0
        public PropertySlot(Slot instance, PropertyInfo property)
        {
            Debug.Assert(property != null);

            this._instance = instance;
            this._property = property;
        }
Exemplo n.º 3
0
 private ReturnFixer(Slot refSlot, Slot argSlot)
 {
     Debug.Assert(refSlot.Type.IsGenericType && refSlot.Type.GetGenericTypeDefinition() == typeof(StrongBox<>));
     Debug.Assert(argSlot.Type.IsByRef);
     this._refSlot = refSlot;
     this._argSlot = argSlot;
 }
Exemplo n.º 4
0
 public Targets(Nullable<Label> breakLabel, Nullable<Label> continueLabel, TargetBlockType blockType, Slot finallyReturns, Statement statement)
 {
     this.breakLabel = breakLabel;
     this.continueLabel = continueLabel;
     this._blockType = blockType;
     this.finallyReturns = finallyReturns;
     this.leaveLabel = null;
     this.statement = statement;
 }
Exemplo n.º 5
0
        public CastSlot(Slot instance, Type type)
        {
            Contract.RequiresNotNull(instance, "instance");
            Contract.RequiresNotNull(type, "type");
            if (!type.IsVisible) throw new ArgumentException(String.Format(Resources.TypeMustBeVisible, type.FullName));

            this._instance = instance;
            this._type = type;
        }
Exemplo n.º 6
0
 public override Slot CreateSlot(Slot instance)
 {
     Debug.Assert(instance != null && typeof(CodeContext).IsAssignableFrom(instance.Type));
     Slot slot = new LocalNamedFrameSlot(instance, _name);
     if (_type != slot.Type) {
         slot = new CastSlot(slot, _type);
     }
     return slot;
 }
 public override Slot CreateSlot(Slot instance)
 {
     var sym = SymbolTable.IdToString(_name);
     Slot s = new FieldSlot(instance, _storageType.GetField(sym));
     if (_type != s.Type)
     {
       s = new CastSlot(s, _type);
     }
     return s;
 }
Exemplo n.º 8
0
        /// <summary>
        /// Generates stub to receive the CLR call and then call the dynamic language code.
        /// </summary>
        public static void  EmitClrCallStub(CodeGen cg, Slot callTarget, int firstArg, CallType functionAttributes) {
            List<ReturnFixer> fixers = new List<ReturnFixer>(0);
            IList<Slot> args = cg.ArgumentSlots;
            int nargs = args.Count - firstArg;
            
            CallAction action;
            if ((functionAttributes & CallType.ArgumentList) != 0) {
                ArgumentInfo[] infos = CompilerHelpers.MakeRepeatedArray(ArgumentInfo.Simple, nargs);
                infos[nargs - 1] = new ArgumentInfo(ArgumentKind.List);

                action = CallAction.Make(new CallSignature(infos));
            } else {
                action = CallAction.Make(nargs);
            }

            bool fast;
            Slot site = cg.CreateDynamicSite(action, 
                CompilerHelpers.MakeRepeatedArray(typeof(object), nargs + 2), 
                out fast);

            site.EmitGet(cg);
            if (!fast) cg.EmitCodeContext();

            if (DynamicSiteHelpers.IsBigTarget(site.Type)) {
                cg.EmitTuple(site.Type.GetGenericArguments()[0], args.Count + 1, delegate(int index) {
                    if (index == 0) {
                        callTarget.EmitGet(cg);
                    } else {
                        ReturnFixer rf = ReturnFixer.EmitArgument(cg, args[index - 1]);
                        if (rf != null) fixers.Add(rf);
                    }
                });
            } else {
                callTarget.EmitGet(cg);

                for (int i = firstArg; i < args.Count; i++) {
                    ReturnFixer rf = ReturnFixer.EmitArgument(cg, args[i]);
                    if (rf != null) fixers.Add(rf);
                }
            }

            cg.EmitCall(site.Type, "Invoke"); 

            foreach (ReturnFixer rf in fixers) {
                rf.FixReturn(cg);
            }
            cg.EmitReturnFromObject();
        }
Exemplo n.º 9
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;
     }
 }
Exemplo n.º 10
0
 public CatchRecord(Slot slot, CatchBlock block)
 {
     _slot = slot;
     _block = block;
 }
Exemplo n.º 11
0
 internal GlobalFieldStorage(Slot slot)
 {
     _slot = slot;
 }
Exemplo n.º 12
0
        // Must override at least one of these two methods or get infinite loop
        public virtual void EmitSet(CodeGen cg, Slot val)
        {
            Contract.RequiresNotNull(val, "val");
            Contract.RequiresNotNull(cg, "cg");

            val.EmitGet(cg);
            EmitSet(cg);
        }
Exemplo n.º 13
0
 public IndexSlot(Slot instance, int index)
     : this(instance, index, typeof(object))
 {
 }
Exemplo n.º 14
0
 public override void EmitSet(CodeGen cg, Slot val)
 {
     _storage.EmitSet(cg, val);
 }
Exemplo n.º 15
0
 public void SetCodeGen(CodeGen cg, Slot dataSlot)
 {
     this._cg = cg;
     this._dataSlot = dataSlot;
 }
 public override Slot CreateSlot(Slot instance)
 {
     Slot slot = instance;
     Type curType = null;
     foreach (PropertyInfo pi in Tuple.GetAccessPath(_tupleType, _index)) {
         slot = new PropertySlot(slot, pi);
         curType = pi.PropertyType;
     }
     if (_type != curType) {
         slot = new CastSlot(slot, _type);
     }
     return slot;
 }
Exemplo n.º 17
0
 public override void EmitSet(CodeGen cg, Slot val)
 {
     _wrapper.EmitGet(cg);
     val.EmitGet(cg);
     cg.EmitPropertySet(typeof(ModuleGlobalWrapper), "CurrentValue");
 }
Exemplo n.º 18
0
 public FieldSlotFactory(TypeGen typeGen, Slot instance)
 {
     this._typeGen  = typeGen;
     this._instance = instance;
 }
Exemplo n.º 19
0
 public void AddClosureAccessSlot(CodeBlock block, Slot slot)
 {
     AddAccessSlot(block, ref _closureAccess, slot);
 }
Exemplo n.º 20
0
 public void AddGeneratorTemp(Slot slot)
 {
     if (_generatorTemps == null) {
         _generatorTemps = new List<Slot>();
     }
     _generatorTemps.Add(slot);
 }
Exemplo n.º 21
0
 public EnvironmentSlot(Slot storage)
 {
     _storage = storage;
 }
Exemplo n.º 22
0
 public void AddScopeAccessSlot(CodeBlock block, Slot slot)
 {
     AddAccessSlot(block, ref _scopeAccess, slot);
 }
Exemplo n.º 23
0
        public override void EmitSet(CodeGen cg, Slot val)
        {
            Contract.RequiresNotNull(cg, "cg");
            Contract.RequiresNotNull(val, "val");

            _instance.EmitGet(cg);
            cg.EmitInt(_index);
            val.EmitGet(cg);
            cg.EmitStoreElement(Type);
        }
Exemplo n.º 24
0
 private void AddAccessSlot(CodeBlock block, ref Dictionary<CodeBlock, Slot> slots, Slot slot)
 {
     if (slots == null) {
         slots = new Dictionary<CodeBlock, Slot>();
     }
     Debug.Assert(!slots.ContainsKey(block) || slots[block] == slot);
     slots[block] = slot;
 }
Exemplo n.º 25
0
 public IndexSlot(Slot instance, int index, Type type)
 {
     this._instance = instance;
     this._index = index;
     this._type = type;
 }
Exemplo n.º 26
0
 public void CreateSlot(CodeGen cg)
 {
     _slot = _variable.CreateSlot(cg);
 }
Exemplo n.º 27
0
 public FieldSlotFactory(TypeGen typeGen, Slot instance)
 {
     this._typeGen = typeGen;
     this._instance = instance;
 }
Exemplo n.º 28
0
 public ParamArraySlot(Slot paramArray, int paramIndex)
 {
     _param = paramArray;
     _index = paramIndex;
 }
Exemplo n.º 29
0
 public override Slot CreateSlot(Slot instance)
 {
     Debug.Assert(typeof(CodeContext).IsAssignableFrom(instance.Type), "wrong instance type");
     return new NamedFrameSlot(instance, _name);
 }
Exemplo n.º 30
0
        /// <summary>
        /// If the finally statement contains break, continue, return or yield, we need to
        /// handle the control flow statement after we exit out of finally via OpCodes.Endfinally.
        /// </summary>
        private static void EmitFinallyFlowControl(CodeGen cg, TryFlowResult flow, Slot flag)
        {
            if (flow.Return || flow.Yield) {
                Debug.Assert(flag != null);

                Label noReturn = cg.DefineLabel();

                flag.EmitGet(cg);
                cg.EmitInt(CodeGen.BranchForReturn);
                cg.Emit(OpCodes.Bne_Un, noReturn);

                if (cg.IsGenerator) {
                    // return true from the generator method
                    cg.Emit(OpCodes.Ldc_I4_1);
                    cg.EmitReturn();
                } else if (flow.Any) {
                    // return the actual value
                    cg.EmitReturnValue();
                    cg.EmitReturn();
                }
                cg.MarkLabel(noReturn);
            }

            // Only emit break handling if it is actually needed
            if (flow.Break) {
                Debug.Assert(flag != null);

                Label noReturn = cg.DefineLabel();
                flag.EmitGet(cg);
                cg.EmitInt(CodeGen.BranchForBreak);
                cg.Emit(OpCodes.Bne_Un, noReturn);
                cg.EmitBreak();
                cg.MarkLabel(noReturn);
            }

            // Only emit continue handling if it if actually needed
            if (flow.Continue) {
                Debug.Assert(flag != null);

                Label noReturn = cg.DefineLabel();
                flag.EmitGet(cg);
                cg.EmitInt(CodeGen.BranchForContinue);
                cg.Emit(OpCodes.Bne_Un, noReturn);
                cg.EmitContinue();
                cg.MarkLabel(noReturn);
            }
        }
Exemplo n.º 31
0
 public override Slot CreateSlot(Slot instance)
 {
     return _slot;
 }
Exemplo n.º 32
0
 public ParamArraySlot(Slot paramArray, int paramIndex)
 {
     _param = paramArray;
     _index = paramIndex;
 }