This repository has been archived on 2025-11-10. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Aryadev Chavali 525694bea7 Added an arena allocator
A page is a flexibly allocated structure of bytes, with a count of the
number of bytes already allocated (used) and number of bytes available
overall (available), with a pointer to the next page, if any.

heap_t is a linked list of pages.  One may allocate a requested size
off the heap which causes one of two things:
1) Either a page already exists with enough space for the requested
size, in which case that page's pointer is used as the base for the
requested pointer
2) No pages satisfy the requested size, so a new page is allocated
which is the new end of the heap.
2023-11-01 19:08:59 +00:00
2023-11-01 19:08:59 +00:00
2023-11-01 18:20:03 +00:00
2023-10-15 01:25:24 +01:00
2023-11-01 19:08:59 +00:00
2023-11-01 18:56:07 +00:00

Oreo's Virtual Machine (OVM)

A stack based virtual machine in C11, with a dynamic register setup which acts as variable space. Deals primarily in bytes, doesn't make assertions about typing and is very simple to target.

How to build

Requires GNU make, a compliant C11 compiler. Code base has been tested against gcc and clang, but given how the project has been written without use of GNU'isms it shouldn't be an issue to compile using something like tcc or another compiler (look at here to change the compiler).

To build everything simply run make. This will build:

  • instruction bytecode system which allows one to target the VM by writing and reading instruction bytecode
  • VM executable which can execute bytecode (your java executable)
  • Assembler executable which can assemble compliant assembly code to VM bytecode
  • Assembly examples which provide some source code examples on common programs one may write. Use this to figure out how to write compliant assembly.

One may also build each component individually through the corresponding recipe:

  • make lib
  • make vm
  • make asm
  • make examples

Instructions to target the virtual machine

You need to link with the object files for base.c, darr.c and inst.c to be able to properly target the OVM. The basic idea is to create instructions via inst_t then using the inst(s)_write_* API to generate bytecode (and write to a file).

Then to execute the program, the virtual machine interpreter ovm.out is used.

For clarity, one may build lib (make lib) then use the resulting object files to link and create bytecode for the virtual machine.

Lines of code

216 ./vm/runtime.h
83 ./vm/main.c
718 ./vm/runtime.c
452 ./lib/inst.c
39 ./lib/darr.h
193 ./lib/inst.h
90 ./lib/base.h
39 ./lib/base.c
77 ./lib/darr.c
315 ./asm/parser.c
140 ./asm/main.c
68 ./asm/lexer.h
37 ./asm/parser.h
439 ./asm/lexer.c
Description
No description provided
Readme 401 KiB
Languages
C++ 93.8%
Makefile 6.2%