43 Commits

Author SHA1 Message Date
Aryadev Chavali
62b9b230c5 Update README 2024-06-25 00:41:43 +01:00
Aryadev Chavali
e3aabff845 Disable -Werror 2024-06-19 19:14:01 +01:00
Aryadev Chavali
d0ab1644cb Modified Makefile for less colours and a release build option 2024-06-18 23:49:42 +01:00
Aryadev Chavali
b77cc5639c Now base.c and inst.c are used to make a shared library
Instead of targeting the needed object files, users just need to link
with the shared library.
2024-05-05 20:20:25 +05:30
Aryadev Chavali
a40eaf29b8 OP_HALT is its own opcode, fixed some other minor bugs 2024-05-01 22:36:34 +05:30
Aryadev Chavali
cd6eeeeafe Fix some undefined behaviour in tests 2024-04-29 00:11:35 +05:30
Aryadev Chavali
fd21e46aa7 Don't run tests on build, make it it's own recipe 2024-04-28 23:29:23 +05:30
Aryadev Chavali
f725c2a668 Started developing a unit test module
Folder per module in test/.  Header only tests with one actual main
file to implement a program that runs them.

Makefile runs the test and provides some eye candy to show if the test
succeeded or failed.  The tests, on the other hand, will show success
or failure for each of them.
2024-04-28 15:33:47 +05:30
Aryadev Chavali
159501168c Split vm/runtime.c into two files
struct.c is used for the general construction, inspection and deletion
of the virtual machine structure (vm_t).  runtime defines the
execution routines, error enum, lookup tables, etc.
2024-04-25 03:18:23 +05:30
Aryadev Chavali
71d423a06b Track dependencies properly 2024-04-16 20:45:02 +06:30
Aryadev Chavali
38d7c13287 Migrate virtual machine from OVM project and rewrite README 2024-04-16 18:21:05 +06:30
Aryadev Chavali
5319fd815d Dependencies stricter and prerequisites for directories in Makefile
Don't need to make a directory every time I compile some code.
2024-04-15 16:25:35 +06:30
Aryadev Chavali
f661438c93 Moved read_file to a general base library 2024-04-15 04:55:51 +06:30
Aryadev Chavali
72ef40e671 parser -> preprocesser + parser
I've decided to split the module parsing into two modules, one for the
preprocessing stage which only deals with tokens and the parsing stage
which generates bytecode.
2024-04-14 17:25:28 +06:30
Aryadev Chavali
e7a09c0de4 Wrote a new lexer API in C++
Essentially a refactor of the C formed lexer into C++ style.  I can
already see some benefits from doing this, in particular speed of
prototyping.
2024-04-14 16:52:58 +06:30
Aryadev Chavali
0ebbf3ca75 Start writing assembler in C++
Best language to use as it's already compatible with the headers I'm
using and can pretty neatly enter the build system while also using
the functions I've built for converting to and from bytecode!
2024-04-14 02:45:48 +06:30
Aryadev Chavali
4e9eb0a42e fix! loops in preprocess_use_blocks iterate to the wrong bound
A token_stream being constructed on the spot has different
used/available properties to a fully constructed one: a fully
constructed token stream uses available to hold the total number of
tokens and used as an internal iterator, while one that is still being
constructed uses the semantics of a standard darr.

