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:
d75b27e
)
Reimplement CONSTANT, VARIABLE, VALUE using DOES>
author
Tim Vaughan
<tgvaughan@gmail.com>
Tue, 24 May 2016 11:54:19 +0000
(23:54 +1200)
committer
Tim Vaughan
<tgvaughan@gmail.com>
Tue, 24 May 2016 11:54:40 +0000
(23:54 +1200)
src/lib.4th
patch
|
blob
|
history
diff --git
a/src/lib.4th
b/src/lib.4th
index
647b499
..
2312aeb
100644
(file)
--- a/
src/lib.4th
+++ b/
src/lib.4th
@@
-496,11
+496,8
@@
( CONSTANTS AND VARIABLES ------------------------------------------------------ )
: CONSTANT
( CONSTANTS AND VARIABLES ------------------------------------------------------ )
: CONSTANT
- BL WORD HEADER ( make dictionary entry (the name follows CONSTANT) )
- DOCOL , ( append DOCOL (the codeword field of this word) )
- ['] LIT , ( append the codeword LIT )
- , ( append the value on the top of the stack )
- ['] EXIT , ( append the codeword EXIT )
+ CREATE ,
+DOES> @
;
: ALLOT ( n -- )
;
: ALLOT ( n -- )
@@
-508,24
+505,19
@@
;
: VARIABLE
;
: VARIABLE
- BL WORD HEADER
- DOVAR ,
+ CREATE
1 CELLS ALLOT ( allocate 1 cell of memory, push the pointer to this memory )
;
: VALUE ( n -- )
1 CELLS ALLOT ( allocate 1 cell of memory, push the pointer to this memory )
;
: VALUE ( n -- )
- BL WORD HEADER ( make the dictionary entry (the name follows VALUE) )
- DOCOL , ( append DOCOL )
- ['] LIT , ( append the codeword LIT )
- , ( append the initial value )
- ['] EXIT , ( append the codeword EXIT )
+ CREATE ,
+DOES> @
;
: TO IMMEDIATE ( n -- )
BL WORD ( get the name of the value )
FIND ( look it up in the dictionary )
>PFA ( get a pointer to the first data field (the 'LIT') )
;
: TO IMMEDIATE ( n -- )
BL WORD ( get the name of the value )
FIND ( look it up in the dictionary )
>PFA ( get a pointer to the first data field (the 'LIT') )
- 1+ ( increment to point at the value )
STATE @ IF ( compiling? )
['] LIT , ( compile LIT )
, ( compile the address of the value )
STATE @ IF ( compiling? )
['] LIT , ( compile LIT )
, ( compile the address of the value )
@@
-540,7
+532,6
@@
BL WORD ( get the name of the value )
FIND ( look it up in the dictionary )
>PFA ( get a pointer to the first data field (the 'LIT') )
BL WORD ( get the name of the value )
FIND ( look it up in the dictionary )
>PFA ( get a pointer to the first data field (the 'LIT') )
- 1+ ( increment to point at the value )
STATE @ IF ( compiling? )
['] LIT , ( compile LIT )
, ( compile the address of the value )
STATE @ IF ( compiling? )
['] LIT , ( compile LIT )
, ( compile the address of the value )