public ModuleGlobalSlot(Slot builtinWrapper) { Debug.Assert(builtinWrapper.Type == typeof(ModuleGlobalWrapper)); if (builtinWrapper.Type != typeof(ModuleGlobalWrapper)) throw new ArgumentException("builtinWrapper " + builtinWrapper.GetType().FullName); _wrapper = builtinWrapper; }
public PropertySlot(Slot instance, PropertyInfo property) { Debug.Assert(property != null); this._instance = instance; this._property = property; }
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; }
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; }
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; }
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; }
/// <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(); }
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 CatchRecord(Slot slot, CatchBlock block) { _slot = slot; _block = block; }
internal GlobalFieldStorage(Slot slot) { _slot = slot; }
// 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); }
public IndexSlot(Slot instance, int index) : this(instance, index, typeof(object)) { }
public override void EmitSet(CodeGen cg, Slot val) { _storage.EmitSet(cg, val); }
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; }
public override void EmitSet(CodeGen cg, Slot val) { _wrapper.EmitGet(cg); val.EmitGet(cg); cg.EmitPropertySet(typeof(ModuleGlobalWrapper), "CurrentValue"); }
public FieldSlotFactory(TypeGen typeGen, Slot instance) { this._typeGen = typeGen; this._instance = instance; }
public void AddClosureAccessSlot(CodeBlock block, Slot slot) { AddAccessSlot(block, ref _closureAccess, slot); }
public void AddGeneratorTemp(Slot slot) { if (_generatorTemps == null) { _generatorTemps = new List<Slot>(); } _generatorTemps.Add(slot); }
public EnvironmentSlot(Slot storage) { _storage = storage; }
public void AddScopeAccessSlot(CodeBlock block, Slot slot) { AddAccessSlot(block, ref _scopeAccess, slot); }
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); }
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; }
public IndexSlot(Slot instance, int index, Type type) { this._instance = instance; this._index = index; this._type = type; }
public void CreateSlot(CodeGen cg) { _slot = _variable.CreateSlot(cg); }
public ParamArraySlot(Slot paramArray, int paramIndex) { _param = paramArray; _index = paramIndex; }
public override Slot CreateSlot(Slot instance) { Debug.Assert(typeof(CodeContext).IsAssignableFrom(instance.Type), "wrong instance type"); return new NamedFrameSlot(instance, _name); }
/// <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); } }
public override Slot CreateSlot(Slot instance) { return _slot; }