planckforth/lib/core.fs

61 lines
977 B
Forth
Raw Normal View History

2021-01-13 11:29:46 +01:00
\ planckforth -
\ Copyright (C) 2021 nineties
2021-01-16 10:52:47 +01:00
\ Ignore test codes. lib/tester.fs will redefine this when
\ running tests.
: T{
begin
word throw
s" }T" streq if exit then
again
;
2021-01-17 15:29:25 +01:00
s" Invalid argument" exception constant INVALID-ARGUMENT
: check-argument ( f -- )
unless INVALID-ARGUMENT throw then
;
2021-12-04 09:22:12 +01:00
( === Builtin Exceptions === )
s" Index out of range" exception constant OUT-OF-RANGE export
2021-12-04 09:22:12 +01:00
defined? roll [unless]
2021-12-08 00:08:13 +01:00
: roll ( w[n-1] ... w0 n -- w[n-2] ... w0 w[n-1] )
2021-12-04 09:22:12 +01:00
dup 0<= if drop else swap >r 1- recurse r> swap then
;
[then]
private{
( === Cons Cell === )
struct
cell% field first
cell% field second
end-struct cons-cell%
: cons ( a b -- cons )
cons-cell% %allocate throw
tuck second !
tuck first !
; export
: car first @ ; export
: cdr second @ ; export
2021-12-07 22:11:20 +01:00
( === Enum === )
\ 0
\ enum A
\ enum B
\ drop
\ 0 constant A
\ 1 constant B
: enum ( n "name" -- n )
dup constant 1+
; export
2021-12-04 09:22:12 +01:00
}private