diff options
Diffstat (limited to 'core.e')
| -rw-r--r-- | core.e | 61 |
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 * ; + |