# dict stuff # marking # note that in order to be ok for forwardreferences to data and code, you need # to use safe-drop when dropping dictionary links. the links themselves cannot # be copied: ghosts are returned if this is attempted. : listhead # ( list -- list head ) >r rsp head r> swap ; # ( symbol list -- ) Move links to list upto and including link with name equal to symbol. : do-mark> >r >r d> # ( link ) ( symbol list )R listhead @ r = # ( link bool.done ) if rdrop drop r> leave then # if done, ignore symbol and leave r> swap >>rl r> do-mark> ;; # else add link to list and recurse : mark [read] last-mark> dup link-word postpone literal () postpone literal postpone do-pass postpone do-mark> ; "( -- )\tCreate a dictionary marker." doc : mark> ` last-mark> interpret ; "( -- list )\tGet marked part of dictionary." doc : empty mark> safe-drop ; "( -- )\tRemove marked part of dictionar." doc # minimal dictionary / object / binder code # all words manipulated on a marked dictionary region : mark>buffer mark> read link-buffer , ; "Move marked part to buffer. Parses word." doc : mark>dictionary mark>buffer does> dict-find ;; "Move marked part to dictionary word. Behaves as 'find'. Parser word." doc : mark>object mark>buffer does> dict-find execute ;; "Move marked part to object word. Behaves as 'find execute'." doc : binder-compile read swap xt>body dict-find xt>ct execute ; : mark>binder mark>buffer ['] binder-compile comp! # move marked part to buffer, set semantics does> # runtime behaves as parsing word 'object method' read swap dict-find execute ;; "Move marked part to binder. Binder behaves as parsing word." doc # this is used a lot, so deserves to be a word in short: create-binder # creates a binder word, which is just a private dictionary accessed # by this word in both interpret and compile semantics. it's mainly # there to abstract stuff in a single word without polluting the # global namespace, and without having to resort to xxx-yyy-zzz names # all the time. : create-binder mark interpret-list mark>binder ; "( code -- )\tCreate a private namespace. Parses next word. Code is a list containing symbolic code." doc # some operations on dictionary buffers # rejoin a dictionary with global one : dictionary>d # ( dictionary.xt -- ) mark xt>body @> reverse ['] >d for-each ; # split off and store in dictionary : d>dictionary # ( dictionary.xt -- ) mark> swap xt>body ! ; # add a dictionary strip word as an alternative for garbage collection: # this should strip a dictionary from all symbols not # accessable from a root list of symbols. this would # enable to clean up unused (startup) junk.