Code for the littler Buttons the Computer used in the Turing Machine portion of the book.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
buttons-computer/src/runner.js

23 lines
617 B

import { ButtonMachine } from '../src/buttons.js';
import fs from "fs";
import assert from "assert";
let machine = new ButtonMachine();
const ops = ButtonMachine.operations();
const registers = machine.register_names();
assert(process.argv[2] !== undefined, "USAGE: runner.js [source.btn]");
const source = fs.readFileSync(process.argv[2]);
const code = machine.parse(source.toString());
console.log("CODE", code);
machine.load(code);
machine.run();
console.log("STACK TOP", machine.stack_top);
console.log("REGISTERS", machine.registers);
console.log("STACK", machine.stack);
console.log("RAM", machine.ram);