398 Commits

Author SHA1 Message Date
Aryadev Chavali
19dc289bb3 Preprocesser: Print lexer error 2024-07-10 02:15:11 +01:00
Aryadev Chavali
82d9eeb190 Preprocesser: do not add file body if there's nothing there
Before this if a file only defined constants and was then included,
the root unit set would still have an empty PP_USE unit.  We should
only have that if there's something there past preprocessing.  Hence,
do not add empty bodies to the unit list.
2024-07-10 02:15:11 +01:00
Aryadev Chavali
3bf7130eda Tidy up a bit 2024-07-10 02:15:11 +01:00
Aryadev Chavali
5b35383edf Preprocesser: Better redefining of constants
A constant can only be redefined by a file that is closer to the root.
If a constant is defined at depth n, it can only be redefined at
depths lower than n.
2024-07-10 02:09:12 +01:00
Aryadev Chavali
d54bea3276 Preprocesser: Fix memory leak in including another file
Fixed a memory leak when included files had an error in lexing due to
not adding them to the token bag before error handling.
2024-07-10 01:36:37 +01:00
Aryadev Chavali
6c3bd47c04 Update Makefile to be more like AVM Makefile
Less colours more information, easier to decode.
2024-07-10 00:42:59 +01:00
Aryadev Chavali
1ad3fdadb4 Update examples for change in memory allocation operations 2024-07-10 00:42:56 +01:00
Aryadev Chavali
c4489af073 Use INFO macro from base.h
Instead of using TERM_YELLOW directly, along with C++'s shit stream
based I/O, let's just use the nice macro defined in base.h
2024-07-10 00:42:56 +01:00
Aryadev Chavali
b7d232720a Update lexer for changes in avm
Added support for shorts, changed semantics around the memory
allocation operations and removed CALL_STACK and JUMP_STACK.
2024-07-07 19:40:17 +01:00
Aryadev Chavali
192ec4df9c Push AVM to latest commit 2024-07-07 19:40:17 +01:00
Aryadev Chavali
d4d2b4715d Update gitignore and dir locals 2024-07-07 19:08:31 +01:00
Aryadev Chavali
aa507a417a Update LOC in README 2024-07-07 19:08:23 +01:00
Aryadev Chavali
e6c659a14d Update TODOs 2024-07-07 19:08:09 +01:00
Aryadev Chavali
6ae0bbedc5 Plug preprocesser into main 2024-07-07 19:06:56 +01:00
Aryadev Chavali
a422c7d1dc A reworked preprocesser with focus on stopping recursive errors
Preprocesser requires one function to use: preprocess.  Takes Tokens
and gives back Units.

A unit is a tree of tokens, where each unit is a node in that tree.  A
unit has a "root" token (value of node) and an "expansion" (children
of node) where the root is some preprocesser token (such as a
reference or USE call) and the expansion is the tokens it yields.  In
the case of a USE call this is the tokens of the file it includes, in
the case of a reference it's the tokens of the constant it refers to.
This means that the leaves of the tree of units are the completely
preprocessed/expanded form of the source code.

The function has many working components, which may need to be
extracted.  In particular, the function ensures we don't include a
source twice through a hash map and that constants are not redefined
in inner include scopes if they're already defined in outer
scopes (i.e. if compiling a.asm which defines constant N, then include
b.asm which defines constant N, then N uses the definition of a.asm
rather than b.asm).

