]> rethought.computer Git - sorel-lang.git/commitdiff
add more complete fib-example keep/9529ebabe8a243bb3bc55531a49f9be4165411a5
authorBryan English <bryan@rethought.computer>
Wed, 28 Jan 2026 04:50:38 +0000 (23:50 -0500)
committerBryan English <bryan@rethought.computer>
Tue, 10 Feb 2026 04:08:54 +0000 (04:08 +0000)
hylo-lang/.gitignore
hylo-lang/fib-example/compile.sh [new file with mode: 0644]
hylo-lang/fib-example/fib.hylo [new file with mode: 0644]
hylo-lang/fib-example/putn.c [new file with mode: 0644]

index 7fa3f17db341b2faf225ad5b6de2d7706a7203a9..82f7d40498e6a44bc62d995ff8fc26b17297c289 100644 (file)
@@ -1,2 +1,4 @@
 target
 qemu/machine
+*.o
+*.asm
diff --git a/hylo-lang/fib-example/compile.sh b/hylo-lang/fib-example/compile.sh
new file mode 100644 (file)
index 0000000..933ef72
--- /dev/null
@@ -0,0 +1,4 @@
+../target/debug/hyloc fib.hylo > fib.asm
+riscv64-unknown-linux-gnu-as -o fib.o fib.asm
+riscv64-unknown-linux-gnu-cc -O1 -no-pie -o test fib.o putn.c -nostartfiles 
+./test
diff --git a/hylo-lang/fib-example/fib.hylo b/hylo-lang/fib-example/fib.hylo
new file mode 100644 (file)
index 0000000..2407f15
--- /dev/null
@@ -0,0 +1,24 @@
+\ foo bar
+: fib
+    dup
+    1
+    >
+    if
+        dup
+        1 - fib
+        swap
+        2
+        -
+        fib
+        +
+    endif
+;
+
+0 fib putn drop
+1 fib putn drop
+2 fib putn drop
+3 fib putn drop
+4 fib putn drop
+5 fib putn drop
+6 fib putn drop
+7 fib putn drop
diff --git a/hylo-lang/fib-example/putn.c b/hylo-lang/fib-example/putn.c
new file mode 100644 (file)
index 0000000..201050c
--- /dev/null
@@ -0,0 +1,16 @@
+#include <stdio.h>
+
+extern unsigned long data_stack_end;
+register unsigned long * stack_pointer asm("s2");
+
+void putn() {
+  unsigned long * stack_index = &data_stack_end;
+  printf("stack: ");
+  while (stack_index != stack_pointer) {
+         printf("%ld ", *stack_index);
+    stack_index -= 1;
+  }
+       printf("%ld\n", *stack_pointer);
+}
+
+