Skip to content

s-mv/smvm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

smvm - the smv virtual machine

~A register based bytecode virtual machine implementation by smv.

(this is a screenshot)

Lightweight and fast, written under 1400 lines of code.

Currently the docs are in making (or being "transported" from past projects) so for now there's only BYTECODE and INSTRUCTIONSET. Updates are major TODO.

This VM is primarily meant to be embedded into C. Practically nobody should be using it barebones without something like a JIT compiler built on top of it. But there's nothing stopping you from doing that. (evil laughter?)

This is mostly a personal project, something that can be embedded into larger systems.


Contents:


Know more:

  1. Instruction set
  2. Bytecode
  3. List of examples: examples/

Usage

The VM is meant to be embedded into C but it can be used as a standalone, to run assembly as well as smvm bytecode.

Basic Usage

To use SMVM as a standalone VM:

  1. Build the VM:
make dev
  1. Run an assembly file:
make run_asmv FILE=examples/test.asmv
# or directly:
./out/smvm examples/test.asmv
  1. Run tests:
make test

C Interoperability

To embed SMVM in your C program:

  1. Install the library:
make install
  1. Include the headers in your C file:
#include <smvm/smvm.h>
  1. Basic usage example:
#include <smvm/smvm.h>

int main() {
  smvm vm;

  smvm_init(&vm);

  char *code =
      "puts \"hello, word! here's my lucky number: \""
      "mov ra 42\n"
      "puti ra\n"
      "halt";

  smvm_assemble(&vm, code);
  smvm_execute(&vm);
  smvm_free(&vm);

  return 0;
}
  1. Compile your program with:
cc your_program.c -lsmvm

Build and Install

  1. Build the development version:
make dev
  1. Install the library system-wide:
make install
  1. Build libraries only:
make out/libsmvm.a    # Static library
make out/libsmvm.so   # Shared library

For more build options:

make help

About

Register-based bytecode VM implementation.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published