I need to make a spec for this.
2024-07-06 17:38:02 +01:00
Aryadev Chavali
1145b97c4c Token to_string now include source name and is printed error style
So instead of the previous weird format, we have the format
<source_name>:<line>:<column>: <TYPE> which also allows me to quickly
go to that token via Emacs' (compile).
2024-07-06 17:36:58 +01:00
Aryadev Chavali
f9acb23671 Lexer errors contain the source name and tokenise_symbol refactor 2024-07-05 22:47:25 +01:00
Aryadev Chavali
036ac03176 Lexer tokens now include source name as part of the token 2024-07-05 18:18:11 +01:00
Aryadev Chavali
65ce50f620 Fix copyright notices and includes 2024-07-03 16:55:19 +01:00
Aryadev Chavali
15d39dcfe7 Reworked lexer to deal with invalid type suffixes
Now ~push.magic~ will result in an error about it being an invalid
type suffix.
2024-07-03 16:55:19 +01:00
Aryadev Chavali
42dbf515f0 Deleted preprocesser
Will be reworking it later
2024-07-03 16:55:19 +01:00
Aryadev Chavali
683636c66d Rewriting lexer TODO 2024-06-01 14:37:06 +01:00
Aryadev Chavali
76bb5ec7d9 (Lexer)+to_string functions for Err, Err::Type 2024-06-01 13:53:54 +01:00
Aryadev Chavali
4625b3b7a5 (Lexer)+to_string functions for Token, Token::Type 2024-06-01 13:51:10 +01:00
Aryadev Chavali
a4689f9dd0 Lexer call pattern is now Err return with reference to token 2024-06-01 13:40:17 +01:00
Aryadev Chavali
7e9af309e3 lerr_t and lerr_type_t -> Lexer::Err and Lexer::Err::Type 2024-06-01 13:40:17 +01:00
Aryadev Chavali
4b85f90a52 Namespace the lexer module
Future proofing any name collisions.
2024-06-01 01:52:17 +01:00
Aryadev Chavali
83ad8b832b token_type_t -> Token::Type
Implicit namespacing using the struct
2024-06-01 01:49:24 +01:00
Aryadev Chavali
f5d8777b7a token_t -> Token
Use C++'s implicit typedef
2024-06-01 01:48:11 +01:00
Aryadev Chavali
f3f7578811 Update lexer trivially
HALT is now an opcode, which we deal with already.
2024-06-01 01:47:16 +01:00
Aryadev Chavali
bbb8ed1337 Merge remote-tracking branch 'github/master' 2024-06-01 01:20:16 +01:00
Aryadev Chavali
2d5d8c7904 Update AVM and clean dir-locals 2024-06-01 01:18:56 +01:00
Aryadev Chavali
1ce5bf556e Update AVM 2024-04-16 20:52:32 +06:30
Aryadev Chavali
52843e2e14 Removed workflow as it doesn't work with submodules 2024-04-16 20:43:56 +06:30
Aryadev Chavali
f060a856d3 Fixed Makefile so it tracks dependencies better
It now tracks main.cpp's dependencies and rebuilds them as needed.
2024-04-16 20:42:51 +06:30
Aryadev Chavali
190bb766cb Added a TODO to write a specification for the assembly language 2024-04-16 19:18:35 +06:30
Aryadev Chavali
3b9e573c4a Made AVM a git submodule, updated the Makefile to build assembler
Also updated dir-locals to make include path resolution accurate.
2024-04-16 19:18:32 +06:30
Aryadev Chavali
9d72c9177d Clean up work tree for making assembler 2024-04-16 19:14:24 +06:30
Aryadev Chavali
2a1d006a88 Updated README about change to project 2024-04-16 15:49:26 +06:30
Aryadev Chavali
8f75241bcb Halting work on preprocesser units and rewrite as a whole
I've decided to split the project into 2 repositories: the assembler
and the runtime.  The runtime will contain both the executable and
lib/ while the assembler will have the runtime as a git submodule and
use it to build.  I think this is a clean solution, a lot cleaner than
having them all in one project where the Makefile has to massively
expand.
2024-04-16 15:42:59 +06:30
Aryadev Chavali
d5c43b1c3f Wrote up some notes on how preprocesser language may work
Bit formal and really excessively written but I needed my thoughts
down.
2024-04-16 15:42:34 +06:30
Aryadev Chavali
715facf015 Updated README lines of code 2024-04-16 15:42:22 +06:30
Aryadev Chavali
4ecd184759 lerr_type_t::UNKNOWN_CHAR -> UNKNOWN_LEXEME 2024-04-16 15:41:01 +06:30
Aryadev Chavali
27d6a47320 Clean up error message from preprocesser 2024-04-16 15:40:49 +06:30
Aryadev Chavali
3fc1f08134 Fix bug where CONST table didn't actually store symbol names
Pretty simple fix, stupid error in hindsight.
2024-04-16 15:40:00 +06:30
Aryadev Chavali
4b3e9b3567 Clear vector after deleting all tokens
Ensures that iteration over vec_out by caller doesn't occur (such as
in a loop to free the memory).
2024-04-16 15:39:20 +06:30
Aryadev Chavali
05136fdd25 Fixed examples for changes in lexer
Name assigned to %CONST is the next symbol in stream, not the symbol
attached to it.
2024-04-16 15:38:24 +06:30
Aryadev Chavali
1e7f1bdee9 Changed %const format in preprocesser now
Instead of %const(<name>) ... %end it will now be %const <name>
... %end i.e. the first symbol after %const will be considered the
name of the constant similar to %use.
2024-04-15 18:39:37 +06:30
Aryadev Chavali
ba3525d533 preprocesser publicly exposes only preprocesser function
The preprocess_* functions are now privately contained within the
implementation file to help the preprocesser outer function.

Furthermore I've simplified the API of the preprocess_* functions by
making them only return pp_err_t and store their results in a vector
parameter taken by reference.
2024-04-15 18:37:45 +06:30
Aryadev Chavali
d594c0c531 Annotate some completed todos in todo.org 2024-04-15 16:35:44 +06:30