-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcross.f
44 lines (33 loc) · 1.36 KB
/
cross.f
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
\ utilities for cross-compilation
\ compile dictionary entries for primitives (either colon words or
\ constants):
variable pddp pddp off
\ adjust real address to address in image and back
: preloc ( a1 -- a2 ) dup if pdictbase @ - pdictaddr @ + then ;
: punreloc ( a1 -- a2 ) dup if pdictaddr @ - pdictbase @ + then ;
: pcreate ( | <word> -- )
here >r pddp @ preloc t, bl word dup c@ 1+ here swap dup >r
cmove r> allot align r> pddp ! ;
: pnative ( a | <word> -- ) pcreate t, ;
: pconstant ( x | <word> -- ) pcreate c:(constant) @ t, t, ;
variable plastprim variable lastprim
\ find cfa in manually created pdict that corresponds to host-cfa
: xmap ( xt -- xt' )
>r plastprim @ lastprim @ begin
?dup while
dup cell+ >cfa r@ = if
r> 2drop cell+ >cfa preloc exit
then
swap t@ punreloc swap @
repeat true abort" unmapped primitive" ;
\ obtain ptr to last primitive in host dictionary
: setlastprim findname 0= abort" can not find (deferred)" 1 cells - lastprim ! ;
c" (deferred)" setlastprim \ c" only works in interpreted mode
' xmap >map-primitive !
\ read .text section from file
: load.text ( a n offset | fname -- )
bl word count r/o open-file ?fcheck >r
here swap r@ read-file ?fcheck drop \ skip header
over textbase !
r@ read-file ?fcheck drop
r> close-file ?fcheck ;