1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ;; UrForth level
1: self
-hosting
32-bit Forth compiler
3 ;; Copyright
(C
) 2020 Ketmar Dark
// Invisible Vector
5 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7 ;; shows current search order
11 begin dup
(forth
-voc
-stack
) u
>= while
16 space
." (ROOT)\nCURRENT: "
19 (CURRENT
-CREATE
-MODE
) (WFLAG
-HIDDEN
) and
if ." private" else ." public" endif
23 ;; makes all newly created words public
24 : <public
-words
> ( -- )
25 (CURRENT
-CREATE
-MODE
) (WFLAG
-HIDDEN
) ~and
to (CURRENT
-CREATE
-MODE
)
28 ;; makes all newly created words hidden
29 : <hidden
-words
> ( -- )
30 (CURRENT
-CREATE
-MODE
) (WFLAG
-HIDDEN
) or
to (CURRENT
-CREATE
-MODE
)
33 ;; sets top context vocabulary as the current one
34 ;; resets current mode
to public
36 context @ current
! <public
-words
>
39 ;; makes top context vocabulary as the only one
, and makes it current too
40 ;; resets current mode
to public
42 (forth
-voc
-stack
) to context
43 ['] forth voc-cfa->vocid context !
47 ;; duplicates top context vocabulary, so it could be replaced with another one
48 ;; resets current mode to public
50 ;; check for vocstack overflow
51 context cell+ dup (forth-voc-stack-end) u>= ERR-VOCABULARY-STACK-OVERFLOW ?error
56 ;; drop topmost context vocabulary
57 ;; resets current mode to public
59 ;; check for vocstack underflow
60 context (forth-voc-stack) u>= if
61 context cell- to context
66 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
67 : forth-wordlist ( -- vocid )
71 ;; 1: immediate; -1: normal
72 : search-wordlist ( addr count vocid -- cfa 1 // cfa -1 // 0 )
74 [ (wflag-smudge) (wflag-hidden) or ] literal voc-find-replace-mask
79 : get-order ( -- vocids... vocid-count )
80 (forth-voc-stack) begin dup context u<= while dup @ swap cell+ repeat drop
81 context (forth-voc-stack) - 2 rshift 1+ ;; counter
84 : set-order ( vocids... vocid-count -- )
86 dup >r ;; save counter, so we will drop all arguments in any case
87 (forth-voc-stack-end) (forth-voc-stack) - 2 rshift ;; maximum
88 \ endcr ." maxvocs: " dup . cr
91 dup 1- cells (forth-voc-stack) + to context
92 (forth-voc-stack) swap
93 1 swap do i pick over ! cell+ -1 +loop
103 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
104 : (vocorder>r) ( -- | vocids... vocid-count current )
105 r> (forth-voc-stack) begin dup context u<= while dup @ >r cell+ repeat drop
106 context (forth-voc-stack) - 2 rshift 1+ >r ;; counter
110 : (r>vocorder) ( | vocids... vocid-count current -- )
111 r> r> current ! r@ if
112 r@ 1- cells (forth-voc-stack) + dup to context
113 r> begin dup while 1- swap r> over ! cell- swap repeat 2drop