Commit graph

86 commits

Author SHA1 Message Date
f54ecb75b9 Make linking and final compile to byte sequence work 2025-07-03 16:58:29 +02:00
f9a69e2da9 Add macro for iterating over ASM-OBJECTs 2025-07-03 16:57:33 +02:00
0117df02f8 Indentation correction 2025-07-03 16:57:20 +02:00
771748d2c2 Compute addresses for all ASM-OBJECTs 2025-07-03 16:56:49 +02:00
a24c5353a5 Add compilation method for IR-IF 2025-07-03 16:56:32 +02:00
3876801960 Add compilation method for IR-JUMP 2025-07-03 16:56:10 +02:00
f9d8ad13d0 Add compilation method for IR-TEST-EQUAL 2025-07-03 16:55:39 +02:00
dda08e6fe7 Make all ASM-OBJECTs hold an address, not just labels 2025-07-03 16:54:49 +02:00
f38d74db4f Correct byte length of a JSR 2025-07-03 16:54:40 +02:00
d88107a209 Add functions for handling bools during code generation 2025-07-03 16:54:22 +02:00
f54e064fda Make ASM-FUNCTION hold an address to be called 2025-07-03 16:53:00 +02:00
3b8c906d75 Store ASM-FUNCTIONs in a hash table keyed on name
TODO: Populate the table based on the asm source code declaration
comments and signal an error when a named function is missing.
2025-07-03 16:51:47 +02:00
094f01d258 Ensure IBLOCK names are unique 2025-07-03 15:59:41 +02:00
7171398c07 Fix broken IR graph flow with merge iblocks 2025-07-03 15:58:56 +02:00
235ca8c07e Rename EMIT-STORE-RESULT's parameter to match similar functions 2025-07-03 10:54:21 +02:00
54d2341ce3 Add code-generator.lisp to ASD 2025-07-03 10:30:14 +02:00
f1cf8ad488 Add alexandria dependency 2025-07-03 10:30:14 +02:00
4899d888aa Add COMPILE-IR method for IR-RETURN 2025-07-03 10:30:14 +02:00
c41fb46457 Make assembly program representation smarter
Storing assembly instructions in a list felt nice since that lets me
just fire and forget, but if we want to properly optimize short
branches (i.e. branches that do not require a full JMP) we'll need to
be able to rewrite assembly after linking, and I feel that's best done
by making assembly instructions hold a NEXT rather than poking at a
list clumsily.

The first linking pass was also moved out to a separate function since
we may want to run the first pass twice, first after the initial
assembling and second after expanding optimistic short branches (those
that turned out to be longer branches than 127/128 bytes) into a long
branch snippet (branch with inverted condition skipping over a JMP).
2025-07-03 10:30:14 +02:00
7d55bc9ed8 Add extremely unfinished 6502 code generator to user-side compiler 2025-07-01 23:12:20 +02:00
f8f5892d98 Somewhat clunky optimization for reusing temporary variable slots 2025-07-01 20:39:09 +02:00
a18c13a86e Add value allocator (typically called register allocator)
It's unfinished and doesn't optimize space used by temporary
variables. Every temporary gets its own memory slot right now.
2025-07-01 13:38:31 +02:00
bdb2a901ca Add more optimization passes to a test snippet 2025-07-01 13:27:24 +02:00
7aff9db800 Add compiler optimization to get rid of IR-FETCHVARs when unneeded
It replaces the IR-FETCHVAR's result with the variable being
fetched. This only works when the only use is in an operation that
does not require a separate fetch be performed, such as those
implemented as CPU instructions.
2025-07-01 13:25:42 +02:00
b7c4a37483 Make data keep track of their last use 2025-07-01 13:22:24 +02:00
9e643e6c6d Add compiler middle stage
The compiler middle stage takes high level nodes and produces code in
an intermediate representation more closely resembling assembly code.

Optimizations and the tools for making those are also included. It's
significantly easier to optimize IR than syntax trees or assembly.

Several things need cleaning up, in particular there are things in
jigs.lisp that really should be documented tools, not
jigs (specifically the compilation setup and finalization).
2025-06-26 13:41:43 +02:00
7703c71141 Add tool for quickly defining common PRINT-OBJECT methods 2025-06-26 12:44:43 +02:00
2c529c368a Reorder parsing so calls get properly parsed inside expressions 2025-06-21 21:04:26 +02:00
4011e3b0db Reorder loading of high-level.lisp 2025-06-21 21:02:58 +02:00
61ea8b3773 Move NODE-CONDITIONAL definition to proper place 2025-06-19 15:07:23 +02:00
2b94745734 Some little cleanup 2025-06-13 09:19:00 +02:00
928cdfd318 Add user-side compiler's parser
It ingests tokens via a "token stream", and feeds out a node
tree. It's a mostly handwritten recursive descent parser with the
occasional Lisp macros for convenience.
2025-05-22 13:14:55 +02:00
f9f2694b96 Add two more code examples 2025-05-22 13:14:55 +02:00
08f9cc4a11 Remove premature code generation from high-level and add new nodes
The new nodes are more directly representational of the syntax, and
code generation will be moved to an intermediate stage with a more
linear (yet still node-based) representation.
2025-05-22 13:14:55 +02:00
3f3d94367f Add PRINT-OBJECT method to TOKEN-NUMBER 2025-05-22 13:14:55 +02:00
12d1a905fe Add stub ASM-FUNCTION class 2025-05-22 13:14:55 +02:00
38406c80ee Add various transformation rules 2025-05-22 13:14:55 +02:00
ebe27cf026 Make methods for nodes to list their potential next nodes 2025-05-22 13:14:55 +02:00
4bf1316536 Half-baked and half-hearted attempt to let nodes hold comments 2025-05-22 13:14:55 +02:00
57c2978b71 Adjust reference PRINT-OBJECTs to not error on unbound slots 2025-05-22 13:14:55 +02:00
3c8835eb7b Make references able to hold a name 2025-05-22 13:14:55 +02:00
7639263bed Make TRANSFORM return OBJ if it's already TO-TYPE 2025-05-22 13:14:55 +02:00
1307e31268 Better handling of operators, source, and comments in tokenizer
...among other minor changes to accomodate the parser.
2025-05-22 13:14:55 +02:00
8acbf2caec Define more atomic tokens, and add shortcut macro for doing it 2025-05-22 13:14:55 +02:00
ae39a48890 Add PRINT-OBJECT method for TOKEN-NAME 2025-05-22 13:14:55 +02:00
25fd7675d0 Rename TOKEN-NAME's TEXT slot to NAME to match TOKEN-KEYWORD 2025-05-22 13:14:55 +02:00
45a66ce323 Give tokens an INITFORM for SOURCE (to NIL) 2025-05-22 13:14:55 +02:00
5a18cc9864 Make NODE-DOTIMES hold a counter variable 2025-05-22 13:14:55 +02:00
6b74c0247e Move and rename syntax-example.txt 2025-05-22 13:14:55 +02:00
e6e2e94404 Add symbol table 2025-05-16 21:00:57 +02:00