summaryrefslogtreecommitdiff
path: root/samples
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2023-06-15 03:04:15 +0200
committerkdx <kikoodx@paranoici.org>2023-06-15 03:04:15 +0200
commit3f00f1d38eb87f02f5e147b1f4b65d55424a1357 (patch)
treee8986637b2415e3eb2b9b5febd0f30ef840d2c67 /samples
parent69aa1b02d3064813da5d19b13ffef231501d58ca (diff)
downloadgolem-3f00f1d38eb87f02f5e147b1f4b65d55424a1357.tar.gz
rewrite malloc example
Diffstat (limited to 'samples')
-rw-r--r--samples/malloc.golem33
1 files changed, 19 insertions, 14 deletions
diff --git a/samples/malloc.golem b/samples/malloc.golem
index 27502d4..a52d51e 100644
--- a/samples/malloc.golem
+++ b/samples/malloc.golem
@@ -1,18 +1,21 @@
-main() {
+main() => nopipe() |> pipe();
+
+nopipe() {
local s;
- s = strdup("coucou le monde");
- dbg s;
- puts(s);
+ s = strdup("yo comment cava\n");
+ write(s);
stoupper(s);
- puts(s);
+ write(s);
}
-puts(s) {
+pipe() => strdup("coucou le monde\n") |> write() |> stoupper() |> write();
+
+write(s) {
+ local o;
+ o = s;
loop {
- if ([s] == 0) {
- wrt '\n';
- return 0;
- }
+ if ([s] == 0)
+ return o;
wrt [s];
s = s + 1;
}
@@ -22,9 +25,8 @@ strlen(s) {
local len;
len = 0;
loop {
- if ([s + len] == 0) {
+ if ([s + len] == 0)
return len;
- }
len = len + 1;
}
}
@@ -45,8 +47,11 @@ strcpy(dst, src) {
}
stoupper(s) {
+ local o;
+ o = s;
loop {
- if ([s] == 0) return 0;
+ if ([s] == 0)
+ return o;
[s] = [s] - ([s] >= 'a' & [s] <= 'z') * 32;
s = s + 1;
}
@@ -60,7 +65,7 @@ malloc(n) {
p = heap + heap_size;
heap_size = heap_size + n;
if (heap_size > 4096) {
- puts("malloc error: heap is full");
+ write("malloc error: heap is full");
return 0;
}
return p;