sd:tinyc_developer_diary
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| sd:tinyc_developer_diary [2026/04/22 09:35] – appledog | sd:tinyc_developer_diary [2026/04/22 17:14] (current) – appledog | ||
|---|---|---|---|
| Line 829: | Line 829: | ||
| 2. In parse function, emit_call, anything to do with backpatching, | 2. In parse function, emit_call, anything to do with backpatching, | ||
| + | |||
| + | 3. Anything which touches HERE or offset 18 of the symbol table. This is an easy search for ex. LDA [@HERE]. | ||
| It took a couple of hours. As I ran through various tests it struck me that there are a series of tests I went through a couple of times before to verify things work. As I ran through them again I had the insight to write them down. | It took a couple of hours. As I ran through various tests it struck me that there are a series of tests I went through a couple of times before to verify things work. As I ran through them again I had the insight to write them down. | ||
| - | === C Test programs | + | === TinyC Test programs |
| These provide the test cases I used to check my compiler. In order. | These provide the test cases I used to check my compiler. In order. | ||
| - | === First | + | ==== First |
| + | < | ||
| int main(void) { return 0; } | int main(void) { return 0; } | ||
| + | </ | ||
| - | === Symbol table | + | ==== Symbol table |
| + | < | ||
| int main(void) { int a = 5; return a; } | int main(void) { int a = 5; return a; } | ||
| + | </ | ||
| - | === Globals | + | 24 bit: |
| + | < | ||
| + | .clear | ||
| + | int main(void) { | ||
| + | int a = 0x123456; | ||
| + | return a; | ||
| + | } | ||
| + | .compile | ||
| + | .run | ||
| + | </ | ||
| + | |||
| + | ==== Globals | ||
| We can't define them when we make them. It seems like I did something wrong here but I don't know how to fix it. Just define them in main. Whoop de doo. | We can't define them when we make them. It seems like I did something wrong here but I don't know how to fix it. Just define them in main. Whoop de doo. | ||
| + | < | ||
| int g; | int g; | ||
| int main(void) { | int main(void) { | ||
| Line 849: | Line 867: | ||
| return g; | return g; | ||
| } | } | ||
| + | </ | ||
| - | === function call | + | ==== function call |
| + | < | ||
| int a(int x) { return x + 1; } | int a(int x) { return x + 1; } | ||
| int main(void) { return a(41); } | int main(void) { return a(41); } | ||
| + | </ | ||
| + | two arguments: | ||
| - | === Forward Declarations | + | < |
| + | .clear | ||
| + | int add(int a, int b) { return a + b; } | ||
| + | int main(void) { return add(20, 22); } | ||
| + | .compile | ||
| + | .run | ||
| + | </ | ||
| + | |||
| + | ==== Forward Declarations | ||
| Single | Single | ||
| - | | + | < |
| - | int main(void) { return a(41); } | + | int a(int x); |
| - | int helper(int x) { return x + 1; } | + | int main(void) { return a(41); } |
| + | int helper(int x) { return x + 1; } | ||
| + | </ | ||
| multiple | multiple | ||
| - | | + | < |
| - | int main(void) { | + | int a(); |
| - | return a() + a(); | + | int main(void) { |
| - | } | + | return a() + a(); |
| - | int a() { return 5; } | + | } |
| + | int a() { return 5; } | ||
| + | </ | ||
| + | ==== Recursion | ||
| + | < | ||
| + | int even(int n); | ||
| + | int odd(int n); | ||
| + | int even(int n) { if (n == 0) { return 1; } return odd(n - 1); } | ||
| + | int odd(int n) { if (n == 0) { return 0; } return even(n - 1); } | ||
| + | int main(void) { return even(10); } | ||
| + | </ | ||
| + | |||
| + | ==== Built-in functions | ||
| + | < | ||
| + | int main(void) { | ||
| + | putchar(' | ||
| + | putchar(' | ||
| + | return 0; | ||
| + | } | ||
| + | </ | ||
| - | === Recursion | + | === Re-wiring pointers |
| - | int even(int n); | + | Unfortunately the changes were far more in depth than I expected, and I had to spend an additional ten hours going over the code to fix pointers, the lexer, and everything in between. Oh, and yet more emitters I forgot needed to be changed. Even the REPL itself didn't print out the full return |
| - | int odd(int n); | + | |
| - | int even(int n) { if (n == 0) { return | + | |
| - | int odd(int n) { if (n == 0) { return 0; } return | + | |
| - | int main(void) { return even(10); } | + | |
sd/tinyc_developer_diary.1776850552.txt.gz · Last modified: by appledog
