-
Notifications
You must be signed in to change notification settings - Fork 1
/
removed.fs
68 lines (51 loc) · 1.88 KB
/
removed.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
\
\ This code has been removed
\
create dtab 4 cells allot
0 variable *latest
\ : newdh ( ca -- dh ) cell+ c@ shr shr shr shr shr cells dtab + ;
: newdh ( ca -- dh ) \ hash function for deriving the hash bucker
0 swap @+ for c@+ rot + swap next drop 3 and cells dtab + ;
: new: ( "word" -- ) \ Creates a name
here *latest !
ba ba 0 , word dup s, dh swap pp then tuck @ over ! swap ! ] ;
: add ( de dh -- ) \ add a dictionary entry to list head
2dup @ swap ! ! ;
0 variable temp
( This code plays with the outer interpreter so its wrapped in quotes
so it'll be executed and then removed from the instruction stack
It should be immediate but the arranging of the dictionary will render
immediate mode unusable until all the code changes are complete.
)
[[
\ clear hash table
dtab 0 !+ 0 !+ 0 !+ 0 !+ drop
\ swap order of word list
latest begin dup @ swap temp add dup 0= until drop
\ add words to hashing table
temp @ begin dup @ swap dup dup *latest ! >name newdh add dup 0= until drop
lit newdh lit dh !
lit new: lit : !
]] dup exec cp !
[[ *latest @ ]] is latest
: domarker ( -- ) \ domarker restores the dictionary / CP to a previous state
pull
@+ *latest ! \ restore latest pointer
@+ dtab 3 cells + ! \ restore fourth hash table head
@+ dtab 2 cells + ! \ restore third hash table head
@+ dtab 1 cells + ! \ restore second hash table head
@+ dtab ! \ restore first hash table head
@+ cp ! \ restore CP
push \ put return address back
;
: marker ( -- ) \ creates a word to restore the state of the machine
here \ push CP
dtab 4 for @+ swap next drop \ push bucket 0-3
latest \ push latest
: ^ domarker 6 for , next pp ;
;
: words ( -- ) \ prints the dictionary
dtab 4 for
dup begin @ dup while dup >name type space repeat drop
cr cr cell+ next drop
;