19 Commits

Author SHA1 Message Date
Aryadev Chavali
a7588ccc61 Use program structure for runtime
Very barebones, essentially a simple refactor.

I need to introduce a feature to append to a program as well, but as
it's a flexible structure it will likely have to be functional.
2023-11-03 19:09:13 +00:00
Aryadev Chavali
4eee6e1a0a Implemented subroutine instructions in runtime
Very easy overall, printing the call stack not so much.
2023-11-02 23:25:33 +00:00
Aryadev Chavali
ac3270777b Implemented OP_MALLOC_STACK and OP_SUB in the runtime 2023-11-01 22:56:24 +00:00
Aryadev Chavali
90ee9b492d Implemented MGET_STACK and MSET_STACK in the runtime
Very easy, they just pop a word then defer to their normal versions.
This is probably the best case where a macro works directly so I
didn't even need to write a function form for them first.  One thing
is that then names for the macros are quite bad right now, probably
need renaming.
2023-11-01 22:08:06 +00:00
Aryadev Chavali
ea715c569e Implemented OP_MSIZE in the VM runtime 2023-11-01 21:47:05 +00:00
Aryadev Chavali
32c1bcb859 Added a print_heap mechanism into vm
Pretty simple implementation, nothing massive.
In VERBOSE mode, heap is tracked for any allocations/deletions,
printing it if so.
2023-11-01 21:39:00 +00:00
Aryadev Chavali
be312cfbbf Implemented instructions in the runtime for memory management
Pretty simple, required some new types of errors.  Obviously there's
space for a macro for the differing instruction implementations, but
these things need to be tested a bit more before I can do that.
2023-11-01 21:38:52 +00:00
Aryadev Chavali
4e64f1fe23 DUP implementation is now part of WORD_ROUTINES
As PUSH_REGISTER and MOV have the same signature of taking a word as
input, DUP may as well be part of it.

This leads to a larger discussion about how signatures of functions
matter: I may need to do a cleanup at some point.
2023-11-01 21:14:04 +00:00
Aryadev Chavali
0f295221ca VM runtime now maintains a heap internally
Now need to create some instructions which manage the heap
2023-11-01 20:08:40 +00:00
Aryadev Chavali
848c2f75e3 Implement OP_MULT in runtime
Lucky surprise: OP_PLUS follows the same principle rules as the
bitwise operators in that they return the same type as the input.
Therefore I can simply use the same macro to implement it and MULT as
those.  Very nice.
2023-11-01 18:10:43 +00:00
Aryadev Chavali
90d901345a Added a routine to cleanup resources allocated to the VM
This means the stack should be heap allocated, which makes sense as
beyond 1KB one should really be using the heap rather than the stack.
2023-11-01 17:52:15 +00:00
Aryadev Chavali
7a1129d80f VM registers are now a dynamic array
Stack based machines generally need "variable space".  This may be
quite via a symbol-to-word association a list, a hashmap, or some
other system.  Here I decide to go for the simplest: extending the
register system to a dynamic/infinite number of them.  This means, in
practice, that we may use a theoretically infinite number of indexed
words, hwords and bytes to act as variable space.  This means that the
onus is on those who are targeting this virtual machine to create
their own association system to create syntactic variables: all the
machinery is technically installed within the VM, without the veneer
that causes extra cruft.
2023-11-01 17:49:33 +00:00
Aryadev Chavali
727081f99a Removed OP_EQ signed versions as they're useless
A negative number under 2s complement can never be equal to its
positive as the top bit *must* be on.  If two numbers are equivalent
bit-by-bit then they are equal for both signed and unsigned numbers.
2023-11-01 14:23:48 +00:00
Aryadev Chavali
5202dfbb26 Remove duplicated code 2023-10-31 21:28:19 +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
4d8b855d87 Created routines for new comparator opcodes (not implemented)
Will cause error if used currently, which is fine.
2023-10-31 20:59:01 +00: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
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