Commit graph

108 commits

Author SHA1 Message Date
dd3fe5369d Fix column off-by-one error in source tracking 2025-07-09 14:37:25 +02:00
c3dc447fe4 Remove any trace of the attempt to parse in C6L comments 2025-07-09 14:36:47 +02:00
b65012ed04 Remove warning for uncompilable operations, these should be errors 2025-07-09 14:34:57 +02:00
ea31bac351 Fix compilation of loops with variable as stop value
It was previously decided that, since the language is not to be
Turing-complete, a loop that takes a variable for its upper bound
should use the variable's value at the time of the loop's start, not
look it up. I forgot this while writing the syntax->IR compiler, so
loops with non-constant stop counts failed to compile.
2025-07-09 13:32:00 +02:00
857fa43df0 Allow names to start with underscore 2025-07-08 13:41:16 +02:00
09dc731444 Add code to populate asm function table using listing declarations 2025-07-08 12:53:18 +02:00
4d6ad30eae Add some proper error handling to user-side compiler 2025-07-07 19:44:57 +02:00
b5fa71c710 Add test program that stores test result for use in later IF 2025-07-07 15:51:56 +02:00
615c66f304 Add remaining arithmetic comparisons (and test program) to USC 2025-07-07 15:51:11 +02:00
4a52ff534f Remove now unused and useless functions from compiler backend 2025-07-07 14:37:45 +02:00
92f2b02675 Add COMPILE-IR methods for remaining arithmetic tests 2025-07-06 22:37:37 +02:00
ccd06bc8cb Fix typo that makes a comment confusing 2025-07-06 22:30:03 +02:00
016d7ededd Various additions and changes to compiler backend for IFs and calls
Branching now exists in a general way (work for tests requiring
multiple branch instructions still needed) that works for both storing
test results and taking branches in code.

De-duplicated arguments to calls now load correctly.
2025-07-06 22:26:34 +02:00
9685f00e10 Make value allocator aware of normal values used in branching
This way we avoid allocating and using a temporary variable when
branching based on the contents of a variable.
2025-07-06 22:22:18 +02:00
b1b7d863b5 Fix parser for "if <variable name> then" 2025-07-06 22:21:59 +02:00
5d9932637d Fix parser for empty argument lists 2025-07-06 22:21:40 +02:00
156edc2f09 Rethink how data works at the assembly code generation level 2025-07-06 19:04:36 +02:00
99d1156e7d Add PRINT-OBJECT method to ASM-FUNCTION 2025-07-06 18:55:27 +02:00
fa4458e2d7 Add example-3.c6l 2025-07-04 11:21:29 +02:00
76cd607bab Add COMPILE-IR method for IR-MINUS 2025-07-03 20:12:59 +02:00
f814f9fbb9 Some horrible flailing for the sake of correctness 2025-07-03 20:11:08 +02:00
c668f4fc78 Some cleanup after deleted code 2025-07-03 19:54:15 +02:00
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