protected internal virtual void EmitBranch(CodeGen g, OptionalLabel labelTrue, OptionalLabel labelFalse) { if (g == null) throw new ArgumentNullException(nameof(g)); OperandExtensions.SetLeakedState(this, false); EmitGet(g); if (labelTrue != null && labelTrue.IsLabelExist) { g.IL.Emit(BranchSet.Normal.BrTrue, labelTrue.Value); if (labelFalse != null && labelFalse.IsLabelExist) { g.IL.Emit(OpCodes.Br, labelFalse.Value); } } else if (labelFalse != null && labelFalse.IsLabelExist) { g.IL.Emit(BranchSet.Normal.BrFalse, labelFalse.Value); } else { throw new InvalidOperationException("No labels passed"); } }
public void EmitRef(CodeGen g) { if (Type.IsValueType) EmitAddressOf(g); else EmitGet(g); }
internal virtual void EmitBranch(CodeGen g, BranchSet branchSet, Label label) { if (g == null) throw new ArgumentNullException("g"); if (branchSet == null) throw new ArgumentNullException("branchSet"); EmitGet(g); g.IL.Emit(branchSet.brTrue, label); }
public void Generate(ParseTree parseTree) { if (parseTree == null) return; GeneratedOK = true; defaultClass = ag.Public.Class("Default"); typeTable.Add("Default", defaultClass); mainMethod = defaultClass.Public.Static.Method(typeof(void), "Main"); //generator stack typeStack.Push(defaultClass); funcStack.Push(mainMethod); //InitIO(); InitRequiredType(); PushScope(); var ioOperand = mainMethod.Local(exp.New(typeTable["IO"])); ParseNode(parseTree.Root); if (GeneratedOK) { ag.Save(); AppDomain.CurrentDomain.ExecuteAssembly(name + ".exe"); } }
public void EmitArgs(CodeGen g, Operand[] args) { if (args.Length != appliedSignature.Length) throw new InvalidOperationException(); if (IsExpanded) { int fixedCount = methodSignature.Length - 1; Type expType = methodSignature[fixedCount].GetElementType(); for (int i = 0; i < fixedCount; i++) EmitArg(g, i, args[i]); int arrayLen = args.Length - methodSignature.Length - 1; g.EmitI4Helper(arrayLen); g.IL.Emit(OpCodes.Newarr, expType); OpCode stelemCode = CodeGen.GetStelemOpCode(expType); for (int i = 0; i < arrayLen; i++) { g.IL.Emit(OpCodes.Dup); g.EmitI4Helper(i); if (stelemCode == OpCodes.Stobj) g.IL.Emit(OpCodes.Ldelema, expType); EmitArg(g, fixedCount + i, args[fixedCount + i]); if (stelemCode == OpCodes.Stobj) g.IL.Emit(OpCodes.Stobj, expType); else g.IL.Emit(stelemCode); } } else { for (int i = 0; i < args.Length; i++) EmitArg(g, i, args[i]); } }
protected void EmitGetHelper(CodeGen g, Operand op, Type desiredType, bool allowExplicitConversion) { g.EmitGetHelper(op, desiredType,allowExplicitConversion); }
protected internal virtual void EmitAddressOf(CodeGen g) { throw new InvalidOperationException(string.Format(null, Properties.Messages.ErrOperandNotReferencible, GetType())); }
internal override void EmitAddressOf(CodeGen g) { CheckScope(g); if (var == null) { RequireType(); var = g.il.DeclareLocal(t); } g.il.Emit(OpCodes.Ldloca, var); }
protected internal override void EmitBranch(CodeGen g, OptionalLabel labelTrue, OptionalLabel labelFalse) { OperandExtensions.SetLeakedState(this, false); _operand.EmitBranch(g, labelTrue, labelFalse); }
public abstract void Emit(CodeGen g, Type from, Type to);
internal override void EmitGet(CodeGen g) { CheckScope(g); if (var == null) throw new InvalidOperationException(Properties.Messages.ErrUninitializedVarAccess); g.il.Emit(OpCodes.Ldloc, var); }
public override void Emit(CodeGen g, Operator op) { g.IL.Emit(OpCodes.Call, method); }
public override void Emit(CodeGen g, Type from, Type to) { var l = g.LocalInitedFromStack(from); Type toUnderlying = Helpers.GetNullableUnderlyingType(to); Type fromUnderlying = Helpers.GetNullableUnderlyingType(from); var cond = new Conditional( l.Property("HasValue"), new NewObject( g.TypeMapper.TypeInfo.FindConstructor(to, new Operand[] { new FakeTypedOperand(toUnderlying), }), new Operand[] { new ConversationWrapper(_internalConversation, l.Property("Value"), fromUnderlying, toUnderlying) }), new DefaultValue(to)); //GetImplicit(l.Property("Value"), toUnderlying, false, g.TypeMapper), l, from, toUnderlying cond.EmitGet(g); }
internal override void EmitAddressOf(CodeGen g) { _op.EmitAddressOf(g); }
public override void Emit(CodeGen g, Operator op) { g.IL.Emit(OpCodes.Call, miRemove); g.IL.Emit(OpCodes.Castclass, ReturnType); }
internal virtual void EmitGet(CodeGen g) { throw new InvalidOperationException(string.Format(null, Messages.ErrOperandNotReadable, GetType())); }
public override void Emit(CodeGen g, Type from, Type to) { _before.Emit(g, from, _fromType); g.IL.Emit(OpCodes.Call, (MethodInfo)_method.Member); _after.Emit(g, _toType, to); }
public override void Emit(CodeGen g, Type from, Type to) { g.IL.Emit(OpCodes.Box, from); }
public override void Emit(CodeGen g, Operator op) { base.Emit(g, op); }
public override void Emit(CodeGen g, Type from, Type to) { throw new AmbiguousMatchException(string.Format(null, Messages.ErrAmbiguousConversion, from.FullName, to.FullName)); }
protected void EmitGetHelper(CodeGen g, Operand op, Type desiredType, bool allowExplicitConversion) { g.EmitGetHelper(op, desiredType, allowExplicitConversion); }
public override void Emit(CodeGen g, Type from, Type to) { g.IL.Emit(OpCodes.Castclass, to); }
public void _ManualEmitGet(CodeGen g) => EmitGet(g);
public override void Emit(CodeGen g, Type from, Type to) { g.EmitConvHelper(Type.GetTypeCode(to)); }
protected internal virtual void EmitSet(CodeGen g, Operand value, bool allowExplicitConversion) { throw new InvalidOperationException(string.Format(null, Properties.Messages.ErrOperandNotWritable, GetType())); }
internal override void EmitSet(CodeGen g, Operand value, bool allowExplicitConversion) { CheckScope(g); if (t == null) t = value.Type; if (var == null) var = g.il.DeclareLocal(t); g.EmitGetHelper(value, t, allowExplicitConversion); g.il.Emit(OpCodes.Stloc, var); }
protected internal override void EmitSet(CodeGen g, Operand value, bool allowExplicitConversion) { OperandExtensions.SetLeakedState(this, false); OperandExtensions.SetLeakedState(this, false); _operand.EmitSet(g, value, allowExplicitConversion); }
protected internal override void EmitAddressOf(CodeGen g) { OperandExtensions.SetLeakedState(this, false); _op.EmitAddressOf(g); }
protected internal void EmitRef(CodeGen g) { OperandExtensions.SetLeakedState(this, false); if (GetReturnType(g.TypeMapper).IsValueType) EmitAddressOf(g); else EmitGet(g); }
protected ILGenerator GetILGenerator(CodeGen g) { return(g.IL); }
public override void Emit(CodeGen g, Type from, Type to) { g.IL.Emit( OpCodes.Call, g.TypeMapper.MapType(typeof(Nullable<>)).MakeGenericType(Helpers.GetNullableUnderlyingType(from)) .GetProperty(nameof(Nullable<int>.Value)).GetGetMethod()); }
protected ILGenerator GetILGenerator(CodeGen g) { return g.IL; }
public override void Emit(CodeGen g, Type from, Type to) { throw new InvalidCastException(string.Format(null, Messages.ErrInvalidConversion, from == null ? "<null>" : from.FullName, to.FullName)); }
public override void Emit(CodeGen g, Type from, Type to) { _fromConv?.Emit(g, from, Helpers.GetNullableUnderlyingType(to)); g.IL.Emit( OpCodes.Newobj, to.GetConstructor(new[] { from })); }
public override void Emit(CodeGen g, Type from, Type to) { throw new AmbiguousMatchException(string.Format(null, Properties.Messages.ErrAmbiguousConversion, from.FullName, to.FullName)); }
public override void Emit(CodeGen g, Type from, Type to) { g.IL.Emit(OpCodes.Unbox_Any, to); }
public override void Emit(CodeGen g, Type from, Type to) { throw new InvalidCastException(string.Format(null, Properties.Messages.ErrInvalidConversion, from == null ? "<null>" : from.FullName, to.FullName)); }
public _Local(CodeGen owner, LocalBuilder var) { this.owner = owner; this.var = var; this.t = var.LocalType; }
void CheckScope(CodeGen g) { if (g != owner) throw new InvalidOperationException(Properties.Messages.ErrInvalidVariableContext); if (scope != null && !owner.blocks.Contains(scope)) throw new InvalidOperationException(Properties.Messages.ErrInvalidVariableScope); }
public override void Emit(CodeGen g, Type from, Type to) { }