public Input(ILValue lValue) { if (lValue == null) { throw new ArgumentNullException(nameof(lValue)); } Prompt = null; LValue = lValue; }
public bool StoreField(DmdFieldInfo field, ILValue value) { InitFields(field.ReflectedType); if (!AllFields.ContainsKey(field)) { return(false); } AllFields[field] = value; return(true); }
public DbgDotNetValue GetDotNetValue(ILValue value) { var dnValue = TryGetDotNetValue(value, canCreateValues: true); if (dnValue != null) { return(dnValue); } throw new InvalidOperationException(); //TODO: }
DbgDotNetValue IDebuggerRuntime.ToDotNetValue(ILValue value) { var dnValue = TryGetDotNetValue(value, canCreateValues: false); if (dnValue != null) { return(dnValue); } throw new InterpreterMessageException(PredefinedEvaluationErrorMessages.InternalDebuggerError); }
public override DbgDotNetValue GetDotNetValue(ILValue value, DmdType targetType = null) { targetType = targetType ?? value.Type; var dnValue = TryGetDotNetValue(value, value.IsNull ? targetType : value.Type, canCreateValue: true); if (dnValue != null) { return(dnValue); } throw new InvalidOperationException(); //TODO: }
public override bool CopyObject(DmdType type, ILValue source) { var sourceAddr = source as AddressILValue; if (sourceAddr == null) { return(false); } WriteValue(sourceAddr.ReadValueImpl()); return(true); }
static bool GetValue(ILValue value, out double result) { if (value is ConstantFloatILValue f) { result = f.Value; return(true); } result = 0; return(false); }
public override ILValue Box(ILValue value, DmdType type) { if (type.IsValueType) { var dnValue = TryGetDotNetValue(value, type, canCreateValue: true) ?? throw new InvalidOperationException(); var boxedValue = dnValue.Box(evalInfo) ?? runtime.Box(evalInfo, dnValue); RecordValue(boxedValue); return(new BoxedValueTypeILValue(this, value, boxedValue.Value, type)); } return(value); }
public virtual ILValue ResolveIdentifierAsGenericInvokation(ILValue context, string id, IEnumerable <Type> generic_arguments, IEnumerable <ILValue> arguments) { string display = id + "<" + generic_arguments.ToString(", ") + ">(" + arguments.GetValueTypes().ToString(", ") + ")"; if (context != null) { return(context.GetILGenericInvoke(id, generic_arguments, arguments) .AssertNotNull(() => new CMinorCompileException("Unable to resolve " + display + " as a generic invokation of " + context.GetValueType()))); } throw new CMinorCompileException("Unable to resolve " + display + " as a generic invokation"); }
public virtual ILValue ResolveIdentifierAsIndexed(ILValue context, string id, ILValue index) { if (context != null) { return(context.GetILProp(id) .AssertNotNull(() => new CMinorCompileException("Unable to resolve " + id + " of " + context.GetValueType() + " for indexing")) .GetILIndexed(index) .AssertNotNull(() => new CMinorCompileException("Unable to resolve indexing of " + context.GetValueType()))); } throw new CMinorCompileException("Unable to resolve []"); }
static bool intConstant(ILExpression c, int index, out ILValue value) { ILValue v; if (c.Arguments.ElementAtOrDefault(index).Match(GMCode.Constant, out v) && v.IntValue != null) { value = v; return(true); } value = default(ILValue); return(false); }
static void scriptArgument(ILExpression expr) { if (expr.Code == GMCode.Constant) { ILValue arg = expr.Operand as ILValue; int instance; if (arg.TryParse(out instance) && (instance > 0 && instance < cr.scriptIndex.Count)) { arg.ValueText = "\"" + cr.scriptIndex[instance].script_name + "\""; } } }
static void fontArgument(ILExpression expr) { if (expr.Code == GMCode.Constant) { ILValue arg = expr.Operand as ILValue; int instance; if (arg.TryParse(out instance) && (instance > 0 && instance < cr.resFonts.Count)) { arg.ValueText = "\"" + cr.resFonts[instance].Name + "\""; } } }
static void instanceArgument(ILExpression expr) { if (expr.Code == GMCode.Constant) { ILValue arg = expr.Operand as ILValue; int instance; if (arg.TryParse(out instance) && (instance > 0 && instance < InstanceList.Count)) { arg.ValueText = "\"" + InstanceList[instance] + "\""; } } }
public override ILStatement Compile(CMinorEnvironment environment) { ILValue dst = ResolveDestination(environment); return(new ILAssign( dst, dst.GetILBinaryOperatorInvokation( GetCMinorBinaryOperator().GetBinaryOperatorType(), GetAssignmentExpression().CompileAsValue(environment) ) )); }
static public ILValue GetILConvertEX(this ILValue item, Type type) { if (item.GetValueType().CanBeTreatedAs(type)) { return(item); } return(item.GetValueType() .GetConversionInvoker(type) .GetILDelegateInvokation(item) .Coalesce(() => item.GetILExplicitCast(type))); }
void ResolveVariable(ILExpression expr, ILExpression instance = null, ILExpression index = null) { Debug.Assert(expr != null); UnresolvedVar uv = expr.Operand as UnresolvedVar; Debug.Assert(uv != null); ILVariable v = null; if (uv.Extra != 0) { Debug.Assert(instance == null); instance = new ILExpression(GMCode.Constant, new ILValue(uv.Extra)); // create a fake instance value } instance = instance.MatchSingleArgument(); if (instance.Code == GMCode.Constant) { ILValue value = instance.Operand as ILValue; v = ILVariable.CreateVariable(uv.Name, (int)value, this.locals); } else if (instance.Code == GMCode.Var) { v = ILVariable.CreateVariable(uv.Name, 0, this.locals); (instance.Operand as ILVariable).Type = GM_Type.Instance; // make sure its an instance } else { throw new Exception("humm"); } if (uv.Operand >= 0) { Debug.Assert(index != null); index = index.MatchSingleArgument(); if (index.Code == GMCode.Var) { ILVariable ivar = index.Operand as ILVariable; // indexs can only be ints, but they can be negitive? ivar.Type = GM_Type.Int; } } else { index = null; } Debug.Assert(v != null); expr.Code = GMCode.Var; expr.Operand = v; expr.Arguments.Clear(); expr.Arguments.Add(instance); if (index != null) { expr.Arguments.Add(index); } }
static private ILStatement GenerateInspectedObjectWrite_Nullable(ILValue value, ILValue buffer) { return(new ILIf( value.GetILIsNotNull(), new ILBlock( buffer.GetILInvoke("WriteBoolean", true), TypeSerializer.GetTypeSerializer(value.GetValueType()).GenerateWrite(value, buffer) ), new ILBlock( buffer.GetILInvoke("WriteBoolean", false) ) )); }
public void CompilePushToSystemObject(ILValue obj, TyonCompiler compiler) { Variable variable; if (compiler.TryGetDesignatedVariable(obj.GetValueType(), GetId(), out variable)) { compiler.AddStatement(variable.CompileSetContents(obj, GetTyonValue().CompileValue(compiler))); } else { compiler.LogMissingField(obj.GetValueType(), GetId()); } }
public ILLocal DefineLocal(TyonObject obj, ILValue value) { ILLocal local = block.CreateCementedLocal(value); object_to_local.Add(obj, local); if (obj.GetTyonAddress() != null) { internal_address_to_local.Add(obj.GetTyonAddress(), local); } return(local); }
public Operation <object, TyonContext> CompileInstanceSystemObject(TyonObject tyon_object) { return(this.GetType().CreateDynamicMethodDelegate <Operation <object, TyonContext> >(delegate(ILValue c) { block = new ILBlock(); context = c; tyon_object.CompileInitialize(this); ILLocal local = tyon_object.CompileLocal(this); block.AddStatement(new ILReturn(local)); return block; })); }
public override ILValue ResolveIdentifierAsValue(ILValue context, string id) { if (context == null) { ILValue value; if (parameters.TryGetValue(id, out value)) { return(value); } } return(base.ResolveIdentifierAsValue(context, id)); }
internal int ToInt32(ILValue value) { if (value is ConstantInt32ILValue i32Value) return i32Value.Value; var dnValue = TryGetDotNetValue(value, canCreateValues: false); if (dnValue != null) { if (dnValue.Type != dnValue.Type.AppDomain.System_Int32) throw new InvalidOperationException(); var rawValue = dnValue.GetRawValue(); if (rawValue.ValueType == DbgSimpleValueType.Int32) return (int)rawValue.RawValue; throw new InvalidOperationException(); } throw new InvalidOperationException(); }
static public ILStatement GenerateInspectedObjectWrite(ILValue src, ILValue buffer) { if (src.GetValueType().HasChildTypes()) { return(GenerateInspectedObjectWrite_Polymorphic(src, buffer)); } if (src.GetValueType().IsNullable()) { return(GenerateInspectedObjectWrite_Nullable(src, buffer)); } return(TypeSerializer.GetTypeSerializer(src.GetValueType()).GenerateWrite(src, buffer)); }
static public ILValue GenerateInspectedObjectRead(Type type, ILValue buffer) { if (type.HasChildTypes()) { return(GenerateInspectedObjectRead_Polymorphic(type, buffer)); } if (type.IsNullable()) { return(GenerateInspectedObjectRead_Nullable(type, buffer)); } return(TypeSerializer.GetTypeSerializer(type).GenerateRead(buffer)); }
public Let(ILValue left, IExpression right) { if (left == null) { throw new ArgumentNullException(nameof(left)); } if (right == null) { throw new ArgumentNullException(nameof(right)); } Left = left; Right = right; }
static private ILStatement GenerateInspectedObjectWrite_Polymorphic(ILValue value, ILValue buffer) { ILBlock block = new ILBlock(); ILLocal type = block.CreateCementedLocal(value.GetILTypeEX()); block.AddStatement(buffer.GetILInvoke("WriteType", type)); block.AddStatement( new ILIf( type.GetILIsNotNull(), typeof(TypeSerializer).GetILInvoke("WriteObject", value) ) ); return(block); }
// This just makes color look easyer to read static void colorArgument(ILExpression expr) { if (expr.Code == GMCode.Constant) { ILValue arg = expr.Operand as ILValue; int color; if (arg.TryParse(out color)) { byte red = (byte)(color & 0xFF); byte green = (byte)(color >> 8 & 0xFF); byte blue = (byte)(color >> 16 & 0xFF); arg.ValueText = "Red=" + red + " ,Green=" + green + " ,Blue=" + blue; } } }
public override ILValue Box(ILValue value, DmdType type) { if (type.IsValueType) { var dnValue = TryGetDotNetValue(value, type, canCreateValues: true) ?? throw new InvalidOperationException(); var boxedValue = dnValue.Box(context, frame, cancellationToken); if (boxedValue == null) { return(new BoxedValueTypeILValue(this, value, dnValue, type)); } RecordValue(boxedValue); return(new BoxedValueTypeILValue(this, value, boxedValue, type)); } return(value); }
public Input(string prompt, ILValue lValue) { if (prompt == null) { throw new ArgumentNullException("prompt"); } if (lValue == null) { throw new ArgumentNullException("lValue"); } Prompt = prompt; LValue = lValue; }
protected ILExpression CreatePushExpression(GMCode code, GM_Type[] types) { ILExpression e = new ILExpression(code, null); e.Types = types; e.Extra = (int)(CurrentRaw & 0xFFFF); Debug.Assert(e.ILRanges.Count == 0); e.AddILRange(CurrentPC); ILValue v = null; switch (types[0]) { case GM_Type.Var: e.Operand = BuildUnresolvedVar(r.ReadInt32()); break; case GM_Type.Short: { v = new ILValue((short)(CurrentRaw & 0xFFFF)); v.DataOffset = (int)(r.BaseStream.Position - 4); e.Arguments.Add(new ILExpression(GMCode.Constant, v)); } break; default: v = ReadConstant(r, types[0]); e.Arguments.Add(new ILExpression(GMCode.Constant, v)); break; } if (v != null) { v.DataOffset += StartingOffset ; DebugILValueOffset(v); } return e; }
void DebugILValueOffset(ILValue v) { Debug.Assert(v.DataOffset != null); int offset = (int) v.DataOffset; BinaryReader r = new BinaryReader(File.DataWinStream); r.BaseStream.Position = offset; if(v.Type != GM_Type.Short) { ILValue test = ReadConstant(r, v.Type); Debug.Assert(test.ToString() == v.ToString()); } else { uint raw = r.ReadUInt32(); short test = (short) (raw & 0xFFFF); Debug.Assert(test == v.IntValue); } }
static protected ILValue ReadConstant(BinaryReader r, GM_Type t) { ILValue v = null; int offset = (int)r.BaseStream.Position; switch (t) { case GM_Type.Double: v= new ILValue(r.ReadDouble()); break; case GM_Type.Float: v= new ILValue(r.ReadSingle()); break; case GM_Type.Int: v= new ILValue(r.ReadInt32()); break;// function? case GM_Type.Long: v= new ILValue(r.ReadInt64()); break;// function? case GM_Type.Bool: v= new ILValue(r.ReadInt32() != 0); break; case GM_Type.String: { int i = r.ReadInt32(); if (i < 0 || i >= File.Strings.Count) v= new ILValue("$BADSTRINGVALUE$"); else v= new ILValue(File.Strings[i].String); } break; default: throw new Exception("Should not get here"); } v.DataOffset = offset; return v; }
static public string InstanceToString(ILValue value) { if (value.Type == GM_Type.Short || value.Type == GM_Type.Int) { return InstanceToString((int)value); } throw new ArgumentException("Bad ILValue type","value"); }