--- gforth/cross.fs 2005/12/31 15:46:08 1.150 +++ gforth/cross.fs 2007/03/31 21:43:18 1.163 @@ -1,7 +1,7 @@ \ CROSS.FS The Cross-Compiler 06oct92py \ Idea and implementation: Bernd Paysan (py) -\ Copyright (C) 1995,1996,1997,1998,1999,2000,2003,2004,2005 Free Software Foundation, Inc. +\ Copyright (C) 1995,1996,1997,1998,1999,2000,2003,2004,2005,2006 Free Software Foundation, Inc. \ This file is part of Gforth. @@ -1175,6 +1175,7 @@ false DefaultValue header false DefaultValue backtrace false DefaultValue new-input false DefaultValue peephole +false DefaultValue primcentric false DefaultValue abranch true DefaultValue f83headerstring true DefaultValue control-rack @@ -1184,6 +1185,7 @@ true DefaultValue gforthcross true DefaultValue interpreter true DefaultValue ITC false DefaultValue rom +false DefaultValue flash true DefaultValue standardthreading \ ANSForth environment stuff @@ -1751,7 +1753,11 @@ Ghost state drop swap -rot bounds ?DO I c@ over X c! X char+ LOOP drop ; 2Variable last-string +X has? rom [IF] $60 [ELSE] $00 [THEN] Constant header-masks +: ht-header, ( addr count -- ) + dup there swap last-string 2! + dup header-masks or T c, H bounds ?DO I c@ T c, H LOOP ; : ht-string, ( addr count -- ) dup there swap last-string 2! dup T c, H bounds ?DO I c@ T c, H LOOP ; @@ -1771,6 +1777,9 @@ Ghost state drop ?DO dup T c@ H I T c! H 1+ tchar +LOOP drop ; +: tcallot ( char size -- ) + 0 ?DO dup T c, H tchar +LOOP drop ; + : td, ( d -- ) \G Store a host value as one cell into the target there tcell X allot TD! ; @@ -2057,7 +2066,7 @@ $20 constant restrict-mask >TARGET X has? f83headerstring [IF] -: name, ( "name" -- ) bl word count ht-string, X cfalign ; +: name, ( "name" -- ) bl word count ht-header, X cfalign ; [ELSE] : name, ( "name" -- ) bl word count ht-lstring, X cfalign ; [THEN] @@ -2307,7 +2316,11 @@ Variable prim# prim# @ (THeader ( S xt ghost ) ['] prim-resolved over >comp ! dup >ghost-flags set-flag - over resolve-noforwards T A, H alias-mask flag! + over resolve-noforwards T A, H + s" EC" T $has? H 0= + IF + alias-mask flag! + THEN -1 prim# +! ; >CROSS @@ -2570,7 +2583,7 @@ Cond: MAXI (THeader (:) ; : :noname ( -- colon-sys ) - X cfalign there + switchrom X cfalign there \ define a nameless ghost here ghostheader dup last-header-ghost ! dup to lastghost (:) ; @@ -2617,7 +2630,7 @@ Cond: [ ( -- ) interpreting-state ;Cond Defer instant-interpret-does>-hook ' noop IS instant-interpret-does>-hook -T has? peephole H [IF] +T has? primcentric H [IF] : does-resolved ( ghost -- ) compile does-exec g>xt T a, H ; [ELSE] @@ -2632,7 +2645,8 @@ T has? peephole H [IF] >TARGET Cond: DOES> - T here 5 cells H + alit, compile (does>2) compile ;s + T here H [ T has? primcentric H [IF] ] 5 [ [ELSE] ] 4 [ [THEN] ] T cells + H + alit, compile (does>2) compile ;s doeshandler, resolve-does>-part ;Cond @@ -2822,7 +2836,7 @@ by Create : u, ( n -- udp ) current-region >r user-region activate - X here swap X , tup@ - + X here swap X , tup@ - r> activate ; : au, ( n -- udp ) @@ -2863,9 +2877,22 @@ by User [THEN] +T has? rom H [IF] Builder (Value) Build: ( n -- ) ;Build -by: :docon ( target-body-addr -- n ) T @ H ;DO +by: :dovalue ( target-body-addr -- n ) T @ @ H ;DO + +Builder Value +Build: T here 0 A, H switchram T align here swap ! , H ;Build +by (Value) + +Builder AValue +Build: T here 0 A, H switchram T align here swap ! A, H ;Build +by (Value) +[ELSE] +Builder (Value) +Build: ( n -- ) ;Build +by: :dovalue ( target-body-addr -- n ) T @ H ;DO Builder Value BuildSmart: T , H ;Build @@ -2874,12 +2901,18 @@ by (Value) Builder AValue BuildSmart: T A, H ;Build by (Value) +[THEN] Defer texecute Builder Defer -BuildSmart: ( -- ) [T'] noop T A, H ;Build -by: :dodefer ( ghost -- ) X @ texecute ;DO +T has? rom H [IF] + Build: ( -- ) T here 0 A, H switchram T align here swap ! H [T'] noop T A, H ( switchrom ) ;Build + by: :dodefer ( ghost -- ) X @ X @ texecute ;DO +[ELSE] + BuildSmart: ( -- ) [T'] noop T A, H ;Build + by: :dodefer ( ghost -- ) X @ texecute ;DO +[THEN] Builder interpret/compile: Build: ( inter comp -- ) swap T A, A, H ;Build-immediate @@ -2932,7 +2965,7 @@ DO: abort" Not in cross mode" ;DO \ optimizer for cross -T has? peephole H [IF] +T has? primcentric H [IF] \ .( loading peephole optimization) cr @@ -3212,10 +3245,19 @@ Cond: ABORT" if, ahead, there [char] >r then, r> compile ALiteral compile c(abort") then, ;Cond [THEN] +X has? rom [IF] +Cond: IS T ' >body @ H compile ALiteral compile ! ;Cond +: IS T >address ' >body @ ! H ; +Cond: TO T ' >body @ H compile ALiteral compile ! ;Cond +: TO T ' >body @ ! H ; +Cond: CTO T ' >body H compile ALiteral compile ! ;Cond +: CTO T ' >body ! H ; +[ELSE] Cond: IS T ' >body H compile ALiteral compile ! ;Cond : IS T >address ' >body ! H ; Cond: TO T ' >body H compile ALiteral compile ! ;Cond : TO T ' >body ! H ; +[THEN] Cond: defers T ' >body @ compile, H ;Cond @@ -3269,6 +3311,7 @@ tchar 8 = 78 and or magic 7 + c! : save-cross ( "image-name" "binary-name" -- ) + .regions \ s" ec" X $has? IF .regions THEN bl parse ." Saving to " 2dup type cr w/o bin create-file throw >r s" header" X $has? IF @@ -3285,7 +3328,8 @@ magic 7 + c! ELSE bl parse 2drop THEN - dictionary >rmem @ there + >rom dictionary >rmem @ there + s" rom" X $has? IF dictionary >rstart @ - THEN r@ write-file throw \ write image s" relocate" X $has? IF dictionary >rbm @ there 1- tcell>bit rshift 1+ @@ -3693,6 +3737,8 @@ previous : 2/ 2/ ; : hex. base @ $10 base ! swap . base ! ; : invert invert ; +: linkstring ( addr u n addr -- ) + X here over X @ X , swap X ! X , ht-string, X align ; \ : . . ; : all-words ['] forced? IS skip? ;