Getting started with the new buttons setup.

master
Zed A. Shaw 3 years ago
parent 17cbaa7455
commit 40da242bd7
  1. 2999
      package-lock.json
  2. 26
      package.json
  3. 6
      src/buttons.js
  4. 7
      tests/basic.btn
  5. 17
      tests/basic_tests.js

2999
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -0,0 +1,26 @@
{
"name": "buttons-computer",
"version": "1.0.0",
"description": "A simple toy fantasty computer to learn about computer using javascript.",
"main": "src/index.js",
"type": "module",
"directories": {
"test": "tests"
},
"scripts": {
"test": "ava test tests"
},
"repository": {
"type": "git",
"url": "git@git.learnjsthehardway.com:learn-javascript-the-hard-way/buttons-computer"
},
"keywords": [
"javascript",
"fantasy-computer"
],
"author": "Zed A. Shaw",
"license": "AGPL-3.0-or-later",
"dependencies": {
"ava": "^4.2.0"
}
}

@ -1,6 +1,6 @@
class ButtonMachine { export class ButtonMachine {
constructor(code) { constructor(code) {
this.stack = []; this.stack = [];
@ -192,4 +192,6 @@ class ButtonMachine {
} }
} }
module.exports = { ButtonMachine }; export default {
ButtonMachine
};

@ -0,0 +1,7 @@
PUSH 10
PUSH 1
SUB
JZ 5
JUMP 1
PUSH 100
HALT

@ -0,0 +1,17 @@
import { ButtonMachine } from "../src/buttons.js";
const cpu = new ButtonMachine([
["PUSH", 10],
["PUSH", 1],
["SUB"],
["JZ", 5],
["JUMP", 1],
["PUSH", 100],
["HALT"]
]);
cpu.run();
console.log("STACK TOP", cpu.stack_top);
console.log("REGISTER", cpu.register_entries);
console.log("STACK", cpu.stack);
Loading…
Cancel
Save