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()); }
/** * @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."); } } }
/** * @param \Brainfart\VM\VM $vm */ public function execute(VM $vm) { $vm->getOutput()->store($vm->getMemory()->fetch()); }
/** * @param \Brainfart\VM\VM $vm */ public function execute(VM $vm) { $vm->getMemory()->move($this->getValue()); }
/** * @param \Brainfart\VM\VM $vm */ public function execute(VM $vm) { sleep($vm->getMemory()->fetch()); }