Beispiel #1
0
        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);
 }
Beispiel #3
0
        public DbgDotNetValue GetDotNetValue(ILValue value)
        {
            var dnValue = TryGetDotNetValue(value, canCreateValues: true);

            if (dnValue != null)
            {
                return(dnValue);
            }
            throw new InvalidOperationException();            //TODO:
        }
Beispiel #4
0
        DbgDotNetValue IDebuggerRuntime.ToDotNetValue(ILValue value)
        {
            var dnValue = TryGetDotNetValue(value, canCreateValues: false);

            if (dnValue != null)
            {
                return(dnValue);
            }
            throw new InterpreterMessageException(PredefinedEvaluationErrorMessages.InternalDebuggerError);
        }
Beispiel #5
0
        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:
        }
Beispiel #6
0
        public override bool CopyObject(DmdType type, ILValue source)
        {
            var sourceAddr = source as AddressILValue;

            if (sourceAddr == null)
            {
                return(false);
            }
            WriteValue(sourceAddr.ReadValueImpl());
            return(true);
        }
Beispiel #7
0
        static bool GetValue(ILValue value, out double result)
        {
            if (value is ConstantFloatILValue f)
            {
                result = f.Value;
                return(true);
            }

            result = 0;
            return(false);
        }
Beispiel #8
0
 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);
 }
Beispiel #9
0
        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");
        }
Beispiel #10
0
        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 []");
        }
Beispiel #11
0
        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);
        }
Beispiel #12
0
 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 + "\"";
         }
     }
 }
Beispiel #13
0
 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 + "\"";
         }
     }
 }
Beispiel #14
0
 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] + "\"";
         }
     }
 }
Beispiel #15
0
        public override ILStatement Compile(CMinorEnvironment environment)
        {
            ILValue dst = ResolveDestination(environment);

            return(new ILAssign(
                       dst,
                       dst.GetILBinaryOperatorInvokation(
                           GetCMinorBinaryOperator().GetBinaryOperatorType(),
                           GetAssignmentExpression().CompileAsValue(environment)
                           )
                       ));
        }
Beispiel #16
0
        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)));
        }
Beispiel #17
0
        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);
            }
        }
Beispiel #18
0
 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)
                    )
                ));
 }
Beispiel #19
0
        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());
            }
        }
Beispiel #20
0
        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);
        }
Beispiel #21
0
        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;
            }));
        }
Beispiel #22
0
        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));
        }
Beispiel #23
0
		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();
		}
Beispiel #24
0
            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));
            }
Beispiel #25
0
            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));
            }
Beispiel #26
0
        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;
        }
Beispiel #27
0
            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);
            }
Beispiel #28
0
 // 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;
         }
     }
 }
Beispiel #29
0
 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);
 }
Beispiel #30
0
        public Input(string prompt, ILValue lValue)
        {
            if (prompt == null)
            {
                throw new ArgumentNullException("prompt");
            }

            if (lValue == null)
            {
                throw new ArgumentNullException("lValue");
            }

            Prompt = prompt;
            LValue = lValue;
        }
Beispiel #31
0
 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;
 }
Beispiel #32
0
 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);
     }
 }
Beispiel #33
0
 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;
 }
Beispiel #34
0
 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");
 }