Commit Graph

67 Commits

Author SHA1 Message Date
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
081661cb6b Fixed bug with comparators where all results were flipped
This is because: say we have {a, b} where a is on top of the stack.  A
comparator C applies in the order C(b, a) i.e. b `C` a.  The previous
version did a `C` b which was wrong.
2023-11-01 17:52:58 +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
6d35283ef0 Clearer VERBOSE messages 2023-11-01 15:22:47 +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
90fb9816b4 Added new macro for bitwise comparison construction
This pushes a datum of the same type as the operands, which is why it
cannot use the comparator macro as that always pushes bytes.
2023-10-31 22:30:58 +00:00
Aryadev Chavali
5045452d7a Added flag which forces the printing of hexes
Anything other than char (which can just use print.byte to print the
hex) and byte (which prints hexes anyway), all other types may be
forced to print a hex rather than a number if PRINT_HEX is 1.
2023-10-31 22:30:53 +00:00
Aryadev Chavali
d9aaaf2a53 Use macros to stop duplication of code
I've made a single macro which defines a function through some common
metric, removing code duplication.  Not particularly readable per se,
but using a macro expansion in your IDE allows one to inspect the code.
2023-10-31 21:42:29 +00:00
Aryadev Chavali
5127202722 Introduced 3 new union members to data_t
These new members are just signed versions of the previous members.
This makes type punning and usage for signed versions easier than
before (no need for memcpy).
2023-10-31 21:41:53 +00:00
Aryadev Chavali
5202dfbb26 Remove duplicated code 2023-10-31 21:28:19 +00:00
Aryadev Chavali
f7f566b106 Implemented all the comparators
So much reused code, I definitely need to find a way to make this cleaner.
2023-10-31 21:24:54 +00:00
Aryadev Chavali
7817b5acc9 Use standardised signed version of word type from base.h 2023-10-31 21:24:50 +00:00
Aryadev Chavali
14a3820e74 Implemented new types of EQ, forced all comparators to push bytes
Just need to call their unsigned versions.

All comparators should push bytes as it makes return types uniform.
2023-10-31 21:05:25 +00:00
Aryadev Chavali
036d3dcfba vm_execute_all: Print every cycle on VERBOSE >= 2, just print final state otherwise
Changed VERBOSE checks to ensure a degree of information.
2023-10-31 21:00:13 +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
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