summary refs log tree commit diff
path: root/core-plus.e
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@irenes.space>2026-05-17 17:29:09 -0700
committerIrene Knapp <ireneista@irenes.space>2026-05-17 17:29:09 -0700
commit3b41dbfa2338c11dd8398026c00922f20f32dc81 (patch)
tree1761f2b8f2da972b830cf617d194c7c5be5b1535 /core-plus.e
parent4f1a07da9c87a1560da34b8a96a9de4cdc90f1fc (diff)
implement log-load-create; add all the pack/unpack stuff to core.e
Force-Push: yes
Change-Id: I04dd65a9eec71f9b50c8875bdcbe5d4be59888d5
Diffstat (limited to 'core-plus.e')
-rw-r--r--core-plus.e33
1 files changed, 33 insertions, 0 deletions
diff --git a/core-plus.e b/core-plus.e
new file mode 100644
index 0000000..d323816
--- /dev/null
+++ b/core-plus.e
@@ -0,0 +1,33 @@
+~ This is a temporary holding place for stuff that probably should be in
+~ core someday, but only after carefully considering whether to rewrite it in
+~ assembly. Most of it originally came from boot_source in quine.asm.
+
+
+~ Now some fancier stack combinators.
+~
+~   While it might be nice, for performance reasons, to do these in
+~ assembler, for now it's more important to have them at all.
+: 1- 1 - ;
+: 1+ 1 + ;
+: max 2dup >= { swap drop } { drop } if-else ;
+: min 2dup <= { swap drop } { drop } if-else ;
+
+: over swap dup 3unroll ;
+: pick 2 + dup roll dup 3roll unroll ;
+
+~ Standard Forth doesn't have equivalents of our ndrop and ndup. The HP
+~ calls them DROPN and DUPN but that doesn't go well with ie. 2dup or 3roll,
+~ so we do it like this.
+: ndrop { dup } { swap drop 1- } while drop ;
+: ndup dup 1+ swap { dup }
+  { swap dup pick 3unroll swap 1- } while 2drop ;
+: 3drop drop drop drop ;
+: 3dup 2 pick 2 pick 2 pick ;
+
+: && 0 != swap 0 != * ;
+: || | 0 != ;
+: not 0 = ;
+: negate -1 * ;
+
+: align-floor dup 3unroll /% swap drop * ;
+