commit 0d5df857d4b85726b8c0bb272fc6fef0a727ac1c from: Benjamin Stürz date: Wed Oct 02 18:37:20 2024 UTC irc: add pub commit - 388764d5d9b81f65b591e7ff8dd8c187b4c7fd5f commit + 0d5df857d4b85726b8c0bb272fc6fef0a727ac1c blob - 7feb311b05ea66737932a84ea795790d8a38e382 blob + 4f23305e9e7be27e144bad3bccb5a7ae6dba821f --- cc/irc/TODO +++ cc/irc/TODO @@ -21,7 +21,6 @@ - register refcnt - optimize memory footprint of irc itself - add global variables -- add `pub` - typecheck function calls - add `extern` functions - add function pointers blob - 21693e9db5bb1de3fd4b22b864482179dc333c5e blob + 98493fda7f5c5faf20099c58dd58caa90463bff0 --- cc/irc/irc.c +++ cc/irc/irc.c @@ -340,6 +340,7 @@ struct func { struct reg regs[NREGS]; struct ir *body; int stoff; + int is_pub; }; // MISC @@ -923,14 +924,22 @@ parse (void) { extern gen (); struct func fn; - int tk; + int tk, is_pub; while ((tk = lex ()) != TK_EOF) { if (tk != TK_IDENT) goto err; + + is_pub = 0; + + if (strcmp (lval.s, "pub") == 0) { + is_pub = 1; + expect (TK_IDENT); + } if (strcmp (lval.s, "fn") == 0) { memset (&fn, 0, sizeof (fn)); + fn.is_pub = is_pub; func (&fn); gen (&fn); reset (); @@ -2052,6 +2061,9 @@ struct func *fn; { struct ir *ir; + if (fn->is_pub) + printf ("global %s\n", fn->name); + printf ("%s:\n", fn->name); puts ("\tpush bp"); puts ("\tmov bp, sp");