~vdupras/duskos

ref: ab62853f9ec65075c9e1a480861b5c0cea7b5e7c duskos/fs/xcomp/tools.fs -rw-r--r-- 849 bytes
ab62853fVirgil Dupras xcomp/tools: fix broken orgifydict 3 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
\ Tools for cross-compiling binaries
\ In Dusk, we don't support cross-compiling Forth. It's too hairy. Here, we're
\ only talking about cross-compiling assembler code, with, optionally, a Forth
\ dict in it.

?f<< /lib/xdict.fs
?f<< /asm/label.fs \ org and binstart are there

newxdict xbindict

: xoffset binstart org - ;
: xcode word xbindict xentry ;

\ Usage: xwordlbl foo call, "foo" being a word name in xbindict
: xwordlbl ( "name" -- pc ) xbindict x' xoffset + ;

\ Traverse xdict and change all its prev field values so that they are related
\ to current org+binstart. Once this is done, the xdict can't be traversed
\ anymore and becomes opaque binary contents.
: orgifydict ( xdict -- )
  @ begin ( a )
    5 - dup @ ( 'prev prev )
    ?dup while ( 'prev prev )
    dup xoffset + ( 'prev oldprev newprev ) rot ! ( prev ) repeat 2drop ;