コード例 #1
0
        public void PopInstruction()
        {
            bytes.push(LiteralFactory.CreateStringLiteral("Hello world"));
            bytes.push(LiteralFactory.CreateIntLiteral(5));
            bytes.push(LiteralFactory.CreateBoolLiteral(true));
            bytes.push((byte)Instruction.EFFECT_DELIMITER);

            List <byte> instructionArr = bytes.popInstruction(dummyCallback);

            Assert.AreEqual(1, instructionArr.Count);
            Assert.AreEqual(Instruction.EFFECT_DELIMITER, (Instruction)instructionArr[0]);

            List <byte> boolArr = bytes.popInstruction(dummyCallback);

            Assert.AreEqual(2, boolArr.Count);
            bytes.push(boolArr);
            Assert.AreEqual(true, bytes.ReadBoolLiteral(dummyCallback));

            List <byte> intArr = bytes.popInstruction(dummyCallback);

            Assert.AreEqual(5, intArr.Count);
            bytes.push(intArr);
            Assert.AreEqual(5, bytes.ReadIntLiteral(dummyCallback));

            List <byte> stringArr = bytes.popInstruction(dummyCallback);

            bytes.push(stringArr);
            Assert.AreEqual("Hello world", bytes.ReadStringLiteral(dummyCallback));
        }
コード例 #2
0
        public void Loop()
        {
            int numLoops = 3;

            List <byte> loopCode = new List <byte>();

            loopCode.Insert(0, (byte)Instruction.EFFECT_DELIMITER);
            loopCode.InsertRange(0, LiteralFactory.CreateIntLiteral(4));
            loopCode.Insert(0, (byte)Instruction.EFFECT_DELIMITER);
            loopCode.InsertRange(0, LiteralFactory.CreateStringLiteral("Hello world"));
            loopCode.Insert(0, (byte)Instruction.EFFECT_DELIMITER);
            loopCode.InsertRange(0, LiteralFactory.CreateBoolLiteral(true));

            bytes.push(InstructionFactory.Make_Loop(
                           LiteralFactory.CreateIntLiteral(numLoops),
                           loopCode
                           ));

            game.ExecuteNext();
            for (int i = 0; i < numLoops; i++)
            {
                Assert.AreEqual(Instruction.EFFECT_DELIMITER, (Instruction)bytes.pop());
                Assert.AreEqual(4, bytes.ReadIntLiteral(game.queryCheck));
                Assert.AreEqual(Instruction.EFFECT_DELIMITER, (Instruction)bytes.pop());
                Assert.AreEqual("Hello world", bytes.ReadStringLiteral(game.queryCheck));
                Assert.AreEqual(Instruction.EFFECT_DELIMITER, (Instruction)bytes.pop());
                Assert.AreEqual(true, bytes.ReadBoolLiteral(game.queryCheck));
            }
        }
コード例 #3
0
        public void NestedLoop()
        {
            int innerLoops = 3;
            int outerLoops = 2;

            List <byte> loopCode = new List <byte>();

            loopCode.Insert(0, (byte)Instruction.EFFECT_DELIMITER);
            loopCode.InsertRange(0, LiteralFactory.CreateIntLiteral(4));
            loopCode.InsertRange(0, LiteralFactory.CreateStringLiteral("Hello world"));

            List <byte> innerLoop = InstructionFactory.Make_Loop(
                LiteralFactory.CreateIntLiteral(innerLoops),
                loopCode
                );
            List <byte> outerLoop = InstructionFactory.Make_Loop(
                LiteralFactory.CreateIntLiteral(outerLoops),
                innerLoop
                );

            bytes.push(outerLoop);

            game.ExecuteNext();
            for (int i = 0; i < outerLoops; i++)
            {
                game.ExecuteNext();
                for (int j = 0; j < innerLoops; j++)
                {
                    Assert.AreEqual(Instruction.EFFECT_DELIMITER, (Instruction)bytes.pop());
                    Assert.AreEqual(4, bytes.ReadIntLiteral(game.queryCheck));
                    Assert.AreEqual("Hello world", bytes.ReadStringLiteral(game.queryCheck));
                }
            }
        }
