summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kdx@42l.fr>2023-03-16 01:03:41 +0100
committerkdx <kdx@42l.fr>2023-03-16 01:03:41 +0100
commit2d32624079bf8c960f17db17e800907462695619 (patch)
treeba87d32eb4dc0640b60e0032d9109a04da92d3f3
parentbfd3c4cf7a324d08e180dce36ea547a51fb50cae (diff)
downloadgolem-2d32624079bf8c960f17db17e800907462695619.tar.gz
local and global merge as let
-rw-r--r--README.md18
-rw-r--r--group.h3
-rw-r--r--identify.c10
-rw-r--r--identify.h3
-rw-r--r--lexer.c6
-rw-r--r--main.c3
-rw-r--r--mvp.golem18
-rw-r--r--token.h3
8 files changed, 26 insertions, 38 deletions
diff --git a/README.md b/README.md
index 5cf75a6..5c10aa3 100644
--- a/README.md
+++ b/README.md
@@ -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]) {
diff --git a/group.h b/group.h
index 051d9b5..edfc7bd 100644
--- a/group.h
+++ b/group.h
@@ -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',
};
diff --git a/identify.c b/identify.c
index f3a102a..fbcdfba 100644
--- a/identify.c
+++ b/identify.c
@@ -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);
}
diff --git a/identify.h b/identify.h
index a70c297..86bd422 100644
--- a/identify.h
+++ b/identify.h
@@ -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);
diff --git a/lexer.c b/lexer.c
index 48b58b3..2297e39 100644
--- a/lexer.c
+++ b/lexer.c
@@ -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;
diff --git a/main.c b/main.c
index a8ad2e2..f1c8a6c 100644
--- a/main.c
+++ b/main.c
@@ -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);
}
diff --git a/mvp.golem b/mvp.golem
index 2ff9be3..3432389 100644
--- a/mvp.golem
+++ b/mvp.golem
@@ -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]) {
diff --git a/token.h b/token.h
index d421176..5afc8cc 100644
--- a/token.h
+++ b/token.h
@@ -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',