projects
/
rrq
/
jonesforth.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
ID. and WORDS
[rrq/jonesforth.git]
/
jonesforth.S
diff --git
a/jonesforth.S
b/jonesforth.S
index 5d1c5834eefc3dfc33bda068fe423ba3fc14fe30..c41cbed029bb72676d7fd5b6a26fb29701138cd0 100644
(file)
--- a/
jonesforth.S
+++ b/
jonesforth.S
@@
-1,11
+1,11
@@
/* A sometimes minimal FORTH compiler and tutorial for Linux / i386 systems. -*- asm -*-
By Richard W.M. Jones <rich@annexia.org> http://annexia.org/forth
This is PUBLIC DOMAIN (see public domain release statement below).
/* A sometimes minimal FORTH compiler and tutorial for Linux / i386 systems. -*- asm -*-
By Richard W.M. Jones <rich@annexia.org> http://annexia.org/forth
This is PUBLIC DOMAIN (see public domain release statement below).
- $Id: jonesforth.S,v 1.2
2 2007-09-23 19:40:4
0 rich Exp $
+ $Id: jonesforth.S,v 1.2
4 2007-09-23 20:06:0
0 rich Exp $
gcc -m32 -nostdlib -static -Wl,-Ttext,0 -o jonesforth jonesforth.S
*/
gcc -m32 -nostdlib -static -Wl,-Ttext,0 -o jonesforth jonesforth.S
*/
- .set JONES_VERSION,2
2
+ .set JONES_VERSION,2
4
/*
INTRODUCTION ----------------------------------------------------------------------
/*
INTRODUCTION ----------------------------------------------------------------------
@@
-579,13
+579,13
@@
cold_start: // High-level code without a codeword.
.bss
/* FORTH return stack. */
.bss
/* FORTH return stack. */
-
#define RETURN_STACK_SIZE
8192
+
.set RETURN_STACK_SIZE,
8192
.align 4096
.space RETURN_STACK_SIZE
return_stack: // Initial top of return stack.
/* The user definitions area: space for user-defined words and general memory allocations. */
.align 4096
.space RETURN_STACK_SIZE
return_stack: // Initial top of return stack.
/* The user definitions area: space for user-defined words and general memory allocations. */
-
#define USER_DEFS_SIZE
16384
+
.set USER_DEFS_SIZE,
16384
.align 4096
user_defs_start:
.space USER_DEFS_SIZE
.align 4096
user_defs_start:
.space USER_DEFS_SIZE
@@
-634,9
+634,9
@@
DOUBLE: .int DOCOL // codeword
*/
/* Flags - these are discussed later. */
*/
/* Flags - these are discussed later. */
-
#define F_IMMED
0x80
-
#define F_HIDDEN
0x20
-
#define F_LENMASK 0x1f
// length mask
+
.set F_IMMED,
0x80
+
.set F_HIDDEN,
0x20
+
.set F_LENMASK,0x1f
// length mask
// Store the chain of links.
.set link,0
// Store the chain of links.
.set link,0
@@
-2522,18
+2522,14
@@
buffer:
)
: ID.
4+ ( skip over the link pointer )
)
: ID.
4+ ( skip over the link pointer )
- .S CR
DUP @b ( get the flags/length byte )
DUP @b ( get the flags/length byte )
- .S CR
- F_LENMASK .S CR AND ( mask out the flags - just want the length )
- .S CR
+ F_LENMASK AND ( mask out the flags - just want the length )
BEGIN
DUP 0> ( length > 0? )
WHILE
SWAP 1+ ( addr len -- len addr+1 )
DUP @b ( len addr -- len addr char | get the next character)
BEGIN
DUP 0> ( length > 0? )
WHILE
SWAP 1+ ( addr len -- len addr+1 )
DUP @b ( len addr -- len addr char | get the next character)
- .\" print: \" DUP . CR
EMIT ( len addr char -- len addr | and print it)
SWAP 1- ( len addr -- addr len-1 | subtract one from length )
REPEAT
EMIT ( len addr char -- len addr | and print it)
SWAP 1- ( len addr -- addr len-1 | subtract one from length )
REPEAT
@@
-2545,20
+2541,18
@@
buffer:
The implementation simply iterates backwards from LATEST using the link pointers.
)
The implementation simply iterates backwards from LATEST using the link pointers.
)
- (
: WORDS
LATEST @ ( start at LATEST dictionary entry )
BEGIN
: WORDS
LATEST @ ( start at LATEST dictionary entry )
BEGIN
- DUP
@ 0<>
( while link pointer is not null )
+ DUP
0<>
( while link pointer is not null )
WHILE
WHILE
-
-
-
-
-
+ DUP ID. ( print the word )
+ SPACE
+ @ ( dereference the link pointer - go to previous word )
REPEAT
DROP
REPEAT
DROP
-; )
+ CR
+;
(
So far we have only allocated words and memory. FORTH provides a rather primitive method
(
So far we have only allocated words and memory. FORTH provides a rather primitive method
@@
-2578,11
+2572,13
@@
buffer:
XXX: Because we wrote VARIABLE to store the variable in memory allocated before the word,
in the current implementation VARIABLE FOO FORGET FOO will leak 1 cell of memory.
)
XXX: Because we wrote VARIABLE to store the variable in memory allocated before the word,
in the current implementation VARIABLE FOO FORGET FOO will leak 1 cell of memory.
)
-\\: FORGET
-
-
+: FORGET
+ WORD FIND ( find the word, gets the dictionary entry address )
+ DUP @ LATEST ! ( set LATEST to point to the previous word )
+ HERE ! ( and store HERE with the dictionary address )
+;
-( While compiling,
[COMPILE] WORD compiles WORD
if it would otherwise be IMMEDIATE. )
+( While compiling,
'[COMPILE] word' compiles 'word'
if it would otherwise be IMMEDIATE. )
: [COMPILE] IMMEDIATE
WORD ( get the next word )
FIND ( find it in the dictionary )
: [COMPILE] IMMEDIATE
WORD ( get the next word )
FIND ( find it in the dictionary )