User Tools

Site Tools


mbstring extension must be loaded in order to run mPDF
sd:tinyc_developer_diary

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
sd:tinyc_developer_diary [2026/04/22 09:41] appledogsd:tinyc_developer_diary [2026/04/22 17:14] (current) appledog
Line 837: Line 837:
 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 
 +<code>
 int main(void) { return 0; } int main(void) { return 0; }
 +</code>
  
-=== Symbol table+==== Symbol table 
 +<code>
 int main(void) { int a = 5; return a; } int main(void) { int a = 5; return a; }
 +</code>
  
-=== Globals+24 bit: 
 +<code> 
 +.clear 
 +int main(void) {  
 +    int a = 0x123456;  
 +    return a;  
 +
 +.compile 
 +.run 
 +</code> 
 + 
 +==== 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.
  
 +<code>
 int g; int g;
 int main(void) { int main(void) {
Line 851: Line 867:
     return g;     return g;
 } }
 +</code>
  
-=== function call+==== function call 
 +<code>
 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); }
 +</code>
  
 +two arguments:
  
-=== Forward Declarations+<code> 
 +.clear 
 +int add(int a, int b) { return a + b; } 
 +int main(void) { return add(20, 22); } 
 +.compile 
 +.run 
 +</code> 
 + 
 +==== Forward Declarations
 Single Single
  
-    int a(int x); +<code> 
-    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; } 
 +</code>
  
 multiple multiple
  
-    int a(); +<code> 
-    int main(void) { +int a(); 
-        return a() + a(); +int main(void) { 
-    +    return a() + a(); 
-    int a() { return 5; }+
 +int a() { return 5; } 
 +</code>
  
 +==== Recursion
 +<code>
 +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); }
 +</code>
 +
 +==== Built-in functions
 +<code>
 +int main(void) {
 +    putchar('h');
 +    putchar('i');
 +    return 0;
 +}
 +</code>
  
-=== 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 value. This makes me reconsider my choice to go with a 16 bit system. Should the SD-8516 have been 32 bit? Maybe, maybe not. In the end, it works. A 16 bit system can run a 32 bit c, no problem. I mean, look at Commodore BASIC 2.0. It used floats for ints. Steve Wozniak even made a Sweet-16 so that it could use 16 bit registers. We can do 32 bit in the languages. No problem. We are not going to get any practical advantage from going 32 bit internal since we're running on WASM which is 64 bit native anyways. See? We can have our cake and eat it too here.
-    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); }+
sd/tinyc_developer_diary.1776850905.txt.gz · Last modified: by appledog

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki