Esempio n. 1
0
 public function testNestedLoop()
 {
     $code = '[+[+]]';
     $expected = [[C::TOKEN_JNE, 6], [C::TOKEN_ADD, 1], [C::TOKEN_JNE, 5], [C::TOKEN_ADD, 1], [C::TOKEN_JMP, 2], [C::TOKEN_JMP, 0], [C::TOKEN_NOOP]];
     $program = $this->compiler->compile($code);
     $this->assertInstanceOf(ProgramInterface::class, $program);
     $this->assertEquals($expected, $program->getInstructions());
 }
Esempio n. 2
0
    public function testComplex()
    {
        $code = <<<FUCK_MY_BRAIN
>++++++++[-<+++++++++>]<.>>+>-[+]++>++>+++[>[-
>+++<<+++>]<<]>-----.>->+++..+++.>-.<<+[>[+>+]
>>]<--------------.>>.+++.------.--------.>+.
FUCK_MY_BRAIN;
        $program = $this->compiler->compile($code);
        $this->assertInstanceOf(ProgramInterface::class, $program);
        $this->vm->execute($program);
        $this->expectOutputString('Hello World!');
    }
Esempio n. 3
0
 /**
  * @dataProvider optimizerDataProdiver
  */
 public function testOptimizer($code, $expected)
 {
     $program = $this->compiler->compile($code)->optimize($this->optimizer);
     $this->assertEquals($expected, $program->getInstructions());
 }