1 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ;; and now
for something completely different
...
3 ;; UrForth
/C Forth Engine
!
4 ;; Copyright
(C
) 2023 Ketmar Dark
// Invisible Vector
6 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12 : MIN
( a b
-- max
-of
-a
-b
) 2DUP
> IF SWAP
ENDIF DROP
;
13 : MAX
( a b
-- max
-of
-a
-b
) 2DUP
< IF SWAP
ENDIF DROP
;
14 : CLAMP
( val a b
-- clamped
-val
) SWAP ROT MAX MIN
;
16 : UMIN
( a b
-- max
-of
-a
-b
) 2DUP U
> IF SWAP
ENDIF DROP
;
17 : UMAX
( a b
-- max
-of
-a
-b
) 2DUP U
< IF SWAP
ENDIF DROP
;
18 : UCLAMP
( val a b
-- clamped
-val
) SWAP ROT UMAX UMIN
;
21 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
22 ;; print number
to buffer
26 ;; the buffer is right before PAD
27 ;; allocate number translation buffer
28 \
0x3464_
97AF HANDLE
:NEW CONSTANT
(#BUF
) ;; arbitrary typeid
29 \ FORTH
:(MAX
-HANDLE
-OFS
) 1+ CONSTANT
(#BUF
-SIZE
)
30 \
(#BUF
-SIZE
) (#BUF
) HANDLE
:SIZE
!
31 (#BUF
) (#BUF
-SIZE
) + CONSTANT
(#BUF
-END)
32 \
0 VARIABLE
(#BUF
-OFS
)
33 (#BUF
) 4- CONSTANT
(#BUF
-OFS
)
39 (#BUF
-OFS
) @ DUP
(#BUF
-SIZE
) U
>= " number too long" ?ERROR
44 : HOLDS
( addr u
-- ) BEGIN DUP
WHILE 1- 2DUP
+ C@ HOLD REPEAT
2DROP
;
48 0< IF [CHAR
] - HOLD
ENDIF
55 : #
> ( n
-- addr count
)
57 (#BUF
-OFS
) @
(#BUF
-END) OVER
- SWAP
61 BASE @ U
/MOD
( n
/base n
%base
)
62 48 + DUP
57 > IF 7 + ENDIF
71 DUP
0< DUP
>R
IF NEGATE
ENDIF
72 #S R
> IF [CHAR
] - HOLD
ENDIF
75 : . ( n
-- ) <# #SIGNED #
> TYPE SPACE
;
78 >R
<# #SIGNED #
> ( addr count | width
)
79 DUP R
> SWAP
- SPACES TYPE
82 : U
. ( n
-- ) <# #S #
> TYPE SPACE
;
85 >R
<# #S #
> ( addr count | width
)
86 DUP R
> SWAP
- SPACES TYPE
89 : 0.R
( n
-- ) <# #SIGNED #
> TYPE
;
90 : 0U.R
( n
-- ) <# #S #
> TYPE
;
92 \
" AAAAAAAAAAAAAAAAAAAAAAAAAAAA\n" TYPE
94 \
" AAAAAAAAAAAAAAAAAAAAAAAAAAAA\n" TYPE