private void CompileForeverBlock(InvokationBlock b, List <Instruction> instructions, Dictionary <string, int> labels) { string label1 = MakeLabel(); instructions.Add(new Label(vm, label1)); CompileExpression(b.Args[0], DataType.Script, instructions, labels); instructions.Add(new Jump(vm, label1)); }
private void CompileIfBlock(InvokationBlock b, List <Instruction> instructions, Dictionary <string, int> labels) { string label1 = MakeLabel(); string label2 = MakeLabel(); CompileExpression(b.Args[0], DataType.Boolean, instructions, labels); instructions.Add(new JumpIfNot(vm, label1)); CompileExpression(b.Args[1], DataType.Script, instructions, labels); instructions.Add(new Jump(vm, label2)); instructions.Add(new Label(vm, label1)); CompileExpression(b.Args[2], DataType.Script, instructions, labels); instructions.Add(new Label(vm, label2)); }
private void CompileRepeatBlock(InvokationBlock b, List <Instruction> instructions, Dictionary <string, int> labels) { string counter = MakeVar(); string doLabel = MakeLabel(); string exitLabel = MakeLabel(); CompileExpression(b.Args[0], DataType.Number, instructions, labels); instructions.Add(new PopLocal(vm, counter)); instructions.Add(new Label(vm, doLabel)); instructions.Add(new PushLocal(vm, counter)); instructions.Add(new JumpIfNot(vm, exitLabel)); CompileExpression(b.Args[1], DataType.Script, instructions, labels); instructions.Add(new PushLocal(vm, counter)); instructions.Add(new ApplyPrim(vm, 1, args => (double)args[0] - 1.0)); instructions.Add(new PopLocal(vm, counter)); instructions.Add(new Jump(vm, doLabel)); instructions.Add(new Label(vm, exitLabel)); }
private void CompileInvokationBlock(InvokationBlock b, DataType type, List <Instruction> instructions, Dictionary <string, int> labels) { if (b.Text == "if % then % else %") { CompileIfBlock(b, instructions, labels); return; } else if (b.Text == "forever %") { CompileForeverBlock(b, instructions, labels); return; } else if (b.Text == "repeat % times %") { CompileRepeatBlock(b, instructions, labels); return; } else if (b.Text == "wait % milliseconds") { CompileWaitBlock(b, instructions, labels); return; } else if (b.Text == "stop script") { CompileStopScriptBlock(b, instructions, labels); return; } DataType[] argTypes = blockSpace.blockInfos[b.Text].ArgTypes; for (int i = argTypes.Length - 1; i >= 0; --i) { CompileExpression(b.Args[i], argTypes[i], instructions, labels); } instructions.Add(GenerateInvokation(b.Text, argTypes.Length)); if (type == DataType.Script) { instructions.Add(new Discard(vm)); } }
private void CompileStopScriptBlock(InvokationBlock b, List <Instruction> instructions, Dictionary <string, int> labels) { instructions.Add(new Stop(vm)); }
private void CompileWaitBlock(InvokationBlock b, List <Instruction> instructions, Dictionary <string, int> labels) { CompileExpression(b.Args[0], DataType.Number, instructions, labels); instructions.Add(new Wait(vm)); }
private void CompileWaitBlock(InvokationBlock b, List<Instruction> instructions, Dictionary<string, int> labels) { CompileExpression(b.Args[0], DataType.Number, instructions, labels); instructions.Add(new Wait(vm)); }
private void CompileStopScriptBlock(InvokationBlock b, List<Instruction> instructions, Dictionary<string, int> labels) { instructions.Add(new Stop(vm)); }
private void CompileRepeatBlock(InvokationBlock b, List<Instruction> instructions, Dictionary<string, int> labels) { string counter = MakeVar(); string doLabel = MakeLabel(); string exitLabel = MakeLabel(); CompileExpression(b.Args[0], DataType.Number, instructions, labels); instructions.Add(new PopLocal(vm, counter)); instructions.Add(new Label(vm, doLabel)); instructions.Add(new PushLocal(vm, counter)); instructions.Add(new JumpIfNot(vm, exitLabel)); CompileExpression(b.Args[1], DataType.Script, instructions, labels); instructions.Add(new PushLocal(vm, counter)); instructions.Add(new ApplyPrim(vm, 1, args=>(double) args[0] - 1.0)); instructions.Add(new PopLocal(vm, counter)); instructions.Add(new Jump(vm, doLabel)); instructions.Add(new Label(vm, exitLabel)); }
private void CompileInvokationBlock(InvokationBlock b, DataType type, List<Instruction> instructions, Dictionary<string, int> labels) { if(b.Text == "if % then % else %") { CompileIfBlock(b, instructions, labels); return; } else if (b.Text == "forever %") { CompileForeverBlock(b, instructions, labels); return; } else if (b.Text == "repeat % times %") { CompileRepeatBlock(b, instructions, labels); return; } else if (b.Text == "wait % milliseconds") { CompileWaitBlock(b, instructions, labels); return; } else if (b.Text == "stop script") { CompileStopScriptBlock(b, instructions, labels); return; } DataType[] argTypes = blockSpace.blockInfos[b.Text].ArgTypes; for (int i = argTypes.Length-1; i >=0 ; --i) { CompileExpression(b.Args[i], argTypes[i], instructions, labels); } instructions.Add(GenerateInvokation(b.Text, argTypes.Length)); if (type == DataType.Script) instructions.Add(new Discard(vm)); }
private void CompileIfBlock(InvokationBlock b, List<Instruction> instructions, Dictionary<string, int> labels) { string label1 = MakeLabel(); string label2 = MakeLabel(); CompileExpression(b.Args[0], DataType.Boolean, instructions, labels); instructions.Add(new JumpIfNot(vm, label1)); CompileExpression(b.Args[1], DataType.Script, instructions, labels); instructions.Add(new Jump(vm, label2)); instructions.Add(new Label(vm, label1)); CompileExpression(b.Args[2], DataType.Script, instructions, labels); instructions.Add(new Label(vm, label2)); }
private void CompileForeverBlock(InvokationBlock b, List<Instruction> instructions, Dictionary<string, int> labels) { string label1 = MakeLabel(); instructions.Add(new Label(vm, label1)); CompileExpression(b.Args[0], DataType.Script, instructions, labels); instructions.Add(new Jump(vm, label1)); }