Commit Graph

291 Commits

Author SHA1 Message Date
Aryadev Chavali
d478522d60 Some rewording of spec.org 2024-04-09 21:23:54 +06:30
Aryadev Chavali
33e1d2ab72 Added some TODOs to lib/inst.c to enforce endian 2024-04-09 21:23:30 +06:30
Aryadev Chavali
d256e06f51 Mid-work through documenting darr.h 2024-04-09 21:21:12 +06:30
Aryadev Chavali
84028dab79 Done TODO: Comment coverage > lib > base.h
Pretty simple
2024-04-09 15:15:00 +06:30
Aryadev Chavali
9d4e56c441 Fixed code in vm_pop_hword DWORD -> DHWORD
Though practically this would work, as the storage for the half word is
not limited in any way, nevertheless it isn't syntactically right and
it's better to fix now.
2024-04-09 15:13:51 +06:30
Aryadev Chavali
afb48b65b9 Completed TODO: Rigid Endian
Just used the endian.h functions to convert host endian to and from
big endian.
2024-04-09 15:11:42 +06:30
Aryadev Chavali
6df6dce153 Added todo to force an endian convention
I've flip flopped a bit on this but I believe the virtual machine
bytecode format must have a convention on endianness.  This is because
of the issue stated in the TODO which may very well happen.
2024-04-09 15:10:26 +06:30
Aryadev Chavali
9250a2a838 Added better documentation to TODO list 2024-04-08 04:44:10 +06:30
Aryadev Chavali
9bf1d123b8 Changed limit for examples/factorial.asm
Did some analysis and found that 21! takes above 64 bit integers to
store hence set the limit to 20 instead.
2024-04-07 03:40:19 +06:30
Aryadev Chavali
04a27bcfec Use a limit on $I rather than on $B for examples/fib.asm 2023-11-29 23:14:01 +00:00
Aryadev Chavali
af142e71ff Fixed issues with getting and setting words for heap pages
Because I was using the hword macros instead of word macros, this
causes truncation of bytes when I didn't want it.
2023-11-29 23:10:32 +00:00
Aryadev Chavali
70c8a03939 Fixed logs in vm/runtime
Just changing some messages and the format of heap printing
2023-11-29 23:10:17 +00:00
Aryadev Chavali
60588129b4 Cleaned up logs in assembler/parser 2023-11-29 23:09:51 +00:00
Aryadev Chavali
fa3ecc0073 Easier to read documentation in examples 2023-11-29 17:00:39 +00:00
Aryadev Chavali
6a34fd2d2e Fixed incorrect free of tokens in error for preprocess_use_blocks
Also error now points to the correct place in the file.
2023-11-29 16:58:26 +00:00
Aryadev Chavali
fd1e6d96f6 Report some stats of the actual program when working 2023-11-29 15:46:44 +00:00
Aryadev Chavali
16dcc88a53 Refactored preprocessor to preprocess_(use|macro)_blocks and process_presults
We have distinct functions for the use blocks and the macro blocks,
which each generate wholesale new token streams via `token_copy` so we
don't run into weird errors around ownership of the internal strings
of each token.

Furthermore, process_presults now uses the stream index in each
presult to report errors when stuff goes wrong.
2023-11-29 15:43:53 +00:00
Aryadev Chavali
48d304056a Refactored presult_t to include a stream pointer
So when a presult_t is constructed it holds an index to where it was
constructed in terms of the token stream.  This will be useful when
implementing an error checker in the preprocessing or result parsing
stages.
2023-11-29 15:43:41 +00:00
Aryadev Chavali
4cee61fc9e Added parse errors for %USE calls
So %USE <STRING> is the expected call pattern, so there's an error if
there isn't a string after %USE.

The other two errors are file I/O errors i.e. nonexistent files or
errors in parsing the other file.  We don't report specifics about the
other file, that should be up to the user to check themselves.
2023-11-29 15:40:14 +00:00
Aryadev Chavali
9b8936ea02 Fixed tokenise_string_literal
Forgot to increment buffer->used and memcpy call was just incorrect.
2023-11-29 15:39:37 +00:00
Aryadev Chavali
ac70d4031c Added function to copy tokens
This essentially just copies the internal string of the token into a
new buffer.
2023-11-29 15:38:57 +00:00
Aryadev Chavali
1cba5ccd8d Added TOKEN_PP_USE to lexer with implementation 2023-11-29 15:38:41 +00:00
Aryadev Chavali
cad92bf3ba Moved preprocessor>Constants to Completed and started work on %USE 2023-11-29 15:37:57 +00:00
Aryadev Chavali
691069fa45 Added todo for preprocessor "%MACRO"
This is different to "%CONST" in that it can take token parameters and
use them.  This allows the construction of user code at compile time,
which can be very useful for a variety of use cases.
2023-11-29 15:36:52 +00:00
Aryadev Chavali
f1fde81b82 Added todo for preprocessor "%USE" blocks
Essentially importing another file *literally* into the file.  This
would happen before parse results are gathered, similar to how
"%CONST" is implemented currently.
2023-11-29 15:36:02 +00:00
Aryadev Chavali
456b9f38f2 Cleaned up todos standard library a bit more 2023-11-29 15:35:44 +00:00
Aryadev Chavali
c9f684cc7d Added string literals in tokeniser
Doesn't do much, invalid for most operations.
2023-11-11 10:16:37 +00:00
Aryadev Chavali
bd6fb54e31 Use constants in examples where possible
Stuff like numeric limits can be codified in constants which act self
documenting.
2023-11-09 08:52:28 +00:00
Aryadev Chavali
f896ad2cb7 Mark off constants as done in TODO.org 2023-11-09 08:52:07 +00:00
Aryadev Chavali
1935277716 Makefile now assembles and interprets instruction-test.asm example first 2023-11-08 18:16:53 +00:00
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