public override void Execute(BHAV bhav, UIBHAVEditor editor) { var newInst = new BHAVInstruction[bhav.Instructions.Length - 1]; byte index = 0; for (int i = 0; i < bhav.Instructions.Length; i++) { if (i != Primitive.InstPtr) { var inst = bhav.Instructions[i]; newInst[index++] = inst; if (inst.TruePointer < 253 && inst.TruePointer > Primitive.InstPtr) inst.TruePointer--; if (inst.FalsePointer < 253 && inst.FalsePointer > Primitive.InstPtr) inst.FalsePointer--; } } foreach (var prim in FromTrue) { prim.TrueUI = null; prim.Instruction.TruePointer = 253; } foreach (var prim in FromFalse) { prim.FalseUI = null; prim.Instruction.FalsePointer = 253; } bhav.Instructions = newInst; editor.BHAVView.RemovePrimitive(Primitive); FSO.SimAntics.VM.BHAVChanged(bhav); }
public UIBHAVEditor(BHAV target, EditorScope scope) { BHAVView = new BHAVContainer(target, scope); PlacingName = new UILabel(); PlacingName.Alignment = TextAlignment.Center; PlacingName.Size = new Vector2(1, 1); PlacingName.CaptionStyle = TextStyle.DefaultLabel.Clone(); PlacingName.CaptionStyle.Font = FSO.Client.GameFacade.EdithFont; PlacingName.CaptionStyle.Size = 14; PlacingName.CaptionStyle.Color = new Color(0, 102, 26); PlacingName.Caption = "Placing Report Metric"; PlacingDesc = new UILabel(); PlacingDesc.Alignment = TextAlignment.Center; PlacingDesc.Size = new Vector2(1, 1); PlacingDesc.CaptionStyle = TextStyle.DefaultLabel.Clone(); PlacingDesc.CaptionStyle.Font = FSO.Client.GameFacade.EdithFont; PlacingDesc.CaptionStyle.Size = 12; PlacingDesc.CaptionStyle.Color = new Color(0, 102, 26); PlacingDesc.Caption = "Press ESC to cancel."; this.Add(BHAVView); this.Add(PlacingName); this.Add(PlacingDesc); }
public ChangeBHAVCommand(BHAV target, EditorScope scope, VMStackFrame frame, BHAVPrimSelect callback) { Target = target; TargetScope = scope; Frame = frame; SelectCallback = callback; }
public override void Undo(BHAV bhav, UIBHAVEditor editor) { var newInst = new BHAVInstruction[bhav.Instructions.Length + 1]; byte index = 0; for (int i = 0; i < newInst.Length; i++) { if (i == Primitive.InstPtr) newInst[i] = Primitive.Instruction; else { var inst = bhav.Instructions[index++]; newInst[i] = inst; if (inst.TruePointer < 252 && inst.TruePointer >= Primitive.InstPtr) inst.TruePointer++; if (inst.FalsePointer < 252 && inst.FalsePointer >= Primitive.InstPtr) inst.FalsePointer++; } } foreach (var prim in FromTrue) { prim.TrueUI = Primitive; prim.Instruction.TruePointer = Primitive.InstPtr; } foreach (var prim in FromFalse) { prim.FalseUI = Primitive; prim.Instruction.FalsePointer = Primitive.InstPtr; } bhav.Instructions = newInst; editor.BHAVView.Primitives.Add(Primitive); editor.BHAVView.RealPrim.Insert(Primitive.InstPtr, Primitive); editor.BHAVView.Add(Primitive); FSO.SimAntics.VM.BHAVChanged(bhav); }
public override void Undo(BHAV bhav, UIBHAVEditor editor) { Prim.Instruction.Operand = OldOp; Prim.RefreshOperand(); Prim.UpdateDisplay(); FSO.SimAntics.VM.BHAVChanged(bhav); }
public override void Execute(BHAV bhav, UIBHAVEditor editor) { if (NewPrimitive.Type != PrimBoxType.Primitive) { editor.BHAVView.Primitives.Add(NewPrimitive); editor.BHAVView.Add(NewPrimitive); } else { var newInst = new BHAVInstruction[bhav.Instructions.Length + 1]; for (int i = 0; i < bhav.Instructions.Length; i++) { newInst[i] = bhav.Instructions[i]; } newInst[newInst.Length - 1] = NewPrimitive.Instruction; NewPrimitive.InstPtr = (byte)(newInst.Length - 1); bhav.Instructions = newInst; editor.BHAVView.AddPrimitive(NewPrimitive); NewPrimitive.UpdateDisplay(); Content.Content.Get().Changes.ChunkChanged(bhav); FSO.SimAntics.VM.BHAVChanged(bhav); } }
public override void Execute(BHAV bhav, UIBHAVEditor editor) { Prim.Instruction.Operand = NewOp; Prim.UpdateDisplay(); Content.Content.Get().Changes.ChunkChanged(bhav); FSO.SimAntics.VM.BHAVChanged(bhav); }
public override void Execute(BHAV bhav, UIBHAVEditor editor) { Old = editor.BHAVView.EditTarget; OldScope = editor.BHAVView.Scope; OldFrame = editor.DebugFrame; editor.BHAVView.OnSelectedChanged -= SelectCallback; editor.SwitchBHAV(Target, TargetScope, Frame); editor.BHAVView.OnSelectedChanged += SelectCallback; }
public void InitBHAV(BHAV bhav, EditorScope scope) { var mainCont = new UIExternalContainer(1024, 768); Editor = new UIBHAVEditor(bhav, scope); mainCont.Add(Editor); GameFacade.Screens.AddExternal(mainCont); SetUI(mainCont); }
public void IDEOpenBHAV(BHAV targetBhav, GameObject targetObj) { new Thread(() => { if (MainWindow.Instance == null) return; MainWindow.Instance.Invoke(new MainWindowDelegate(() => { MainWindow.Instance.BHAVManager.OpenEditor(targetBhav, targetObj); }), null); }).Start(); }
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; }
public void InjectIDEInto(UIScreen screen, VM vm, BHAV targetBhav, GameObject targetObj) { EditorResource.Get().Init(GameFacade.GraphicsDevice); EditorScope.Behaviour = new Files.Formats.IFF.IffFile(Content.Content.Get().GetPath("objectdata/globals/behavior.iff")); EditorScope.Globals = FSO.Content.Content.Get().WorldObjectGlobals.Get("global"); new Thread(() => { var editor = new BHAVEditor(targetBhav, new EditorScope(targetObj, targetBhav)); Application.Run(editor); }).Start(); }
public override void Undo(BHAV bhav, UIBHAVEditor editor) { //primitive we added should be at the end var newInst = new BHAVInstruction[bhav.Instructions.Length - 1]; for (int i = 0; i < newInst.Length; i++) { newInst[i] = bhav.Instructions[i]; } bhav.Instructions = newInst; editor.BHAVView.RemovePrimitive(NewPrimitive); FSO.SimAntics.VM.BHAVChanged(bhav); }
public override void Undo(BHAV bhav, UIBHAVEditor editor) { if (TrueBranch) { InstUI.Instruction.TruePointer = (OldDestUI == null) ? (byte)253 : OldDestUI.InstPtr; InstUI.TrueUI = OldDestUI; } else { InstUI.Instruction.FalsePointer = (OldDestUI == null) ? (byte)253 : OldDestUI.InstPtr; InstUI.FalseUI = OldDestUI; } FSO.SimAntics.VM.BHAVChanged(bhav); }
public override void Execute(BHAV bhav, UIBHAVEditor editor) { var newInst = new BHAVInstruction[bhav.Instructions.Length + 1]; for (int i = 0; i < bhav.Instructions.Length; i++) { newInst[i] = bhav.Instructions[i]; } newInst[newInst.Length - 1] = NewPrimitive.Instruction; NewPrimitive.InstPtr = (byte)(newInst.Length - 1); bhav.Instructions = newInst; editor.BHAVView.AddPrimitive(NewPrimitive); NewPrimitive.UpdateDisplay(); FSO.SimAntics.VM.BHAVChanged(bhav); }
public override void Execute(BHAV bhav, UIBHAVEditor editor) { if (TrueBranch) { InstUI.Instruction.TruePointer = (DestUI == null)?(byte)253:DestUI.InstPtr; InstUI.TrueUI = DestUI; } else { InstUI.Instruction.FalsePointer = (DestUI == null) ? (byte)253 : DestUI.InstPtr; InstUI.FalseUI = DestUI; } Content.Content.Get().Changes.ChunkChanged(bhav); FSO.SimAntics.VM.BHAVChanged(bhav); }
public BHAVEditor(BHAV bhav, EditorScope scope) : this() { DebugMode = false; MainTable.ColumnStyles[2].SizeType = SizeType.Absolute; MainTable.ColumnStyles[2].Width = 0; Scope = scope; this.bhav = bhav; Text = scope.GetFilename(scope.GetScopeFromID(bhav.ChunkID))+"::"+bhav.ChunkLabel; EditorControl.InitBHAV(bhav, scope, null, null, SelectionChanged); Editor.DisableDebugger += DisableDebugger; PrimGroupChange(AllBtn, null); }
public void CorrectConnections(BHAV bhav) { //make sure there are enough primitives for the bhav var realPrimCount = bhav.Instructions.Length; var treePrimCount = Entries.FindLastIndex(x => x.Type == TREEBoxType.Primitive) + 1; ApplyPointerDelta(realPrimCount - treePrimCount, treePrimCount); if (realPrimCount > treePrimCount) { //add new treeboxes for (int i = treePrimCount; i < realPrimCount; i++) { var box = new TREEBox(this); box.InternalID = (short)i; box.PosisionInvalid = true; box.Type = TREEBoxType.Primitive; Entries.Insert(i, box); } } else if (treePrimCount > realPrimCount) { //remove treeboxes for (int i = treePrimCount; i > realPrimCount; i--) { Entries.RemoveAt(i - 1); } } //make sure connections for each of the primitives match the BHAV //if they don't, reconnect them or generate new boxes (true/false endpoints, maybe gotos in future) for (int i = 0; i < realPrimCount; i++) { var prim = bhav.Instructions[i]; var box = Entries[i]; if (prim.TruePointer != GetTrueID(box.TruePointer)) { box.TruePointer = GetCorrectBox(prim.TruePointer); } if (prim.FalsePointer != GetTrueID((short)box.FalsePointer)) { box.FalsePointer = GetCorrectBox(prim.FalsePointer); } } }
public BHAVEditor(BHAV bhav, EditorScope scope) { Scope = scope; this.bhav = bhav; InitializeComponent(); Text = scope.GetFilename(scope.GetScopeFromID(bhav.ChunkID))+"::"+bhav.ChunkLabel.Trim('\0'); EditorControl.InitBHAV(bhav, scope); PrimitiveList.Items.AddRange(scope.GetAllSubroutines(ScopeSource.Private).ToArray()); /*PrimitiveList.Items.Add("Generic Sims Online Call"); PrimitiveList.Items.Add("Sleep"); PrimitiveList.Items.Add("Idle for Input"); PrimitiveList.Items.Add("Notify Stack Object out of Idle"); PrimitiveList.Items.Add("Push Interaction"); PrimitiveList.Items.Add("Find Best Object For Function"); PrimitiveList.Items.Add("Run Functional Tree"); PrimitiveList.Items.Add("Run Tree By Name"); PrimitiveList.Items.Add("Add / Change Action String");*/ ButtonGroups = new Dictionary<Button, PrimitiveGroup>() { {SubroutineBtn, PrimitiveGroup.Subroutine}, {ControlBtn, PrimitiveGroup.Control}, {DebugBtn, PrimitiveGroup.Debug}, {MathBtn, PrimitiveGroup.Math}, {SimBtn, PrimitiveGroup.Sim}, {ObjectBtn, PrimitiveGroup.Object}, {LooksBtn, PrimitiveGroup.Looks}, {PositionBtn, PrimitiveGroup.Position}, {TSOBtn, PrimitiveGroup.TSO}, {AllBtn, PrimitiveGroup.All } }; ButtonColors = new Dictionary<PrimitiveGroup, Color>(); foreach (var btn in ButtonGroups) { ButtonColors.Add(btn.Value, btn.Key.BackColor); btn.Key.Click += PrimGroupChange; } PrimGroupChange(AllBtn, null); EditorCont.OnSelectedChanged += SelectionChanged; }
public BHAVEditor OpenEditor(BHAV bhav, GameObject srcobj) { BHAVEditor window; if (Editors.ContainsKey(bhav)) { window = Editors[bhav]; var form = (Form)window; if (form.WindowState == FormWindowState.Minimized) form.WindowState = FormWindowState.Normal; window.Activate(); return window; } window = new BHAVEditor(bhav, new EditorComponent.EditorScope(srcobj, bhav)); window.Show(); window.Activate(); Editors.Add(bhav, window); return window; }
public static TREE GenerateEmpty(BHAV bhav) { var result = new TREE(); result.ChunkLabel = ""; result.ChunkID = bhav.ChunkID; result.AddedByPatch = true; result.ChunkProcessed = true; result.RuntimeInfo = ChunkRuntimeState.Modified; result.ChunkType = "TREE"; result.CorrectConnections(bhav); return(result); /* * var additionID = bhav.Instructions.Length; * * Func<byte, short> resolveTrueFalse = (byte pointer) => * { * switch (pointer) * { * case 253: * return -1; * case 255: * //generate false * case 254: * //generate true * } * if (pointer == 255) return -1; * else if (pointer == 2) * }; * * //make an entry for each instruction. positions and sizes don't matter - we have a runtime flag to indicate they are not valid * for (int i=0; i<bhav.Instructions.Length; i++) * { * var inst = bhav.Instructions[i]; * var box = new TREEBox(result); * box.InternalID = i; * box.PosisionInvalid = true; * box.Type = TREEBoxType.Primitive; * box.TruePointer = * } */ }
public BHAVContainer(BHAV target, EditorScope scope) { Scope = scope; EditTarget = target; Selected = new List<PrimitiveBox>(); Primitives = new List<PrimitiveBox>(); RealPrim = new List<PrimitiveBox>(); byte i = 0; foreach (var inst in EditTarget.Instructions) { var ui = new PrimitiveBox(inst, i++, this); Primitives.Add(ui); RealPrim.Add(ui); this.Add(ui); } var RealPrims = new List<PrimitiveBox>(Primitives); foreach (var prim in RealPrims) { if (prim.Instruction.FalsePointer > 252 && prim.Returns != PrimitiveReturnTypes.Done) { var dest = new PrimitiveBox((prim.Instruction.FalsePointer == 254) ? PrimBoxType.True : PrimBoxType.False, this); Primitives.Add(dest); this.Add(dest); prim.FalseUI = dest; } else if (prim.Instruction.FalsePointer < RealPrim.Count) prim.FalseUI = RealPrim[prim.Instruction.FalsePointer]; if (prim.Instruction.TruePointer > 252) { var dest = new PrimitiveBox((prim.Instruction.TruePointer == 254) ? PrimBoxType.True : PrimBoxType.False, this); Primitives.Add(dest); this.Add(dest); prim.TrueUI = dest; } else if (prim.Instruction.TruePointer < RealPrim.Count) prim.TrueUI = RealPrim[prim.Instruction.TruePointer]; } CleanPosition(); HitTest = ListenForMouse(new Rectangle(Int32.MinValue/2, Int32.MinValue / 2, Int32.MaxValue, Int32.MaxValue), new UIMouseEvent(DragMouseEvents)); }
public void InitBHAV(BHAV bhav, EditorScope scope, VMEntity debugEnt, VMStackFrame debugFrame, BHAVPrimSelect callback) { if (FSOUI == null) { var mainCont = new UIExternalContainer(1024, 768); Editor = new UIBHAVEditor(bhav, scope, debugEnt); mainCont.Add(Editor); GameFacade.Screens.AddExternal(mainCont); SetUI(mainCont); Editor.BHAVView.OnSelectedChanged += callback; } else { //reuse existing lock (FSOUI) { Editor.QueueCommand(new ChangeBHAVCommand(bhav, scope, debugFrame, callback)); } } }
public override void Undo(BHAV bhav, UIBHAVEditor editor) { if (Primitive.Type != PrimBoxType.Primitive) { //do nothing. } else { bhav.Instructions[0] = Old0.Instruction; bhav.Instructions[OldPtr] = Primitive.Instruction; Primitive.InstPtr = OldPtr; Old0.InstPtr = 0; foreach (var prim in FromTrue) prim.Instruction.TruePointer = OldPtr; foreach (var prim in FromFalse) prim.Instruction.FalsePointer = OldPtr; foreach (var prim in FromTrue0) prim.Instruction.TruePointer = 0; foreach (var prim in FromFalse0) prim.Instruction.FalsePointer = 0; Content.Content.Get().Changes.ChunkChanged(bhav); FSO.SimAntics.VM.BHAVChanged(bhav); } }
public override void Undo(BHAV bhav, UIBHAVEditor editor) { if (NewPrimitive.Type != PrimBoxType.Primitive) { editor.BHAVView.Primitives.Remove(NewPrimitive); editor.BHAVView.Remove(NewPrimitive); } else { //primitive we added should be at the end var newInst = new BHAVInstruction[bhav.Instructions.Length - 1]; for (int i = 0; i < newInst.Length; i++) { newInst[i] = bhav.Instructions[i]; } bhav.Instructions = newInst; editor.BHAVView.RemovePrimitive(NewPrimitive); Content.Content.Get().Changes.ChunkChanged(bhav); FSO.SimAntics.VM.BHAVChanged(bhav); } }
public UIBHAVEditor(BHAV target, EditorScope scope, VMEntity debugEnt) { if (debugEnt != null) { DebugMode = true; DebugEntity = debugEnt; } ContainerByID = new Dictionary<ushort, BHAVContainer>(); BHAVView = new BHAVContainer(target, scope); ContainerByID.Add(target.ChunkID, BHAVView); this.Add(BHAVView); PlacingName = new UILabel(); PlacingName.Alignment = TextAlignment.Center; PlacingName.Size = new Vector2(1, 1); PlacingName.CaptionStyle = TextStyle.DefaultLabel.Clone(); PlacingName.CaptionStyle.Font = FSO.Client.GameFacade.EdithFont; PlacingName.CaptionStyle.Size = 14; PlacingName.CaptionStyle.Color = new Color(0, 102, 26); PlacingName.Caption = "Placing Report Metric"; PlacingDesc = new UILabel(); PlacingDesc.Alignment = TextAlignment.Center; PlacingDesc.Size = new Vector2(1, 1); PlacingDesc.CaptionStyle = TextStyle.DefaultLabel.Clone(); PlacingDesc.CaptionStyle.Font = FSO.Client.GameFacade.EdithFont; PlacingDesc.CaptionStyle.Size = 12; PlacingDesc.CaptionStyle.Color = new Color(0, 102, 26); PlacingDesc.Caption = "Press ESC to cancel."; this.Add(PlacingName); this.Add(PlacingDesc); if (DebugMode) { DebugFrame = debugEnt.Thread.Stack.LastOrDefault(); UpdateDebugPointer(DebugFrame); DebugGo = new UIButton(); DebugGo.Caption = "Go"; DebugGo.Position = new Vector2(15, 15); Add(DebugGo); DebugGo.OnButtonClick += DebugButtonClick; DebugStepOver = new UIButton(); DebugStepOver.Caption = "Step Over"; DebugStepOver.Position = new Vector2(83, 15); Add(DebugStepOver); DebugStepOver.OnButtonClick += DebugButtonClick; DebugStepIn = new UIButton(); DebugStepIn.Caption = "Step In"; DebugStepIn.Position = new Vector2(193, 15); Add(DebugStepIn); DebugStepIn.OnButtonClick += DebugButtonClick; DebugStepOut = new UIButton(); DebugStepOut.Caption = "Step Out"; DebugStepOut.Position = new Vector2(293, 15); Add(DebugStepOut); DebugStepOut.OnButtonClick += DebugButtonClick; DebugTrue = new UIButton(); DebugTrue.Caption = "Return True"; DebugTrue.Position = new Vector2(402, 15); Add(DebugTrue); DebugTrue.OnButtonClick += DebugButtonClick; DebugFalse = new UIButton(); DebugFalse.Caption = "Return False"; DebugFalse.Position = new Vector2(522, 15); Add(DebugFalse); DebugFalse.OnButtonClick += DebugButtonClick; } }
public void SwitchBHAV(BHAV target, EditorScope scope, VMStackFrame frame) { Remove(BHAVView); if (ContainerByID.ContainsKey(target.ChunkID)) { BHAVView = ContainerByID[target.ChunkID]; AddAt(0, BHAVView); } else { BHAVView = new BHAVContainer(target, scope); ContainerByID.Add(target.ChunkID, BHAVView); AddAt(0, BHAVView); } if (DebugMode) { DebugFrame = frame; UpdateDebugPointer(frame); } }
public bool RunInMyStack(BHAV bhav, GameObject CodeOwner, short[] passVars, VMEntity stackObj) { var OldStack = Stack; var OldQueue = Queue; VMStackFrame prevFrame = new VMStackFrame() { Caller = Entity, Callee = Entity }; if (Stack.Count > 0) { prevFrame = Stack[Stack.Count - 1]; Stack = new List<VMStackFrame>() { prevFrame }; } else { Stack = new List<VMStackFrame>(); } if (Queue.Count > 0) { Queue = new List<VMQueuedAction>() { Queue[0] }; } else { Queue = new List<VMQueuedAction>(); } ExecuteSubRoutine(prevFrame, bhav, CodeOwner, new VMSubRoutineOperand(passVars)); Stack.RemoveAt(0); if (Stack.Count == 0) { Stack = OldStack; Queue = OldQueue; return false; //bhav was invalid/empty } var frame = Stack[Stack.Count - 1]; frame.StackObject = stackObj; while (Stack.Count > 0) { NextInstruction(); } //copy child stack things to parent stack //prevFrame.Args = frame.Args; //prevFrame.StackObject = frame.StackObject; Stack = OldStack; Queue = OldQueue; return (LastStackExitCode == VMPrimitiveExitCode.RETURN_TRUE) ? true : false; }
public static void BHAVChanged(BHAV bhav) { lock (_Assembled) { bhav.RuntimeVer++; if (_Assembled.ContainsKey(bhav)) _Assembled.Remove(bhav); } if (OnBHAVChange != null) OnBHAVChange(); }
public bool RunInMyStack(BHAV bhav, GameObject CodeOwner, short[] passVars, VMEntity stackObj) { //a little bit hacky. We may not need to do as serious a context switch as this. var OldStack = Stack; var OldQueue = Queue; var OldCheck = IsCheck; var OldQueueBlock = ActiveQueueBlock; VMStackFrame prevFrame = new VMStackFrame() { Caller = Entity, Callee = Entity }; if (Stack.Count > 0) { prevFrame = Stack[Stack.Count - 1]; Stack = new List<VMStackFrame>() { prevFrame }; } else { Stack = new List<VMStackFrame>(); } Queue = new List<VMQueuedAction>(); if (Queue.Count > 0) Queue.Add(Queue[0]); IsCheck = true; ExecuteSubRoutine(prevFrame, bhav, CodeOwner, new VMSubRoutineOperand(passVars)); Stack.RemoveAt(0); if (Stack.Count == 0) { Stack = OldStack; Queue = OldQueue; return false; //bhav was invalid/empty } var frame = Stack[Stack.Count - 1]; frame.StackObject = stackObj; try { while (Stack.Count > 0) { NextInstruction(); } } catch (Exception) { //we need to catch these so that the parent can be restored. } //copy child stack things to parent stack Stack = OldStack; Queue = OldQueue; IsCheck = OldCheck; ActiveQueueBlock = OldQueueBlock; return (LastStackExitCode == VMPrimitiveExitCode.RETURN_TRUE) ? true : false; }
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); }
/// <summary> /// Assembles a set of instructions. /// </summary> /// <param name="bhav">The instruction set to assemble.</param> /// <returns>A VMRoutine instance.</returns> public VMRoutine Assemble(BHAV bhav) { if (_Assembled.ContainsKey(bhav)) return _Assembled[bhav]; lock (_Assembled) { if (_Assembled.ContainsKey(bhav)) { return _Assembled[bhav]; } var routine = VMTranslator.Assemble(this, bhav); _Assembled.Add(bhav, routine); return routine; } }