X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?p=forth.jl.git;a=blobdiff_plain;f=src%2Flib_8_vocab.4th;fp=src%2Flib_8_vocab.4th;h=34b82517c42ce91c0c9c0051164f819424b8cbb4;hp=0000000000000000000000000000000000000000;hb=4437e4ba8255ef676faf94682a8ecc2579d0f12d;hpb=a02d0aced80ab33dad899f91106ede749882b883 diff --git a/src/lib_8_vocab.4th b/src/lib_8_vocab.4th new file mode 100644 index 0000000..34b8251 --- /dev/null +++ b/src/lib_8_vocab.4th @@ -0,0 +1,82 @@ +\ Vocabulary management + +: FORGET + BL WORD FIND >LINK ( find the word, gets the dictionary entry address ) + DUP @ LATEST ! ( set LATEST to point to the previous word ) + H ! ( and store H with the dictionary address ) +; + +: HIDE + BL WORD FIND DROP >NAME + DUP @ F_HIDDEN OR SWAP ! +; + +: VOCAB>LATEST ( vcfa -- vlatest ) + 1+ @ @ ; + +\ Create new vocabulary +: VOCABULARY + create 0 , +does> + body> context #context @ 1- + ! +; + +: DEFINITIONS + context #context @ 1- + @ current ! +; + +\ Define root vocabulary (always available) +vocabulary ROOT + +: ONLY + 1 #context ! + root + 2 #context ! + root +; + +: PREVIOUS + 1 #context -! +; + +: ALSO + context #context @ + dup 1- @ swap ! + 1 #context +! +; + +also root definitions + + : FORTH forth ; + + \ Display search order and compilation dictionary + : ORDER + + \ Search order + context #context @ 1- + context swap + do + i @ >name .name space + -1 +loop + + \ Current (definitions) + 5 spaces + current @ >name .name + ; + + \ Display transient vocabulary contents + : WORDS + cr + context #context @ 1- + @ + 1+ @ + BEGIN + ?DUP ( while link pointer is not 0 ) + WHILE + DUP ?HIDDEN NOT IF ( ignore hidden words ) + DUP 1+ .NAME ( but if not hidden, print the word ) + SPACE + THEN + @ ( dereference the link pointer - go to previous word ) + REPEAT + CR + ; + +only forth also definitions