461 Commits

Author SHA1 Message Date
Aryadev Chavali
cb2416554b Added a preprocessing routine in assembler
Preprocessor handles macros and macro blocks by working at the token
level, not doing any high level parsing or instruction making.
Essentially every macro is recorded in a registry, recording the name
and the tokens assigned to it.  Then for every caller it just inserts
the tokens inline, creating a new stream and freeing the old one.  It
leaves actual high level parsing to `parse_next` and
`process_presults`.
2023-11-08 18:15:26 +00:00
Aryadev Chavali
253bebb467 Added log in assembler for reading a certain number of bytes 2023-11-08 18:14:59 +00:00
Aryadev Chavali
642a8ae944 Lexer symbols now recognise macro constants and references 2023-11-08 18:14:41 +00:00
Aryadev Chavali
8fa40d8515 Fixed issue where, on error, runtime would show wrong instruction
When an error occurred, because prog->ptr was incremented beforehand
the trace would show the next instruction as the culprit rather than
the actual instruction.  This commit fixes that by incrementing the
program if and only if the command was run successfully.
2023-11-08 18:12:52 +00:00
Aryadev Chavali
6e524569c3 Current work on preprocessor 2023-11-06 08:16:15 +00:00
Aryadev Chavali
4ae6c05276 Current work on preprocessor implementation
Lots to refactor and test
2023-11-05 16:21:09 +00:00
Aryadev Chavali
aadb21853a Redefined proposed syntax for preprocessor in TODO.org 2023-11-05 16:20:14 +00:00
Aryadev Chavali
a3d8e5ee1f Added TODO for inlining labels 2023-11-04 06:40:56 +00:00
Aryadev Chavali
262a271f42 Added tags for TODO.org 2023-11-04 06:40:42 +00:00
Aryadev Chavali
eebacc0998 Did some more work on the spec 2023-11-04 06:40:27 +00:00
Aryadev Chavali
dc047fd69b Fixed up example comments and some assembly 2023-11-04 06:40:14 +00:00
Aryadev Chavali
e6effcf654 Added steps to creating an in memory instance of the VM
This would be useful when writing an interpreted language where the
"assembly" and the "execution" occur within the same executable.
2023-11-03 22:14:24 +00:00
Aryadev Chavali
26ef47fbfb Updated LOC 2023-11-03 21:53:57 +00:00
Aryadev Chavali
92c8f497c8 Cleaned up How to build section of README 2023-11-03 21:53:27 +00:00
Aryadev Chavali
b2e3e39a39 Added Makefile recipe to interpret all examples 2023-11-03 21:51:46 +00:00
Aryadev Chavali
e9eead1177 Symbols may now include digits in lexer
This is mostly so labels get to have digits.  This won't affect number
tokens as that happens before symbols.
2023-11-03 21:50:55 +00:00
Aryadev Chavali
e6f580ba56 Removed tabs from VERBOSE logs in asm/main.c 2023-11-03 21:50:44 +00:00
Aryadev Chavali
32ee84ef70 Used more subroutines in fib.asm to make code clearer
Looks way more high level but parses down to a very simple bytecode.
However, because of lack of inline code processing, it relies on the
call stack quite heavily.  With inline labels this would be a much
more compact bytecode.
2023-11-03 21:49:40 +00:00
Aryadev Chavali
bc4c57b243 Use label features and entry points for examples 2023-11-03 21:27:18 +00:00
Aryadev Chavali
dea8e23807 Added note in TODO.org
Implementing start points has made features necessary for a standard
library setup easier to see.
2023-11-03 21:23:26 +00:00
Aryadev Chavali
232252c252 Completed start points TODO 2023-11-03 21:23:19 +00:00
Aryadev Chavali
3fde04e1d2 Fixed bug where labels were off by one
Was used in a previous fix but not necessary anymore
2023-11-03 21:22:02 +00:00
Aryadev Chavali
96a83db92b Fixed bug where runtime would not start program at the right place
In vm_execute_all set the program pointer to the start address in the
header of the program payload.
2023-11-03 21:21:33 +00:00
Aryadev Chavali
fc5393b010 Added memory-print.asm to examples list in Makefile 2023-11-03 21:15:35 +00:00
Aryadev Chavali
b8f6232bb2 Refactor assembler to use prog_t structure
Set the program structure correctly with a header using the parsed
global instruction.
2023-11-03 21:15:30 +00:00
Aryadev Chavali
92f4f9011d Refactor vm/main to use refactor to program structure 2023-11-03 21:15:30 +00:00
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
fe7f26256b Defined a program structure
Essentially a "program header", followed by a count, followed by
instructions.

Provides a stronger format for bytecode files and allows for better
bounds checking on instructions.
2023-11-03 19:07:10 +00:00
Aryadev Chavali
b5a1582976 Added a start address (equivalent to main) to assembler
Creates a jump address to the label delegated by "global" so program
starts at that point.
2023-11-03 19:01:31 +00:00
Aryadev Chavali
32d50a9342 Added todo for making a standard library
Some considerations as to how to do this (dynamic or static linking)
and changes needed in VM/assembler for this to work.
2023-11-03 08:19:21 +00:00
Aryadev Chavali
d024ecf2e0 Added todo to make a "main routine" specification in assembler 2023-11-03 08:19:17 +00:00
Aryadev Chavali
6194cb6d2c Mark off completed tasks in todo.org 2023-11-03 08:15:21 +00:00
Aryadev Chavali
1d4817eb82 Started work on spec for data storage types in VM 2023-11-03 08:14:47 +00:00
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