diff options
author | kdx <kdx@42l.fr> | 2023-03-16 01:03:41 +0100 |
---|---|---|
committer | kdx <kdx@42l.fr> | 2023-03-16 01:03:41 +0100 |
commit | 2d32624079bf8c960f17db17e800907462695619 (patch) | |
tree | ba87d32eb4dc0640b60e0032d9109a04da92d3f3 | |
parent | bfd3c4cf7a324d08e180dce36ea547a51fb50cae (diff) | |
download | golem-2d32624079bf8c960f17db17e800907462695619.tar.gz |
local and global merge as let
-rw-r--r-- | README.md | 18 | ||||
-rw-r--r-- | group.h | 3 | ||||
-rw-r--r-- | identify.c | 10 | ||||
-rw-r--r-- | identify.h | 3 | ||||
-rw-r--r-- | lexer.c | 6 | ||||
-rw-r--r-- | main.c | 3 | ||||
-rw-r--r-- | mvp.golem | 18 | ||||
-rw-r--r-- | token.h | 3 |
8 files changed, 26 insertions, 38 deletions
@@ -10,12 +10,12 @@ Work in progress bytecode language created by and for [kdx](https://kdx.re). // The weird mixture of C and Lisp is a feature, I swear. // Global scope is initialized to zero. -global g_heap; -global g_another g_one; +let g_heap; +let g_another g_one; main argc argv { - local hello; - local world; + let hello; + let world; g_heap = 8000; hello = (strdup "bonjour");;; @@ -28,7 +28,7 @@ main argc argv { } alloc size { - local ptr; + let ptr; ptr = g_heap; g_heap = (add g_heap size); @@ -37,14 +37,14 @@ alloc size { } strdup str { - local dest; - local i; + let dest; + let i; dest = (alloc (add [str 0] 1)); i = 0; while (lesseq i [str 0]) { - local smile please; + let smile please; [dest i] = [str i]; i = (add i 1); @@ -54,7 +54,7 @@ strdup str { } print str { - local i; + let i; i = 1; while (lesseq i [str 0]) { @@ -6,8 +6,7 @@ enum { GROUP_ATOM = 'a', GROUP_FUNCTION = 'f', GROUP_ASSIGN = '=', - GROUP_DEC_LOCAL = 'l', - GROUP_DEC_GLOBAL = 'g', + GROUP_LET = 'l', GROUP_DEREF = 'd', }; @@ -44,13 +44,7 @@ identify_function(Token **list) } int -identify_global(Token **list) +identify_let(Token **list) { - return identify_dec(list, TOK_KW_GLOBAL); -} - -int -identify_local(Token **list) -{ - return identify_dec(list, TOK_KW_LOCAL); + return identify_dec(list, TOK_KW_LET); } @@ -3,5 +3,4 @@ void identify(Token *list, int (*fun)(Token**), unsigned int type, int recurse); int identify_function(Token **list); -int identify_global(Token **list); -int identify_local(Token **list); +int identify_let(Token **list); @@ -92,12 +92,10 @@ lexer(Slice slice) type = TOK_KW_IF; else if (slice_equal(word, slice_from_str("else"))) type = TOK_KW_ELSE; - else if (slice_equal(word, slice_from_str("local"))) - type = TOK_KW_LOCAL; + else if (slice_equal(word, slice_from_str("let"))) + type = TOK_KW_LET; else if (slice_equal(word, slice_from_str("return"))) type = TOK_KW_RETURN; - else if (slice_equal(word, slice_from_str("global"))) - type = TOK_KW_GLOBAL; token_append(&toks, token_create(word, type)); i = word.end; @@ -38,8 +38,7 @@ main(int argc, char **argv) group_scope(&tokens); group_atom(&tokens); identify(tokens, identify_function, GROUP_FUNCTION, 0); - identify(tokens, identify_global, GROUP_DEC_GLOBAL, 0); - identify(tokens, identify_local, GROUP_DEC_LOCAL, 1); + identify(tokens, identify_let, GROUP_LET, 1); token_print(tokens, 1, 0); token_destroy(tokens); } @@ -3,12 +3,12 @@ // The weird mixture of C and Lisp is a feature, I swear. // Global scope is initialized to zero. -global g_heap; -global g_another g_one; +let g_heap; +let g_another g_one; main argc argv { - local hello; - local world; + let hello; + let world; g_heap = 8000; hello = (strdup "bonjour");;; @@ -21,7 +21,7 @@ main argc argv { } alloc size { - local ptr; + let ptr; ptr = g_heap; g_heap = (add g_heap size); @@ -30,14 +30,14 @@ alloc size { } strdup str { - local dest; - local i; + let dest; + let i; dest = (alloc (add [str 0] 1)); i = 0; while (lesseq i [str 0]) { - local smile please; + let smile please; [dest i] = [str i]; i = (add i 1); @@ -47,7 +47,7 @@ strdup str { } print str { - local i; + let i; i = 1; while (lesseq i [str 0]) { @@ -17,8 +17,7 @@ enum { TOK_CHARACTER = 'a', TOK_STRING = 's', TOK_WORD = 'w', - TOK_KW_LOCAL = 'L', - TOK_KW_GLOBAL = 'G', + TOK_KW_LET = 'L', TOK_KW_IF = 'I', TOK_KW_ELSE = 'E', TOK_KW_WHILE = 'W', |