home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-09-13 | 5.3 KB | 246 lines | [TEXT/MSET] |
- \ The Dreaded GetOp - builds the operand structure
-
- 0 -> dlevel
-
- \ 0 value OPPTR Changed to an ObjPtr - in AsmUtilities
-
- 0 value TOKEN_TYPE
-
- objPtr OPDESC class_is operand
-
-
- : (FORMAT) { addr len -- fmt } \ Finds operand format
- addr c@
- CASE & B OF Bfmt ENDOF
- & W OF Wfmt ENDOF
- & L OF Lfmt ENDOF
- & S OF Sfmt ENDOF
- & D OF Dfmt ENDOF
- & X OF Xfmt ENDOF
- & P OF Pfmt ENDOF
-
- 202 AsmError \ Bad operand format
- ENDCASE ;
-
-
- : NEXTOPERAND
- nextToken -> token_type
- " ," get: token s=
- IF
- nextToken -> token_type
- THEN ;
-
-
- : GETFORMAT
- restOfLine nif drop exit then \ Out if line empty
- c@ & . <> ?EXIT \ Or if we don't have a format code
- nextToken drop \ Gobble "."
- nextToken drop \ Get format code
- get: token (format) -> opFmt ;
-
-
- : CLEAROP { opPtr -- }
- 0 opPtr seta/d: operand
- 0 opPtr setauxsize: operand
- 0 opPtr setReg: operand
- 0 opPtr setval: operand
- 0 opPtr setmode: operand
- 0 opPtr setauxreg: operand
- 0 opPtr setpcmode: operand ;
-
-
- : ABSMODE
- msg" absolute mode"
- 7 setMode: opPtr
- get: token " ." s=
- IF ( Length explicitly specified )
- nextToken drop
- get: token (format) 1- 0 max
- ELSE ( Supply length here )
- value: opPtr
- -32768 $ 7FFF inRange? 1+ \ 0 word, 1 long
- THEN
- dup setReg: opPtr 7 + setpcmode: opPtr ;
-
- : HANDLE_INDEX
- msg" index mode"
- nextToken drop \ should be comma
- nextToken drop token query: operands drop -> opDesc
- mode: opDesc dup 20 = swap 21 = or
- IF \ No len associated with index reg
- reg: opDesc setAuxReg: opPtr
- mode: opDesc 20 - val" a/d to" setA/D: opPtr
- 2 setAuxSize: opPtr \ Default for Mops is long
- ELSE
- nextToken 3 = \ should be '.', len associated
- \ with index reg
- IF
- reg: opDesc setAuxReg: opPtr
- mode: opDesc setA/D: opPtr
- nextToken drop get: token (format)
- setAuxSize: opPtr
- ELSE
- 203 asmError \ unknown operand
- THEN
- THEN ;
-
- : AnREL+
- -1 setAbs: opPtr \ This wasn't a dic ref
- ( mode: opDesc ) dup setpcmode: opPtr
- 7 min val" setMode to" setMode: opPtr
- mode: opPtr 2 =
- IF 5 setMode: opPtr THEN
- reg: opDesc val" setReg to" setReg: opPtr
- mode: opDesc dup 6 = swap 10 = or
- IF handle_index THEN ;
-
-
- : GETDICTTOKEN \ Parses a dictionary name (which can contain all sorts
- \ of strange characters). Following the Neon syntax, we
- \ take it as anything up to the next ].
- \ Sorry, this means that you can't refer to a dic name
- \ containing ] from the assembler. I think space would
- \ have been better, but then this may well have caused
- \ other problems.
- tib pos + tiblen pos - put: token
- & ] chsearch: token drop
- tiblen
- size: token lim: token - ( # chars left )
- - -> pos ;
-
-
- : GETDICTPTR \ ( -- addr ) "Dic" read. Returns dic address.
- getDictToken
- get: token 2dup upper str255 find
- IF
- val" dic addr"
- ELSE
- 216 asmError
- THEN
- nextToken drop ; \ "]"
-
-
- : GETGLOB \ ( -- addr ) " Glob[" read. Returns global address.
- getDictToken
- get: token 2dup upper
- $>glob
- nextToken drop ; \ "]"
-
- : GETKONST \ ( -- kval ) " konst[" read. Returns the value.
- getDictToken
- get: token 2dup upper
- $>konst
- nextToken drop ; \ "]"
-
- : COMPBD
- abs: opPtr
- >b&dComp \ convert to ( base displ )
- setval: opPtr \ set displ
- setReg: opPtr \ set base reg
- AnRelMode setmode: opPtr ; \ mode = d(An)
-
-
- : DICREF \ "dic", "glob" etc. read
- msg" dic reference"
- nextToken drop \ Should be "[" - we'll check
- get: token 1 <> IF 217 asmerror THEN
- c@ & [ <> IF 217 asmerror THEN
- opDesc reg: operand
- SELECT{
- 3 IS{ getGlob }END
- 4 IS{ getKonst }END
- DEFAULT{
- getDictPtr \ get dic addr
- opDesc reg: operand 2 = \ If an object ref,
- IF >obj THEN \ adjust address
- }SELECT
- value: opPtr + \ add any displacement
- dup setAbs: opPtr
- setVal: opPtr
- opDesc reg: operand
- SELECT{
- 0 IS{ \ rel[...]
- 9 setMode: opPtr \ set PC-relative mode
- 2 setReg: opPtr }END
- 3 IS{ \ glob[...]
- 7 setMode: opPtr \ set absolute mode
- 0 setReg: opPtr }END
- 4 IS{ \ konst[...]
- 11 setMode: opPtr \ set immediate mode
- 4 setReg: opPtr }END
- DEFAULT{ compBD
- }SELECT ;
-
-
- : HANDLE_LABEL
- msg" handling label"
- pass 2 =
- IF
- token query: symTab
- dup nilP =
- IF
- 251 asmError \ Undef. label
- ELSE
- get: var
- value: opPtr + \ Add any displacement
- dup setAbs: opPtr setVal: opPtr
- THEN
- THEN
- compBD ;
-
-
- : LABDISP \ Handles disp(label).
- 1 skip: token -1 more: token handle_label
- nextToken drop ;
-
-
- : HANDLE_#
- msg" number read"
- get: token >num val" number is"
- setVal: opPtr
- nextToken drop
- token query: operands
- NIF
- 1st: token & ( =
- IF labDisp ELSE absMode THEN
- EXIT
- THEN
- -> opDesc
- opDesc mode: operand val" mode is "
- dup (An)Mode = over IndexMode = or
- over PCrelMode = or over PCindexMode = or
- IF AnRel+ EXIT THEN
- ( mode: opDesc ) DicMode =
- IF ( nnn(dic[ )
- dicRef
- nextToken drop \ Gobble ")"
- EXIT
- THEN
- 203 AsmError ;
-
-
- : HANDLE_IMM
- nextToken 1 =
- IF
- get: token >num setVal: opPtr
- ELSE
- 205 asmError
- THEN ;
-
-
- : HANDLE_NAME
- token query: operands
- val" F means Label" NIF handle_label EXIT THEN
- -> opDesc
- reg: opDesc val" reg is " setReg: opPtr
- mode: opDesc val" mode is " setMode: opPtr
- mode: opPtr immedMode = IF handle_imm EXIT THEN
- mode: opPtr dicMode =
- IF dicRef THEN ;
-
-
- : GETOP
- -> opPtr
- opptr clearOp nextOperand
- token_type 1 = IF handle_# ELSE handle_name THEN ;
-