summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2023-06-10 18:37:19 +0200
committerkdx <kikoodx@paranoici.org>2023-06-10 18:37:19 +0200
commita4a117871b56e72fc1638c6561d2d3670de929dc (patch)
tree8444924a228fee1c1564f36cb6897606697a5447
parent4f3af2d3b0e7967155324746993b2c283d212147 (diff)
downloadgolem-a4a117871b56e72fc1638c6561d2d3670de929dc.tar.gz
tiny bits
-rw-r--r--samples/helloworld.golem64
-rw-r--r--src/main.c4
2 files changed, 47 insertions, 21 deletions
diff --git a/samples/helloworld.golem b/samples/helloworld.golem
index 5dbc6b5..d1758ac 100644
--- a/samples/helloworld.golem
+++ b/samples/helloworld.golem
@@ -1,21 +1,21 @@
global str[32];
-global str_i = 0;
main() {
local i;
- strappend('H');
- strappend('e');
- strappend('l');
- strappend('l');
- strappend('o');
- strappend(' ');
- strappend('W');
- strappend('o');
- strappend('r');
- strappend('l');
- strappend('d');
- strappend('!');
+ strappend(str, 'H');
+ strappend(str, 'e');
+ strappend(str, 'L');
+ strappend(str, 'l');
+ strappend(str, 'o');
+ strappend(str, ' ');
+ strappend(str, 'W');
+ strappend(str, 'o');
+ strappend(str, 'R');
+ strappend(str, 'l');
+ strappend(str, 'd');
+ strappend(str, '!');
+ strappend(str, '\n');
i = 0;
loop {
@@ -23,22 +23,48 @@ main() {
if (i > 9)
break;
print(str);
- nl();
+ uprint(str);
}
}
-strappend(c) {
- [str+str_i] = c;
- str_i = str_i + 1;
+strappend(s, c) {
+ loop {
+ if ([s] == 0) {
+ [s] = c;
+ return 0;
+ }
+ s = s + 1;
+ }
}
-print(s)
+print(s) {
loop {
if ([s] == 0)
return 0;
wrt [s];
s = s + 1;
}
+}
-nl()
+uprint(s) {
+ loop {
+ if ([s] == 0)
+ return 0;
+ wrt toupper([s]);
+ s = s + 1;
+ }
+}
+
+nl() {
wrt '\n';
+}
+
+toupper(c) {
+ if (c >= 'a' & c <= 'z')
+ return c - 32;
+ return c;
+}
+
+fast_toupper(c) {
+ return c - 32 * (c >= 'a' & c <= 'z');
+}
diff --git a/src/main.c b/src/main.c
index 978dd31..ecb539a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -87,7 +87,7 @@ is_punct(const char *p)
if (strchr("=!<>", p[0]) != NULL && p[1] == '=')
return 2;
- return (strchr("+-/*()<>,;{}[]=", p[0]) != NULL);
+ return (strchr("+-/*()<>,;{}[]=&^|", p[0]) != NULL);
}
static Token *
@@ -714,7 +714,7 @@ gen_expr(Node *node)
case NOD_EQU: op = "EQU"; break;
case NOD_NEQ: op = "NEQ"; break;
case NOD_LT: op = "LTH"; break;
- case NOD_LE: op = "GTH NOT"; break;
+ case NOD_LE: op = "GTH LIT 0001 XOR"; break;
case NOD_AND: op = "AND"; break;
case NOD_OR: op = "OR"; break;
case NOD_XOR: op = "XOR"; break;