public void SetVariable() { AbstractMachineState state = SetupMachine(); SetVariableInstruction i = new SetVariableInstruction(); object[] args = { "X0" }; i.Process(args); i.Execute(state); Assert.AreEqual("set_variable", i.Name()); Assert.AreEqual(1, i.NumberOfArguments()); AbstractTerm X0 = ((AbstractTerm)state["X0"]).Dereference(); AMHeap heap = (AMHeap)state.DataArea; Assert.AreSame(X0, heap.Top()); }
public AMInstructionSet() { _instructions["allocate"] = new AllocateInstruction(); _instructions["bcall"] = new BCallInstruction(); _instructions["call"] = new CallInstruction(); _instructions["cut"] = new CutInstruction(); _instructions["deallocate"] = new DeallocateInstruction(); _instructions["execute"] = new ExecuteInstruction(); _instructions["fcall"] = new FCallInstruction(); _instructions["fail"] = new FailInstruction(); _instructions["get_constant"] = new GetConstantInstruction(); _instructions["get_list"] = new GetListInstruction(); _instructions["get_structure"] = new GetStructureInstruction(); _instructions["get_value"] = new GetValueInstruction(); _instructions["get_variable"] = new GetVariableInstruction(); _instructions["halt"] = new HaltInstruction(); _instructions["nop"] = new NopInstruction(); _instructions["proceed"] = new ProceedInstruction(); _instructions["put_constant"] = new PutConstantInstruction(); _instructions["put_list"] = new PutListInstruction(); _instructions["put_structure"] = new PutStructureInstruction(); _instructions["put_unsafe_value"] = new PutUnsafeValueInstruction(); _instructions["put_variable"] = new PutVariableInstruction(); _instructions["put_value"] = new PutValueInstruction(); _instructions["retry_me_else"] = new RetryMeElseInstruction(); _instructions["set_constant"] = new SetConstantInstruction(); _instructions["set_local_value"] = new SetLocalValueInstruction(); _instructions["set_value"] = new SetValueInstruction(); _instructions["set_variable"] = new SetVariableInstruction(); _instructions["set_void"] = new SetVoidInstruction(); _instructions["trust_me"] = new TrustMeInstruction(); _instructions["try_me_else"] = new TryMeElseInstruction(); _instructions["unify_constant"] = new UnifyConstantInstruction(); _instructions["unify_local_value"] = new UnifyLocalValueInstruction(); _instructions["unify_variable"] = new UnifyVariableInstruction(); _instructions["unify_value"] = new UnifyValueInstruction(); _instructions["unify_void"] = new UnifyVoidInstruction(); _instructions["procedure"] = new ProcedureInstruction(); }
protected override void SetMyBlockInternalArg() { myBlockInternalArg = new SetVariableInstruction(this); }
public void evalInstruction(InstructionExpression instr) { if (instr is ValueExpression) { valueExp = (ValueExpression)instr; if (valueExp.type == ObjectType.intType) { variables.Add(valueExp.name, new ObjectExpression(valueExp.type, 0)); } else if (valueExp.type == ObjectType.booleanType) { variables.Add(valueExp.name, new ObjectExpression(valueExp.type, false)); } else if (valueExp.type == ObjectType.stringType) { variables.Add(valueExp.name, new ObjectExpression(valueExp.type, "")); } if (valueExp.value != null) { variables[valueExp.name] = new ObjectExpression(valueExp.type, evalSimpleExpression(valueExp.value).value); } return; } else if (instr is AssignExpression) { assignExp = (AssignExpression)instr; variables[assignExp.name] = evalSimpleExpression(assignExp.value); return; } else if (instr is OpenMsgDialogInstruction) { gScreen.msgBox.openBox(); return; } else if (instr is MsgDisplayInstruction) { msgExp = (MsgDisplayInstruction)instr; o1 = evalSimpleExpression(msgExp.msg); if (o1.type != ObjectType.stringType) { return; } gScreen.msgBox.setText((string)o1.value); return; } else if (instr is NextMsgDialogInstruction) { shouldEvalSeq = false; gScreen.msgBox.showNextButton(); return; } else if (instr is CloseMsgDialogInstruction) { shouldEvalSeq = false; gScreen.msgBox.showCloseButton(); return; } else if (instr is SwitchCharacterInstruction) { try { gScreen.msgBox.switchCharacter(IrisData.characters[((SwitchCharacterInstruction)instr).character.name]); } catch (Exception e) { return; } return; } else if (instr is RemoveCharacter) { gScreen.msgBox.removeCharacter(); return; } else if (instr is SetVariableInstruction) { setExp = (SetVariableInstruction)instr; /*if (!playerVariables.ContainsKey(setExp.variable.name)) * { * playerVariables.Add(setExp.variable.name, -1); * } * * playerVariables[setExp.variable.name] = (int)(evalSimpleExpression(setExp.value).value);*/ IrisData.setPlayerVariable(setExp.variable.name, (int)(evalSimpleExpression(setExp.value).value)); return; } else if (instr is InputInstruction) { inputExp = (InputInstruction)instr; o1 = variables[inputExp.name]; shouldEvalSeq = false; if (o1.type == ObjectType.intType) { gScreen.iBox.openBox(InputBox.InputType.INT_INPUT); lastInstr = inputExp; } else if (o1.type == ObjectType.stringType) { gScreen.iBox.openBox(InputBox.InputType.STRING_INPUT); lastInstr = inputExp; } return; } else if (instr is MenuInstruction) { menuExp = (MenuInstruction)instr; shouldEvalSeq = false; gScreen.menBox.setChoices(((MenuInstruction)instr).choices); gScreen.menBox.openMenu(); lastInstr = menuExp; return; } else if (instr is PlayMediaInstruction) { playExp = (PlayMediaInstruction)instr; /*if (!IrisData.sounds.ContainsKey(playExp.name)) * { * return; * }*/ //else if(IrisData. try { gScreen.playMedia(IrisData.sounds[playExp.name]); } catch (Exception e) { return; } return; } else if (instr is StopMediaInstruction) { gScreen.stopMedia(); return; } else if (instr is ShowImageInstruction) { showExp = (ShowImageInstruction)instr; if (showExp.image is VariableExpression) { img = IrisData.images[((VariableExpression)showExp.image).name]; } else { memberExp = (MemberAccessExpression)showExp.image; charac = IrisData.characters[memberExp.name]; img = charac.getImage(memberExp.field); } gScreen.showImage(img, showExp.position); return; } else if (instr is SetBackgroundInstruction) { bgdInstr = (SetBackgroundInstruction)instr; try { gScreen.setBackground(IrisData.backgrounds[bgdInstr.image.name]); } catch (Exception e) { return; } return; } else if (instr is CleanBackgroundInstruction) { gScreen.clearBackground(); return; } else if (instr is CleanForegroundInstruction) { gScreen.clearForeGround(); return; } else if (instr is GotoInstruction) { gotoExp = (GotoInstruction)instr; npcExp = gotoExp.npc; evalExpression(IrisData.npcs[npcExp.npc].labels[npcExp.label]); return; } }