1. Go to this page and download the library: Download superinstance/flux-vm library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
superinstance / flux-vm example snippets
use SuperInstance\FluxVM\FluxVM;
use SuperInstance\FluxVM\Assembler;
use SuperInstance\FluxVM\Loader;
$vm = new FluxVM();
// Load bytecode from file
$bytecode = Loader::load('program.flux');
$vm->load($bytecode);
$vm->run();
// Or assemble from source
$source = '
# Compute factorial of 5
IMov R0, 5 # counter
IMov R1, 1 # accumulator
loop:
IMul R1, R1, R0 # R1 = R1 * R0
IDec R0, 1 # R0--
JumpIfNot R0, loop # if R0 != 0, jump to loop
Halt # done
';
$bytecode = Assembler::assemble($source);
$vm->load($bytecode);
$vm->run();
echo "Result: " . $vm->getGP(1) . "\n"; // 120 (5!)
bash
git clone https://github.com/SuperInstance/flux-vm-php.git
cd flux-vm-php
composer install
bash
# Run bytecode
php src/CLI.php run program.flux
# Assemble assembly to bytecode
php src/CLI.php asm program.asm
# Disassemble bytecode
php src/CLI.php dis program.flux
# Start REPL
php src/CLI.php repl