--- gforth/cross.fs 1998/07/05 20:49:59 1.56 +++ gforth/cross.fs 1998/12/11 22:54:26 1.59 @@ -1,7 +1,7 @@ \ CROSS.FS The Cross-Compiler 06oct92py \ Idea and implementation: Bernd Paysan (py) -\ Copyright (C) 1995 Free Software Foundation, Inc. +\ Copyright (C) 1995,1996,1997,1998 Free Software Foundation, Inc. \ This file is part of Gforth. @@ -52,6 +52,7 @@ Warnings off \ words that are generaly useful +: KB 400 * ; : >wordlist ( vocabulary-xt -- wordlist-struct ) also execute get-order swap >r 1- set-order r> ; @@ -302,6 +303,7 @@ true SetValue cross true SetValue standard-threading >TARGET previous + mach-file count included hex >ENVIRON @@ -334,14 +336,16 @@ s" relocate" T environment? H \ \ Create additional parameters 19jan95py +1 8 lshift Constant maxbyte T NIL Constant TNIL cell Constant tcell cell<< Constant tcell<< cell>bit Constant tcell>bit bits/byte Constant tbits/byte +bits/byte 8 / Constant tchar float Constant tfloat -1 bits/byte lshift Constant maxbyte +1 bits/byte lshift Constant tmaxbyte H \ Variables 06oct92py @@ -589,11 +593,19 @@ bigendian DO maxbyte ud/mod rot I c! -1 +LOOP 2drop ; : S@ ( addr -- n ) >r 0 0 r> tcell bounds DO maxbyte * swap maxbyte um* rot + swap I c@ + swap LOOP d>s ; + : Sc! ( n addr -- ) >r s>d r> tchar bounds swap 1- + DO maxbyte ud/mod rot I c! -1 +LOOP 2drop ; + : Sc@ ( addr -- n ) >r 0 0 r> tchar bounds + DO maxbyte * swap maxbyte um* rot + swap I c@ + swap LOOP d>s ; [ELSE] : S! ( n addr -- ) >r s>d r> tcell bounds DO maxbyte ud/mod rot I c! LOOP 2drop ; : S@ ( addr -- n ) >r 0 0 r> tcell bounds swap 1- DO maxbyte * swap maxbyte um* rot + swap I c@ + swap -1 +LOOP d>s ; + : Sc! ( n addr -- ) >r s>d r> tchar bounds + DO maxbyte ud/mod rot I c! LOOP 2drop ; + : Sc@ ( addr -- n ) >r 0 0 r> tchar bounds swap 1- + DO maxbyte * swap maxbyte um* rot + swap I c@ + swap -1 +LOOP d>s ; [THEN] >CROSS @@ -629,8 +641,8 @@ CREATE Bittable 80 c, 40 c, 20 c, 10 c, >TARGET : @ ( taddr -- w ) >image S@ ; : ! ( w taddr -- ) >image S! ; -: c@ ( taddr -- char ) >image c@ ; -: c! ( char taddr -- ) >image c! ; +: c@ ( taddr -- char ) >image Sc@ ; +: c! ( char taddr -- ) >image Sc! ; : 2@ ( taddr -- x1 x2 ) T dup cell+ @ swap @ H ; : 2! ( x1 x2 taddr -- ) T swap over ! cell+ ! H ; @@ -640,21 +652,22 @@ CREATE Bittable 80 c, 40 c, 20 c, 10 c, : here ( -- there ) there ; : allot ( n -- ) tdp +! ; : , ( w -- ) T here H tcell T allot ! H T here drop H ; -: c, ( char -- ) T here 1 allot c! H ; +: c, ( char -- ) T here tchar allot c! H ; : align ( -- ) T here H align+ 0 ?DO bl T c, H LOOP ; : cfalign ( -- ) - T here H cfalign+ 0 ?DO bl T c, H LOOP ; + T here H cfalign+ 0 ?DO bl T c, tchar H +LOOP ; -: A! dup relon T ! H ; -: A, ( w -- ) T here H relon T , H ; +: >address dup 0>= IF tchar / THEN ; +: A! swap >address swap dup relon T ! H ; +: A, ( w -- ) >address T here H relon T , H ; >CROSS : tcmove ( source dest len -- ) \G cmove in target memory - bounds + tchar * bounds ?DO dup T c@ H I T c! H 1+ - LOOP drop ; + tchar +LOOP drop ; >TARGET H also Forth definitions \ ." asm: " order @@ -1105,7 +1118,7 @@ NoHeaderFlag off IF NoHeaderFlag off ELSE T align H view, - tlast @ dup 0> IF T 1 cells - THEN A, H there tlast ! + tlast @ dup 0> IF T 1 cells - H THEN T A, H there tlast ! 1 headers-named +! \ Statistic >in @ T name, H >in ! THEN @@ -1213,7 +1226,7 @@ Cond: ['] T ' H alit, ;Cond \ modularized 14jun97jaw : fillcfa ( usedcells -- ) - T cells H xt>body swap - 0 ?DO 0 T c, H LOOP ; + T cells H xt>body swap - 0 ?DO 0 T c, tchar H +LOOP ; : (>body) ( cfa -- pfa ) xt>body + ; ' (>body) T IS >body H @@ -1263,7 +1276,7 @@ Defer (end-code) ELSE true ABORT" CROSS: Stack empty" THEN ; -Cond: chars ;Cond +( Cond ) : chars tchar * ; ( Cond ) >CROSS @@ -1621,7 +1634,7 @@ Builder Field : sys? ( sys -- sys ) dup 0= ?struc ; : >mark ( -- sys ) T here ( dup ." M" hex. ) 0 , H ; -: branchoffset ( src dest -- ) - ; +: branchoffset ( src dest -- ) - tchar / ; : >resolve ( sys -- ) T here ( dup ." >" hex. ) over branchoffset swap ! H ; @@ -1944,6 +1957,7 @@ previous Create magic s" Gforth10" here over allot swap move char 1 bigendian + tcell + magic 7 + c! +char 0 tchar + magic 6 + c! : save-cross ( "image-name" "binary-name" -- ) bl parse ." Saving to " 2dup type cr