Code Monkey home page Code Monkey logo

stacky_mcstackface's Introduction

Stack Machine VM

A stack based virtual machine and compiler based off of the instruction set outlined in this book.

Rationale and Design Considerations

  • I wanted to write my own FORTH, but didn't want to go through the trouble of learning a real assembly environment.
  • You don't tell me what to do! IM JUST HAVING FUN OK!?

Architecture

  • vm.IP - Next instruction that will be processed if you execute vm.tick().
  • vm.RSP - Points to next free slot in the return stack.
  • vm.PSP - Points to next free slot in the parameter stack. Often just called "The Stack".

Road Map

  • Memory.
  • Really basic compiler.
  • Instruction set.
  • Add support for labels to compiler.
  • Interupts.
  • vm.subscribe(addr) to observe memory address changes.
  • I/O.
  • FORTH compiler.

Installation

  1. npm install
  2. typings install
  3. (Optional) npm test to verify installation.

Usage

import { VM, Compiler } from "stacky_mcstackface";

// Instantiate a 64 word (128 byte) virtual machine.
    let vm = new VM(64); // 64 words (16 bit each).

// Create a compiler instance.
    let compileFn = Compiler();

// Compile text source code into numeric byte code.
    let program = compileFn(`PUSH 1 PUSH 5 ADD 4 SUB`);
    // => [ 2, 1, 2, 5, 8, 4, 9 ];

// Load the VM.
   vm.load(program);

// Execute "cycles"
    vm.tick(); // => PUSH 1
    vm.tick(); // => PUSH 5
    vm.tick(); // => ADD  4
    vm.tick(); // => SUB

Instruction Set

See documentation in default_instructions.ts.

stacky_mcstackface's People

Contributors

rickcarlino avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.