From 9529ebabe8a243bb3bc55531a49f9be4165411a5 Mon Sep 17 00:00:00 2001 From: Bryan English Date: Tue, 27 Jan 2026 23:50:38 -0500 Subject: [PATCH] add more complete fib-example --- hylo-lang/.gitignore | 2 ++ hylo-lang/fib-example/compile.sh | 4 ++++ hylo-lang/fib-example/fib.hylo | 24 ++++++++++++++++++++++++ hylo-lang/fib-example/putn.c | 16 ++++++++++++++++ 4 files changed, 46 insertions(+) create mode 100644 hylo-lang/fib-example/compile.sh create mode 100644 hylo-lang/fib-example/fib.hylo create mode 100644 hylo-lang/fib-example/putn.c diff --git a/hylo-lang/.gitignore b/hylo-lang/.gitignore index 7fa3f17..82f7d40 100644 --- a/hylo-lang/.gitignore +++ b/hylo-lang/.gitignore @@ -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 index 0000000..933ef72 --- /dev/null +++ b/hylo-lang/fib-example/compile.sh @@ -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 index 0000000..2407f15 --- /dev/null +++ b/hylo-lang/fib-example/fib.hylo @@ -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 index 0000000..201050c --- /dev/null +++ b/hylo-lang/fib-example/putn.c @@ -0,0 +1,16 @@ +#include + +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); +} + + -- 2.43.0