Giter Club home page Giter Club logo

gc-vm's Introduction

VM

This is my first VM based on baby's first garbage collector post.

I've implemented a little VM over the types that the GC manages. I've also written a little assembler.

The assembler currently supports a bunch of mnemonics and one macro:

Instructions

push <number>       ; push i32 value
pop                 ; pop value from the stack (not accessible anymore)
pair                ; pop two values from the stack and push them as a pair
out                 ; output the bytes saved on the last pushed value recursively, i.e if pair it outputs all the bytes from first and snd
in                  ; pushes the result of `getchar`.
swap                ; swap the last two values of the stack.
gc                  ; force garbage collection.
die <msg>           ; output <msg> to stderr as an error and halt
halt                ; halt the machine.
assert_allocated <n> <msg> ; Used for tests. asserts that the number of allocated objects at the moment is <n>, if not it exits with <msg> as its error.

Assembler helpers:

print <string> ; print <string> to stdout, including the '\n'.

%repeat <n> [<binding>] ; repeats (statically) the contents of <scope>, optionally binding a value for each
                        ; iteration of the loop. The binding will be set to 0-<n> (not including n) accordingly
                        ; to the current iteration.
<scope>
%end

Syntax

I have made a syntax file for vim/neovim inside the syntax/ directory. You can install it to see the syntax highlighting.

Disclaimer

The VM is at a very early stage; it doesn't support any kind of math/conditionals/dynamic loops. The assembly of course isn't Turing-complete. There is one test which I could not implement using the current set of instructions that the machine has: test4.

gc-vm's People

Contributors

cg-jl avatar

Stargazers

 avatar  avatar  avatar

Watchers

 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.