aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMirek Kratochvil <exa.exa@gmail.com>2023-08-15 11:08:16 +0200
committerMirek Kratochvil <exa.exa@gmail.com>2023-08-15 11:08:16 +0200
commit7d5d0dc3c8e7b4de06461df73791874321d1db06 (patch)
treed272c79df02b156d9db80cf8d19abeb106e95ae1
parent8ec7f1f1caf35e493b7e7eb6ac8159bee1a6610d (diff)
downloaduskel-7d5d0dc3c8e7b4de06461df73791874321d1db06.tar.gz
uskel-7d5d0dc3c8e7b4de06461df73791874321d1db06.tar.bz2
add the apply_over example
-rw-r--r--apply_over.s51
1 files changed, 51 insertions, 0 deletions
diff --git a/apply_over.s b/apply_over.s
new file mode 100644
index 0000000..4e86d17
--- /dev/null
+++ b/apply_over.s
@@ -0,0 +1,51 @@
+
+
+.include "include/uskel.s"
+
+.include "include/apply.s"
+.include "include/intops.s"
+.include "include/io.s"
+.include "include/main_exit.s"
+
+# | int | int | -> int
+.thunkcode const_int
+ mov %rsi, %rax
+ mov 020(%rbp), %rsi
+ enter %rax
+
+# | int | int | -> int
+.thunkcode tsnoc_int
+ mov %rsi, %rax
+ mov 030(%rbp), %rsi
+ enter %rax
+
+# | int | -> (| int | int | -> int)
+.primop1 if_int
+ mov 010(%rsi), %rax
+ mov $const_int, %r10
+ mov $tsnoc_int, %r11
+ test %rax, %rax
+ cmovz %r11, %r10
+ thunkto %r10, $FUN2_code, %r10, $0
+ primop1_cont_indirect %r10
+
+.thunkcode main
+ # make integers
+ thunkto %r10, $INT_code, $0
+ thunkto %r11, $INT_code, $1
+ thunkto %r12, $INT_code, $2
+
+ # make the function
+ thunkto %r13, $FUN1_code, $if_int, $0
+
+ # send enough arguments
+ thunkto %r13, $apply, $4, %r13, %r10, %r11, %r12
+
+ # print the result
+ thunkto %r13, $print, $1, %r13
+
+ # make a continuation for main (exit) and set it for print call
+ thunkto %rsi, $main_exit, $1, %rsi
+
+ # start evaluating the print
+ enter %r13