Commit Graph

228 Commits

Author SHA1 Message Date
Aryadev Chavali
134c06a6fe Added TODO and WIP tags for spec 2023-11-03 08:14:40 +00:00
Aryadev Chavali
b4fce03177 Made test.asm an example asm program 2023-11-03 07:55:23 +00:00
Aryadev Chavali
fc4b9702d2 Added comments to test.asm 2023-11-02 23:39:31 +00:00
Aryadev Chavali
0b0dc4c498 Update spec footnotes 2023-11-02 23:33:35 +00:00
Aryadev Chavali
be3cebe211 Updated LOC in README 2023-11-02 23:32:11 +00:00
Aryadev Chavali
85558c1ae2 Started working on a spec, still needs a lot of work 2023-11-02 23:31:13 +00:00
Aryadev Chavali
698a823bf2 Added recipes to assemble or interpret individually 2023-11-02 23:30:17 +00:00
Aryadev Chavali
07f64b796d Implemented a routine which prints out a buffer of characters and use it
All in my assembly/virtual machine!
2023-11-02 23:29:50 +00:00
Aryadev Chavali
6dfc4ceaeb Better logs for assembler 2023-11-02 23:29:43 +00:00
Aryadev Chavali
6c4469958e Implemented CALL(_STACK) and RET on the assembler 2023-11-02 23:29:23 +00:00
Aryadev Chavali
bd39c2b283 Made lexer more error prone so parser is less
Lexer now will straight away attempt to eat up any type or later
portions of an opcode rather than leaving everything but the root.
This means checking for type in the parser is a direct check against
the name rather than prefixed with a dot.

Checks are a bit more strong to cause more tokens to go straight to
symbol rather than getting checked after one routine in at on the
parser side.
2023-11-02 23:29:07 +00:00
Aryadev Chavali
c74c36333b Fixed bug where deleting a page meant not being able to allocate another
This was due to the beg or end page being not set correctly (dangling
pointer).
2023-11-02 23:25:57 +00:00
Aryadev Chavali
f433febb22 Added memory leak dialog in vm_stop
Stack, call stack and heap are evaluated to check for leaks.
2023-11-02 23:25:37 +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
86977fe3c1 Introduced instructions to engage with a call stack
Essentially you may "call" an absolute program address, which pushes
the current address onto the call stack.  CALL_STACK does the same
thing but the absolute program address is taken from the data stack.
RET pops an address off the call stack then jumps to that address.
2023-11-02 21:01:21 +00:00
Aryadev Chavali
9afeed6d61 Made separate tokens for JUMP_ABS and JUMP_STACK
Makes more sense, don't need to fiddle around with strings as much in
the parser due to this!
2023-11-02 20:54:26 +00:00
Aryadev Chavali
bc3f129093 Updated instruction-test example for removal of jump.register 2023-11-02 20:42:05 +00:00
Aryadev Chavali
114fb82990 Removed instruction OP_JUMP_REGISTER
Not necessary when you can just push the relevant word onto the stack
then just do OP_JUMP_STACK.
2023-11-02 20:41:36 +00:00
Aryadev Chavali
99b0ebdfa6 Small fixes 2023-11-02 20:35:47 +00:00
Aryadev Chavali
4990d93a1c Created a preprocessing unit presult_t and a function to process them
Essentially a presult_t contains one of these:

1) A label construction, which stores the label symbol into
`label` (PRES_LABEL)

2) An instruction that calls upon a label, storing the instruction
in `instruction` and the label name in `label` (PRES_LABEL_ADDRESS)

3) An instruction that uses a relative address offset, storing the
instruction in `instruction` and the offset wanted into
`relative_address` (PRES_RELATIVE_ADDRESS)

4) An instruction that requires no further processing, storing the
instruction into `instruction` (PRES_COMPLETE_INSTRUCTION)

In the processing stage, we resolve all calls by iterating one by one
and maintaining an absolute instruction address.  Pretty nice, lots
more machinery involved in parsing now.
2023-11-02 20:31:55 +00:00
Aryadev Chavali
d5e311c9d4 Started work on preprocessing jump addresses 2023-11-02 20:31:22 +00:00
Aryadev Chavali
d12820cd25 Added a TODO file for tasks 2023-11-02 14:40:56 +00:00
Aryadev Chavali
34b1d1d024 A small program I am currently working on: reverses an allocated buffer of bytes, returning a new set 2023-11-01 23:28:35 +00:00
Aryadev Chavali
753514e9a8 Added MALLOC_STACK and SUB to instruction-test example 2023-11-01 22:57:31 +00:00
Aryadev Chavali
740627b12d Implemented MALLOC_STACK and SUB in the assembler 2023-11-01 22:56:40 +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
46e5abbac9 Added instructions for MALLOC_STACK and SUB
MALLOC_STACK is a stack based version of MALLOC, SUB does subtraction.
2023-11-01 22:55:41 +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
101d7d372d Updated instruction-test example file for new memory management instructions 2023-11-01 22:12:58 +00:00
Aryadev Chavali
90e04542a2 Implemented stack versions of MGET and MSET in assembler 2023-11-01 22:09:39 +00:00
Aryadev Chavali
26dea6ce72 Added todos to rename the constructive macros in runtime.c 2023-11-01 22:09:26 +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
0649b3f380 Added stack based versions of MSET and MGET
Essentially they use the stack for their one and only operand.  This
allows user level control, in particular it allows for loops to work
correctly while using these operands.
2023-11-01 22:07:08 +00:00
Aryadev Chavali
44125d7ad9 Implemented OP_MSIZE into lexer/parser of ASM 2023-11-01 21:47:19 +00:00
Aryadev Chavali
ea715c569e Implemented OP_MSIZE in the VM runtime 2023-11-01 21:47:05 +00:00
Aryadev Chavali
cb1cfde0c4 Added instruction to get the size of some allocation
This will allow for more library level code to be written.  For
example, say you wanted to write a generic byte level reversal
algorithm for dynamically sized allocations.  Getting the size of the
allocation would be fundamental to this operation.
2023-11-01 21:45:47 +00:00
Aryadev Chavali
7564938113 Implemented lexer and parser for new memory management instructions 2023-11-01 21:40:25 +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
eda49755bc Added instructions for allocating, setting, getting and deleting heap memory
One may allocate any number of (bytes|hwords|words), set or get some
index from allocated memory, and delete heap memory.

The idea is that all the relevant datums will be on the stack, so no
register usage.  This means no instructions should use register space
at all (other than POP, which I'm debating about currently).  Register
space is purely for users.
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
a5afaee3d0 heap_free_page returns true if page was successfully deleted 2023-11-01 21:13:00 +00:00
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
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
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
d648344c2c Updated README LOC 2023-11-01 18:56:07 +00:00
Aryadev Chavali
6677424f12 Deleted fib.c as fib.asm replaces it 2023-11-01 18:49:59 +00:00
Aryadev Chavali
f4ae33949b Lines of Code heading for README 2023-11-01 18:48:28 +00:00
Aryadev Chavali
044afc302e Updated README with build instructions 2023-11-01 18:41:01 +00:00
Aryadev Chavali
cb8b3f3b8c Fix off by one issues in register implementations
word register 0 refers to the first 8 bytes of the dynamic array.
Hence the used counter should be at least 8 bytes.  This deals with
those issues.  Also print more useful information in
vm_print_registers (how many byte|hword|word registers are currently
in use, how many are available).
2023-11-01 18:31:11 +00:00