home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
forth
/
compiler
/
fpc
/
source
/
longlabl.seq
< prev
next >
Wrap
Text File
|
1990-12-17
|
4KB
|
120 lines
\\ LONGLABL.SEQ Modified local labels for long branches
{
: %"ERRMSG3 ( cfa A1 N1 -- ) \ a dummy filler till real one
cr type drop ;
DEFER "ERRMSG3 ' %"errmsg3 is "errmsg3
ASSEMBLER DEFINITIONS ALSO
\ following defined in DIS05:
\ DEFER T@ FORTH ' @ ASSEMBLER IS T@
' HERE ALIAS ASMHERE
}
=========================================================
BEGIN LOCAL LABELS SECTION:
=========================================================
{
FORTH DEFINITIONS
0 value ?long
0 value ?long_lib
: long_branch ( -- )
on> ?long ;
: short_branch ( -- )
off> ?long ;
: long_library ( -- )
on> ?long_lib ;
: short_library ( -- )
off> ?long_lib ;
short_branch \ default to short branches
short_library \ also use short branches in library
ASSEMBLER DEFINITIONS
}
Translates a label reference to the appropriate dictionary
location and sets the "ever referenced?" flag.
If the reference is a forward reference, then a linked list
of the forward references themselves is built using the
dictionary byte locations where the jump offsets are
"compiled". The reason for using this technique at all is
that it allows an arbitrary number of forward references per
label to be made (within the jump offset limitations of
course) and that it requires table space only for the linked
list head pointer. The technique is eloquent if convoluted
and, as a minimum, needs explanation.
{
' $ ALIAS $| ( n1 -- n2 )
}
Resolves all local label forward references for a given
label.
{
: >resL ( ^line -- )
[ FORTH ]
2+ @ dup 0= \ if nothing to resolve
IF drop exit \ then exit
THEN DUP>R
1+ BEGIN \ stack contains directory address of
\ displacement to be resolved
DUP 1- TC@ $E9 = \ if we have a JMP WORD instruction
IF DUP T@ >R \ save link for now
ASMHERE OVER - 2- \ calculate displacement
OVER T! \ and put in jump instruction
R> $FFFD OVER <> \ $FFFD signifies end of list
ELSE DUP TC@ >R
ASMHERE OVER - 1-
DUP $7F U>
if 0 " Branch out of range, use LONG_BRANCH"
"errmsg3 abort
then
OVER TC! R> $FE OVER <> \ $FE signifies end of list
THEN
WHILE
R@ TC@ $E9 <>
IF $ff00 or \ sign extend since link is backward
THEN
+ 2+ \ now move to next item on list
REPEAT
R>DROP 2DROP ;
: $$:f ( n -- ) \ defines a local label
[ FORTH ]
true !> ll-used? \ set "labels used?" flag
llab>line
dup @ 0<>
if 0 " Label can't be multiply defined" "errmsg3 abort
then
dup >resL \ resolve forward references if needed
ASMHERE swap ! ; \ and set label for subsequent refs
: $:| ( n -- ) \ allow use as prefix/postfix
[ FORTH ]
?LONG 0=
IF ['] $:f
ELSE ['] $$:f
THEN a;! a; ;
ONLY FORTH ALSO DEFINITIONS
}
=========================================================
END LOCAL LABELS SECTION:
=========================================================