Download V5N1 - Forth

Transcript
interpretation is by calls to
subroutines rather than threaded
code. There is no code address
generated for COLON (:) or SEMI (;).
variable/RAM memory space is
a u t o m a t i c a l l y separated f r o m
program code (ROMable version)
rather than intermixed with program
code.
Record Structure
Using the same technique as for
data structure, a COBOL-like
structure for contiguous memory
space is easily implemented. Data can
then be described as items or arrays of
word, byte, bit(s), string or decimal.
FORTH systems with program code
space separated from the variable
space (ROMable system) a r e
particularly suitable for inclusion of
such a record structure.
The record structure implemented
consists of about 2K bytes of
compiling code and 4K bytes of
program code (ROMable code). This
does not include dictionary space.
Spically citing A? or A = for a
record structure involves an executive
speed of between 4 to 6 times that of
the Word + . The increase in execution
speed due to runtime interpretation is
found to be negligible for applications
on Motorola M6800 and M6809
processors at IMHZ. A typical
application program would be
reasonably interrupt intensive, VDU
display orientated and consist of over
6 4 K bytes of ROMable code.
Dictionary space, while heavily used,
is not included in the target
application.
Implementation Details
A record data structure is described
internally by
the address of an executable
environment pointer.
the relative offset position from the
start of the record structure.
the internal encoded description of
the data structure.
An environment pointer is allocated
when a record header definition
appears in the source program. All
data structures within a record refer to
the same environment pointer which
may be switched by context or
executed as required while the
program is running.
The relative offset position is
determined by the data structures
FORTH Dimensions
LlSTING 2:
DATA STRUCTURE
US2.0
SCR..E
0
1
7
!
6
7
8
9
: CREATECXI
CREATEX
: CREATE-ARRAY
3
JAN 83
PAGE- 2
;
CREATECXI
: CRERTEC=j
13D CREATE-ARRAY
: CREATE[?;
." : CREATErLii3F CREATE-ARRAY
rn
11
(
IN @ OVER [CONSTANTI IN !
14C 3 ADJUST-NARE
12
13
(
PSWl = LIRIT
CREATE NARE
)
)
14
SCR..9
0 NOTE
RAY NEED ONE MORE WORD
DEPENDING ON UHETHER 'NEXT' INTREPRETATION IS
PRE- OR POST- INCREMENTr
USE NACHINE CODE FOR SPEED
1
2
J
1!
EXAMPLE FOR M6809 PROCESSOR
MID JSR/RTS SUBROUTINE CALL IS
PULS x
LDD
C3,Xl
SUBROUTINE CALL IS 3 BYTES
PSHU D
PUSH INTO P-STACK
RTS
DOUBLE EXIT
FOR DO-VAR?
6
7
8
9
10
11
12
13
16
->
15
SCR..lO
0 NOTE
1
2
3
LEAVE OUT THE WORD C ( NOT POINTED TO
FOR A NON RORABLE SYSTEH
EG: R >
zt
)
e
FOR DO-VAR?
4
5
SCR..11
0
1
:
J
4
5
5
8
9
: DO-VAR?
: DO-CVAR?
R)
zt
e e
2+
(
e ce
I?>
2t
(
(
(
10
11
12
13
14
: DO-ARRAYC?I
p
->
15
SCR..lZ
0
1
2
3
4
5
: DO-VAR=
8
9
10
11
12
13
14
+
'NEXT
I
1
)
ce
R > 4 + @ !
R'
: DO-ARRAYC=l
R>
e C!
4
t
4
+ e + C!
->
15
SCR.. 13
e
t INSTEAD OF 2+
FOR PTE-INCRERENT
4
,
: DO-CVAR=
6
7
zt
FOR 2 BYTES AWRY 1
EQUALS 1 WORD
)
0 NOTE
1
2
3
4
MODIFY R-VAR M-CVAR R-ARRAY AS REQUIRED
SEPARATE DICTIONARY FROM GENERATED CODE,
SUPPLYING CODE ADDRESS AS REQUIRED
::
CHANGE ORDER OF ACTION
LISTING IS FOR SYSTEM
UHICH ALREADY SEPARATED DICTIONARY FROR CODE
78
9
10
11
12
13
DO-VARIS ERPLACING YHICH GENERATES THE CODE.
\
14
15
->
(Listing Continued)
24
Volume V, No. 1