All Projects → BranislavLazic → Rooster

BranislavLazic / Rooster

Licence: apache-2.0
Example of primitive stack based virtual machine

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Rooster

Minic Hosting
A simple stack-based virtual machine that runs C in the browser.
Stars: ✭ 628 (+1925.81%)
Mutual labels:  virtual-machine
Construct
JavaScript Digital Organisms simulator
Stars: ✭ 17 (-45.16%)
Mutual labels:  virtual-machine
Burrow
https://wiki.hyperledger.org/display/burrow
Stars: ✭ 851 (+2645.16%)
Mutual labels:  virtual-machine
Lc3 Vm
Write your own virtual machine for the LC-3 computer!
Stars: ✭ 631 (+1935.48%)
Mutual labels:  virtual-machine
Threatpursuit Vm
Threat Pursuit Virtual Machine (VM): A fully customizable, open-sourced Windows-based distribution focused on threat intelligence analysis and hunting designed for intel and malware analysts as well as threat hunters to get up and running quickly.
Stars: ✭ 814 (+2525.81%)
Mutual labels:  virtual-machine
Hbc
API of homomorphic binary operations such as binary comparisons or binary divisions using the library HElib
Stars: ✭ 23 (-25.81%)
Mutual labels:  virtual-machine
Runtime
OCI (Open Containers Initiative) compatible runtime using Virtual Machines
Stars: ✭ 588 (+1796.77%)
Mutual labels:  virtual-machine
Multidocker
Creates a system where users are forced to login in dedicated independent docker containers.
Stars: ✭ 21 (-32.26%)
Mutual labels:  virtual-machine
Ethereumjs Monorepo
Monorepo for the Ethereum VM TypeScript Implementation
Stars: ✭ 813 (+2522.58%)
Mutual labels:  virtual-machine
Awesome Virtualization
Collection of resources about Virtualization
Stars: ✭ 846 (+2629.03%)
Mutual labels:  virtual-machine
Ring
Innovative and practical general-purpose multi-paradigm language
Stars: ✭ 716 (+2209.68%)
Mutual labels:  virtual-machine
Liko 12
LIKO-12 is an open source fantasy computer made using LÖVE.
Stars: ✭ 811 (+2516.13%)
Mutual labels:  virtual-machine
Hyperplatform
Intel VT-x based hypervisor aiming to provide a thin VM-exit filtering platform on Windows.
Stars: ✭ 925 (+2883.87%)
Mutual labels:  virtual-machine
Mac
bytecode interpreter in c (blog post)
Stars: ✭ 628 (+1925.81%)
Mutual labels:  virtual-machine
Enigma
An Erlang VM implementation in Rust
Stars: ✭ 877 (+2729.03%)
Mutual labels:  virtual-machine
Customarch
Arch Linux Based Custom ISOs Made With "Archiso"
Stars: ✭ 606 (+1854.84%)
Mutual labels:  virtual-machine
Malboxes
Builds malware analysis Windows VMs so that you don't have to.
Stars: ✭ 900 (+2803.23%)
Mutual labels:  virtual-machine
Esta
Interpreted language and bytecode VM of my own design written in Rust [Unmaintained]
Stars: ✭ 28 (-9.68%)
Mutual labels:  virtual-machine
Sysbench Docker Hpe
Sysbench Dockerfiles and Scripts for VM and Container benchmarking MySQL
Stars: ✭ 14 (-54.84%)
Mutual labels:  virtual-machine
Atmosphere
Atmosphere cloud platform
Stars: ✭ 7 (-77.42%)
Mutual labels:  virtual-machine

Rooster

Example of very primitive stack based virtual machine

Build

Execute: go build ./cmd/rooster or make

and execute programs:

./rooster program.rcode

Examples

Example of program that adds two numbers and prints the result:

ICONST 7     # 0 - push 7 in stack
ICONST 5     # 2 - push 5 in stack
IADD         # 4 - add numbers
PRINT        # 5 - print the result of addition
HALT         # 6 - stop the program

More complex example that demonstrates calculation of product recursively:

# Use of recursion to calculate a product of numbers
ICONST 1
GSTORE 0 # Set initial accumulation value to 1

# Push four values on stack
ICONST 1
ICONST 2
ICONST 3
ICONST 4


CALL product 1 # Call "product" procedure recursively until the stack is depleted
GLOAD 0        # After the stack is depleted, load value from global memory
PRINT          # And print it out
HALT

product:

    GLOAD  0 # Load initial accumulation value from global memory
    LOAD   0 # Load value from frame stack
    IMUL     # Multiply value from global memory and the one from frame stack
    GSTORE 0 # Put the result in the same address in global memory
    JMP   12 # Repeat
    RET

More examples can be found in examples directory.

Server

To start HTTP server execute: ./server and server will start at 8000 port. To start server on different port: ./server --port=8001

Working principle

Virtual machine

Virtual machine itself works on a quite simple principle. It basically ingests a "slice" (an array) of instructions represented with integers. The "slice" of instructions is then matched against a "switch" statement. Rooster is a stack-based VM. It means that all operations are performed through a virtual stack. E.g. if we want to add two integer numbers, we "push" those numbers on the stack with ICONST stack operation and then we use IADD operation to "pop" them from stack, add them, and then "push" the result again on the stack. Rooster also features a memory for global variables which can be manipulated via GLOAD and GSTORE operations. When it comes to procedures, Rooster creates a chunk of special local memory called "frame" that contains all local variables for a procedure and an address of instruction where it should return after the procedure finishes its computation. For each procedure, new "frame" is created and "pushed" on the stack of frames.

Lexer

Lexer is a piece of our program that performs so called "tokenization" and checks for code grammar. Tokenization is essentially a process of converting particular chunks of source code into tokens. And in the end, token is piece of source code that can have some meaning for us. E.g. token is a comment. Keyword such as ICONST is also a token. Even very special characters such as "end of line" or "end of file" can be tokens.

Parser

After lexer performs tokenization, we can parse our code. In parser, we are converting collection of tokens into instruction set which will be ingested by our VM. Notice that we are not building AST (abstract syntax tree). The reason for that is that our VM assembly (rcode) simply doesn't require such a thing. Parser will simply check for valid and relevant tokens. E.g. comment tokens will simply be discarded since they are irrelevant for VM. Also, if invalid token is present, parsing will fail. That's simply because our code is syntactically incorrect.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].