public void PopValue(CilProgram program, CilType cilType, out IValue val) { Pop(out var stackVal); var valType = cilType.GetValueType(program); val = ConvertToValue(stackVal, valType); }
public override IValue CreateDefaultValue(CilProgram program) { if (program.IsExternalType(ClassName)) { var type = ReflectionHelper.GetExternalType(ClassName); var getDefault = GetType().GetMethod(nameof(GetDefaultGeneric), BindingFlags.NonPublic | BindingFlags.Static).MakeGenericMethod(type); var defaultValue = getDefault.Invoke(null, null); return(new CilValueExternal(defaultValue)); } var @class = program.AllClasses.Single(c => c.Name.ToString() == ClassName.ToString()); if (@class.IsInterface) { return(new CilValueNull()); } if (IsValueType(program)) { var emptyInstance = new CilClassInstance(@class, program, null); return(new CilValueValueType(emptyInstance)); } return(new CilValueNull()); }
public override Type GetRuntimeType(CilProgram program) { var lengths = Enumerable.Repeat(0, Dimensions).ToArray(); var fakeArray = Array.CreateInstance(ElementType.GetRuntimeType(program), lengths); var result = fakeArray.GetType(); return(result); }
public object AsRuntime(CilType cilType, CilManagedMemory managedMemory, CilProgram program) { if (cilType is CilTypeUInt32) { return(Value); } throw new System.NotImplementedException(); }
public static Type GetExternalType(CilTypeSpec typeSpec, CilProgram program) { if (typeSpec.ClassName != null) { return(GetExternalType(typeSpec.ClassName)); } return(typeSpec.Type.GetRuntimeType(program)); }
public override Type GetValueType(CilProgram program) { if (program.IsExternalType(ClassName)) { return(typeof(CilValueExternal)); } return(typeof(CilValueValueType)); }
public override Type GetRuntimeType(CilProgram program) { if (program.IsExternalType(ClassName)) { return(ReflectionHelper.GetExternalType(ClassName)); } throw new NotImplementedException(); }
public override Type GetValueType(CilProgram program) { if (IsValueType(program)) { return(typeof(CilValueValueType)); } return(typeof(CilValueReference)); }
public CilArray(CilType type, int numElems, CilProgram program) { _array = new IValue[numElems]; for (int i = 0; i < numElems; i++) { _array[i] = type.CreateDefaultValue(program); } _type = type; }
public CilOrderedDictionary(List <CilSigArg> localsSigArgs, CilProgram program) { _dict = new OrderedDictionary(localsSigArgs.Count); _typesDict = new OrderedDictionary(localsSigArgs.Count); foreach (var sigArg in localsSigArgs) { _dict.Add(sigArg.Id, sigArg.Type.CreateDefaultValue(program)); _typesDict.Add(sigArg.Id, sigArg.Type); } }
public CilClassStaticInstance(CilClass @class, CilProgram program) { _class = @class; StaticFields = new Dictionary <string, IValue>(); foreach (var field in @class.Fields.Where(f => f.IsStatic)) { var initValue = field.InitValue ?? field.Type.CreateDefaultValue(program); StaticFields.Add(field.Name, initValue); } }
public override IValue Unbox(CilObject obj, CilManagedMemory managedMemory, CilProgram program) { if (obj is CilObjectExternal objExternal) { if (objExternal.ExternalObject.GetType().IsEnum) { var result = Convert.ToInt32(objExternal.ExternalObject); return(new CilValueInt32(result)); } } throw new NotImplementedException(); }
public CilClassInstance(CilClass @class, CilProgram program, CilManagedMemory managedMemory) { Class = @class; Fields = new Dictionary <string, IValue>(); foreach (var field in @class.Fields.Where(f => !f.IsStatic)) { Fields.Add(field.Name, field.Type.CreateDefaultValue(program)); } var runtimeType = program.IsValueType(@class.Name) ? Class.BuildRuntimeType(program, managedMemory) : Class.BuildRuntimeProxy(program); _externalInstance = FormatterServices.GetUninitializedObject(runtimeType); }
public override IValue CreateDefaultValue(CilProgram program) { if (program.IsExternalType(ClassName)) { var type = ReflectionHelper.GetExternalType(ClassName); var getDefault = GetType().GetMethod(nameof(GetDefaultGeneric), BindingFlags.NonPublic | BindingFlags.Static).MakeGenericMethod(type); var defaultValue = getDefault.Invoke(null, null); return(new CilValueExternal(defaultValue)); } var classType = new CilTypeClass(ClassName); return(classType.CreateDefaultValue(program)); }
public bool IsInstanceOf(CilTypeSpec typeSpec, CilProgram program) { var cilType = typeSpec.GetCilType(program); if (cilType is CilTypeClass cilTypeClass) { if (cilTypeClass.ClassName.ToString() == this.Class.Name.ToString()) { return(true); } throw new System.NotImplementedException(); } else { throw new System.NotImplementedException(); } }
public CilInterpreterInstructionsVisitor(CilProgram program) { var state = new CilControlState(program); var managedMemory = new CilDictionaryManagedMemory(); _executionState = new CilExecutionState(state, managedMemory); _instructionNoneVisitor = new InstructionNoneInterpreterVisitor(program, _executionState); _instructionMethodVisitor = new InstructionMethodInterpreterVisitor(program, _executionState); _instructionStringVisitor = new InstructionStringInterpreterVisitor(program, _executionState); _instructionIVisitor = new InstructionIInterpreterVisitor(program, _executionState); _instructionTypeVisitor = new InstructionTypeInterpreterVisitor(program, _executionState); _instructionVarVisitor = new InstructionVarInterpreterVisitor(program, _executionState); _instructionRVisitor = new InstructionRInterpreterVisitor(program, _executionState); _instructionBrVisitor = new InstructionBrInterpreterVisitor(program, _executionState); _instructionFieldVisitor = new InstructionFieldInterpreterVisitor(program, _executionState); _instructionI8InterpreterVisitor = new InstructionI8InterpreterVisitor(program, _executionState); _instructionSwitchInterpreterVisitor = new InstructionSwitchInterpreterVisitor(program, _executionState); _instructionTokInterpreterVisitor = new InstructionTokInterpreterVisitor(program, _executionState); }
private bool CheckSupported(CilProgram program) { foreach (var method in program.AllMethods) { foreach (var instruction in method.Instructions) { if (!instruction.IsSupported) { throw new InstructionNotSupportedException(instruction); } } } if (program.Datas.Count > 0) { throw new FeatureNotSupportedException(".data"); } return(true); }
public CilControlState(CilProgram program) { CallStack = new Stack <CilMethodState>(); CallStack.Push(new CilMethodState(program.EntryPoint, new List <CilSigArg>(), new List <IValue>(), program)); var cctors = program.Classes .Select(c => c.Methods.FirstOrDefault(m => m.Name == ".cctor")) .Where(m => m != null) .ToList(); foreach (var cctor in cctors) { CallStack.Push(new CilMethodState(cctor, new List <CilSigArg>(), new List <IValue>(), program)); } StaticInstances = new Dictionary <string, CilClassStaticInstance>(); foreach (var @class in program.Classes) { StaticInstances.Add(@class.Name.ToString(), new CilClassStaticInstance(@class, program)); } }
public object AsRuntime(CilType cilType, CilManagedMemory managedMemory, CilProgram program) { if (cilType is CilTypeChar) { return((char)Value); } if (cilType is CilTypeInt16) { return(Value); } if (cilType is CilTypeUInt16) { return((ushort)Value); } if (cilType is CilTypeValueType) { return(Value); } throw new System.NotImplementedException(); }
public CilParserResult Parse(string sourceCode) { var ironyParseTree = _ironyParser.Parse(sourceCode); if (ironyParseTree.Status == ParseTreeStatus.Error) { return(new CilParserResult { Status = CilParserStatus.ParsingError, Errors = ironyParseTree.ParserMessages.Select(pm => BuildIronyParserMessage(pm)).ToList() }); } var decls = (ironyParseTree.Root.AstNode as DeclsAstNode).Decls; var cilProgram = new CilProgram(decls); return(new CilParserResult { Status = CilParserStatus.Success, Program = cilProgram }); }
public override object AsRuntime(CilType type, CilManagedMemory managedMemory, CilProgram program) { if (type is CilTypeObject) { return(ExternalObject); } if (type.GetRuntimeType(program).IsAssignableFrom(ExternalObject.GetType())) { return(ExternalObject); } throw new NotImplementedException(); }
public object AsRuntime(CilType cilType, CilManagedMemory managedMemory, CilProgram program) { throw new NotImplementedException(); }
public InstructionMethodInterpreterVisitor(CilProgram program, CilExecutionState executionState) { _executionState = executionState; _program = program; }
public override IValue Unbox(CilObject obj, CilManagedMemory managedMemory, CilProgram program) { throw new NotImplementedException(); }
public override IValue CreateDefaultValue(CilProgram program) { return(new CilValueInt8(default(sbyte))); }
public override IValue CreateValueFromRuntime(object obj, CilManagedMemory managedMemory, CilProgram program) { var value = new CilValueInt8((sbyte)obj); return(value); }
public override Type GetValueType(CilProgram program) { return(typeof(CilValueInt8)); }
public override Type GetRuntimeType(CilProgram program) { return(typeof(sbyte)); }
public override bool IsValueType(CilProgram program) { throw new NotImplementedException(); }
public void Interpret(CilProgram program) { var interpreter = new CilInterpreter(program); interpreter.Interpret(); }