public static VMRoutine Assemble(VM vm, BHAV bhav) { var context = vm.Context; var routine = new VMRoutine(); routine.Locals = bhav.Locals; routine.Arguments = bhav.Args; routine.Type = bhav.Type; routine.ID = bhav.ChunkID; routine.Chunk = bhav; routine.VM = vm; routine.Rti = new VMFunctionRTI { Name = bhav.ChunkLabel }; VMInstruction[] instructions = new VMInstruction[bhav.Instructions.Length]; for (var i = 0; i < bhav.Instructions.Length; i++) { var bhavInstruction = bhav.Instructions[i]; var instruction = new VMInstruction(); instruction.Index = (byte)i; instruction.Opcode = bhavInstruction.Opcode; instruction.Operand = null; instruction.FalsePointer = bhavInstruction.FalsePointer; instruction.TruePointer = bhavInstruction.TruePointer; instruction.Breakpoint = bhavInstruction.Breakpoint; instruction.Function = routine; /** Routine call **/ if (instruction.Opcode >= 256) { var operand = new VMSubRoutineOperand(); operand.Read(bhavInstruction.Operand); instruction.Operand = operand; } else { var primitive = context.Primitives[instruction.Opcode]; if (primitive != null) { if (primitive.OperandModel != null) { VMPrimitiveOperand operand = (VMPrimitiveOperand)Activator.CreateInstance(primitive.OperandModel); operand.Read(bhavInstruction.Operand); instruction.Operand = operand; } } } instructions[i] = instruction; } routine.Instructions = instructions; return(routine); }
public static VMRoutine Assemble(VM vm, BHAV bhav) { var context = vm.Context; var routine = new VMRoutine(); routine.Locals = bhav.Locals; routine.Arguments = bhav.Args; routine.Type = bhav.Type; routine.ID = bhav.ChunkID; routine.VM = vm; routine.Rti = new VMFunctionRTI { Name = bhav.ChunkLabel }; VMInstruction[] instructions = new VMInstruction[bhav.Instructions.Length]; for (var i = 0; i < bhav.Instructions.Length; i++) { var bhavInstruction = bhav.Instructions[i]; var instruction = new VMInstruction(); instruction.Index = (byte)i; instruction.Opcode = bhavInstruction.Opcode; instruction.Operand = null; instruction.FalsePointer = bhavInstruction.FalsePointer; instruction.TruePointer = bhavInstruction.TruePointer; instruction.Function = routine; /** Routine call **/ if (instruction.Opcode >= 256) { var operand = new VMSubRoutineOperand(); operand.Read(bhavInstruction.Operand); instruction.Operand = operand; } else { var primitive = context.Primitives[instruction.Opcode]; if (primitive != null) { if (primitive.OperandModel != null) { VMPrimitiveOperand operand = (VMPrimitiveOperand)Activator.CreateInstance(primitive.OperandModel); operand.Read(bhavInstruction.Operand); instruction.Operand = operand; } } } instructions[i] = instruction; } routine.Instructions = instructions; return routine; }
protected void PopulateRoutineFields(BHAV bhav, VMRoutine routine) { routine.Locals = bhav.Locals; routine.Arguments = bhav.Args; routine.Type = bhav.Type; routine.ID = bhav.ChunkID; routine.Chunk = bhav; routine.Rti = new VMFunctionRTI { Name = bhav.ChunkLabel }; VMInstruction[] instructions = new VMInstruction[bhav.Instructions.Length]; for (var i = 0; i < bhav.Instructions.Length; i++) { var bhavInstruction = bhav.Instructions[i]; var instruction = new VMInstruction(); instruction.Index = (byte)i; instruction.Opcode = bhavInstruction.Opcode; instruction.Operand = null; instruction.FalsePointer = bhavInstruction.FalsePointer; instruction.TruePointer = bhavInstruction.TruePointer; instruction.Breakpoint = bhavInstruction.Breakpoint; instruction.Function = routine; /** Routine call **/ if (instruction.Opcode >= 256) { var operand = new VMSubRoutineOperand(); operand.Read(bhavInstruction.Operand); instruction.Operand = operand; } else { var primitive = VMContext.Primitives[instruction.Opcode]; if (primitive != null) { if (primitive.OperandModel != null) { VMPrimitiveOperand operand = (VMPrimitiveOperand)Activator.CreateInstance(primitive.OperandModel); operand.Read(bhavInstruction.Operand); instruction.Operand = operand; } } } instructions[i] = instruction; } routine.Instructions = instructions; }
public void ExecuteSubRoutine(VMStackFrame frame, BHAV bhav, GameObject codeOwner, VMSubRoutineOperand args) { if (bhav == null) { Pop(VMPrimitiveExitCode.ERROR); return; } var routine = Context.VM.Assemble(bhav); var childFrame = new VMStackFrame { Routine = routine, Caller = frame.Caller, Callee = frame.Callee, CodeOwner = codeOwner, StackObject = frame.StackObject, ActionTree = frame.ActionTree }; childFrame.Args = new short[(routine.Arguments > 4) ? routine.Arguments : 4]; for (var i = 0; i < childFrame.Args.Length; i++) { short argValue = (i > 3) ? (short)-1 : args.Arguments[i]; if (argValue == -1 && args.UseTemp0) { argValue = TempRegisters[i]; } childFrame.Args[i] = argValue; } Push(childFrame); }
public void ExecuteSubRoutine(VMStackFrame frame, BHAV bhav, GameIffResource codeOwner, VMSubRoutineOperand args) { if (bhav == null) { Pop(VMPrimitiveExitCode.ERROR); return; } var routine = frame.VM.Assemble(bhav); var childFrame = new VMStackFrame { Routine = routine, Caller = frame.Caller, Callee = frame.Callee, CodeOwner = codeOwner, StackObject = frame.StackObject }; childFrame.Args = new short[4]; for (var i = 0; i < childFrame.Args.Length; i++) { var argValue = args.Arguments[i]; if (argValue == -1) { argValue = TempRegisters[i]; } childFrame.Args[i] = argValue; } Push(childFrame); }
public void ExecuteSubRoutine(VMStackFrame frame, VMRoutine routine, GameObject codeOwner, VMSubRoutineOperand args) { if (routine == null) { Pop(VMPrimitiveExitCode.ERROR); return; } var childFrame = new VMStackFrame { Routine = routine, Caller = frame.Caller, Callee = frame.Callee, CodeOwner = codeOwner, StackObject = frame.StackObject, _StackObjectID = frame.StackObjectID, //pass this without doing a lookup ActionTree = frame.ActionTree }; childFrame.Args = new short[(routine.Arguments > 4) ? routine.Arguments : 4]; for (var i = 0; i < childFrame.Args.Length; i++) { short argValue = (i > 3) ? (short)-1 : args.Arguments[i]; if (argValue == -1 && args.UseTemp0) { argValue = TempRegisters[i]; } childFrame.Args[i] = argValue; } Push(childFrame); }
public void ExecuteSubRoutine(VMStackFrame frame, BHAV bhav, GameObject codeOwner, VMSubRoutineOperand args) { if (bhav == null){ Pop(VMPrimitiveExitCode.ERROR); return; } var routine = Context.VM.Assemble(bhav); var childFrame = new VMStackFrame { Routine = routine, Caller = frame.Caller, Callee = frame.Callee, CodeOwner = codeOwner, StackObject = frame.StackObject }; childFrame.Args = new short[(routine.Arguments>4)?routine.Arguments:4]; for (var i = 0; i < childFrame.Args.Length; i++){ short argValue = (i>3)?(short)-1:args.Arguments[i]; if (argValue == -1) { argValue = TempRegisters[i]; } childFrame.Args[i] = argValue; } Push(childFrame); }
private void ExecuteSubRoutine(VMStackFrame frame, BHAV bhav, GameIffResource codeOwner, VMSubRoutineOperand args) { if (bhav == null) { Pop(VMPrimitiveExitCode.ERROR); return; } System.Diagnostics.Debug.WriteLine("Invoke: " + bhav.ChunkLabel); System.Diagnostics.Debug.WriteLine(""); var routine = frame.VM.Assemble(bhav); var childFrame = new VMStackFrame { Routine = routine, Caller = frame.Caller, Callee = frame.Callee, CodeOwner = codeOwner, StackObject = frame.StackObject }; childFrame.Args = new short[routine.Arguments]; for (var i = 0; i < childFrame.Args.Length; i++) { var argValue = args.Arguments[i]; if (argValue == -1) { /** TODO: Is this the right rule? Maybe a flag decides when to copy from temp? **/ argValue = TempRegisters[i]; } childFrame.Args[i] = argValue; } Push(childFrame); }
public VMPrimitiveExitCode ExecuteSubRoutine(VMStackFrame frame, ushort opcode, VMSubRoutineOperand operand) { VMRoutine bhav = null; GameObject CodeOwner; if (opcode >= 8192) { // Semi-Global sub-routine call bhav = (VMRoutine)frame.ScopeResource.SemiGlobal.GetRoutine(opcode); } else if (opcode >= 4096) { // Private sub-routine call bhav = (VMRoutine)frame.ScopeResource.GetRoutine(opcode); } else { // Global sub-routine call //CodeOwner = frame.Global.Resource; bhav = (VMRoutine)frame.Global.Resource.GetRoutine(opcode); } CodeOwner = frame.CodeOwner; ExecuteSubRoutine(frame, bhav, CodeOwner, operand); #if IDE_COMPAT if (Stack.LastOrDefault().GetCurrentInstruction().Breakpoint || ThreadBreak == VMThreadBreakMode.StepIn) { Breakpoint(frame, "Stepped in."); ContinueExecution = false; } else #endif { ContinueExecution = true; } return(VMPrimitiveExitCode.CONTINUE); }