public override CilValueReference Store(CilObject obj) { var address = _nextAddress; _dictionary[address] = obj; _nextAddress++; return(new CilValueReference(address)); }
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 override void VisitBoxInstruction(BoxInstruction instruction) { var cilType = instruction.TypeSpec.GetCilType(_program); ControlState.EvaluationStack.PopValue(_program, cilType, out var val); CilObject obj = null; if (cilType.IsValueType(_program) && !cilType.IsNullable) { obj = val.Box(); } var objRef = ManagedMemory.Store(obj); ControlState.EvaluationStack.PushValue(objRef); ControlState.MoveToNextInstruction(); }
public override void VisitCallVirtualInstruction(CallVirtualInstruction instruction) { if (!instruction.CallConv.IsInstance) { throw new System.NotImplementedException(); } var methodArgs = PopMethodArgs(instruction); ControlState.EvaluationStack.PopValue(_program, instruction.TypeSpec.GetCilType(_program), out var thisVal); var callExternal = true; CilClassInstance thisClassInstance = null; CilObject thisObject = null; if (thisVal is CilValueReference thisValRef) { var thisObj = ManagedMemory.Load(thisValRef); if (thisObj is CilClassInstance) { thisClassInstance = thisObj as CilClassInstance; } else { thisObject = thisObj; callExternal = true; } } else { throw new System.NotImplementedException(); } CilMethod method = null; if (thisClassInstance != null) { var currentClass = thisClassInstance.Class; while (true) { var possibleMethod = currentClass.Methods.SingleOrDefault(m => m.Name == instruction.MethodName && AreArgumentsAssignable(instruction.SigArgs, m.Arguments)); if (possibleMethod != null) { method = possibleMethod; callExternal = false; break; } currentClass = currentClass.Extends; if (currentClass == null) { callExternal = true; break; } } } if (callExternal) { var result = CallExternalMethod(instruction, thisVal, methodArgs.ToArray(), null); if (!(instruction.ReturnType is CilTypeVoid)) { var resultVal = instruction.ReturnType.CreateValueFromRuntime(result, ManagedMemory, _program); ControlState.EvaluationStack.PushValue(resultVal); } ControlState.MoveToNextInstruction(); } else { var sigArgsWithThis = CompleteSigArgs(instruction, method); var argsWithThis = CompleteArgs(instruction, methodArgs, thisVal); var newMethodState = new CilMethodState(method, sigArgsWithThis, argsWithThis, _program); ControlState.MoveToNextInstruction(); ControlState.CallStack.Push(newMethodState); } }
public override IValue Unbox(CilObject obj, CilManagedMemory managedMemory, CilProgram program) { throw new NotImplementedException(); }
public abstract CilValueReference Store(CilObject obj);
public abstract IValue Unbox(CilObject obj, CilManagedMemory managedMemory, CilProgram program);