예제 #1
0
파일: VMTest.php 프로젝트: yrizos/brainfart
 public function testVM()
 {
     $vm = new VM("", 10);
     $this->assertInstanceOf("Brainfart\\VM\\Memory", $vm->getMemory());
     $this->assertInstanceOf("Brainfart\\VM\\Output", $vm->getOutput());
     $this->assertInstanceOf("Brainfart\\VM\\Input", $vm->getInput());
     $this->assertEquals(10, $vm->getLoopLimit());
 }
예제 #2
0
 /**
  * @param \Brainfart\VM\VM $vm
  *
  * @throws \RuntimeException
  */
 public function execute(VM $vm)
 {
     $operations = $this->getOperations();
     $limit = $vm->getLoopLimit();
     $i = 0;
     while ($this->getMaster() || $vm->getMemory()->fetch() != 0) {
         foreach ($operations as $operation) {
             /** @noinspection PhpUndefinedMethodInspection */
             $operation->execute($vm);
         }
         if ($this->getMaster()) {
             break;
         }
         $i++;
         if ($limit > 0 && $limit < $i) {
             throw new \RuntimeException("Limit of {$limit} operations per loop reached.");
         }
     }
 }
예제 #3
0
 /**
  * @param \Brainfart\VM\VM $vm
  */
 public function execute(VM $vm)
 {
     $vm->getOutput()->store($vm->getMemory()->fetch());
 }
예제 #4
0
 /**
  * @param \Brainfart\VM\VM $vm
  */
 public function execute(VM $vm)
 {
     $vm->getMemory()->move($this->getValue());
 }
예제 #5
0
 /**
  * @param \Brainfart\VM\VM $vm
  */
 public function execute(VM $vm)
 {
     sleep($vm->getMemory()->fetch());
 }