The Lambda Lab
/
projects
/
forth.jl.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
0724d1b
)
Implemented COUNT, renamed TELL to TYPE
author
Tim Vaughan
<tgvaughan@gmail.com>
Fri, 6 May 2016 08:22:35 +0000
(20:22 +1200)
committer
Tim Vaughan
<tgvaughan@gmail.com>
Fri, 6 May 2016 08:22:35 +0000
(20:22 +1200)
src/forth.jl
patch
|
blob
|
history
src/lib.4th
patch
|
blob
|
history
diff --git
a/src/forth.jl
b/src/forth.jl
index
b1d782c
..
bf2c8fe
100644
(file)
--- a/
src/forth.jl
+++ b/
src/forth.jl
@@
-857,7
+857,7
@@
LITSTRING = defPrimWord("LITSTRING", () -> begin
return NEXT
end)
return NEXT
end)
-T
ELL = defPrimWord("TELL
", () -> begin
+T
YPE = defPrimWord("TYPE
", () -> begin
len = popPS()
addr = popPS()
str = getString(addr, len)
len = popPS()
addr = popPS()
str = getString(addr, len)
@@
-986,17
+986,7
@@
EOF_WORD = defPrimWord("\x04", () -> begin
end
end, flags=F_IMMED)
end
end, flags=F_IMMED)
-# Odds and Ends
-
-CHAR = defPrimWord("CHAR", () -> begin
- callPrim(mem[WORD])
- wordLen = popPS()
- wordAddr = popPS()
- word = getString(wordAddr, wordLen)
- pushPS(Int64(word[1]))
-
- return NEXT
-end)
+#### VM loop ####
initialized = false
initFileName = nothing
initialized = false
initFileName = nothing
@@
-1006,8
+996,6
@@
elseif isfile(Pkg.dir("forth/src/lib.4th"))
initFileName = Pkg.dir("forth/src/lib.4th")
end
initFileName = Pkg.dir("forth/src/lib.4th")
end
-
-#### VM loop ####
function run(;initialize=true)
# Begin with STDIN as source
push!(sources, STDIN)
function run(;initialize=true)
# Begin with STDIN as source
push!(sources, STDIN)
diff --git
a/src/lib.4th
b/src/lib.4th
index
955cadf
..
c38faa1
100644
(file)
--- a/
src/lib.4th
+++ b/
src/lib.4th
@@
-33,6
+33,11
@@
: LITERAL IMMEDIATE ['] LIT , , ;
: LITERAL IMMEDIATE ['] LIT , , ;
+: CHAR
+ WORD
+ DROP @
+;
+
: [CHAR] IMMEDIATE
CHAR
['] LIT , ,
: [CHAR] IMMEDIATE
CHAR
['] LIT , ,
@@
-454,7
+459,7
@@
: ." IMMEDIATE ( -- )
[COMPILE] S" ( read the string, and compile LITSTRING, etc. )
: ." IMMEDIATE ( -- )
[COMPILE] S" ( read the string, and compile LITSTRING, etc. )
- ['] T
ELL , ( compile the final TELL
)
+ ['] T
YPE , ( compile the final TYPE
)
;
: .(
;
: .(
@@
-469,6
+474,11
@@
AGAIN
;
AGAIN
;
+( Converts address of counted string into address of
+ start of string and length of string. )
+: COUNT ( addr1 -- addr2 n )
+ DUP 1+ SWAP @ ;
+
( CONSTANTS AND VARIABLES ------------------------------------------------------ )
( CONSTANTS AND VARIABLES ------------------------------------------------------ )
@@
-621,7
+631,14
@@
;
: SEE
;
: SEE
- WORD FIND ( find the dictionary entry to decompile )
+ WORD 2DUP FIND ( find the dictionary entry to decompile )
+
+ ?DUP 0= IF
+ ." Word '" TYPE ." ' not found in dictionary."
+ EXIT
+ THEN
+
+ -ROT 2DROP
( Now we search again, looking for the next word in the dictionary. This gives us
the length of the word that we will be decompiling. (Well, mostly it does). )
( Now we search again, looking for the next word in the dictionary. This gives us
the length of the word that we will be decompiling. (Well, mostly it does). )
@@
-684,7
+701,7
@@
[CHAR] S EMIT [CHAR] " EMIT SPACE ( print S"<space> )
1+ DUP @ ( get the length word )
SWAP 1+ SWAP ( end start+1 length )
[CHAR] S EMIT [CHAR] " EMIT SPACE ( print S"<space> )
1+ DUP @ ( get the length word )
SWAP 1+ SWAP ( end start+1 length )
- 2DUP T
ELL
( print the string )
+ 2DUP T
YPE
( print the string )
[CHAR] " EMIT SPACE ( finish the string with a final quote )
+ ( end start+1+len, aligned )
1- ( because we're about to add 4 below )
[CHAR] " EMIT SPACE ( finish the string with a final quote )
+ ( end start+1+len, aligned )
1- ( because we're about to add 4 below )