--- gforth/cross.fs 1994/09/02 15:23:33 1.11 +++ gforth/cross.fs 1995/01/24 17:31:17 1.20 @@ -1,7 +1,7 @@ \ CROSS.FS The Cross-Compiler 06oct92py -\ $Id: cross.fs,v 1.11 1994/09/02 15:23:33 pazsan Exp $ +\ $Id: cross.fs,v 1.20 1995/01/24 17:31:17 pazsan Exp $ \ Idea and implementation: Bernd Paysan (py) -\ Copyright 1992 by the ANSI figForth Development Group +\ Copyright 1992-94 by the GNU Forth Development Group \ Log: \ changed in ; [ to state off 12may93jaw @@ -40,7 +40,7 @@ VARIABLE GhostNames 0 GhostNames ! : GhostName ( -- addr ) here GhostNames @ , GhostNames ! here 0 , - name count + bl word count \ 2dup type space dup c, here over chars allot swap move align ; @@ -84,19 +84,30 @@ Variable tdp \ Parameter for target systems 06oct92py -include-file +included + +\ Create additional parameters 19jan95py + +T +cell Constant tcell +cell<< Constant tcell<< +cell>bit Constant tcell>bit +bits/byte Constant tbits/byte +float Constant tfloat +1 bits/byte lshift Constant maxbyte +H >TARGET \ Byte ordering and cell size 06oct92py -: cell+ cell + ; -: cells cell<< lshift ; +: cell+ tcell + ; +: cells tcell<< lshift ; : chars ; -: floats float * ; +: floats tfloat * ; >CROSS -: cell/ cell<< rshift ; +: cell/ tcell<< rshift ; >TARGET 20 CONSTANT bl -1 Constant NIL @@ -110,12 +121,17 @@ include-file >CROSS -endian 0 pad ! -1 pad c! pad @ 0< -= [IF] : bswap ; immediate -[ELSE] : bswap ( big / little -- little / big ) 0 - cell 1- FOR bits/byte lshift over - [ 1 bits/byte lshift 1- ] Literal and or - swap bits/byte rshift swap NEXT nip ; +bigendian +[IF] + : T! ( n addr -- ) >r s>d r> tcell bounds swap 1- + DO maxbyte ud/mod rot I c! -1 +LOOP 2drop ; + : T@ ( addr -- n ) >r 0 0 r> tcell bounds + DO maxbyte * swap maxbyte um* rot + swap I c@ + swap LOOP d>s ; +[ELSE] + : T! ( n addr -- ) >r s>d r> tcell bounds + DO maxbyte ud/mod rot I c! LOOP 2drop ; + : T@ ( addr -- n ) >r 0 0 r> tcell bounds swap 1- + DO maxbyte * swap maxbyte um* rot + swap I c@ + swap -1 +LOOP d>s ; [THEN] \ Memory initialisation 05dec92py @@ -164,8 +180,8 @@ CREATE Bittable 80 c, 40 c, 20 c, 10 c, >CROSS : >image ( taddr -- absaddr ) image @ + ; >TARGET -: @ ( taddr -- w ) >image @ bswap ; -: ! ( w taddr -- ) >r bswap r> >image ! ; +: @ ( taddr -- w ) >image t@ ; +: ! ( w taddr -- ) >image t! ; : c@ ( taddr -- char ) >image c@ ; : c! ( char taddr -- ) >image c! ; : 2@ ( taddr -- x1 x2 ) T dup cell+ @ swap @ H ; @@ -234,15 +250,13 @@ Variable last-ghost \ searches for string in word-list ghosts \ !! wouldn't it be simpler to just use search-wordlist ? ae dup count [ ' ghosts >body ] ALiteral search-wordlist -\ >r get-order 0 set-order also ghosts r> find >r >r - >r r@ IF >body nip THEN r> ; -\ set-order r> r@ IF >body THEN r> ; + dup IF >r >body nip r> THEN ; VARIABLE Already : ghost ( "name" -- ghost ) Already off - >in @ name gfind IF Already on nip EXIT THEN + >in @ bl word gfind IF Already on nip EXIT THEN drop >in ! Make-Ghost ; \ resolve 14oct92py @@ -258,7 +272,7 @@ VARIABLE Already BEGIN @ dup WHILE 2dup cell+ @ = UNTIL - nip 2 cells + count cr ." CROSS: Exists: " type 4 spaces + 2 cells + count cr ." CROSS: Exists: " type 4 spaces drop swap cell+ ! ELSE true ABORT" CROSS: Ghostnames inconsistent" THEN ; @@ -314,7 +328,7 @@ VARIABLE ^imm >TARGET : immediate 20 flag! - ^imm @ @ dup = ?EXIT + ^imm @ @ dup = IF drop EXIT THEN <> ABORT" CROSS: Cannot immediate a unresolved word" ^imm @ ! ; : restrict 40 flag! ; @@ -324,13 +338,13 @@ VARIABLE ^imm : ALIAS2 create here 0 , DOES> @ execute ; \ usage: -\ ' alias2 bla ! +\ ' alias2 bla ! \ Target Header Creation 01nov92py : string, ( addr count -- ) dup T c, H bounds DO I c@ T c, H LOOP ; -: name, ( "name" -- ) name count string, T align H ; +: name, ( "name" -- ) bl word count string, T align H ; : view, ( -- ) ( dummy ) ; VARIABLE CreateFlag CreateFlag off @@ -339,10 +353,10 @@ VARIABLE CreateFlag CreateFlag off tlast @ dup 0> IF T 1 cells - THEN A, H there tlast ! >in @ name, >in ! T here H tlastcfa ! CreateFlag @ IF - >in @ alias2 swap >in ! \ create alias in target - >in @ ghost swap >in ! - swap also ghosts ' previous swap ! \ tick ghost and store in alias - CreateFlag off + >in @ alias2 swap >in ! \ create alias in target + >in @ ghost swap >in ! + swap also ghosts ' previous swap ! \ tick ghost and store in alias + CreateFlag off ELSE ghost THEN dup >magic ^imm ! \ a pointer for immediate Already @ IF dup >end tdoes ! @@ -398,18 +412,20 @@ ghost ' : compile ( -- ) \ name restrict? - name gfind dup 0= ABORT" CROSS: Can't compile " + bl word gfind dup 0= ABORT" CROSS: Can't compile " 0> ( immediate? ) IF >exec @ compile, ELSE postpone literal postpone gexecute THEN ; immediate >TARGET -: ' ( -- cfa ) name gfind 0= ABORT" CROSS: undefined " +: ' ( -- cfa ) bl word gfind 0= ABORT" CROSS: undefined " dup >magic @ = ABORT" CROSS: forward " >link @ ; Cond: ['] compile lit ghost gexecute ;Cond +Cond: chars ;Cond + >CROSS \ tLiteral 12dec92py @@ -442,7 +458,7 @@ Cond: [Char] ( "" -- ) restrict : ] state on BEGIN - BEGIN >in @ name + BEGIN >in @ bl word dup c@ 0= WHILE 2drop refill 0= ABORT" CROSS: End of file while target compiling" REPEAT @@ -547,10 +563,10 @@ Variable tup 0 tup ! Variable tudp 0 tudp ! : u, ( n -- udp ) tup @ tudp @ + T ! H - tudp @ dup cell+ tudp ! ; + tudp @ dup T cell+ H tudp ! ; : au, ( n -- udp ) tup @ tudp @ + T A! H - tudp @ dup cell+ tudp ! ; + tudp @ dup T cell+ H tudp ! ; >TARGET Build: T 0 u, , H ; @@ -672,14 +688,14 @@ Cond: TO T ' >body H compile ALit \ compile must be last 22feb93py Cond: compile ( -- ) restrict? \ name - name gfind dup 0= ABORT" CROSS: Can't compile" + bl word gfind dup 0= ABORT" CROSS: Can't compile" 0> IF gexecute ELSE dup >magic @ = IF gexecute ELSE compile (compile) gexecute THEN THEN ;Cond Cond: postpone ( -- ) restrict? \ name - name gfind dup 0= ABORT" CROSS: Can't compile" + bl word gfind dup 0= ABORT" CROSS: Can't compile" 0> IF gexecute ELSE dup >magic @ = IF gexecute @@ -693,7 +709,7 @@ also minimal \ define new [IFDEF] and [IFUNDEF] 20may93jaw -: there? name gfind IF >magic @ <> ELSE drop false THEN ; +: there? bl word gfind IF >magic @ <> ELSE drop false THEN ; : [IFDEF] there? postpone [IF] ; : [IFUNDEF] there? 0= postpone [IF] ; @@ -733,13 +749,15 @@ Cond: [ELSE] [ELSE] ;Cond \ [THEN] \ included throw after create-file 11may93jaw -endian Constant endian +bigendian Constant bigendian : save-cross ( "name" -- ) bl parse ." Saving to " 2dup type w/o bin create-file throw >r - image @ there r@ write-file throw - bit$ @ there 1- cell>bit rshift 1+ r@ write-file throw + s" gforth00" r@ write-file throw \ write magic + image @ there r@ write-file throw \ write image + bit$ @ there 1- cell>bit rshift 1+ + r@ write-file throw \ write tags r> close-file throw ; \ words that should be in minimal @@ -749,6 +767,10 @@ endian Constant endian : * * ; : / / ; : dup dup ; : over over ; : swap swap ; : rot rot ; +: drop drop ; : = = ; +: lshift lshift ; : 2/ 2/ ; +: . . ; +cell constant cell \ include bug5.fs \ only forth also minimal definitions