コード例 #4
0
 public void String()
 {
     bytes.push(LiteralFactory.CreateStringLiteral("hello world"));
     Assert.AreEqual(
         bytes.ReportStackContent(),
         "STRING(hello world) "
         );
 }
コード例 #5
0
 public void ReadCounter()
 {
     game.Variables.SetCounter("my-key", 11);
     bytes.push(InstructionFactory.Make_ReadCounter(
                    LiteralFactory.CreateStringLiteral("my-key")
                    ));
     game.ExecuteNext();
     Assert.AreEqual(bytes.ReadIntLiteral(game.queryCheck), 11);
 }
コード例 #6
0
 public void SetCounter()
 {
     bytes.push(InstructionFactory.Make_SetCounter(
                    LiteralFactory.CreateStringLiteral("my-key"),
                    LiteralFactory.CreateIntLiteral(44)
                    ));
     game.ExecuteNext();
     Assert.AreEqual(game.Variables.GetCounter("my-key"), 44);
 }
コード例 #7
0
        public void SetStenchTo10()
        {
            List <byte> bytes = InstructionFactory.Make_SetCounter(
                LiteralFactory.CreateStringLiteral("stench"),
                LiteralFactory.CreateIntLiteral(10)
                );
            string text = getText(bytes);

            Assert.AreEqual("Set STENCH to 10.", text);
        }
コード例 #8
0
        public void StringBytecode()
        {
            bytes.push(LiteralFactory.CreateStringLiteral("Hello World 👋"));
            bytes.push(LiteralFactory.CreateStringLiteral("The quick brown fox jumped over the lazy dog."));
            bytes.push(LiteralFactory.CreateStringLiteral("Hello World!"));
            bytes.push(LiteralFactory.CreateStringLiteral("A"));

            Assert.AreEqual(bytes.ReadStringLiteral(dummyCallback), "A");
            Assert.AreEqual(bytes.ReadStringLiteral(dummyCallback), "Hello World!");
            Assert.AreEqual(bytes.ReadStringLiteral(dummyCallback), "The quick brown fox jumped over the lazy dog.");
            Assert.AreEqual(bytes.ReadStringLiteral(dummyCallback), "Hello World 👋");
        }
コード例 #9
0
        public void IfStenchOver50ResetStench()
        {
            List <byte> bytes = InstructionFactory.Make_If(
                InstructionFactory.Make_SetCounter(
                    LiteralFactory.CreateStringLiteral("stench"),
                    LiteralFactory.CreateIntLiteral(0)
                    ),
                InstructionFactory.Make_NumComparison(
                    InstructionFactory.Make_ReadCounter(
                        LiteralFactory.CreateStringLiteral("stench")
                        ),
                    LiteralFactory.CreateIntLiteral(50),
                    (byte)ConditionOperator.MORE_THAN
                    )
                );
            string text = getText(bytes);

            Assert.AreEqual("If STENCH is more than 50, then set STENCH to 0.", text);
        }
コード例 #10
0
    public void SubmitTextInput()
    {
        string selection = InputFieldText.text;

        if (String.IsNullOrEmpty(selection))
        {
            return;
        }

        switch (currentFieldData.enterValue)
        {
        case EnterValueType.NUMBER: {
            if (Int32.TryParse(selection, out int numValue))
            {
                List <byte> arr = LiteralFactory.CreateIntLiteral(numValue);
                currentCompilerNode.Add(
                    new EffectBuilderItem(arr)
                    );
            }
            else
            {
                Debug.Log($"Couldn't parse {selection}");
            }
            break;
        }

        case EnterValueType.TEXT: {
            List <byte> arr = LiteralFactory.CreateStringLiteral(selection);
            currentCompilerNode.Add(
                new EffectBuilderItem(arr)
                );
            break;
        }

        default:
            Debug.LogWarning("Unsupported text input type: " + currentFieldData.enterValue);
            break;
        }
        Next();
    }