summaryrefslogtreecommitdiff
path: root/samples/malloc.golem
diff options
context:
space:
mode:
Diffstat (limited to 'samples/malloc.golem')
-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;