コード例 #1
0
ファイル: Compiler.cs プロジェクト: samiz/kitsune
        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));
        }
コード例 #2
0
ファイル: Compiler.cs プロジェクト: samiz/kitsune
        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));
        }
コード例 #3
0
ファイル: Compiler.cs プロジェクト: samiz/kitsune
        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));
        }
コード例 #4
0
ファイル: Compiler.cs プロジェクト: samiz/kitsune
        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));
            }
        }
コード例 #5
0
ファイル: Compiler.cs プロジェクト: samiz/kitsune
 private void CompileStopScriptBlock(InvokationBlock b, List <Instruction> instructions, Dictionary <string, int> labels)
 {
     instructions.Add(new Stop(vm));
 }
コード例 #6
0
ファイル: Compiler.cs プロジェクト: samiz/kitsune
 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));
 }
コード例 #7
0
ファイル: Compiler.cs プロジェクト: andyhebear/kitsune
 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));
 }
コード例 #8
0
ファイル: Compiler.cs プロジェクト: andyhebear/kitsune
 private void CompileStopScriptBlock(InvokationBlock b, List<Instruction> instructions, Dictionary<string, int> labels)
 {
     instructions.Add(new Stop(vm));
 }
コード例 #9
0
ファイル: Compiler.cs プロジェクト: andyhebear/kitsune
        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));
        }
コード例 #10
0
ファイル: Compiler.cs プロジェクト: andyhebear/kitsune
        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));
        }
コード例 #11
0
ファイル: Compiler.cs プロジェクト: andyhebear/kitsune
        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));
        }
コード例 #12
0
ファイル: Compiler.cs プロジェクト: andyhebear/kitsune
        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));
        }