Commit Graph

16 Commits

Author SHA1 Message Date
Aryadev Chavali
206dce7bab Heap now maintains a new page per allocation
Instead of having each page be an area of memory, where multiple
pointers to differing data may lie, we instead have each page being
one allocation.  This ensures that a deletion algorithm, as provided,
would actually work without destroying older pointers which may have
been allocated.  Great!
2023-11-01 20:44:37 +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
4be04d2518 Introduced a new mathematical operator MULT
Thankfully multiplication, like addition, is the same under 2s
complement as it is for unsigned numbers.  So I just need to implement
those versions to be fine.
2023-11-01 18:08:11 +00:00
Aryadev Chavali
693ec7a9d0 Changed inst bytecode methods for new register system
As registers may be theoretically infinite in number, we should use
the largest size possible when referring to them in bytecode (a word).
2023-11-01 17:54:15 +00:00
Aryadev Chavali
89fd2b0d17 Set any new data allocated to 0 for clarity
This is only new data allocated, so it's a very careful procedure.
2023-11-01 17:25: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
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
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
095e62b86f Introduced signed versions of common types
For each type T there is the signed version s_T
2023-10-31 21:23:00 +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
157c79d53c Added a "usage" message and colours for assembler
Prints useful and pretty messages when verbose being at least 1.
2023-10-29 16:59:31 +00:00
Aryadev Chavali
1177a5a45b Auto-fill copyright notice in examples/fib.c 2023-10-29 16:56:19 +00:00
Aryadev Chavali
32dfcc109c Added macro to do safe subtractions on a word
Default C just lets overflows occur for subtraction, so this macro
will default to 0 if the subtraction causes an overflow.
2023-10-28 18:16:50 +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
3aad3926d2 Removed assertion in darr_read_file
If an empty file is read, we want to deal with it in later user code
rather than just failing immediately.
2023-10-24 18:20:22 +01:00
Aryadev Chavali
ac57e32a02 Added lib folder for general stuff, introduced as target to Makefile 2023-10-23 04:25:48 +01:00