summary refs log tree commit diff
path: root/core.e
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@irenes.space>2026-05-20 22:12:57 -0700
committerIrene Knapp <ireneista@irenes.space>2026-05-20 22:12:57 -0700
commit54d5bfe751d8489ae727eec1cb8d4a9a2279a5e5 (patch)
treec727dccb9f50f5a74c4d541a3fdf38a89cf379f3 /core.e
parent272c9cf16bbca81ff0e15840c4dc8fd0bbce3ad8 (diff)
tidied away core-plus.e
it's merged into core now. that just made the most sense... a couple of its combinators are too useful to not use once you know about them

Force-Push: yes
Change-Id: I3857f353a8603960bebbf34f24572e3d5815f0de
Diffstat (limited to 'core.e')
-rw-r--r--core.e61
1 files changed, 61 insertions, 0 deletions
diff --git a/core.e b/core.e
index 1bc73e1..491b73c 100644
--- a/core.e
+++ b/core.e
@@ -356,6 +356,22 @@ here !
     :rax push-reg64              ~ quotient
     here ! ] ;asm
 
+~   We define a pair of words that increment and decrement a single item.
+~ These were inspired by Common Lisp, where they're constantly useful.
+: 1+
+  [ here @
+    :rax pop-reg64
+    :rax inc-reg64
+    :rax push-reg64
+    here ! ] ;asm
+
+: 1-
+  [ here @
+    :rax pop-reg64
+    :rax dec-reg64
+    :rax push-reg64
+    here ! ] ;asm
+
 
 ~ Comparison routines
 ~ ~~~~~~~~~~~~~~~~~~~
@@ -1236,3 +1252,48 @@ here !
     hlt
     here ! ] ;asm
 
+
+~ Additional conveniences
+~ ~~~~~~~~~~~~~~~~~~~~~~~
+~
+~   Please feel free to find an organizing principle for these and put them
+~ where they go. It would be kind of nice to re-write these either in
+~ assembly, or with high-level flow control, but it doesn't seem urgent...
+
+: max
+  2dup >=
+  0branch [ 2 8 * , ] swap
+  drop ;
+
+: min
+  2dup <=
+  0branch [ 2 8 * , ] swap
+  drop ;
+
+: 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 0branch [ 6 8 * , ] swap drop 1-
+  branch [ -7 8 * , ]
+  drop ;
+
+: ndup
+  dup 1+ swap
+  dup 0branch [ 9 8 * , ] swap dup pick 3unroll swap 1-
+  branch [ -10 8 * , ]
+  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 * ;
+