diff options
author | kdx <kikoodx@paranoici.org> | 2023-06-10 01:56:21 +0200 |
---|---|---|
committer | kdx <kikoodx@paranoici.org> | 2023-06-10 02:02:33 +0200 |
commit | 7c0d15878c7e9ed459bebd10737499b9667f6b21 (patch) | |
tree | 6f7e2481c8e7e00cb919995de9988e406a88e4fd | |
parent | db48a58769ac267a8de49f456cb4e5b27bfddb40 (diff) | |
download | golem-7c0d15878c7e9ed459bebd10737499b9667f6b21.tar.gz |
wrt builtin
-rw-r--r-- | src/main.c | 26 | ||||
-rwxr-xr-x | testing.sh | 1 |
2 files changed, 23 insertions, 4 deletions
@@ -117,6 +117,13 @@ tokenize(char *p) continue; } + if (strncmp(p, "'\\n'", 4) == 0) { + cur = cur->next = new_token(TOK_NUM, p, p + 4); + cur->val = '\n'; + p += 4; + continue; + } + const int punct = is_punct(p); if (punct) { cur = cur->next = new_token(TOK_PUNCT, p, p + punct); @@ -169,6 +176,12 @@ struct Node { int len; }; +static bool +node_equal(const Node *node, const char *op) +{ + return memcmp(node->loc, op, node->len) == 0 && op[node->len] == '\0'; +} + static Node * new_node(NodeType type) { @@ -477,7 +490,7 @@ static void gen_expr(Node *node) { if (node->type == NOD_NUM) { - printf("\tLIT %04d\n", node->val); + printf("\tLIT %04x\n", node->val); depth += 1; return; } @@ -532,7 +545,7 @@ static void gen_globaldec(Node *node) { printf("@__gl_%.*s\n", node->len, node->loc); - printf("\tLIT %04d\n", node->val); + printf("\tLIT %04x\n", node->val); } static void @@ -544,8 +557,13 @@ gen_fncall(Node *node) depth -= 1; cur = cur->next; } - printf("\tJRT ,__fn_%.*s\n", node->len, node->loc); - depth += 1; + if (node_equal(node, "wrt")) { + printf("\tWRT\n\tLIT 0000\n"); + depth += 1; + } else { + printf("\tJRT ,__fn_%.*s\n", node->len, node->loc); + depth += 1; + } } static void @@ -20,4 +20,5 @@ test "$1" "global abc; main(){ return abc; }" test "$1" "global abc = 5; main(){ return abc; }" test "$1" "main(){ return abc; } global abc = 5;" test "$1" "global abc = 5; main(){ inc(); return abc; } inc() { abc = abc + 1; }" +test "$1" "main() { wrt('H'); wrt('e'); wrt('l'); wrt('l'); wrt('o'); wrt('!'); wrt('\n'); }" rm -f build/tmp.* |