Furthermore, some loops didn't divide by ~sizeof(token_t)~ which lead
to iteration over bound errors.
2024-04-14 02:00:17 +06:30
Aryadev Chavali
1935277716 Makefile now assembles and interprets instruction-test.asm example first 2023-11-08 18:16:53 +00:00
Aryadev Chavali
b2e3e39a39 Added Makefile recipe to interpret all examples 2023-11-03 21:51:46 +00:00
Aryadev Chavali
fc5393b010 Added memory-print.asm to examples list in Makefile 2023-11-03 21:15:35 +00:00
Aryadev Chavali
698a823bf2 Added recipes to assemble or interpret individually 2023-11-02 23:30:17 +00:00
Aryadev Chavali
b6e359f5eb Fixed issue where sometimes vm_print_registers wouldn't work for bytes
Happened because we weren't printing all relevant words due to
naturally flooring the result of division.  Here I ceil the division
to ensure we get the maximal number of words necessary.
2023-11-01 22:54:45 +00:00
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
Aryadev Chavali
dab1729f61 Makefile now has recipes for example assembly programs
Dependencies are just ASM_OUT binary and the corresponding assembly
program for the bytecode output file.  Actually works very well, with
changes triggering a recompilation.  Also an `exec` recipe is
introduced to do the task of compiling an assembly program and
executing the corresponding bytecode all at once.
2023-11-01 18:28:56 +00:00
Aryadev Chavali
b6daa58cab Makefile now has green colours for binaries and yellow for object files 2023-11-01 15:40:10 +00:00
Aryadev Chavali
5d800d4366 Moved inst module to lib
As it has no dependencies on vm specifically, and it's more necessary
for any vendors who wish to target the virtual machine, it makes more
sense for inst to be a lib module rather than a vm module.
2023-10-31 21:14:14 +00:00
Aryadev Chavali
c534a53b6f Make Verbose a universal flag
All objects target LIB anyway, so VERBOSE is a universal macro for
this code base.
2023-10-29 16:59:37 +00:00
Aryadev Chavali
2fe2af22a9 Implemented a rudimentary parser with support for 4 instruction types 2023-10-26 11:17:55 +01:00
Aryadev Chavali
d1f84a6a2c Makefile now prints dependencies on successful compilation 2023-10-26 10:22:10 +01:00
Aryadev Chavali
74a85268c4 Moved base functions from inst.c to dedicated file
Doesn't make sense for them to be in the VM module when they have a
more general purpose now.
2023-10-26 10:19:10 +01:00
Aryadev Chavali
94abb9e3d4 Separated lexer from main file in asm 2023-10-25 21:43:13 +01:00
Aryadev Chavali
92855ebb3e Starting development on assembly language 2023-10-23 16:53:50 +01:00
Aryadev Chavali
42ac28d44a Make root directory an include path, set #include's properly
Easier to write includes now just using < with the module name, in
comparison to using relative paths.
2023-10-23 04:46:09 +01:00
Aryadev Chavali
0ac634a9be Reintroduced example fib.c via examples/ folder 2023-10-23 04:25:48 +01:00
Aryadev Chavali
ac57e32a02 Added lib folder for general stuff, introduced as target to Makefile 2023-10-23 04:25:48 +01:00
Aryadev Chavali
b44a61be41 src->vm, Makefile is now a bit more abstracted and pretty colours
Changed folder names for sake of clarity (will be introducing a new
build target soon), and Makefile can now easily support more targets.
2023-10-23 03:58:34 +01:00
Aryadev Chavali
919fae2df8 Added an example program fib.c
This is simply a program with an embedded set of instructions which
indefinitely computes and prints fibonacci numbers, computing them in
pairs.

Does it completely through the virtual machine rather than just hard C
instructions.

Also amended the Makefile to compile it.  Required moving the main.c
object file into the dependencies of $(DIST)/$(OUT).

I should track the dependencies for fib.c and main.c as well.
2023-10-23 00:45:23 +01:00
Aryadev Chavali
ed63025927 Added flag to Makefile to set VERBOSE macro in base.h 2023-10-22 18:26:33 +01:00
Aryadev Chavali
cf23a62008 Made a debug and release configuration via flags
Also split out the check for whether $(DIST) exists by making it its
own recipe.  Removes the repeated checks in each object compilation.
2023-10-22 18:07:41 +01:00
Aryadev Chavali
6038363d2f Added functionality to read and write instruction bytecode
Uses some bit hacks to quickly check what data type an opcode may have
by shifting down to units then casting it to a data_type_t.
Not very well tested yet, we'll need to see now.
2023-10-16 01:18:05 +01:00
Aryadev Chavali
c24c1d1607 Implemented a dynamically sized byte array
Pretty simple, want to ensure amortised constant big O so I use a
REALLOC_MULT, which can be redefined if wished.
2023-10-15 21:50:31 +01:00
Aryadev Chavali
639808a092 Moved vm_* code to its own file (runtime.(h|c)) 2023-10-15 21:41:16 +01:00
Aryadev Chavali
16e2275576 First commit!
This is a from the ground rework of an old project of the same name.
I'm hoping to be more concerned with runtime efficiency, bytecode size
and all those things that should actually matter for something that
may host time/space critical code.
2023-10-15 01:25:24 +01:00