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 (parent:
dafc678
)
Using standard field conversion words.
author
Tim Vaughan
<tgvaughan@gmail.com>
Wed, 1 Jun 2016 09:05:36 +0000
(21:05 +1200)
committer
Tim Vaughan
<tgvaughan@gmail.com>
Wed, 1 Jun 2016 09:05:36 +0000
(21:05 +1200)
src/forth.jl
patch
|
blob
|
history
src/lib_1_basic.4th
patch
|
blob
|
history
src/lib_6_variables.4th
patch
|
blob
|
history
src/lib_8_decompiler.4th
patch
|
blob
|
history
src/lib_9_vocab.4th
patch
|
blob
|
history
diff --git
a/src/forth.jl
b/src/forth.jl
index
da7321b
..
c5c7175
100644
(file)
--- a/
src/forth.jl
+++ b/
src/forth.jl
@@
-698,7
+698,7
@@
end)
# Dictionary searches
# Dictionary searches
-
LFATOCFA_CFA = defPrimWord("LFA>CFA
", () -> begin
+
FROMLINK_CFA = defPrimWord("LINK>
", () -> begin
addr = popPS()
lenAndFlags = mem[addr+1]
addr = popPS()
lenAndFlags = mem[addr+1]
@@
-709,8
+709,6
@@
LFATOCFA_CFA = defPrimWord("LFA>CFA", () -> begin
return NEXT
end)
return NEXT
end)
-TOBODY_CFA = defWord(">BODY", [INCR_CFA, EXIT_CFA])
-
CONTEXT, CONTEXT_CFA = defNewVar("CONTEXT", zeros(Int64, 100))
mem[CONTEXT] = FORTH_CFA
NUMCONTEXT, NUMCONTEXT_CFA = defNewVar("#CONTEXT", 1)
CONTEXT, CONTEXT_CFA = defNewVar("CONTEXT", zeros(Int64, 100))
mem[CONTEXT] = FORTH_CFA
NUMCONTEXT, NUMCONTEXT_CFA = defNewVar("#CONTEXT", 1)
@@
-755,7
+753,7
@@
FIND_CFA = defPrimWord("FIND", () -> begin
if lfa > 0
pushPS(lfa)
if lfa > 0
pushPS(lfa)
- callPrim(mem[
LFATOCFA
_CFA])
+ callPrim(mem[
FROMLINK
_CFA])
if (lenAndFlags & F_IMMED) == F_IMMED
pushPS(1)
else
if (lenAndFlags & F_IMMED) == F_IMMED
pushPS(1)
else
@@
-890,7
+888,7
@@
end, name="DODOES")
DOES_HELPER_CFA = defPrimWord("(DOES>)", () -> begin
pushPS(mem[mem[CURRENT]])
DOES_HELPER_CFA = defPrimWord("(DOES>)", () -> begin
pushPS(mem[mem[CURRENT]])
- callPrim(mem[
LFATOCFA
_CFA])
+ callPrim(mem[
FROMLINK
_CFA])
cfa = popPS()
runtimeAddr = popPS()
cfa = popPS()
runtimeAddr = popPS()
diff --git
a/src/lib_1_basic.4th
b/src/lib_1_basic.4th
index
dc8c584
..
00b200d
100644
(file)
--- a/
src/lib_1_basic.4th
+++ b/
src/lib_1_basic.4th
@@
-36,17
+36,22
@@
: C@ @ ;
: C, , ;
: C@ @ ;
: C, , ;
+\ Retrieve stack depth
: DEPTH PSP@ PSP0 - ;
: DEPTH PSP@ PSP0 - ;
+\ Words for whitespace
: '\n' 10 ;
: BL 32 ;
: CR '\n' emit ;
: SPACE BL emit ;
: '\n' 10 ;
: BL 32 ;
: CR '\n' emit ;
: SPACE BL emit ;
+\ CFA retrieval
: ' BL WORD FIND DROP ;
: ['] IMMEDIATE
LIT LIT , ' , ;
: ' BL WORD FIND DROP ;
: ['] IMMEDIATE
LIT LIT , ' , ;
+\ Compilation
+
: [COMPILE] IMMEDIATE ' , ;
: COMPILE IMMEDIATE
LIT LIT , ' , LIT , , ;
: [COMPILE] IMMEDIATE ' , ;
: COMPILE IMMEDIATE
LIT LIT , ' , LIT , , ;
@@
-59,12
+64,14
@@
['] LIT , ,
;
['] LIT , ,
;
+\ LFA of most recent definition
: LATEST
CURRENT @ ;
: LATEST
CURRENT @ ;
+\ Compile in recursive call to current word
: RECURSE IMMEDIATE
LATEST @ \ LATEST points to the word being compiled at the moment
: RECURSE IMMEDIATE
LATEST @ \ LATEST points to the word being compiled at the moment
- L
FA>CFA
\ get the codeword
+ L
INK>
\ get the codeword
, \ compile it
;
, \ compile it
;
diff --git
a/src/lib_6_variables.4th
b/src/lib_6_variables.4th
index
6829c9c
..
a7aea70
100644
(file)
--- a/
src/lib_6_variables.4th
+++ b/
src/lib_6_variables.4th
@@
-1,3
+1,20
@@
+\ Remaining field address conversion words
+
+: >NAME
+ BEGIN
+ 1- DUP @
+ NFA_MARK AND
+ NFA_MARK = UNTIL
+;
+
+: NAME> 1- LINK> ;
+
+: >LINK >NAME 1- ;
+
+: >BODY 1+ ;
+
+: BODY> 1- ;
+
\ Constants and Variables
: CONSTANT
\ Constants and Variables
: CONSTANT
diff --git
a/src/lib_8_decompiler.4th
b/src/lib_8_decompiler.4th
index
5daa501
..
e1470f3
100644
(file)
--- a/
src/lib_8_decompiler.4th
+++ b/
src/lib_8_decompiler.4th
@@
-1,14
+1,5
@@
\ Decompilation
\ Decompilation
-: >NAME
- BEGIN
- 1- DUP @
- NFA_MARK AND
- NFA_MARK = UNTIL
-;
-
-: >LFA >NAME 1- ;
-
: SEE
BL WORD FIND ( find the dictionary entry to decompile )
: SEE
BL WORD FIND ( find the dictionary entry to decompile )
@@
-19,7
+10,7
@@
EXIT
THEN
EXIT
THEN
- >L
FA
+ >L
INK
( 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). )
@@
-37,7
+28,7
@@
DROP ( at this point, the stack is: start-of-word end-of-word )
SWAP ( end-of-word start-of-word )
DROP ( at this point, the stack is: start-of-word end-of-word )
SWAP ( end-of-word start-of-word )
- DUP L
FA>CFA
@ CASE
+ DUP L
INK>
@ CASE
DOCOL OF
\ Colon definition
[CHAR] : EMIT SPACE DUP 1+ .NAME SPACE
DOCOL OF
\ Colon definition
[CHAR] : EMIT SPACE DUP 1+ .NAME SPACE
@@
-61,7
+52,7
@@
4 SPACES
4 SPACES
- L
FA>CFA
>BODY ( get the data address, ie. points after DOCOL | end-of-word start-of-data )
+ L
INK>
>BODY ( get the data address, ie. points after DOCOL | end-of-word start-of-data )
( now we start decompiling until we hit the end of the word )
BEGIN ( end start )
( now we start decompiling until we hit the end of the word )
BEGIN ( end start )
diff --git
a/src/lib_9_vocab.4th
b/src/lib_9_vocab.4th
index
32d12c2
..
2b10730
100644
(file)
--- a/
src/lib_9_vocab.4th
+++ b/
src/lib_9_vocab.4th
@@
-1,7
+1,7
@@
\ Vocabulary management
: FORGET
\ Vocabulary management
: FORGET
- BL WORD FIND >L
FA
( find the word, gets the dictionary entry address )
+ BL WORD FIND >L
INK
( 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 )
;
DUP @ LATEST ! ( set LATEST to point to the previous word )
H ! ( and store H with the dictionary address )
;