[gforth] / gforth / cross.fs  

gforth: gforth/cross.fs


1 : anton 1.1 \ CROSS.FS The Cross-Compiler 06oct92py
2 :     \ Idea and implementation: Bernd Paysan (py)
3 : anton 1.30
4 : anton 1.138 \ Copyright (C) 1995,1996,1997,1998,1999,2000,2003 Free Software Foundation, Inc.
5 : anton 1.30
6 :     \ This file is part of Gforth.
7 :    
8 :     \ Gforth is free software; you can redistribute it and/or
9 :     \ modify it under the terms of the GNU General Public License
10 :     \ as published by the Free Software Foundation; either version 2
11 :     \ of the License, or (at your option) any later version.
12 :    
13 :     \ This program is distributed in the hope that it will be useful,
14 :     \ but WITHOUT ANY WARRANTY; without even the implied warranty of
15 :     \ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 :     \ GNU General Public License for more details.
17 :    
18 :     \ You should have received a copy of the GNU General Public License
19 :     \ along with this program; if not, write to the Free Software
20 : anton 1.87 \ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
21 : anton 1.1
22 : jwilke 1.67 0
23 :     [IF]
24 :    
25 :     ToDo:
26 : jwilke 1.107 - Crossdoc destination ./doc/crossdoc.fd makes no sense when
27 :     cross.fs is used seperately. jaw
28 :     - Do we need this char translation with >address and in branchoffset?
29 :     (>body also affected) jaw
30 : jwilke 1.67
31 :     [THEN]
32 : anton 1.48
33 : anton 1.128 s" compat/strcomp.fs" included
34 :    
35 : jwilke 1.77 hex
36 :    
37 :     \ debugging for compiling
38 :    
39 :     \ print stack at each colon definition
40 :     \ : : save-input cr bl word count type restore-input throw .s : ;
41 :    
42 :     \ print stack at each created word
43 :     \ : create save-input cr bl word count type restore-input throw .s create ;
44 :    
45 :    
46 :     \ \ ------------- Setup Vocabularies
47 :    
48 :     \ Remark: Vocabulary is not ANS, but it should work...
49 :    
50 :     Vocabulary Cross
51 :     Vocabulary Target
52 :     Vocabulary Ghosts
53 :     Vocabulary Minimal
54 :     only Forth also Target also also
55 :     definitions Forth
56 :    
57 : jwilke 1.78 : T previous Ghosts also Target ; immediate
58 : jwilke 1.77 : G Ghosts ; immediate
59 :     : H previous Forth also Cross ; immediate
60 :    
61 :     forth definitions
62 :    
63 : jwilke 1.78 : T previous Ghosts also Target ; immediate
64 : jwilke 1.77 : G Ghosts ; immediate
65 :    
66 : jwilke 1.105
67 : jwilke 1.77 : >cross also Cross definitions previous ;
68 :     : >target also Target definitions previous ;
69 :     : >minimal also Minimal definitions previous ;
70 :    
71 :     H
72 :    
73 :     >CROSS
74 :    
75 : jwilke 1.123 \ Test against this definitions to find out whether we are cross-compiling
76 :     \ may be usefull for assemblers
77 :     0 Constant gforth-cross-indicator
78 :    
79 : jwilke 1.77 \ find out whether we are compiling with gforth
80 :    
81 :     : defined? bl word find nip ;
82 :     defined? emit-file defined? toupper and \ drop 0
83 :     [IF]
84 :     \ use this in a gforth system
85 :     : \GFORTH ; immediate
86 :     : \ANSI postpone \ ; immediate
87 :     [ELSE]
88 :     : \GFORTH postpone \ ; immediate
89 :     : \ANSI ; immediate
90 :     [THEN]
91 :    
92 :     \ANSI : [IFUNDEF] defined? 0= postpone [IF] ; immediate
93 :     \ANSI : [IFDEF] defined? postpone [IF] ; immediate
94 :     0 \ANSI drop 1
95 :     [IF]
96 :     : \G postpone \ ; immediate
97 :     : rdrop postpone r> postpone drop ; immediate
98 :     : name bl word count ;
99 :     : bounds over + swap ;
100 :     : scan >r BEGIN dup WHILE over c@ r@ <> WHILE 1 /string REPEAT THEN rdrop ;
101 :     : linked here over @ , swap ! ;
102 :     : alias create , DOES> @ EXECUTE ;
103 :     : defer ['] noop alias ;
104 :     : is state @
105 :     IF ' >body postpone literal postpone !
106 :     ELSE ' >body ! THEN ; immediate
107 :     : 0>= 0< 0= ;
108 :     : d<> rot <> -rot <> or ;
109 :     : toupper dup [char] a [char] z 1+ within IF [char] A [char] a - + THEN ;
110 :     Variable ebuf
111 :     : emit-file ( c fd -- ior ) swap ebuf c! ebuf 1 chars rot write-file ;
112 :     0a Constant #lf
113 :     0d Constant #cr
114 :    
115 :     [IFUNDEF] Warnings Variable Warnings [THEN]
116 :    
117 :     \ \ Number parsing 23feb93py
118 :    
119 :     \ number? number 23feb93py
120 :    
121 :     Variable dpl
122 :    
123 :     hex
124 :     Create bases 10 , 2 , A , 100 ,
125 :     \ 16 2 10 character
126 :    
127 :     \ !! protect BASE saving wrapper against exceptions
128 :     : getbase ( addr u -- addr' u' )
129 :     over c@ [char] $ - dup 4 u<
130 :     IF
131 :     cells bases + @ base ! 1 /string
132 :     ELSE
133 :     drop
134 :     THEN ;
135 :    
136 :     : sign? ( addr u -- addr u flag )
137 :     over c@ [char] - = dup >r
138 :     IF
139 :     1 /string
140 :     THEN
141 :     r> ;
142 :    
143 :     : s>unumber? ( addr u -- ud flag )
144 : jwilke 1.78 over [char] ' =
145 :     IF \ a ' alone is rather unusual :-)
146 :     drop char+ c@ 0 true EXIT
147 :     THEN
148 : jwilke 1.77 base @ >r dpl on getbase
149 :     0. 2swap
150 :     BEGIN ( d addr len )
151 :     dup >r >number dup
152 :     WHILE \ there are characters left
153 :     dup r> -
154 :     WHILE \ the last >number parsed something
155 :     dup 1- dpl ! over c@ [char] . =
156 :     WHILE \ the current char is '.'
157 :     1 /string
158 :     REPEAT THEN \ there are unparseable characters left
159 :     2drop false
160 :     ELSE
161 :     rdrop 2drop true
162 :     THEN
163 :     r> base ! ;
164 :    
165 :     \ ouch, this is complicated; there must be a simpler way - anton
166 :     : s>number? ( addr len -- d f )
167 :     \ converts string addr len into d, flag indicates success
168 :     sign? >r
169 :     s>unumber?
170 :     0= IF
171 :     rdrop false
172 :     ELSE \ no characters left, all ok
173 :     r>
174 :     IF
175 :     dnegate
176 :     THEN
177 :     true
178 :     THEN ;
179 :    
180 :     : s>number ( addr len -- d )
181 :     \ don't use this, there is no way to tell success
182 :     s>number? drop ;
183 :    
184 :     : snumber? ( c-addr u -- 0 / n -1 / d 0> )
185 :     s>number? 0=
186 :     IF
187 :     2drop false EXIT
188 :     THEN
189 :     dpl @ dup 0< IF
190 :     nip
191 :     ELSE
192 :     1+
193 :     THEN ;
194 :    
195 :     : number? ( string -- string 0 / n -1 / d 0> )
196 :     dup >r count snumber? dup if
197 :     rdrop
198 :     else
199 :     r> swap
200 :     then ;
201 :    
202 :     : number ( string -- d )
203 :     number? ?dup 0= abort" ?" 0<
204 :     IF
205 :     s>d
206 :     THEN ;
207 :    
208 :     [THEN]
209 : anton 1.48
210 : jwilke 1.115 \ this provides assert( and struct stuff
211 :     \GFORTH [IFUNDEF] assert1(
212 :     \GFORTH also forth definitions require assert.fs previous
213 :     \GFORTH [THEN]
214 :    
215 :     >CROSS
216 :    
217 : jwilke 1.52 hex \ the defualt base for the cross-compiler is hex !!
218 : jwilke 1.78 \ Warnings off
219 : jwilke 1.52
220 :     \ words that are generaly useful
221 :    
222 : pazsan 1.59 : KB 400 * ;
223 : jwilke 1.52 : >wordlist ( vocabulary-xt -- wordlist-struct )
224 :     also execute get-order swap >r 1- set-order r> ;
225 :    
226 :     : umax 2dup u< IF swap THEN drop ;
227 :     : umin 2dup u> IF swap THEN drop ;
228 : anton 1.1
229 : pazsan 1.23 : string, ( c-addr u -- )
230 :     \ puts down string as cstring
231 :     dup c, here swap chars dup allot move ;
232 : pazsan 1.5
233 : jwilke 1.77 : ," [char] " parse string, ;
234 :    
235 : jwilke 1.52 : SetValue ( n -- <name> )
236 : pazsan 1.54 \G Same behaviour as "Value" if the <name> is not defined
237 :     \G Same behaviour as "to" if <name> is defined
238 : jwilke 1.52 \G SetValue searches in the current vocabulary
239 : jwilke 1.68 save-input bl word >r restore-input throw r> count
240 :     get-current search-wordlist
241 :     IF drop >r
242 :     \ we have to set current to be topmost context wordlist
243 :     get-order get-order get-current swap 1+ set-order
244 :     r> ['] to execute
245 : jwilke 1.74 set-order
246 : jwilke 1.68 ELSE Value THEN ;
247 : jwilke 1.52
248 :     : DefaultValue ( n -- <name> )
249 : pazsan 1.54 \G Same behaviour as "Value" if the <name> is not defined
250 :     \G DefaultValue searches in the current vocabulary
251 : jwilke 1.52 save-input bl word >r restore-input throw r> count
252 :     get-current search-wordlist
253 : pazsan 1.56 IF bl word drop 2drop ELSE Value THEN ;
254 : anton 1.1
255 :     hex
256 :    
257 : jwilke 1.120 \ FIXME delete`
258 : jwilke 1.52 \ 1 Constant Cross-Flag \ to check whether assembler compiler plug-ins are
259 :     \ for cross-compiling
260 :     \ No! we use "[IFUNDEF]" there to find out whether we are target compiling!!!
261 :    
262 : jwilke 1.120 \ FIXME move down
263 : jwilke 1.52 : comment? ( c-addr u -- c-addr u )
264 : anton 1.128 2dup s" (" str=
265 : jwilke 1.52 IF postpone (
266 : anton 1.128 ELSE 2dup s" \" str= IF postpone \ THEN
267 : jwilke 1.52 THEN ;
268 :    
269 : jwilke 1.120 : X ( -- <name> )
270 :     \G The next word in the input is a target word.
271 :     \G Equivalent to T <name> but without permanent
272 :     \G switch to target dictionary. Used as prefix e.g. for @, !, here etc.
273 :     bl word count [ ' target >wordlist ] Literal search-wordlist
274 :     IF state @ IF compile, ELSE execute THEN
275 :     ELSE -1 ABORT" Cross: access method not supported!"
276 :     THEN ; immediate
277 : jwilke 1.105
278 : jwilke 1.52 \ Begin CROSS COMPILER:
279 :    
280 : jwilke 1.74 \ debugging
281 : jwilke 1.52
282 : jwilke 1.74 0 [IF]
283 :    
284 :     This implements debugflags for the cross compiler and the compiled
285 :     images. It works identical to the has-flags in the environment.
286 :     The debugflags are defined in a vocabluary. If the word exists and
287 :     its value is true, the flag is switched on.
288 :    
289 :     [THEN]
290 :    
291 : jwilke 1.77 >CROSS
292 :    
293 : jwilke 1.74 Vocabulary debugflags \ debug flags for cross
294 :     also debugflags get-order over
295 :     Constant debugflags-wl
296 :     set-order previous
297 :    
298 :     : DebugFlag
299 :     get-current >r debugflags-wl set-current
300 :     SetValue
301 :     r> set-current ;
302 :    
303 :     : Debug? ( adr u -- flag )
304 :     \G return true if debug flag is defined or switched on
305 :     debugflags-wl search-wordlist
306 :     IF EXECUTE
307 :     ELSE false THEN ;
308 :    
309 :     : D? ( <name> -- flag )
310 :     \G return true if debug flag is defined or switched on
311 :     \G while compiling we do not return the current value but
312 :     bl word count debug? ;
313 :    
314 :     : [d?]
315 :     \G compile the value-xt so the debug flag can be switched
316 :     \G the flag must exist!
317 :     bl word count debugflags-wl search-wordlist
318 :     IF compile,
319 :     ELSE -1 ABORT" unknown debug flag"
320 :     \ POSTPONE false
321 :     THEN ; immediate
322 : pazsan 1.54
323 : jwilke 1.123 : symentry ( adr len taddr -- )
324 :     \G Produce a symbol table (an optional symbol address
325 :     \G map) if wanted
326 :     [ [IFDEF] fd-symbol-table ]
327 :     base @ swap hex s>d <# 8 0 DO # LOOP #> fd-symbol-table write-file throw base !
328 :     s" :" fd-symbol-table write-file throw
329 :     fd-symbol-table write-line throw
330 :     [ [ELSE] ]
331 :     2drop drop
332 :     [ [THEN] ] ;
333 :    
334 :    
335 : jwilke 1.77 \ \ -------------------- source file
336 :    
337 :     decimal
338 :    
339 :     Variable cross-file-list
340 :     0 cross-file-list !
341 :     Variable target-file-list
342 :     0 target-file-list !
343 :     Variable host-file-list
344 :     0 host-file-list !
345 :    
346 :     cross-file-list Value file-list
347 :     0 Value source-desc
348 :    
349 :     \ file loading
350 :    
351 :     : >fl-id 1 cells + ;
352 :     : >fl-name 2 cells + ;
353 :    
354 :     Variable filelist 0 filelist !
355 :     Create NoFile ," #load-file#"
356 :    
357 :     : loadfile ( -- adr )
358 :     source-desc ?dup IF >fl-name ELSE NoFile THEN ;
359 :    
360 :     : sourcefilename ( -- adr len )
361 :     loadfile count ;
362 :    
363 :     \ANSI : sourceline# 0 ;
364 :    
365 :     \ \ -------------------- path handling from kernel/paths.fs
366 :    
367 :     \ paths.fs path file handling 03may97jaw
368 :    
369 :     \ -Changing the search-path:
370 :     \ fpath+ <path> adds a directory to the searchpath
371 :     \ fpath= <path>|<path> makes complete now searchpath
372 :     \ seperator is |
373 :     \ .fpath displays the search path
374 :     \ remark I:
375 :     \ a ./ in the beginning of filename is expanded to the directory the
376 :     \ current file comes from. ./ can also be included in the search-path!
377 :     \ ~+/ loads from the current working directory
378 :    
379 :     \ remark II:
380 :     \ if there is no sufficient space for the search path increase it!
381 :    
382 :    
383 :     \ -Creating custom paths:
384 :    
385 :     \ It is possible to use the search mechanism on yourself.
386 :    
387 :     \ Make a buffer for the path:
388 :     \ create mypath 100 chars , \ maximum length (is checked)
389 :     \ 0 , \ real len
390 :     \ 100 chars allot \ space for path
391 :     \ use the same functions as above with:
392 :     \ mypath path+
393 :     \ mypath path=
394 :     \ mypath .path
395 :    
396 :     \ do a open with the search path:
397 :     \ open-path-file ( adr len path -- fd adr len ior )
398 :     \ the file is opened read-only; if the file is not found an error is generated
399 :    
400 :     \ questions to: wilke@jwdt.com
401 :    
402 :     [IFUNDEF] +place
403 :     : +place ( adr len adr )
404 :     2dup >r >r
405 :     dup c@ char+ + swap move
406 :     r> r> dup c@ rot + swap c! ;
407 :     [THEN]
408 :    
409 :     [IFUNDEF] place
410 :     : place ( c-addr1 u c-addr2 )
411 :     2dup c! char+ swap move ;
412 :     [THEN]
413 :    
414 :     \ if we have path handling, use this and the setup of it
415 :     [IFUNDEF] open-fpath-file
416 :    
417 :     create sourcepath 1024 chars , 0 , 1024 chars allot \ !! make this dynamic
418 :     sourcepath value fpath
419 :    
420 :     : also-path ( adr len path^ -- )
421 :     >r
422 :     \ len check
423 :     r@ cell+ @ over + r@ @ u> ABORT" path buffer too small!"
424 :     \ copy into
425 :     tuck r@ cell+ dup @ cell+ + swap cmove
426 :     \ make delimiter
427 :     0 r@ cell+ dup @ cell+ + 2 pick + c! 1 + r> cell+ +!
428 :     ;
429 :    
430 :     : only-path ( adr len path^ -- )
431 :     dup 0 swap cell+ ! also-path ;
432 :    
433 :     : path+ ( path-addr "dir" -- ) \ gforth
434 :     \G Add the directory @var{dir} to the search path @var{path-addr}.
435 :     name rot also-path ;
436 :    
437 :     : fpath+ ( "dir" ) \ gforth
438 :     \G Add directory @var{dir} to the Forth search path.
439 :     fpath path+ ;
440 :    
441 :     : path= ( path-addr "dir1|dir2|dir3" ) \ gforth
442 :     \G Make a complete new search path; the path separator is |.
443 :     name 2dup bounds ?DO i c@ [char] | = IF 0 i c! THEN LOOP
444 :     rot only-path ;
445 :    
446 :     : fpath= ( "dir1|dir2|dir3" ) \ gforth
447 :     \G Make a complete new Forth search path; the path separator is |.
448 :     fpath path= ;
449 :    
450 :     : path>counted cell+ dup cell+ swap @ ;
451 :    
452 :     : next-path ( adr len -- adr2 len2 )
453 :     2dup 0 scan
454 :     dup 0= IF 2drop 0 -rot 0 -rot EXIT THEN
455 :     >r 1+ -rot r@ 1- -rot
456 :     r> - ;
457 :    
458 :     : previous-path ( path^ -- )
459 :     dup path>counted
460 :     BEGIN tuck dup WHILE repeat ;
461 :    
462 :     : .path ( path-addr -- ) \ gforth
463 :     \G Display the contents of the search path @var{path-addr}.
464 :     path>counted
465 :     BEGIN next-path dup WHILE type space REPEAT 2drop 2drop ;
466 :    
467 :     : .fpath ( -- ) \ gforth
468 :     \G Display the contents of the Forth search path.
469 :     fpath .path ;
470 :    
471 :     : absolut-path? ( addr u -- flag ) \ gforth
472 :     \G A path is absolute if it starts with a / or a ~ (~ expansion),
473 :     \G or if it is in the form ./*, extended regexp: ^[/~]|./, or if
474 :     \G it has a colon as second character ("C:..."). Paths simply
475 :     \G containing a / are not absolute!
476 :     2dup 2 u> swap 1+ c@ [char] : = and >r \ dos absoulte: c:/....
477 :     over c@ [char] / = >r
478 :     over c@ [char] ~ = >r
479 : anton 1.128 \ 2dup S" ../" string-prefix? r> or >r \ not catered for in expandtopic
480 :     S" ./" string-prefix?
481 : jwilke 1.77 r> r> r> or or or ;
482 :    
483 :     Create ofile 0 c, 255 chars allot
484 :     Create tfile 0 c, 255 chars allot
485 :    
486 :     : pathsep? dup [char] / = swap [char] \ = or ;
487 :    
488 :     : need/ ofile dup c@ + c@ pathsep? 0= IF s" /" ofile +place THEN ;
489 :    
490 :     : extractpath ( adr len -- adr len2 )
491 :     BEGIN dup WHILE 1-
492 :     2dup + c@ pathsep? IF EXIT THEN
493 :     REPEAT ;
494 :    
495 :     : remove~+ ( -- )
496 : anton 1.128 ofile count s" ~+/" string-prefix?
497 : jwilke 1.77 IF
498 :     ofile count 3 /string ofile place
499 :     THEN ;
500 :    
501 :     : expandtopic ( -- ) \ stack effect correct? - anton
502 :     \ expands "./" into an absolute name
503 : anton 1.128 ofile count s" ./" string-prefix?
504 : jwilke 1.77 IF
505 :     ofile count 1 /string tfile place
506 :     0 ofile c! sourcefilename extractpath ofile place
507 :     ofile c@ IF need/ THEN
508 :     tfile count over c@ pathsep? IF 1 /string THEN
509 :     ofile +place
510 :     THEN ;
511 :    
512 :     : compact.. ( adr len -- adr2 len2 )
513 : pazsan 1.85 \ deletes phrases like "xy/.." out of our directory name 2dec97jaw
514 :     over swap
515 :     BEGIN dup WHILE
516 : anton 1.128 dup >r '/ scan 2dup s" /../" string-prefix?
517 : pazsan 1.85 IF
518 :     dup r> - >r 4 /string over r> + 4 -
519 :     swap 2dup + >r move dup r> over -
520 :     ELSE
521 :     rdrop dup 1 min /string
522 :     THEN
523 :     REPEAT drop over - ;
524 : jwilke 1.77
525 :     : reworkdir ( -- )
526 :     remove~+
527 :     ofile count compact..
528 :     nip ofile c! ;
529 :    
530 :     : open-ofile ( -- fid ior )
531 :     \G opens the file whose name is in ofile
532 :     expandtopic reworkdir
533 :     ofile count r/o open-file ;
534 :    
535 :     : check-path ( adr1 len1 adr2 len2 -- fd 0 | 0 <>0 )
536 :     0 ofile ! >r >r ofile place need/
537 :     r> r> ofile +place
538 :     open-ofile ;
539 :    
540 :     : open-path-file ( addr1 u1 path-addr -- wfileid addr2 u2 0 | ior ) \ gforth
541 :     \G Look in path @var{path-addr} for the file specified by @var{addr1 u1}.
542 :     \G If found, the resulting path and an open file descriptor
543 :     \G are returned. If the file is not found, @var{ior} is non-zero.
544 :     >r
545 :     2dup absolut-path?
546 :     IF rdrop
547 :     ofile place open-ofile
548 :     dup 0= IF >r ofile count r> THEN EXIT
549 :     ELSE r> path>counted
550 :     BEGIN next-path dup
551 :     WHILE 5 pick 5 pick check-path
552 :     0= IF >r 2drop 2drop r> ofile count 0 EXIT ELSE drop THEN
553 :     REPEAT
554 :     2drop 2drop 2drop -38
555 :     THEN ;
556 :    
557 :     : open-fpath-file ( addr1 u1 -- wfileid addr2 u2 0 | ior ) \ gforth
558 :     \G Look in the Forth search path for the file specified by @var{addr1 u1}.
559 :     \G If found, the resulting path and an open file descriptor
560 :     \G are returned. If the file is not found, @var{ior} is non-zero.
561 :     fpath open-path-file ;
562 :    
563 :     fpath= ~+
564 :    
565 :     [THEN]
566 :    
567 :     \ \ -------------------- include require 13may99jaw
568 :    
569 :     >CROSS
570 :    
571 :     : add-included-file ( adr len -- adr )
572 :     dup >fl-name char+ allocate throw >r
573 :     file-list @ r@ ! r@ file-list !
574 :     r@ >fl-name place r> ;
575 :    
576 :     : included? ( c-addr u -- f )
577 :     file-list
578 :     BEGIN @ dup
579 : anton 1.128 WHILE >r 2dup r@ >fl-name count str=
580 : jwilke 1.77 IF rdrop 2drop true EXIT THEN
581 :     r>
582 :     REPEAT
583 :     2drop drop false ;
584 :    
585 :     false DebugFlag showincludedfiles
586 :    
587 :     : included1 ( fd adr u -- )
588 :     \ include file adr u / fd
589 :     \ we don't use fd with include-file, because the forth system
590 :     \ doesn't know the name of the file to get a nice error report
591 :     [d?] showincludedfiles
592 :     IF cr ." Including: " 2dup type ." ..." THEN
593 :     rot close-file throw
594 :     source-desc >r
595 :     add-included-file to source-desc
596 :     sourcefilename
597 :     ['] included catch
598 :     r> to source-desc
599 :     throw ;
600 :    
601 :     : included ( adr len -- )
602 :     cross-file-list to file-list
603 :     open-fpath-file throw
604 :     included1 ;
605 :    
606 :     : required ( adr len -- )
607 :     cross-file-list to file-list
608 :     open-fpath-file throw \ 2dup cr ." R:" type
609 :     2dup included?
610 :     IF 2drop close-file throw
611 :     ELSE included1
612 :     THEN ;
613 :    
614 :     : include bl word count included ;
615 :    
616 :     : require bl word count required ;
617 :    
618 : jwilke 1.78 0 [IF]
619 :    
620 : jwilke 1.77 also forth definitions previous
621 :    
622 :     : included ( adr len -- ) included ;
623 :    
624 :     : required ( adr len -- ) required ;
625 :    
626 :     : include include ;
627 :    
628 :     : require require ;
629 :    
630 : jwilke 1.78 [THEN]
631 :    
632 : jwilke 1.77 >CROSS
633 :     hex
634 :    
635 :     \ \ -------------------- Error Handling 05aug97jaw
636 :    
637 :     \ Flags
638 :    
639 :     also forth definitions \ these values may be predefined before
640 :     \ the cross-compiler is loaded
641 :    
642 :     false DefaultValue stack-warn \ check on empty stack at any definition
643 :     false DefaultValue create-forward-warn \ warn on forward declaration of created words
644 :    
645 :     previous >CROSS
646 :    
647 :     : .dec
648 :     base @ decimal swap . base ! ;
649 :    
650 :     : .sourcepos
651 :     cr sourcefilename type ." :"
652 :     sourceline# .dec ;
653 :    
654 :     : warnhead
655 :     \G display error-message head
656 :     \G perhaps with linenumber and filename
657 :     .sourcepos ." Warning: " ;
658 :    
659 :     : empty? depth IF .sourcepos ." Stack not empty!" THEN ;
660 :    
661 :     stack-warn [IF]
662 :     : defempty? empty? ;
663 :     [ELSE]
664 :     : defempty? ; immediate
665 : jwilke 1.139 \ : defempty? .sourcepos ;
666 : jwilke 1.77 [THEN]
667 :    
668 : jwilke 1.105 \ \ -------------------- Compiler Plug Ins 01aug97jaw
669 :    
670 :     >CROSS
671 :    
672 :     \ Compiler States
673 :    
674 :     Variable comp-state
675 :     0 Constant interpreting
676 :     1 Constant compiling
677 :     2 Constant resolving
678 :     3 Constant assembling
679 :    
680 :     : compiling? comp-state @ compiling = ;
681 :    
682 :     : pi-undefined -1 ABORT" Plugin undefined" ;
683 :    
684 :     : Plugin ( -- : pluginname )
685 :     Create
686 :     \ for normal cross-compiling only one action
687 :     \ exists, this fields are identical. For the instant
688 :     \ simulation environment we need, two actions for each plugin
689 :     \ the target one and the one that generates the simulation code
690 :     ['] pi-undefined , \ action
691 :     ['] pi-undefined , \ target plugin action
692 :     8765 , \ plugin magic
693 :     DOES> perform ;
694 :    
695 :     Plugin DummyPlugin
696 :    
697 :     : 'PI ( -- addr : pluginname )
698 :     ' >body dup 2 cells + @ 8765 <> ABORT" not a plugin" ;
699 :    
700 :     : plugin-of ( xt -- : pluginname )
701 :     dup 'PI 2! ;
702 :    
703 :     : action-of ( xt -- : plunginname )
704 :     'PI cell+ ! ;
705 :    
706 :     : TPA ( -- : plugin )
707 :     \ target plugin action
708 :     \ executes current target action of plugin
709 :     'PI cell+ POSTPONE literal POSTPONE perform ; immediate
710 :    
711 :     Variable ppi-temp 0 ppi-temp !
712 :    
713 :     : pa:
714 :     \g define plugin action
715 :     ppi-temp @ ABORT" pa: definition not closed"
716 :     'PI ppi-temp ! :noname ;
717 :    
718 :     : ;pa
719 :     \g end a definition for plugin action
720 :     POSTPONE ; ppi-temp @ ! 0 ppi-temp ! ; immediate
721 :    
722 :    
723 : jwilke 1.107 Plugin dlit, ( d -- ) \ compile numerical value the target
724 : jwilke 1.105 Plugin lit, ( n -- )
725 :     Plugin alit, ( n -- )
726 :    
727 :     Plugin branch, ( target-addr -- ) \ compiles a branch
728 :     Plugin ?branch, ( target-addr -- ) \ compiles a ?branch
729 :     Plugin branchmark, ( -- branch-addr ) \ reserves room for a branch
730 :     Plugin ?branchmark, ( -- branch-addr ) \ reserves room for a ?branch
731 :     Plugin ?domark, ( -- branch-addr ) \ reserves room for a ?do branch
732 :     Plugin branchto, ( -- ) \ actual program position is target of a branch (do e.g. alignment)
733 :     ' NOOP plugin-of branchto,
734 :     Plugin branchtoresolve, ( branch-addr -- ) \ resolves a forward reference from branchmark
735 :     Plugin branchtomark, ( -- target-addr ) \ marks a branch destination
736 :    
737 :     Plugin colon, ( tcfa -- ) \ compiles call to tcfa at current position
738 :     Plugin prim, ( tcfa -- ) \ compiles primitive invocation
739 :     Plugin colonmark, ( -- addr ) \ marks a colon call
740 :     Plugin colon-resolve ( tcfa addr -- )
741 :    
742 :     Plugin addr-resolve ( target-addr addr -- )
743 :     Plugin doer-resolve ( ghost res-pnt target-addr addr -- ghost res-pnt )
744 :    
745 :     Plugin ncontrols? ( [ xn ... x1 ] n -- ) \ checks wheter n control structures are open
746 :     Plugin if, ( -- if-token )
747 :     Plugin else, ( if-token -- if-token )
748 :     Plugin then, ( if-token -- )
749 :     Plugin ahead,
750 :     Plugin begin,
751 :     Plugin while,
752 :     Plugin until,
753 :     Plugin again,
754 :     Plugin repeat,
755 :     Plugin cs-swap ( x1 x2 -- x2 x1 )
756 :    
757 :     Plugin case, ( -- n )
758 :     Plugin of, ( n -- x1 n )
759 :     Plugin endof, ( x1 n -- x2 n )
760 :     Plugin endcase, ( x1 .. xn n -- )
761 :    
762 :     Plugin do, ( -- do-token )
763 :     Plugin ?do, ( -- ?do-token )
764 :     Plugin for, ( -- for-token )
765 :     Plugin loop, ( do-token / ?do-token -- )
766 :     Plugin +loop, ( do-token / ?do-token -- )
767 :     Plugin next, ( for-token )
768 :     Plugin leave, ( -- )
769 :     Plugin ?leave, ( -- )
770 :    
771 : jwilke 1.121 Plugin ca>native \ Convert a code address to the processors
772 :     \ native address. This is used in doprim, and
773 :     \ code/code: primitive definitions word to
774 :     \ convert the addresses.
775 :     \ The only target where we need this is the misc
776 :     \ which is a 16 Bit processor with word addresses
777 :     \ but the forth system we build has a normal byte
778 :     \ addressed memory model
779 : jwilke 1.105
780 :     Plugin doprim, \ compiles start of a primitive
781 :     Plugin docol, \ compiles start of a colon definition
782 :     Plugin doer,
783 :     Plugin fini, \ compiles end of definition ;s
784 :     Plugin doeshandler,
785 :     Plugin dodoes,
786 :    
787 :     Plugin colon-start
788 :     ' noop plugin-of colon-start
789 :     Plugin colon-end
790 :     ' noop plugin-of colon-end
791 :    
792 :     Plugin ]comp \ starts compilation
793 :     ' noop plugin-of ]comp
794 :     Plugin comp[ \ ends compilation
795 :     ' noop plugin-of comp[
796 :    
797 :     Plugin t>body \ we need the system >body
798 :     \ and the target >body
799 :    
800 :     >TARGET
801 :     : >body t>body ;
802 :    
803 :    
804 : jwilke 1.103 \ Ghost Builder 06oct92py
805 :    
806 : jwilke 1.105 >CROSS
807 : jwilke 1.103 hex
808 : jwilke 1.105 \ Values for ghost magic
809 : jwilke 1.103 4711 Constant <fwd> 4712 Constant <res>
810 :     4713 Constant <imm> 4714 Constant <do:>
811 :     4715 Constant <skip>
812 :    
813 : jwilke 1.105 \ Bitmask for ghost flags
814 : jwilke 1.103 1 Constant <unique>
815 : jwilke 1.105 2 Constant <primitive>
816 :    
817 :     \ FXIME: move this to general stuff?
818 :     : set-flag ( addr flag -- )
819 :     over @ or swap ! ;
820 :    
821 :     : reset-flag ( addr flag -- )
822 :     invert over @ and swap ! ;
823 :    
824 :     : get-flag ( addr flag -- f )
825 :     swap @ and 0<> ;
826 :    
827 : jwilke 1.103
828 :     Struct
829 : jwilke 1.52
830 : jwilke 1.103 \ link to next ghost (always the first element)
831 :     cell% field >next-ghost
832 : jwilke 1.52
833 : jwilke 1.103 \ type of ghost
834 :     cell% field >magic
835 :    
836 :     \ pointer where ghost is in target, or if unresolved
837 :     \ points to the where we have to resolve (linked-list)
838 :     cell% field >link
839 : jwilke 1.52
840 : jwilke 1.106 \ execution semantics (while target compiling) of ghost
841 : jwilke 1.103 cell% field >exec
842 : jwilke 1.52
843 : jwilke 1.106 \ compilation action of this ghost; this is what is
844 :     \ done to compile a call (or whatever) to this definition.
845 :     \ E.g. >comp contains the semantic of postpone s"
846 :     \ whereas >exec-compile contains the semantic of s"
847 : jwilke 1.105 cell% field >comp
848 :    
849 : jwilke 1.106 \ Compilation sematics (while parsing) of this ghost. E.g.
850 :     \ "\" will skip the rest of line.
851 :     \ These semantics are defined by Cond: and
852 :     \ if a word is made immediate in instant, then the >exec2 field
853 :     \ gets copied to here
854 : jwilke 1.103 cell% field >exec-compile
855 : jwilke 1.52
856 : jwilke 1.106 \ Additional execution semantics of this ghost. This is used
857 :     \ for code generated by instant and for the doer-xt of created
858 :     \ words
859 : jwilke 1.103 cell% field >exec2
860 : jwilke 1.52
861 : jwilke 1.103 cell% field >created
862 : jwilke 1.52
863 : jwilke 1.103 \ the xt of the created ghost word itself
864 :     cell% field >ghost-xt
865 : jwilke 1.52
866 : jwilke 1.103 \ pointer to the counted string of the assiciated
867 :     \ assembler label
868 :     cell% field >asm-name
869 : jwilke 1.52
870 : jwilke 1.103 \ mapped primitives have a special address, so
871 :     \ we are able to detect them
872 :     cell% field >asm-dummyaddr
873 :    
874 :     \ for builder (create, variable...) words
875 :     \ the execution symantics of words built are placed here
876 :     \ this is a doer ghost or a dummy ghost
877 :     cell% field >do:ghost
878 : pazsan 1.93
879 : jwilke 1.103 cell% field >ghost-flags
880 : pazsan 1.93
881 : jwilke 1.103 cell% field >ghost-name
882 : jwilke 1.52
883 : jwilke 1.103 End-Struct ghost-struct
884 : jwilke 1.52
885 : jwilke 1.103 Variable ghost-list
886 :     0 ghost-list !
887 : jwilke 1.52
888 :     Variable executed-ghost \ last executed ghost, needed in tcreate and gdoes>
889 : jwilke 1.103 \ Variable last-ghost \ last ghost that is created
890 : jwilke 1.52 Variable last-header-ghost \ last ghost definitions with header
891 :    
892 : jwilke 1.103 \ space for ghosts resolve structure
893 :     \ we create ghosts in a sepearte space
894 :     \ and not to the current host dp, because this
895 :     \ gives trouble with instant while compiling and creating
896 :     \ a ghost for a forward reference
897 :     \ BTW: we cannot allocate another memory region
898 :     \ because allot will check the overflow!!
899 :     Variable cross-space-dp
900 :     Create cross-space 250000 allot here 100 allot align
901 :     Constant cross-space-end
902 :     cross-space cross-space-dp !
903 :     Variable cross-space-dp-orig
904 :    
905 :     : cross-space-used cross-space-dp @ cross-space - ;
906 :    
907 :     : >space ( -- )
908 :     dp @ cross-space-dp-orig !
909 :     cross-space-dp @ dp ! ;
910 :    
911 :     : space> ( -- )
912 :     dp @ dup cross-space-dp !
913 :     cross-space-end u> ABORT" CROSS: cross-space overflow"
914 :     cross-space-dp-orig @ dp ! ;
915 :    
916 : jwilke 1.106 \ this is just for debugging, to see this in the backtrace
917 : jwilke 1.103 : execute-exec execute ;
918 :     : execute-exec2 execute ;
919 :     : execute-exec-compile execute ;
920 :    
921 :     : NoExec
922 :     executed-ghost @ >exec2 @
923 :     ?dup
924 :     IF execute-exec2
925 :     ELSE true ABORT" CROSS: Don't execute ghost, or immediate target word"
926 :     THEN ;
927 :    
928 : jwilke 1.105 Defer is-forward
929 :    
930 : jwilke 1.103 : (ghostheader) ( -- )
931 : jwilke 1.121 ghost-list linked <fwd> , 0 , ['] NoExec , ['] is-forward ,
932 : pazsan 1.118 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , ;
933 : jwilke 1.103
934 :     : ghostheader ( -- ) (ghostheader) 0 , ;
935 :    
936 :     ' Ghosts >wordlist Constant ghosts-wordlist
937 :    
938 :     \ the current wordlist for ghost definitions in the host
939 :     ghosts-wordlist Value current-ghosts
940 :    
941 : jwilke 1.52 : Make-Ghost ( "name" -- ghost )
942 : jwilke 1.103 >space
943 :     \ save current and create in ghost vocabulary
944 :     get-current >r current-ghosts set-current
945 :     >in @ Create >in !
946 :     \ some forth systems like iForth need the immediate directly
947 :     \ after the word is created
948 :     \ restore current
949 :     r> set-current
950 :     here (ghostheader)
951 :     bl word count string, align
952 :     space>
953 :     \ set ghost-xt field by doing a search
954 :     dup >ghost-name count
955 :     current-ghosts search-wordlist
956 :     0= ABORT" CROSS: Just created, must be there!"
957 :     over >ghost-xt !
958 :     DOES>
959 :     dup executed-ghost !
960 :     >exec @ execute-exec ;
961 : jwilke 1.52
962 :     \ ghost words 14oct92py
963 :     \ changed: 10may93py/jaw
964 :    
965 : jwilke 1.103 Defer search-ghosts
966 :    
967 :     : (search-ghosts) ( adr len -- cfa true | 0 )
968 :     current-ghosts search-wordlist ;
969 :    
970 :     ' (search-ghosts) IS search-ghosts
971 :    
972 :     : gsearch ( addr len -- ghost true | 0 )
973 :     search-ghosts
974 :     dup IF swap >body swap THEN ;
975 :    
976 :     : gfind ( string -- ghost true / string false )
977 : jwilke 1.52 \ searches for string in word-list ghosts
978 : jwilke 1.103 \ dup count type space
979 :     dup >r count gsearch
980 :     dup IF rdrop ELSE r> swap THEN ;
981 : jwilke 1.52
982 :     : gdiscover ( xt -- ghost true | xt false )
983 : jwilke 1.103 >r ghost-list
984 : jwilke 1.52 BEGIN @ dup
985 : jwilke 1.103 WHILE dup >magic @ <fwd> <>
986 :     IF dup >link @ r@ =
987 :     IF rdrop true EXIT THEN
988 :     THEN
989 : jwilke 1.52 REPEAT
990 : jwilke 1.103 drop r> false ;
991 : jwilke 1.52
992 : jwilke 1.105 : xt>ghost ( xt -- ghost )
993 :     gdiscover 0= ABORT" CROSS: ghost not found for this xt" ;
994 :    
995 : jwilke 1.103 : Ghost ( "name" -- ghost )
996 :     >in @ bl word gfind IF nip EXIT THEN
997 : jwilke 1.52 drop >in ! Make-Ghost ;
998 :    
999 :     : >ghostname ( ghost -- adr len )
1000 : jwilke 1.103 >ghost-name count ;
1001 :    
1002 :     : forward? ( ghost -- flag )
1003 :     >magic @ <fwd> = ;
1004 :    
1005 :     : undefined? ( ghost -- flag )
1006 :     >magic @ dup <fwd> = swap <skip> = or ;
1007 :    
1008 :     : immediate? ( ghost -- flag )
1009 :     >magic @ <imm> = ;
1010 :    
1011 :     Variable TWarnings
1012 :     TWarnings on
1013 :     Variable Exists-Warnings
1014 :     Exists-Warnings on
1015 :    
1016 :     : exists-warning ( ghost -- ghost )
1017 :     TWarnings @ Exists-Warnings @ and
1018 :     IF dup >ghostname warnhead type ." exists " THEN ;
1019 :    
1020 :     \ : HeaderGhost Ghost ;
1021 :    
1022 :     Variable reuse-ghosts reuse-ghosts off
1023 :    
1024 :     : HeaderGhost ( "name" -- ghost )
1025 :     >in @
1026 :     bl word count
1027 :     \ 2dup type space
1028 :     current-ghosts search-wordlist
1029 :     IF >body dup undefined? reuse-ghosts @ or
1030 :     IF nip EXIT
1031 :     ELSE exists-warning
1032 :     THEN
1033 :     drop >in !
1034 :     ELSE >in !
1035 :     THEN
1036 :     \ we keep the execution semantics of the prviously
1037 :     \ defined words, this is a workaround
1038 :     \ for the redefined \ until vocs work
1039 :     Make-Ghost ;
1040 :    
1041 : jwilke 1.78 : .ghost ( ghost -- ) >ghostname type ;
1042 :    
1043 : jwilke 1.77 \ ' >ghostname ALIAS @name
1044 : jwilke 1.52
1045 : jwilke 1.115 : findghost ( "ghostname" -- ghost )
1046 :     bl word gfind 0= ABORT" CROSS: Ghost don't exists" ;
1047 :    
1048 : jwilke 1.103 : [G'] ( -- ghost : name )
1049 :     \G ticks a ghost and returns its address
1050 : jwilke 1.115 findghost
1051 :     state @ IF postpone literal THEN ; immediate
1052 : jwilke 1.103
1053 : jwilke 1.105 : g>xt ( ghost -- xt )
1054 :     \G Returns the xt (cfa) of a ghost. Issues a warning if undefined.
1055 : jwilke 1.103 dup undefined? ABORT" CROSS: forward " >link @ ;
1056 :    
1057 : jwilke 1.105 : g>body ( ghost -- body )
1058 :     \G Returns the body-address (pfa) of a ghost.
1059 :     \G Issues a warning if undefined (a forward-reference).
1060 :     g>xt X >body ;
1061 :    
1062 : jwilke 1.103 1 Constant <label>
1063 : jwilke 1.52
1064 : jwilke 1.103 Struct
1065 :     \ bitmask of address type (not used for now)
1066 :     cell% field addr-type
1067 :     \ if this address is an xt, this field points to the ghost
1068 :     cell% field addr-xt-ghost
1069 :     \ a bit mask that tells as what part of the cell
1070 :     \ is refenced from an address pointer, used for assembler generation
1071 :     cell% field addr-refs
1072 :     End-Struct addr-struct
1073 :    
1074 :     : %allocerase ( align size -- addr )
1075 :     dup >r %alloc dup r> erase ;
1076 :    
1077 :     \ returns the addr struct, define it if 0 reference
1078 :     : define-addr-struct ( addr -- struct-addr )
1079 :     dup @ ?dup IF nip EXIT THEN
1080 :     addr-struct %allocerase tuck swap ! ;
1081 : jwilke 1.75
1082 : pazsan 1.118 >cross
1083 :    
1084 : jwilke 1.52 \ Predefined ghosts 12dec92py
1085 :    
1086 : jwilke 1.114 Ghost - drop \ need a ghost otherwise "-" would be treated as a number
1087 :    
1088 : jwilke 1.103 Ghost 0= drop
1089 :     Ghost branch Ghost ?branch 2drop
1090 :     Ghost unloop Ghost ;S 2drop
1091 : pazsan 1.118 Ghost lit Ghost ! 2drop
1092 :     Ghost noop drop
1093 : jwilke 1.103 Ghost over Ghost = Ghost drop 2drop drop
1094 :     Ghost 2drop drop
1095 :     Ghost 2dup drop
1096 : jwilke 1.115 Ghost call drop
1097 :     Ghost @ drop
1098 :     Ghost useraddr drop
1099 :     Ghost execute drop
1100 :     Ghost + drop
1101 :     Ghost decimal drop
1102 :     Ghost hex drop
1103 : pazsan 1.118 Ghost lit@ drop
1104 :     Ghost lit-perform drop
1105 :     Ghost lit+ drop
1106 :     Ghost does-exec drop
1107 : jwilke 1.52
1108 : pazsan 1.119 Ghost :docol Ghost :doesjump Ghost :dodoes 2drop drop
1109 :     Ghost :dovar drop
1110 :    
1111 : jwilke 1.52 \ \ Parameter for target systems 06oct92py
1112 :    
1113 : jwilke 1.103
1114 : jwilke 1.52 \ we define it ans like...
1115 :     wordlist Constant target-environment
1116 :    
1117 : jwilke 1.103 \ save information of current dictionary to restore with environ>
1118 :     Variable env-current
1119 : jwilke 1.52
1120 :     : >ENVIRON get-current env-current ! target-environment set-current ;
1121 :     : ENVIRON> env-current @ set-current ;
1122 : pazsan 1.43
1123 : anton 1.48 >TARGET
1124 : pazsan 1.43
1125 : jwilke 1.103 : environment? ( addr len -- [ x ] true | false )
1126 :     \G returns the content of environment variable and true or
1127 :     \G false if not present
1128 :     target-environment search-wordlist
1129 :     IF EXECUTE true ELSE false THEN ;
1130 :    
1131 :     : $has? ( addr len -- x | false )
1132 :     \G returns the content of environment variable
1133 :     \G or false if not present
1134 :     T environment? H dup IF drop THEN ;
1135 :    
1136 :     : e? ( "name" -- x )
1137 :     \G returns the content of environment variable.
1138 :     \G The variable is expected to exist. If not, issue an error.
1139 :     bl word count T environment? H
1140 :     0= ABORT" environment variable not defined!" ;
1141 :    
1142 :     : has? ( "name" --- x | false )
1143 :     \G returns the content of environment variable
1144 :     \G or false if not present
1145 :     bl word count T $has? H ;
1146 : jwilke 1.52
1147 : anton 1.48
1148 : pazsan 1.54 >ENVIRON get-order get-current swap 1+ set-order
1149 :     true SetValue compiler
1150 : pazsan 1.83 true SetValue cross
1151 : pazsan 1.54 true SetValue standard-threading
1152 :     >TARGET previous
1153 : jwilke 1.52
1154 : jwilke 1.77 0
1155 : jwilke 1.103 [IFDEF] mach-file drop mach-file count 1 [THEN]
1156 :     [IFDEF] machine-file drop machine-file 1 [THEN]
1157 :     [IF] included hex
1158 : jwilke 1.77 [ELSE] cr ." No machine description!" ABORT
1159 :     [THEN]
1160 : pazsan 1.43
1161 : jwilke 1.53 >ENVIRON
1162 :    
1163 : pazsan 1.54 T has? ec H
1164 :     [IF]
1165 :     false DefaultValue relocate
1166 :     false DefaultValue file
1167 :     false DefaultValue OS
1168 :     false DefaultValue prims
1169 :     false DefaultValue floating
1170 :     false DefaultValue glocals
1171 :     false DefaultValue dcomps
1172 :     false DefaultValue hash
1173 :     false DefaultValue xconds
1174 :     false DefaultValue header
1175 : jwilke 1.105 false DefaultValue backtrace
1176 :     false DefaultValue new-input
1177 :     false DefaultValue peephole
1178 : jwilke 1.129 false DefaultValue abranch
1179 : jwilke 1.139 true DefaultValue f83headerstring
1180 : pazsan 1.141 true DefaultValue control-rack
1181 : pazsan 1.54 [THEN]
1182 :    
1183 : jwilke 1.139 true DefaultValue gforthcross
1184 : pazsan 1.54 true DefaultValue interpreter
1185 :     true DefaultValue ITC
1186 :     false DefaultValue rom
1187 : jwilke 1.73 true DefaultValue standardthreading
1188 : jwilke 1.53
1189 : jwilke 1.139 \ ANSForth environment stuff
1190 :     8 DefaultValue ADDRESS-UNIT-BITS
1191 :     255 DefaultValue MAX-CHAR
1192 :     255 DefaultValue /COUNTED-STRING
1193 :    
1194 : jwilke 1.52 >TARGET
1195 : jwilke 1.53 s" relocate" T environment? H
1196 : jwilke 1.103 \ JAW why set NIL to this?!
1197 :     [IF] drop \ SetValue NIL
1198 : jwilke 1.113 [ELSE] >ENVIRON X NIL SetValue relocate
1199 : jwilke 1.53 [THEN]
1200 : jwilke 1.113 >TARGET
1201 :    
1202 :     0 Constant NIL
1203 : pazsan 1.43
1204 :     >CROSS
1205 :    
1206 : jwilke 1.52 \ \ Create additional parameters 19jan95py
1207 : pazsan 1.19
1208 : jwilke 1.71 \ currently cross only works for host machines with address-unit-bits
1209 :     \ eual to 8 because of s! and sc!
1210 :     \ but I start to query the environment just to modularize a little bit
1211 :    
1212 :     : check-address-unit-bits ( -- )
1213 :     \ s" ADDRESS-UNIT-BITS" environment?
1214 :     \ IF 8 <> ELSE true THEN
1215 :     \ ABORT" ADDRESS-UNIT-BITS unknown or not equal to 8!"
1216 :    
1217 :     \ shit, this doesn't work because environment? is only defined for
1218 :     \ gforth.fi and not kernl???.fi
1219 :     ;
1220 :    
1221 :     check-address-unit-bits
1222 :     8 Constant bits/byte \ we define: byte is address-unit
1223 :    
1224 :     1 bits/byte lshift Constant maxbyte
1225 : jwilke 1.77 \ this sets byte size for the target machine, (probably right guess) jaw
1226 : jwilke 1.67
1227 : pazsan 1.19 T
1228 : jwilke 1.71 NIL Constant TNIL
1229 :     cell Constant tcell
1230 :     cell<< Constant tcell<<
1231 :     cell>bit Constant tcell>bit
1232 :     bits/char Constant tbits/char
1233 :     bits/char H bits/byte T /
1234 :     Constant tchar
1235 :     float Constant tfloat
1236 :     1 bits/char lshift Constant tmaxchar
1237 :     [IFUNDEF] bits/byte
1238 :     8 Constant tbits/byte
1239 :     [ELSE]
1240 :     bits/byte Constant tbits/byte
1241 :     [THEN]
1242 : pazsan 1.19 H
1243 : pazsan 1.81 tbits/char bits/byte / Constant tbyte
1244 : jwilke 1.71
1245 : pazsan 1.19
1246 : anton 1.48 \ Variables 06oct92py
1247 :    
1248 : jwilke 1.124 Variable (tlast)
1249 :     (tlast) Value tlast TNIL tlast ! \ Last name field
1250 : anton 1.48 Variable tlastcfa \ Last code field
1251 : jwilke 1.52
1252 :     \ statistics 10jun97jaw
1253 :    
1254 :     Variable headers-named 0 headers-named !
1255 :     Variable user-vars 0 user-vars !
1256 :    
1257 : jwilke 1.67 : target>bitmask-size ( u1 -- u2 )
1258 :     1- tcell>bit rshift 1+ ;
1259 :    
1260 : jwilke 1.105 : allocatetarget ( size -- adr )
1261 : jwilke 1.67 dup allocate ABORT" CROSS: No memory for target"
1262 :     swap over swap erase ;
1263 : jwilke 1.52
1264 : pazsan 1.54 \ \ memregion.fs
1265 : jwilke 1.52
1266 :    
1267 :     Variable last-defined-region \ pointer to last defined region
1268 :     Variable region-link \ linked list with all regions
1269 :     Variable mirrored-link \ linked list for mirrored regions
1270 :     0 dup mirrored-link ! region-link !
1271 :    
1272 : jwilke 1.139 : >rname 9 cells + ;
1273 :     : >rtouch 8 cells + ; \ executed when region is accessed
1274 : jwilke 1.124 : >rbm 4 cells + ; \ bitfield per cell witch indicates relocation
1275 : jwilke 1.103 : >rmem 5 cells + ;
1276 : jwilke 1.124 : >rtype 6 cells + ; \ field per cell witch points to a type struct
1277 :     : >rrom 7 cells + ; \ a -1 indicates that this region is rom
1278 : jwilke 1.67 : >rlink 3 cells + ;
1279 : jwilke 1.52 : >rdp 2 cells + ;
1280 :     : >rlen cell+ ;
1281 :     : >rstart ;
1282 :    
1283 : jwilke 1.113 : (region) ( addr len region -- )
1284 :     \G change startaddress and length of an existing region
1285 :     >r r@ last-defined-region !
1286 :     r@ >rlen ! dup r@ >rstart ! r> >rdp ! ;
1287 : jwilke 1.52
1288 : jwilke 1.139 : uninitialized -1 ABORT" CROSS: Region is uninitialized" ;
1289 :    
1290 : jwilke 1.123 : region ( addr len -- "name" )
1291 : jwilke 1.103 \G create a new region
1292 : jwilke 1.52 \ check whether predefined region exists
1293 :     save-input bl word find >r >r restore-input throw r> r> 0=
1294 :     IF \ make region
1295 :     drop
1296 :     save-input create restore-input throw
1297 :     here last-defined-region !
1298 :     over ( startaddr ) , ( length ) , ( dp ) ,
1299 : jwilke 1.139 region-link linked 0 , 0 , 0 , 0 ,
1300 :     ['] uninitialized ,
1301 :     bl word count string,
1302 : jwilke 1.52 ELSE \ store new parameters in region
1303 :     bl word drop
1304 : jwilke 1.113 >body (region)
1305 : jwilke 1.52 THEN ;
1306 :    
1307 : jwilke 1.103 : borders ( region -- startaddr endaddr )
1308 :     \G returns lower and upper region border
1309 : jwilke 1.67 dup >rstart @ swap >rlen @ over + ;
1310 : jwilke 1.52
1311 : jwilke 1.103 : extent ( region -- startaddr len )
1312 :     \G returns the really used area
1313 : jwilke 1.67 dup >rstart @ swap >rdp @ over - ;
1314 : jwilke 1.52
1315 : jwilke 1.103 : area ( region -- startaddr totallen )
1316 :     \G returns the total area
1317 : jwilke 1.79 dup >rstart @ swap >rlen @ ;
1318 : jwilke 1.52
1319 : jwilke 1.139 : dp@ ( region -- dp )
1320 :     >rdp @ ;
1321 :    
1322 : jwilke 1.124 : mirrored ( -- )
1323 :     \G mark last defined region as mirrored
1324 : jwilke 1.52 mirrored-link
1325 : jwilke 1.68 align linked last-defined-region @ , ;
1326 : jwilke 1.52
1327 : jwilke 1.124 : writeprotected
1328 :     \G mark a region as write protected
1329 :     -1 last-defined-region @ >rrom ! ;
1330 :    
1331 : jwilke 1.67 : .addr ( u -- )
1332 :     \G prints a 16 or 32 Bit nice hex value
1333 : jwilke 1.52 base @ >r hex
1334 :     tcell 2 u>
1335 : jwilke 1.77 IF s>d <# # # # # [char] . hold # # # # #> type
1336 : jwilke 1.52 ELSE s>d <# # # # # # #> type
1337 : jwilke 1.103 THEN r> base ! space ;
1338 : jwilke 1.52
1339 :     : .regions \G display region statistic
1340 :    
1341 :     \ we want to list the regions in the right order
1342 :     \ so first collect all regions on stack
1343 :     0 region-link @
1344 :     BEGIN dup WHILE dup @ REPEAT drop
1345 :     BEGIN dup
1346 : jwilke 1.67 WHILE cr
1347 :     0 >rlink - >r
1348 :     r@ >rname count tuck type
1349 : jwilke 1.52 12 swap - 0 max spaces space
1350 : jwilke 1.67 ." Start: " r@ >rstart @ dup .addr space
1351 :     ." End: " r@ >rlen @ + .addr space
1352 :     ." DP: " r> >rdp @ .addr
1353 : jwilke 1.52 REPEAT drop
1354 : jwilke 1.53 s" rom" T $has? H 0= ?EXIT
1355 : jwilke 1.52 cr ." Mirrored:"
1356 :     mirrored-link @
1357 :     BEGIN dup
1358 : jwilke 1.67 WHILE space dup cell+ @ >rname count type @
1359 : jwilke 1.52 REPEAT drop cr
1360 :     ;
1361 :    
1362 :     \ -------- predefined regions
1363 :    
1364 :     0 0 region address-space
1365 :     \ total memory addressed and used by the target system
1366 :    
1367 : jwilke 1.139 0 0 region user-region
1368 :     \ data for user variables goes here
1369 :     \ this has to be defined before dictionary or ram-dictionary
1370 :    
1371 : jwilke 1.52 0 0 region dictionary
1372 :     \ rom area for the compiler
1373 :    
1374 : jwilke 1.53 T has? rom H
1375 : jwilke 1.52 [IF]
1376 :     0 0 region ram-dictionary mirrored
1377 :     \ ram area for the compiler
1378 :     [ELSE]
1379 :     ' dictionary ALIAS ram-dictionary
1380 :     [THEN]
1381 :    
1382 :     0 0 region return-stack
1383 :    
1384 :     0 0 region data-stack
1385 :    
1386 :     0 0 region tib-region
1387 :    
1388 :     ' dictionary ALIAS rom-dictionary
1389 :    
1390 : jwilke 1.139 : setup-region ( region -- )
1391 :     >r
1392 :     \ allocate mem
1393 :     r@ >rlen @ allocatetarget
1394 :     r@ >rmem !
1395 :    
1396 :     r@ >rlen @
1397 :     target>bitmask-size allocatetarget
1398 :     r@ >rbm !
1399 :    
1400 :     r@ >rlen @
1401 :     tcell / 1+ cells allocatetarget r@ >rtype !
1402 :    
1403 :     ['] noop r@ >rtouch !
1404 :     rdrop ;
1405 : jwilke 1.52
1406 : jwilke 1.105 : setup-target ( -- ) \G initialize target's memory space
1407 : jwilke 1.53 s" rom" T $has? H
1408 : jwilke 1.52 IF \ check for ram and rom...
1409 : jwilke 1.72 \ address-space area nip 0<>
1410 : jwilke 1.67 ram-dictionary area nip 0<>
1411 :     rom-dictionary area nip 0<>
1412 : jwilke 1.72 and 0=
1413 : jwilke 1.52 ABORT" CROSS: define address-space, rom- , ram-dictionary, with rom-support!"
1414 :     THEN
1415 :     address-space area nip
1416 :     IF
1417 :     address-space area
1418 :     ELSE
1419 :     dictionary area
1420 :     THEN
1421 : jwilke 1.67 nip 0=
1422 : jwilke 1.52 ABORT" CROSS: define at least address-space or dictionary!!"
1423 : jwilke 1.67
1424 :     \ allocate target for each region
1425 :     region-link
1426 :     BEGIN @ dup
1427 :     WHILE dup
1428 :     0 >rlink - >r
1429 :     r@ >rlen @
1430 : jwilke 1.139 IF r@ setup-region
1431 :     THEN rdrop
1432 : jwilke 1.72 REPEAT drop ;
1433 :    
1434 : jwilke 1.105 \ MakeKernel 22feb99jaw
1435 : jwilke 1.72
1436 : pazsan 1.134 : makekernel ( start targetsize -- )
1437 : jwilke 1.113 \G convenience word to setup the memory of the target
1438 :     \G used by main.fs of the c-engine based systems
1439 : pazsan 1.134 dictionary (region) setup-target ;
1440 : jwilke 1.72
1441 :     >MINIMAL
1442 :     : makekernel makekernel ;
1443 :     >CROSS
1444 : jwilke 1.52
1445 : pazsan 1.54 \ \ switched tdp for rom support 03jun97jaw
1446 : jwilke 1.52
1447 :     \ second value is here to store some maximal value for statistics
1448 :     \ tempdp is also embedded here but has nothing to do with rom support
1449 :     \ (needs switched dp)
1450 :    
1451 :     variable tempdp 0 , \ temporary dp for resolving
1452 :     variable tempdp-save
1453 :    
1454 :     0 [IF]
1455 :     variable romdp 0 , \ Dictionary-Pointer for ramarea
1456 :     variable ramdp 0 , \ Dictionary-Pointer for romarea
1457 :    
1458 :     \
1459 :     variable sramdp \ start of ram-area for forth
1460 :     variable sromdp \ start of rom-area for forth
1461 :    
1462 :     [THEN]
1463 :    
1464 : jwilke 1.123 0 Value current-region
1465 :     0 Value tdp
1466 :     Variable fixed \ flag: true: no automatic switching
1467 : jwilke 1.52 \ false: switching is done automatically
1468 :    
1469 :     \ Switch-Policy:
1470 :     \
1471 :     \ a header is always compiled into rom
1472 :     \ after a created word (create and variable) compilation goes to ram
1473 :     \
1474 :     \ Be careful: If you want to make the data behind create into rom
1475 :     \ you have to put >rom before create!
1476 :    
1477 :     variable constflag constflag off
1478 :    
1479 : jwilke 1.67 : activate ( region -- )
1480 :     \G next code goes to this region
1481 : jwilke 1.123 dup to current-region >rdp to tdp ;
1482 : jwilke 1.67
1483 : jwilke 1.52 : (switchram)
1484 : jwilke 1.53 fixed @ ?EXIT s" rom" T $has? H 0= ?EXIT
1485 : jwilke 1.67 ram-dictionary activate ;
1486 : jwilke 1.52
1487 :     : switchram
1488 :     constflag @
1489 :     IF constflag off ELSE (switchram) THEN ;
1490 :    
1491 :     : switchrom
1492 : jwilke 1.67 fixed @ ?EXIT rom-dictionary activate ;
1493 : jwilke 1.52
1494 :     : >tempdp ( addr -- )
1495 :     tdp tempdp-save ! tempdp to tdp tdp ! ;
1496 :     : tempdp> ( -- )
1497 :     tempdp-save @ to tdp ;
1498 :    
1499 :     : >ram fixed off (switchram) fixed on ;
1500 :     : >rom fixed off switchrom fixed on ;
1501 :     : >auto fixed off switchrom ;
1502 :    
1503 :    
1504 :    
1505 :     \ : romstart dup sromdp ! romdp ! ;
1506 :     \ : ramstart dup sramdp ! ramdp ! ;
1507 :    
1508 : jwilke 1.67 \ default compilation goes to rom
1509 : jwilke 1.52 \ when romable support is off, only the rom switch is used (!!)
1510 :     >auto
1511 :    
1512 : anton 1.48 : there tdp @ ;
1513 :    
1514 : jwilke 1.52 >TARGET
1515 : anton 1.48
1516 : jwilke 1.52 \ \ Target Memory Handling
1517 : anton 1.1
1518 :     \ Byte ordering and cell size 06oct92py
1519 :    
1520 : pazsan 1.19 : cell+ tcell + ;
1521 :     : cells tcell<< lshift ;
1522 : jwilke 1.71 : chars tchar * ;
1523 :     : char+ tchar + ;
1524 : pazsan 1.19 : floats tfloat * ;
1525 : anton 1.6
1526 : anton 1.1 >CROSS
1527 : pazsan 1.19 : cell/ tcell<< rshift ;
1528 : anton 1.1 >TARGET
1529 :     20 CONSTANT bl
1530 : jwilke 1.52 \ TNIL Constant NIL
1531 : anton 1.1
1532 :     >CROSS
1533 :    
1534 : pazsan 1.20 bigendian
1535 :     [IF]
1536 : jwilke 1.106 : DS! ( d addr -- ) tcell bounds swap 1-
1537 : pazsan 1.20 DO maxbyte ud/mod rot I c! -1 +LOOP 2drop ;
1538 : jwilke 1.106 : DS@ ( addr -- d ) >r 0 0 r> tcell bounds
1539 :     DO maxbyte * swap maxbyte um* rot + swap I c@ + swap LOOP ;
1540 : pazsan 1.57 : Sc! ( n addr -- ) >r s>d r> tchar bounds swap 1-
1541 :     DO maxbyte ud/mod rot I c! -1 +LOOP 2drop ;
1542 :     : Sc@ ( addr -- n ) >r 0 0 r> tchar bounds
1543 :     DO maxbyte * swap maxbyte um* rot + swap I c@ + swap LOOP d>s ;
1544 : pazsan 1.19 [ELSE]
1545 : jwilke 1.106 : DS! ( d addr -- ) tcell bounds
1546 : pazsan 1.20 DO maxbyte ud/mod rot I c! LOOP 2drop ;
1547 : jwilke 1.106 : DS@ ( addr -- n ) >r 0 0 r> tcell bounds swap 1-
1548 :     DO maxbyte * swap maxbyte um* rot + swap I c@ + swap -1 +LOOP ;
1549 : pazsan 1.57 : Sc! ( n addr -- ) >r s>d r> tchar bounds
1550 :     DO maxbyte ud/mod rot I c! LOOP 2drop ;
1551 :     : Sc@ ( addr -- n ) >r 0 0 r> tchar bounds swap 1-
1552 :     DO maxbyte * swap maxbyte um* rot + swap I c@ + swap -1 +LOOP d>s ;
1553 : anton 1.1 [THEN]
1554 :    
1555 : jwilke 1.106 : S! ( n addr -- ) >r s>d r> DS! ;
1556 :     : S@ ( addr -- n ) DS@ d>s ;
1557 :    
1558 : jwilke 1.67 : taddr>region ( taddr -- region | 0 )
1559 :     \G finds for a target-address the correct region
1560 :     \G returns 0 if taddr is not in range of a target memory region
1561 :     region-link
1562 :     BEGIN @ dup
1563 :     WHILE dup >r
1564 :     0 >rlink - >r
1565 :     r@ >rlen @
1566 :     IF dup r@ borders within
1567 : jwilke 1.139 IF r> r> drop nip
1568 :     dup >rtouch @ EXECUTE EXIT
1569 :     THEN
1570 : jwilke 1.67 THEN
1571 :     r> drop
1572 :     r>
1573 :     REPEAT
1574 :     2drop 0 ;
1575 :    
1576 : jwilke 1.103 : taddr>region-abort ( taddr -- region | 0 )
1577 : jwilke 1.122 \G Same as taddr>region but aborts if taddr is not
1578 :     \G a valid address in the target address space
1579 : jwilke 1.103 dup taddr>region dup 0=
1580 :     IF drop cr ." Wrong address: " .addr
1581 :     -1 ABORT" Address out of range!"
1582 :     THEN nip ;
1583 :    
1584 : jwilke 1.67 : (>regionimage) ( taddr -- 'taddr )
1585 :     dup
1586 :     \ find region we want to address
1587 : jwilke 1.103 taddr>region-abort
1588 : jwilke 1.67 >r
1589 :     \ calculate offset in region
1590 :     r@ >rstart @ -
1591 :     \ add regions real address in our memory
1592 :     r> >rmem @ + ;
1593 :    
1594 : jwilke 1.124 : (>regionramimage) ( taddr -- 'taddr )
1595 :     \G same as (>regionimage) but aborts if the region is rom
1596 :     dup
1597 :     \ find region we want to address
1598 :     taddr>region-abort
1599 :     >r
1600 :     r@ >rrom @ ABORT" CROSS: region is write-protected!"
1601 :     \ calculate offset in region
1602 :     r@ >rstart @ -
1603 :     \ add regions real address in our memory
1604 :     r> >rmem @ + ;
1605 :    
1606 : jwilke 1.103 : (>regionbm) ( taddr -- 'taddr bitmaskbaseaddr )
1607 :     dup
1608 :     \ find region we want to address
1609 :     taddr>region-abort
1610 :     >r
1611 :     \ calculate offset in region
1612 :     r@ >rstart @ -
1613 :     \ add regions real address in our memory
1614 :     r> >rbm @ ;
1615 :    
1616 :     : (>regiontype) ( taddr -- 'taddr )
1617 :     dup
1618 :     \ find region we want to address
1619 :     taddr>region-abort
1620 :     >r
1621 :     \ calculate offset in region
1622 :     r@ >rstart @ - tcell / cells
1623 :     \ add regions real address in our memory
1624 :     r> >rtype @ + ;
1625 :    
1626 : anton 1.1 \ Bit string manipulation 06oct92py
1627 :     \ 9may93jaw
1628 :     CREATE Bittable 80 c, 40 c, 20 c, 10 c, 8 c, 4 c, 2 c, 1 c,
1629 :     : bits ( n -- n ) chars Bittable + c@ ;
1630 :    
1631 :     : >bit ( addr n -- c-addr mask ) 8 /mod rot + swap bits ;
1632 :     : +bit ( addr n -- ) >bit over c@ or swap c! ;
1633 : pazsan 1.4 : -bit ( addr n -- ) >bit invert over c@ and swap c! ;
1634 : jwilke 1.67
1635 : jwilke 1.103 : @relbit ( taddr -- f ) (>regionbm) swap cell/ >bit swap c@ and ;
1636 :    
1637 : jwilke 1.84 : (relon) ( taddr -- )
1638 :     [ [IFDEF] fd-relocation-table ]
1639 :     s" +" fd-relocation-table write-file throw
1640 :     dup s>d <# #s #> fd-relocation-table write-line throw
1641 :     [ [THEN] ]
1642 : jwilke 1.103 (>regionbm) swap cell/ +bit ;
1643 : jwilke 1.84
1644 :     : (reloff) ( taddr -- )
1645 :     [ [IFDEF] fd-relocation-table ]
1646 :     s" -" fd-relocation-table write-file throw
1647 :     dup s>d <# #s #> fd-relocation-table write-line throw
1648 :     [ [THEN] ]
1649 : jwilke 1.103 (>regionbm) swap cell/ -bit ;
1650 : jwilke 1.67
1651 :     DEFER >image
1652 : jwilke 1.124 DEFER >ramimage
1653 : jwilke 1.67 DEFER relon
1654 :     DEFER reloff
1655 :     DEFER correcter
1656 :    
1657 :     T has? relocate H
1658 :     [IF]
1659 :     ' (relon) IS relon
1660 :     ' (reloff) IS reloff
1661 : jwilke 1.103 ' (>regionimage) IS >image
1662 : jwilke 1.124 ' (>regionimage) IS >ramimage
1663 : jwilke 1.67 [ELSE]
1664 :     ' drop IS relon
1665 :     ' drop IS reloff
1666 : jwilke 1.68 ' (>regionimage) IS >image
1667 : jwilke 1.124 ' (>regionimage) IS >ramimage
1668 : jwilke 1.67 [THEN]
1669 : anton 1.1
1670 : jwilke 1.124 : enforce-writeprotection ( -- )
1671 :     ['] (>regionramimage) IS >ramimage ;
1672 :    
1673 :     : relax-writeprotection ( -- )
1674 :     ['] (>regionimage) IS >ramimage ;
1675 :    
1676 :     : writeprotection-relaxed? ( -- )
1677 :     ['] >ramimage >body @ ['] (>regionimage) = ;
1678 :    
1679 : anton 1.1 \ Target memory access 06oct92py
1680 :    
1681 :     : align+ ( taddr -- rest )
1682 : anton 1.48 tcell tuck 1- and - [ tcell 1- ] Literal and ;
1683 : anton 1.22 : cfalign+ ( taddr -- rest )
1684 : pazsan 1.39 \ see kernel.fs:cfaligned
1685 : pazsan 1.43 /maxalign tuck 1- and - [ /maxalign 1- ] Literal and ;
1686 : anton 1.1
1687 :     >TARGET
1688 :     : aligned ( taddr -- ta-addr ) dup align+ + ;
1689 :     \ assumes cell alignment granularity (as GNU C)
1690 :    
1691 : anton 1.22 : cfaligned ( taddr1 -- taddr2 )
1692 : pazsan 1.39 \ see kernel.fs
1693 : anton 1.22 dup cfalign+ + ;
1694 :    
1695 : jwilke 1.52 : @ ( taddr -- w ) >image S@ ;
1696 : jwilke 1.124 : ! ( w taddr -- ) >ramimage S! ;
1697 : pazsan 1.57 : c@ ( taddr -- char ) >image Sc@ ;
1698 : jwilke 1.124 : c! ( char taddr -- ) >ramimage Sc! ;
1699 : anton 1.7 : 2@ ( taddr -- x1 x2 ) T dup cell+ @ swap @ H ;
1700 : pazsan 1.82 : 2! ( x1 x2 taddr -- ) T tuck ! cell+ ! H ;
1701 : anton 1.1
1702 :     \ Target compilation primitives 06oct92py
1703 :     \ included A! 16may93jaw
1704 :    
1705 :     : here ( -- there ) there ;
1706 :     : allot ( n -- ) tdp +! ;
1707 : jwilke 1.78 : , ( w -- ) T here H tcell T allot ! H ;
1708 :     : c, ( char -- ) T here H tchar T allot c! H ;
1709 :     : align ( -- ) T here H align+ 0 ?DO bl T c, H tchar +LOOP ;
1710 : anton 1.22 : cfalign ( -- )
1711 : jwilke 1.78 T here H cfalign+ 0 ?DO bl T c, H tchar +LOOP ;
1712 : anton 1.1
1713 : jwilke 1.71 : >address dup 0>= IF tbyte / THEN ; \ ?? jaw
1714 : pazsan 1.59 : A! swap >address swap dup relon T ! H ;
1715 :     : A, ( w -- ) >address T here H relon T , H ;
1716 : anton 1.1
1717 : pazsan 1.118 \ high-level ghosts
1718 :    
1719 :     >CROSS
1720 :    
1721 :     Ghost (do) Ghost (?do) 2drop
1722 :     Ghost (for) drop
1723 :     Ghost (loop) Ghost (+loop) 2drop
1724 :     Ghost (next) drop
1725 :     Ghost (does>) Ghost (compile) 2drop
1726 :     Ghost (.") Ghost (S") Ghost (ABORT") 2drop drop
1727 : pazsan 1.130 Ghost (C") Ghost c(abort") Ghost type 2drop drop
1728 : pazsan 1.118 Ghost ' drop
1729 :    
1730 :     \ user ghosts
1731 :    
1732 :     Ghost state drop
1733 : jwilke 1.103
1734 :     \ \ -------------------- Host/Target copy etc. 29aug01jaw
1735 :    
1736 :    
1737 :     >CROSS
1738 :    
1739 : jwilke 1.107 : TD! >image DS! ;
1740 :     : TD@ >image DS@ ;
1741 :    
1742 : jwilke 1.103 : th-count ( taddr -- host-addr len )
1743 :     \G returns host address of target string
1744 :     assert1( tbyte 1 = )
1745 :     dup X c@ swap X char+ >image swap ;
1746 :    
1747 :     : ht-move ( haddr taddr len -- )
1748 :     \G moves data from host-addr to destination in target-addr
1749 :     \G character by character
1750 :     swap -rot bounds ?DO I c@ over X c! X char+ LOOP drop ;
1751 :    
1752 :     2Variable last-string
1753 :    
1754 :     : ht-string, ( addr count -- )
1755 :     dup there swap last-string 2!
1756 : pazsan 1.130 dup T c, H bounds ?DO I c@ T c, H LOOP ;
1757 :     : ht-mem, ( addr count )
1758 :     bounds ?DO I c@ T c, H LOOP ;
1759 : jwilke 1.103
1760 :     >TARGET
1761 :    
1762 :     : count dup X c@ swap X char+ swap ;
1763 : jwilke 1.110
1764 :     : on -1 -1 rot TD! ;
1765 : jwilke 1.103 : off T 0 swap ! H ;
1766 : anton 1.1
1767 : jwilke 1.107 : tcmove ( source dest len -- )
1768 :     \G cmove in target memory
1769 :     tchar * bounds
1770 :     ?DO dup T c@ H I T c! H 1+
1771 :     tchar +LOOP drop ;
1772 :    
1773 :     : td, ( d -- )
1774 :     \G Store a host value as one cell into the target
1775 :     there tcell X allot TD! ;
1776 :    
1777 :     \ \ Load Assembler
1778 :    
1779 :     >TARGET
1780 :     H also Forth definitions
1781 :    
1782 :     \ FIXME: should we include the assembler really in the forth
1783 :     \ dictionary?!?!?!? This conflicts with the existing assembler
1784 :     \ of the host forth system!!
1785 :     [IFDEF] asm-include asm-include [THEN] hex
1786 :    
1787 :     previous
1788 :    
1789 :    
1790 : jwilke 1.52 >CROSS
1791 :    
1792 : jwilke 1.103 : (cc) T a, H ; ' (cc) plugin-of colon,
1793 : jwilke 1.105 : (prim) T a, H ; ' (prim) plugin-of prim,
1794 : jwilke 1.52
1795 : pazsan 1.118 : (cr) >tempdp colon, tempdp> ; ' (cr) plugin-of colon-resolve
1796 : jwilke 1.103 : (ar) T ! H ; ' (ar) plugin-of addr-resolve
1797 : pazsan 1.54 : (dr) ( ghost res-pnt target-addr addr )
1798 :     >tempdp drop over
1799 :     dup >magic @ <do:> =
1800 :     IF doer,
1801 :     ELSE dodoes,
1802 :     THEN
1803 : jwilke 1.103 tempdp> ; ' (dr) plugin-of doer-resolve
1804 : pazsan 1.54
1805 :     : (cm) ( -- addr )
1806 : jwilke 1.121 there -1 colon, ; ' (cm) plugin-of colonmark,
1807 : anton 1.1
1808 : jwilke 1.52 >TARGET
1809 : jwilke 1.105 : compile, ( xt -- )
1810 : jwilke 1.107 dup xt>ghost >comp @ EXECUTE ;
1811 : jwilke 1.52 >CROSS
1812 : anton 1.1
1813 : jwilke 1.102 \ resolve structure
1814 :    
1815 :     : >next ; \ link to next field
1816 :     : >tag cell+ ; \ indecates type of reference: 0: call, 1: address, 2: doer
1817 :     : >taddr cell+ cell+ ;
1818 :     : >ghost 3 cells + ;
1819 :     : >file 4 cells + ;
1820 :     : >line 5 cells + ;
1821 :    
1822 :     : (refered) ( ghost addr tag -- )
1823 :     \G creates a reference to ghost at address taddr
1824 : jwilke 1.103 >space
1825 :     rot >link linked
1826 : jwilke 1.102 ( taddr tag ) ,
1827 :     ( taddr ) ,
1828 :     last-header-ghost @ ,
1829 :     loadfile ,
1830 :     sourceline# ,
1831 : jwilke 1.103 space>
1832 : pazsan 1.118 ;
1833 :    
1834 : jwilke 1.52 : refered ( ghost tag -- )
1835 : jwilke 1.53 \G creates a resolve structure
1836 : pazsan 1.54 T here aligned H swap (refered)
1837 :     ;
1838 :    
1839 :     : killref ( addr ghost -- )
1840 :     \G kills a forward reference to ghost at position addr
1841 :     \G this is used to eleminate a :dovar refence after making a DOES>
1842 :     dup >magic @ <fwd> <> IF 2drop EXIT THEN
1843 :     swap >r >link
1844 :     BEGIN dup @ dup ( addr last this )
1845 :     WHILE dup >taddr @ r@ =
1846 :     IF @ over !
1847 :     ELSE nip THEN
1848 :     REPEAT rdrop 2drop
1849 : jwilke 1.53 ;
1850 : anton 1.48
1851 : jwilke 1.52 Defer resolve-warning
1852 : anton 1.1
1853 : jwilke 1.52 : reswarn-test ( ghost res-struct -- ghost res-struct )
1854 : jwilke 1.78 over cr ." Resolving " .ghost dup ." in " >ghost @ .ghost ;
1855 : anton 1.1
1856 : jwilke 1.52 : reswarn-forward ( ghost res-struct -- ghost res-struct )
1857 : jwilke 1.78 over warnhead .ghost dup ." is referenced in "
1858 :     >ghost @ .ghost ;
1859 : anton 1.1
1860 : jwilke 1.52 \ ' reswarn-test IS resolve-warning
1861 :    
1862 : anton 1.1 \ resolve 14oct92py
1863 :    
1864 : pazsan 1.54 : resolve-loop ( ghost resolve-list tcfa -- )
1865 :     >r
1866 :     BEGIN dup WHILE
1867 :     \ dup >tag @ 2 = IF reswarn-forward THEN
1868 :     resolve-warning
1869 :     r@ over >taddr @
1870 :     2 pick >tag @
1871 :     CASE 0 OF colon-resolve ENDOF
1872 :     1 OF addr-resolve ENDOF
1873 :     2 OF doer-resolve ENDOF
1874 :     ENDCASE
1875 :     @ \ next list element
1876 :     REPEAT 2drop rdrop
1877 :     ;
1878 : jwilke 1.52
1879 :     \ : resolve-loop ( ghost tcfa -- ghost tcfa )
1880 :     \ >r dup >link @
1881 :     \ BEGIN dup WHILE dup T @ H r@ rot T ! H REPEAT drop r> ;
1882 : anton 1.1
1883 :     \ exists 9may93jaw
1884 :    
1885 : jwilke 1.103 : exists ( ghost tcfa -- )
1886 :     \G print warning and set new target link in ghost
1887 :     swap exists-warning
1888 :     >link ! ;
1889 : jwilke 1.52
1890 : jwilke 1.105 : colon-resolved ( ghost -- )
1891 : jwilke 1.121 \ compiles a call to a colon definition,
1892 :     \ compile action for >comp field
1893 :     >link @ colon, ;
1894 : jwilke 1.105
1895 :     : prim-resolved ( ghost -- )
1896 : jwilke 1.121 \ compiles a call to a primitive
1897 : jwilke 1.105 >link @ prim, ;
1898 :    
1899 : jwilke 1.121 : (is-forward) ( ghost -- )
1900 :     colonmark, 0 (refered) ; \ compile space for call
1901 :     ' (is-forward) IS is-forward
1902 :    
1903 : pazsan 1.118 0 Value resolved
1904 : anton 1.1
1905 : jwilke 1.122 : resolve-forward-references ( ghost resolve-list -- )
1906 :     \ loop through forward referencies
1907 :     comp-state @ >r Resolving comp-state !
1908 :     over >link @ resolve-loop
1909 :     r> comp-state !
1910 :    
1911 :     ['] noop IS resolve-warning ;
1912 :    
1913 :    
1914 :     : (resolve) ( ghost tcfa -- ghost resolve-list )
1915 :     \ check for a valid address, it is a primitive reference
1916 :     \ otherwise
1917 : jwilke 1.103 dup taddr>region 0<> IF
1918 : jwilke 1.122 \ define this address in the region address type table
1919 : jwilke 1.103 2dup (>regiontype) define-addr-struct addr-xt-ghost
1920 :     \ we define new address only if empty
1921 : jwilke 1.105 \ this is for not to take over the alias ghost
1922 :     \ (different ghost, but identical xt)
1923 : jwilke 1.103 \ but the very first that really defines it
1924 :     dup @ 0= IF ! ELSE 2drop THEN
1925 :     THEN
1926 : jwilke 1.122 swap >r
1927 : pazsan 1.118 r@ to resolved
1928 : jwilke 1.121
1929 :     \ r@ >comp @ ['] is-forward =
1930 :     \ ABORT" >comp action not set on a resolved ghost"
1931 :    
1932 :     \ copmile action defaults to colon-resolved
1933 :     \ if this is not right something must be set before
1934 :     \ calling resolve
1935 :     r@ >comp @ ['] is-forward = IF
1936 : jwilke 1.122 ['] colon-resolved r@ >comp !
1937 :     THEN
1938 :     r@ >link @ swap \ ( list tcfa R: ghost )
1939 :     \ mark ghost as resolved
1940 :     r@ >link ! <res> r@ >magic !
1941 :     r> swap ;
1942 : pazsan 1.54
1943 : jwilke 1.122 : resolve ( ghost tcfa -- )
1944 :     \G resolve referencies to ghost with tcfa
1945 :     \ is ghost resolved?, second resolve means another
1946 :     \ definition with the same name
1947 :     over undefined? 0= IF exists EXIT THEN
1948 :     (resolve)
1949 :     ( ghost resolve-list )
1950 :     resolve-forward-references ;
1951 :    
1952 :     : resolve-noforwards ( ghost tcfa -- )
1953 :     \G Same as resolve but complain if there are any
1954 :     \G forward references on this ghost
1955 :     \ is ghost resolved?, second resolve means another
1956 :     \ definition with the same name
1957 :     over undefined? 0= IF exists EXIT THEN
1958 :     (resolve)
1959 :     IF cr ." No forward references allowed on: " .ghost cr
1960 :     -1 ABORT" Illegal forward reference"
1961 :     THEN
1962 :     drop ;
1963 : anton 1.1
1964 :     \ gexecute ghost, 01nov92py
1965 :    
1966 : jwilke 1.103 : (gexecute) ( ghost -- )
1967 : jwilke 1.105 dup >comp @ EXECUTE ;
1968 : jwilke 1.103
1969 :     : gexecute ( ghost -- )
1970 : jwilke 1.120 dup >magic @ <imm> = ABORT" CROSS: gexecute on immediate word"
1971 : jwilke 1.103 (gexecute) ;
1972 : jwilke 1.52
1973 :     : addr, ( ghost -- )
1974 : jwilke 1.105 dup forward? IF 1 refered 0 T a, H ELSE >link @ T a, H THEN ;
1975 : jwilke 1.52
1976 : anton 1.1 \ .unresolved 11may93jaw
1977 :    
1978 :     variable ResolveFlag
1979 :    
1980 :     \ ?touched 11may93jaw
1981 :    
1982 : jwilke 1.52 : ?touched ( ghost -- flag ) dup forward? swap >link @
1983 : anton 1.1 0 <> and ;
1984 :    
1985 : jwilke 1.53 : .forwarddefs ( ghost -- )
1986 : jwilke 1.103 ." appeared in:"
1987 :     >link
1988 :     BEGIN @ dup
1989 :     WHILE cr 5 spaces
1990 :     dup >ghost @ .ghost
1991 :     ." file " dup >file @ ?dup IF count type ELSE ." CON" THEN
1992 :     ." line " dup >line @ .dec
1993 :     REPEAT
1994 :     drop ;
1995 :    
1996 :     : ?resolved ( ghost -- )
1997 :     dup ?touched
1998 :     IF ResolveFlag on
1999 :     dup cr .ghost .forwarddefs
2000 : jwilke 1.53 ELSE drop
2001 :     THEN ;
2002 : anton 1.1
2003 :     : .unresolved ( -- )
2004 :     ResolveFlag off cr ." Unresolved: "
2005 : jwilke 1.103 ghost-list
2006 : anton 1.1 BEGIN @ dup
2007 :     WHILE dup ?resolved
2008 : anton 1.10 REPEAT drop ResolveFlag @
2009 :     IF
2010 : anton 1.48 -1 abort" Unresolved words!"
2011 : anton 1.10 ELSE
2012 :     ." Nothing!"
2013 :     THEN
2014 :     cr ;
2015 : anton 1.1
2016 : jwilke 1.52 : .stats
2017 :     base @ >r decimal
2018 :     cr ." named Headers: " headers-named @ .
2019 :     r> base ! ;
2020 :    
2021 : jwilke 1.79 >MINIMAL
2022 :    
2023 :     : .unresolved .unresolved ;
2024 :    
2025 : anton 1.1 >CROSS
2026 :     \ Header states 12dec92py
2027 :    
2028 : jwilke 1.102 \ : flag! ( 8b -- ) tlast @ dup >r T c@ xor r> c! H ;
2029 : pazsan 1.142 X has? f83headerstring bigendian or [IF] 0 [ELSE] tcell 1- [THEN] Constant flag+
2030 : pazsan 1.90 : flag! ( w -- ) tlast @ flag+ + dup >r T c@ xor r> c! H ;
2031 : anton 1.1
2032 :     VARIABLE ^imm
2033 :    
2034 : jwilke 1.105 \ !! should be target wordsize specific
2035 :     $80 constant alias-mask
2036 :     $40 constant immediate-mask
2037 :     $20 constant restrict-mask
2038 :    
2039 : anton 1.1 >TARGET
2040 : jwilke 1.105 : immediate immediate-mask flag!
2041 : pazsan 1.18 ^imm @ @ dup <imm> = IF drop EXIT THEN
2042 : anton 1.1 <res> <> ABORT" CROSS: Cannot immediate a unresolved word"
2043 :     <imm> ^imm @ ! ;
2044 : jwilke 1.105 : restrict restrict-mask flag! ;
2045 : jwilke 1.52
2046 : pazsan 1.54 : isdoer
2047 :     \G define a forth word as doer, this makes obviously only sence on
2048 :     \G forth processors such as the PSC1000
2049 :     <do:> last-header-ghost @ >magic ! ;
2050 : anton 1.1 >CROSS
2051 :    
2052 :     \ Target Header Creation 01nov92py
2053 :    
2054 : jwilke 1.103 : ht-lstring, ( addr count -- )
2055 : jwilke 1.102 dup T , H bounds ?DO I c@ T c, H LOOP ;
2056 :    
2057 : jwilke 1.103 >TARGET
2058 : jwilke 1.139 X has? f83headerstring [IF]
2059 :     : name, ( "name" -- ) bl word count ht-string, X cfalign ;
2060 :     [ELSE]
2061 : jwilke 1.103 : name, ( "name" -- ) bl word count ht-lstring, X cfalign ;
2062 : jwilke 1.139 [THEN]
2063 : anton 1.1 : view, ( -- ) ( dummy ) ;
2064 : jwilke 1.52 >CROSS
2065 : anton 1.1
2066 : pazsan 1.25 \ Target Document Creation (goes to crossdoc.fd) 05jul95py
2067 :    
2068 : pazsan 1.55 s" ./doc/crossdoc.fd" r/w create-file throw value doc-file-id
2069 : pazsan 1.25 \ contains the file-id of the documentation file
2070 :    
2071 : pazsan 1.40 : T-\G ( -- )
2072 : pazsan 1.25 source >in @ /string doc-file-id write-line throw
2073 : pazsan 1.40 postpone \ ;
2074 : pazsan 1.25
2075 : pazsan 1.39 Variable to-doc to-doc on
2076 : pazsan 1.25
2077 :     : cross-doc-entry ( -- )
2078 :     to-doc @ tlast @ 0<> and \ not an anonymous (i.e. noname) header
2079 :     IF
2080 :     s" " doc-file-id write-line throw
2081 :     s" make-doc " doc-file-id write-file throw
2082 : jwilke 1.102
2083 : jwilke 1.105 Last-Header-Ghost @ >ghostname doc-file-id write-file throw
2084 : pazsan 1.25 >in @
2085 :     [char] ( parse 2drop
2086 :     [char] ) parse doc-file-id write-file throw
2087 :     s" )" doc-file-id write-file throw
2088 :     [char] \ parse 2drop
2089 : pazsan 1.40 T-\G
2090 : pazsan 1.25 >in !
2091 : pazsan 1.39 THEN ;
2092 : pazsan 1.25
2093 : pazsan 1.28 \ Target TAGS creation
2094 :    
2095 : pazsan 1.39 s" kernel.TAGS" r/w create-file throw value tag-file-id
2096 : pazsan 1.116 s" kernel.tags" r/w create-file throw value vi-tag-file-id
2097 : pazsan 1.28 \ contains the file-id of the tags file
2098 :    
2099 : anton 1.137 Create tag-beg 1 c, 7F c,
2100 :     Create tag-end 1 c, 01 c,
2101 : pazsan 1.28 Create tag-bof 1 c, 0C c,
2102 : pazsan 1.116 Create tag-tab 1 c, 09 c,
2103 : pazsan 1.28
2104 :     2variable last-loadfilename 0 0 last-loadfilename 2!
2105 :    
2106 :     : put-load-file-name ( -- )
2107 : jwilke 1.77 sourcefilename last-loadfilename 2@ d<>
2108 : pazsan 1.28 IF
2109 :     tag-bof count tag-file-id write-line throw
2110 : anton 1.31 sourcefilename 2dup
2111 : pazsan 1.28 tag-file-id write-file throw
2112 :     last-loadfilename 2!
2113 :     s" ,0" tag-file-id write-line throw
2114 :     THEN ;
2115 :    
2116 : pazsan 1.116 : cross-gnu-tag-entry ( -- )
2117 : pazsan 1.28 tlast @ 0<> \ not an anonymous (i.e. noname) header
2118 :     IF
2119 :     put-load-file-name
2120 :     source >in @ min tag-file-id write-file throw
2121 :     tag-beg count tag-file-id write-file throw
2122 : pazsan 1.116 Last-Header-Ghost @ >ghostname tag-file-id write-file throw
2123 : pazsan 1.28 tag-end count tag-file-id write-file throw
2124 : anton 1.31 base @ decimal sourceline# 0 <# #s #> tag-file-id write-file throw
2125 : pazsan 1.28 \ >in @ 0 <# #s [char] , hold #> tag-file-id write-line throw
2126 :     s" ,0" tag-file-id write-line throw
2127 :     base !
2128 :     THEN ;
2129 : pazsan 1.116
2130 :     : cross-vi-tag-entry ( -- )
2131 :     tlast @ 0<> \ not an anonymous (i.e. noname) header
2132 :     IF
2133 :     sourcefilename vi-tag-file-id write-file throw
2134 :     tag-tab count vi-tag-file-id write-file throw
2135 :     Last-Header-Ghost @ >ghostname vi-tag-file-id write-file throw
2136 :     tag-tab count vi-tag-file-id write-file throw
2137 :     s" /^" vi-tag-file-id write-file throw
2138 :     source vi-tag-file-id write-file throw
2139 :     s" $/" vi-tag-file-id write-line throw
2140 :     THEN ;
2141 :    
2142 :     : cross-tag-entry ( -- )
2143 :     cross-gnu-tag-entry
2144 :     cross-vi-tag-entry ;
2145 : pazsan 1.28
2146 : pazsan 1.43 \ Check for words
2147 :    
2148 :     Defer skip? ' false IS skip?
2149 :    
2150 : jwilke 1.103 : skipdef ( "name" -- )
2151 : jwilke 1.79 \G skip definition of an undefined word in undef-words and
2152 :     \G all-words mode
2153 : jwilke 1.103 Ghost dup forward?
2154 : jwilke 1.75 IF >magic <skip> swap !
2155 :     ELSE drop THEN ;
2156 :    
2157 : jwilke 1.103 : tdefined? ( "name" -- flag )
2158 :     Ghost undefined? 0= ;
2159 : jwilke 1.75
2160 : jwilke 1.103 : defined2? ( "name" -- flag )
2161 : jwilke 1.75 \G return true for anything else than forward, even for <skip>
2162 :     \G that's what we want
2163 : jwilke 1.103 Ghost forward? 0= ;
2164 : pazsan 1.43
2165 : jwilke 1.103 : forced? ( "name" -- flag )
2166 : jwilke 1.79 \G return ture if it is a foreced skip with defskip
2167 : jwilke 1.103 Ghost >magic @ <skip> = ;
2168 : jwilke 1.79
2169 : pazsan 1.43 : needed? ( -- flag ) \ name
2170 : anton 1.48 \G returns a false flag when
2171 :     \G a word is not defined
2172 :     \G a forward reference exists
2173 :     \G so the definition is not skipped!
2174 :     bl word gfind
2175 : jwilke 1.75 IF dup undefined?
2176 : anton 1.48 nip
2177 :     0=
2178 :     ELSE drop true THEN ;
2179 : pazsan 1.43
2180 : jwilke 1.139 : doer? ( "name" -- 0 | addr ) \ name
2181 :     Ghost dup >magic @ <do:> =
2182 :     IF >link @ ELSE drop 0 THEN ;
2183 : pazsan 1.44
2184 : pazsan 1.43 : skip-defs ( -- )
2185 :     BEGIN refill WHILE source -trailing nip 0= UNTIL THEN ;
2186 :    
2187 : pazsan 1.28 \ Target header creation
2188 :    
2189 : pazsan 1.54 Variable NoHeaderFlag
2190 :     NoHeaderFlag off
2191 : anton 1.1
2192 : pazsan 1.54 : 0.r ( n1 n2 -- )
2193 :     base @ >r hex
2194 :     0 swap <# 0 ?DO # LOOP #> type
2195 :     r> base ! ;
2196 : jwilke 1.84
2197 :     : .sym ( adr len -- )
2198 :     \G escapes / and \ to produce sed output
2199 : jwilke 1.52 bounds
2200 :     DO I c@ dup
2201 : jwilke 1.77 CASE [char] / OF drop ." \/" ENDOF
2202 :     [char] \ OF drop ." \\" ENDOF
2203 : jwilke 1.52 dup OF emit ENDOF
2204 :     ENDCASE
2205 : pazsan 1.54 LOOP ;
2206 : jwilke 1.52
2207 : jwilke 1.103 Defer setup-execution-semantics
2208 :     0 Value lastghost
2209 :    
2210 :     : (THeader ( "name" -- ghost )
2211 : pazsan 1.54 \ >in @ bl word count type 2 spaces >in !
2212 :     \ wordheaders will always be compiled to rom
2213 :     switchrom
2214 :     \ build header in target
2215 :     NoHeaderFlag @
2216 :     IF NoHeaderFlag off
2217 :     ELSE
2218 :     T align H view,
2219 : jwilke 1.78 tlast @ dup 0> IF tcell - THEN T A, H there tlast !
2220 : pazsan 1.54 1 headers-named +! \ Statistic
2221 :     >in @ T name, H >in !
2222 :     THEN
2223 :     T cfalign here H tlastcfa !
2224 : jwilke 1.84 \ Old Symbol table sed-script
2225 : pazsan 1.54 \ >in @ cr ." sym:s/CFA=" there 4 0.r ." /" bl word count .sym ." /g" cr >in !
2226 : jwilke 1.103 HeaderGhost
2227 : jwilke 1.84 \ output symbol table to extra file
2228 : jwilke 1.123 dup >ghostname there symentry
2229 : jwilke 1.103 dup Last-Header-Ghost ! dup to lastghost
2230 : pazsan 1.54 dup >magic ^imm ! \ a pointer for immediate
2231 : jwilke 1.105 alias-mask flag!
2232 : jwilke 1.103 cross-doc-entry cross-tag-entry
2233 :     setup-execution-semantics
2234 :     ;
2235 : anton 1.1
2236 : jwilke 1.52 \ this is the resolver information from ":"
2237 :     \ resolving is done by ";"
2238 : jwilke 1.103 Variable ;Resolve 1 cells allot
2239 :    
2240 :     : hereresolve ( ghost -- )
2241 :     there resolve 0 ;Resolve ! ;
2242 : anton 1.1
2243 : pazsan 1.11 : Theader ( "name" -- ghost )
2244 : jwilke 1.103 (THeader dup hereresolve ;
2245 :    
2246 :     Variable aprim-nr -20 aprim-nr !
2247 :    
2248 :     : copy-execution-semantics ( ghost-from ghost-dest -- )
2249 :     >r
2250 :     dup >exec @ r@ >exec !
2251 : pazsan 1.117 dup >comp @ r@ >comp !
2252 : jwilke 1.103 dup >exec2 @ r@ >exec2 !
2253 :     dup >exec-compile @ r@ >exec-compile !
2254 :     dup >ghost-xt @ r@ >ghost-xt !
2255 :     dup >created @ r@ >created !
2256 :     rdrop drop ;
2257 : anton 1.1
2258 :     >TARGET
2259 : jwilke 1.103
2260 : anton 1.1 : Alias ( cfa -- ) \ name
2261 : jwilke 1.103 >in @ skip? IF 2drop EXIT THEN >in !
2262 :     (THeader ( S xt ghost )
2263 : jwilke 1.105 2dup swap xt>ghost swap copy-execution-semantics
2264 :     over resolve T A, H alias-mask flag! ;
2265 : jwilke 1.103
2266 :     Variable last-prim-ghost
2267 :     0 last-prim-ghost !
2268 :    
2269 :     : asmprimname, ( ghost -- : name )
2270 :     dup last-prim-ghost !
2271 :     >r
2272 :     here bl word count string, r@ >asm-name !
2273 :     aprim-nr @ r> >asm-dummyaddr ! ;
2274 :    
2275 :     Defer setup-prim-semantics
2276 :    
2277 : jwilke 1.112 : mapprim ( "forthname" "asmlabel" -- )
2278 : jwilke 1.103 THeader -1 aprim-nr +! aprim-nr @ T A, H
2279 :     asmprimname,
2280 :     setup-prim-semantics ;
2281 :    
2282 : jwilke 1.112 : mapprim: ( "forthname" "asmlabel" -- )
2283 : jwilke 1.103 -1 aprim-nr +! aprim-nr @
2284 : jwilke 1.122 Ghost tuck swap resolve-noforwards <do:> swap tuck >magic !
2285 : jwilke 1.103 asmprimname, ;
2286 :    
2287 : pazsan 1.119 : Doer: ( cfa -- ) \ name
2288 : jwilke 1.103 >in @ skip? IF 2drop EXIT THEN >in !
2289 :     dup 0< s" prims" T $has? H 0= and
2290 :     IF
2291 :     .sourcepos ." needs doer: " >in @ bl word count type >in ! cr
2292 :     THEN
2293 : pazsan 1.119 Ghost
2294 : jwilke 1.122 tuck swap resolve-noforwards <do:> swap >magic ! ;
2295 : pazsan 1.64
2296 :     Variable prim#
2297 :     : first-primitive ( n -- ) prim# ! ;
2298 : pazsan 1.132 : group 0 word drop prim# @ 1- -$200 and prim# ! ;
2299 : pazsan 1.140 : groupadd ( n -- ) drop ;
2300 : pazsan 1.64 : Primitive ( -- ) \ name
2301 : pazsan 1.117 >in @ skip? IF drop EXIT THEN >in !
2302 :     s" prims" T $has? H 0=
2303 : jwilke 1.103 IF
2304 :     .sourcepos ." needs prim: " >in @ bl word count type >in ! cr
2305 :     THEN
2306 :     prim# @ (THeader ( S xt ghost )
2307 : jwilke 1.121 ['] prim-resolved over >comp !
2308 : jwilke 1.105 dup >ghost-flags <primitive> set-flag
2309 : jwilke 1.122 over resolve-noforwards T A, H alias-mask flag!
2310 : jwilke 1.103 -1 prim# +! ;
2311 : anton 1.1 >CROSS
2312 :    
2313 :     \ Conditionals and Comments 11may93jaw
2314 :    
2315 : jwilke 1.103 \G saves the existing cond action, this is used for redefining in
2316 :     \G instant
2317 :     Variable cond-xt-old
2318 :    
2319 :     : cond-target ( -- )
2320 :     \G Compiles semantic of redefined cond into new one
2321 :     cond-xt-old @ compile, ; immediate restrict
2322 :    
2323 : anton 1.1 : ;Cond
2324 :     postpone ;
2325 :     swap ! ; immediate
2326 :    
2327 : jwilke 1.103 : Cond: ( "name" -- )
2328 :     \g defines a conditional or another word that must
2329 :     \g be executed directly while compiling
2330 :     \g these words have no interpretative semantics by default
2331 :     Ghost
2332 :     >exec-compile
2333 :     dup @ cond-xt-old !
2334 : anton 1.1 :NONAME ;
2335 :    
2336 :    
2337 :     : Comment ( -- )
2338 : jwilke 1.103 >in @ Ghost swap >in ! ' swap
2339 :     2dup >exec-compile ! >exec ! ;
2340 : anton 1.1
2341 :     Comment ( Comment \
2342 :    
2343 :     \ compile 10may93jaw
2344 :    
2345 : jwilke 1.103 : compile ( "name" -- ) \ name
2346 : jwilke 1.115 findghost
2347 : jwilke 1.103 dup >exec-compile @ ?dup
2348 :     IF nip compile,
2349 :     ELSE postpone literal postpone gexecute THEN ; immediate restrict
2350 :    
2351 : jwilke 1.52 >TARGET
2352 :    
2353 : jwilke 1.105 : ' ( -- xt )
2354 :     \G returns the target-cfa of a ghost
2355 : jwilke 1.52 bl word gfind 0= ABORT" CROSS: Ghost don't exists"
2356 : jwilke 1.105 g>xt ;
2357 : jwilke 1.52
2358 : jwilke 1.103 \ FIXME: this works for the current use cases, but is not
2359 :     \ in all cases correct ;-)
2360 :     : comp' X ' 0 ;
2361 :    
2362 : jwilke 1.52 Cond: ['] T ' H alit, ;Cond
2363 :    
2364 :     >CROSS
2365 :    
2366 :     : [T']
2367 :     \ returns the target-cfa of a ghost, or compiles it as literal
2368 : jwilke 1.115 postpone [G']
2369 :     state @ IF postpone g>xt ELSE g>xt THEN ; immediate
2370 : pazsan 1.42
2371 : jwilke 1.52 \ \ threading modell 13dec92py
2372 :     \ modularized 14jun97jaw
2373 :    
2374 : jwilke 1.106 T 2 cells H Value xt>body
2375 : jwilke 1.52
2376 : jwilke 1.103 : (>body) ( cfa -- pfa )
2377 : jwilke 1.105 xt>body + ; ' (>body) plugin-of t>body
2378 :    
2379 :     : fillcfa ( usedcells -- )
2380 : jwilke 1.106 T cells H xt>body swap -
2381 : jwilke 1.105 assert1( dup 0 >= )
2382 :     0 ?DO 0 X c, tchar +LOOP ;
2383 : jwilke 1.52
2384 : jwilke 1.103 : (doer,) ( ghost -- )
2385 : jwilke 1.105 addr, 1 fillcfa ; ' (doer,) plugin-of doer,
2386 : jwilke 1.52
2387 : jwilke 1.105 : (docol,) ( -- ) [G'] :docol (doer,) ; ' (docol,) plugin-of docol,
2388 : jwilke 1.52
2389 : jwilke 1.121 ' NOOP plugin-of ca>native
2390 :    
2391 : jwilke 1.52 : (doprim,) ( -- )
2392 : jwilke 1.105 there xt>body + ca>native T a, H 1 fillcfa ; ' (doprim,) plugin-of doprim,
2393 : jwilke 1.52
2394 :     : (doeshandler,) ( -- )
2395 : pazsan 1.119 T cfalign H [G'] :doesjump addr, T 0 , H ; ' (doeshandler,) plugin-of doeshandler,
2396 : jwilke 1.52
2397 :     : (dodoes,) ( does-action-ghost -- )
2398 : pazsan 1.119 ]comp [G'] :dodoes addr, comp[
2399 : jwilke 1.52 addr,
2400 : jwilke 1.103 \ the relocator in the c engine, does not like the
2401 :     \ does-address to marked for relocation
2402 :     [ T e? ec H 0= [IF] ] T here H tcell - reloff [ [THEN] ]
2403 : jwilke 1.105 2 fillcfa ; ' (dodoes,) plugin-of dodoes,
2404 : jwilke 1.52
2405 : jwilke 1.107 : (dlit,) ( n -- ) compile lit td, ; ' (dlit,) plugin-of dlit,
2406 :    
2407 :     : (lit,) ( n -- ) s>d dlit, ; ' (lit,) plugin-of lit,
2408 : jwilke 1.52
2409 : jwilke 1.67 \ if we dont produce relocatable code alit, defaults to lit, jaw
2410 : jwilke 1.84 \ this is just for convenience, so we don't have to define alit,
2411 :     \ seperately for embedded systems....
2412 :     T has? relocate H
2413 : jwilke 1.67 [IF]
2414 : jwilke 1.105 : (alit,) ( n -- ) compile lit T a, H ; ' (alit,) plugin-of alit,
2415 : jwilke 1.67 [ELSE]
2416 : jwilke 1.105 : (alit,) ( n -- ) lit, ; ' (alit,) plugin-of alit,
2417 : jwilke 1.67 [THEN]
2418 : jwilke 1.52
2419 : jwilke 1.105 : (fini,) compile ;s ; ' (fini,) plugin-of fini,
2420 : pazsan 1.42
2421 : pazsan 1.43 [IFUNDEF] (code)
2422 :     Defer (code)
2423 :     Defer (end-code)
2424 :     [THEN]
2425 :    
2426 : anton 1.1 >TARGET
2427 : pazsan 1.43 : Code
2428 : jwilke 1.52 defempty?
2429 : jwilke 1.121 (THeader ( ghost )
2430 :     ['] prim-resolved over >comp !
2431 : jwilke 1.122 there resolve-noforwards
2432 : jwilke 1.121
2433 : jwilke 1.53 [ T e? prims H 0= [IF] T e? ITC H [ELSE] true [THEN] ] [IF]
2434 : jwilke 1.52 doprim,
2435 : anton 1.48 [THEN]
2436 :     depth (code) ;
2437 : pazsan 1.43
2438 : jwilke 1.121 \ FIXME : no-compile -1 ABORT" this ghost is not for compilation" ;
2439 :    
2440 : pazsan 1.43 : Code:
2441 : jwilke 1.52 defempty?
2442 : jwilke 1.121 Ghost >r
2443 : jwilke 1.123 r@ >ghostname there symentry
2444 : jwilke 1.122 r@ there ca>native resolve-noforwards
2445 : jwilke 1.121 <do:> r@ >magic !
2446 :     r> drop
2447 : pazsan 1.43 depth (code) ;
2448 :    
2449 :     : end-code
2450 : jwilke 1.52 (end-code)
2451 : pazsan 1.43 depth ?dup IF 1- <> ABORT" CROSS: Stack changed"
2452 :     ELSE true ABORT" CROSS: Stack empty" THEN
2453 : jwilke 1.52 ;
2454 : anton 1.14
2455 : anton 1.1 >CROSS
2456 : jwilke 1.52
2457 : anton 1.1 \ tLiteral 12dec92py
2458 :    
2459 :     >TARGET
2460 : pazsan 1.40 Cond: \G T-\G ;Cond
2461 :    
2462 : jwilke 1.105 Cond: Literal ( n -- ) lit, ;Cond
2463 : jwilke 1.103 Cond: ALiteral ( n -- ) alit, ;Cond
2464 : anton 1.1
2465 :     : Char ( "<char>" -- ) bl word char+ c@ ;
2466 : jwilke 1.103 Cond: [Char] ( "<char>" -- ) Char lit, ;Cond
2467 :    
2468 : jwilke 1.139 : (x#) ( adr len base -- )
2469 :     base @ >r base ! 0 0 name >number 2drop drop r> base ! ;
2470 :    
2471 :     : d# $0a (x#) ;
2472 :     : h# $010 (x#) ;
2473 :    
2474 :     Cond: d# $0a (x#) lit, ;Cond
2475 :     Cond: h# $010 (x#) lit, ;Cond
2476 :    
2477 : jwilke 1.104 tchar 1 = [IF]
2478 : jwilke 1.110 Cond: chars ;Cond
2479 : jwilke 1.104 [THEN]
2480 : anton 1.1
2481 : pazsan 1.43 \ some special literals 27jan97jaw
2482 :    
2483 :     Cond: MAXU
2484 : jwilke 1.125 -1 s>d dlit,
2485 : jwilke 1.52 ;Cond
2486 : pazsan 1.43
2487 : jwilke 1.125 tcell 2 = tcell 4 = or tcell 8 = or 0=
2488 :     [IF]
2489 :     .( Warning: MINI and MAXI may not work with this host) cr
2490 :     [THEN]
2491 :    
2492 : pazsan 1.43 Cond: MINI
2493 : jwilke 1.125 tcell 2 = IF $8000 ELSE $80000000 THEN 0
2494 :     tcell 8 = IF swap THEN dlit,
2495 : jwilke 1.52 ;Cond
2496 : pazsan 1.43
2497 :     Cond: MAXI
2498 : jwilke 1.125 tcell 2 = IF $7fff ELSE $7fffffff THEN 0
2499 :     tcell 8 = IF drop -1 swap THEN dlit,
2500 :     ;Cond
2501 : pazsan 1.43
2502 : anton 1.1 >CROSS
2503 : jwilke 1.115
2504 : anton 1.1 \ Target compiling loop 12dec92py
2505 :     \ ">tib trick thrown out 10may93jaw
2506 :     \ number? defined at the top 11may93jaw
2507 : jwilke 1.77 \ replaced >in by save-input
2508 :    
2509 :     : discard 0 ?DO drop LOOP ;
2510 : anton 1.1
2511 :     \ compiled word might leave items on stack!
2512 : jwilke 1.77 : tcom ( x1 .. xn n name -- )
2513 :     \ dup count type space
2514 : jwilke 1.103 gfind
2515 :     IF >r ( discard saved input state ) discard r>
2516 :     dup >exec-compile @ ?dup
2517 :     IF nip execute-exec-compile ELSE gexecute THEN
2518 : jwilke 1.77 EXIT
2519 :     THEN
2520 :     number? dup
2521 :     IF 0> IF swap lit, THEN lit, discard
2522 : jwilke 1.103 ELSE 2drop restore-input throw Ghost gexecute THEN ;
2523 : anton 1.1
2524 :     \ : ; DOES> 13dec92py
2525 :     \ ] 9may93py/jaw
2526 :    
2527 : jwilke 1.115 >CROSS
2528 :    
2529 : jwilke 1.105 : compiling-state ( -- )
2530 :     \G set states to compililng
2531 : pazsan 1.54 Compiling comp-state !
2532 : jwilke 1.103 \ if we have a state in target, change it with the compile state
2533 : jwilke 1.105 [G'] state dup undefined? 0=
2534 :     IF >ghost-xt @ execute X on ELSE drop THEN ;
2535 :    
2536 :     : interpreting-state ( -- )
2537 :     \G set states to interpreting
2538 :     \ if target has a state variable, change it according to our state
2539 :     [G'] state dup undefined? 0=
2540 :     IF >ghost-xt @ execute X off ELSE drop THEN
2541 :     Interpreting comp-state ! ;
2542 : jwilke 1.115
2543 :     >TARGET
2544 : jwilke 1.105
2545 :     : ]
2546 :     compiling-state
2547 : anton 1.1 BEGIN
2548 : jwilke 1.77 BEGIN save-input bl word
2549 :     dup c@ 0= WHILE drop discard refill 0=
2550 : anton 1.1 ABORT" CROSS: End of file while target compiling"
2551 :     REPEAT
2552 :     tcom
2553 : jwilke 1.103 compiling? 0=
2554 : anton 1.1 UNTIL ;
2555 :    
2556 :     \ by the way: defining a second interpreter (a compiler-)loop
2557 :     \ is not allowed if a system should be ans conform
2558 :    
2559 : jwilke 1.110 : (:) ( ghost -- )
2560 :     \ common factor of : and :noname. Prepare ;Resolve and start definition
2561 :     ;Resolve ! there ;Resolve cell+ !
2562 :     docol, ]comp colon-start depth T ] H ;
2563 :    
2564 : anton 1.1 : : ( -- colon-sys ) \ Name
2565 : jwilke 1.52 defempty?
2566 :     constflag off \ don't let this flag work over colon defs
2567 :     \ just to go sure nothing unwanted happens
2568 : pazsan 1.43 >in @ skip? IF drop skip-defs EXIT THEN >in !
2569 : jwilke 1.110 (THeader (:) ;
2570 : anton 1.1
2571 : pazsan 1.37 : :noname ( -- colon-sys )
2572 : jwilke 1.110 X cfalign there
2573 :     \ define a nameless ghost
2574 :     here ghostheader dup last-header-ghost ! dup to lastghost
2575 :     (:) ;
2576 : pazsan 1.37
2577 : jwilke 1.103 Cond: EXIT ( -- ) compile ;S ;Cond
2578 : anton 1.6
2579 :     Cond: ?EXIT ( -- ) 1 abort" CROSS: using ?exit" ;Cond
2580 : pazsan 1.2
2581 : jwilke 1.52 >CROSS
2582 :     : LastXT ;Resolve @ 0= abort" CROSS: no definition for LastXT"
2583 :     ;Resolve cell+ @ ;
2584 :    
2585 :     >TARGET
2586 :    
2587 : jwilke 1.103 Cond: recurse ( -- ) Last-Header-Ghost @ gexecute ;Cond
2588 : jwilke 1.52
2589 : jwilke 1.103 Cond: ; ( -- )
2590 : jwilke 1.105 depth ?dup
2591 :     IF 1- <> ABORT" CROSS: Stack changed"
2592 :     ELSE true ABORT" CROSS: Stack empty"
2593 :     THEN
2594 :     colon-end
2595 :     fini,
2596 :     comp[
2597 :     ;Resolve @
2598 : pazsan 1.118 IF ['] colon-resolved ;Resolve @ >comp !
2599 :     ;Resolve @ ;Resolve cell+ @ resolve
2600 : jwilke 1.105 THEN
2601 :     interpreting-state
2602 :     ;Cond
2603 :    
2604 :     Cond: [ ( -- ) interpreting-state ;Cond
2605 : anton 1.1
2606 :     >CROSS
2607 : pazsan 1.54
2608 : pazsan 1.117 0 Value created
2609 : pazsan 1.54
2610 : jwilke 1.52 : !does ( does-action -- )
2611 : pazsan 1.54 tlastcfa @ [G'] :dovar killref
2612 : pazsan 1.117 >space here >r ghostheader space>
2613 : jwilke 1.121 ['] colon-resolved r@ >comp !
2614 : pazsan 1.117 r@ created >do:ghost ! r@ swap resolve
2615 :     r> tlastcfa @ >tempdp dodoes, tempdp> ;
2616 : jwilke 1.103
2617 :     Defer instant-interpret-does>-hook
2618 :    
2619 : pazsan 1.134 T has? peephole H [IF]
2620 : pazsan 1.118 : does-resolved ( ghost -- )
2621 :     compile does-exec g>xt T a, H ;
2622 : pazsan 1.134 [ELSE]
2623 :     : does-resolved ( ghost -- )
2624 :     g>xt T a, H ;
2625 :     [THEN]
2626 : pazsan 1.118
2627 : jwilke 1.103 : resolve-does>-part ( -- )
2628 :     \ resolve words made by builders
2629 : jwilke 1.105 Last-Header-Ghost @ >do:ghost @ ?dup
2630 : pazsan 1.117 IF there resolve THEN ;
2631 : jwilke 1.103
2632 : anton 1.1 >TARGET
2633 : jwilke 1.103 Cond: DOES>
2634 :     compile (does>) doeshandler,
2635 :     resolve-does>-part
2636 : anton 1.1 ;Cond
2637 : jwilke 1.103
2638 : pazsan 1.118 : DOES>
2639 :     ['] does-resolved created >comp !
2640 :     switchrom doeshandler, T here H !does
2641 :     instant-interpret-does>-hook
2642 :     depth T ] H ;
2643 : anton 1.1
2644 :     >CROSS
2645 : jwilke 1.108 \ Creation 01nov92py
2646 : anton 1.1
2647 :     \ Builder 11may93jaw
2648 :    
2649 : jwilke 1.108 0 Value built
2650 :    
2651 : jwilke 1.105 : Builder ( Create-xt do-ghost "name" -- )
2652 : jwilke 1.52 \ builds up a builder in current vocabulary
2653 :     \ create-xt is executed when word is interpreted
2654 : jwilke 1.106 \ do:-xt is executed when the created word from builder is executed
2655 : jwilke 1.105 \ for do:-xt an additional entry after the normal ghost-entrys is used
2656 : jwilke 1.52
2657 : jwilke 1.109 ghost to built
2658 : jwilke 1.108 built >created @ 0= IF
2659 :     built >created on
2660 :     THEN ;
2661 : anton 1.1
2662 : jwilke 1.52 : gdoes, ( ghost -- )
2663 :     \ makes the codefield for a word that is built
2664 : jwilke 1.103 >do:ghost @ dup undefined? 0=
2665 : jwilke 1.52 IF
2666 : pazsan 1.42 dup >magic @ <do:> =
2667 : pazsan 1.54 IF doer,
2668 :     ELSE dodoes,
2669 :     THEN
2670 :     EXIT
2671 : jwilke 1.52 THEN
2672 :     \ compile :dodoes gexecute
2673 :     \ T here H tcell - reloff
2674 : pazsan 1.54 2 refered
2675 :     0 fillcfa
2676 :     ;
2677 : anton 1.1
2678 : jwilke 1.103 : takeover-x-semantics ( S constructor-ghost new-ghost -- )
2679 : pazsan 1.117 \g stores execution semantic and compilation semantic in the built word
2680 :     swap >do:ghost @ 2dup swap >do:ghost !
2681 : jwilke 1.110 \ we use the >exec2 field for the semantic of a created word,
2682 :     \ using exec or exec2 makes no difference for normal cross-compilation
2683 :     \ but is usefull for instant where the exec field is already
2684 :     \ defined (e.g. Vocabularies)
2685 : jwilke 1.105 2dup >exec @ swap >exec2 !
2686 :     >comp @ swap >comp ! ;
2687 : jwilke 1.103
2688 : pazsan 1.118 0 Value createhere
2689 :    
2690 :     : create-resolve ( -- )
2691 :     created createhere resolve 0 ;Resolve ! ;
2692 :     : create-resolve-immediate ( -- )
2693 :     create-resolve T immediate H ;
2694 :    
2695 : jwilke 1.52 : TCreate ( <name> -- )
2696 :     create-forward-warn
2697 :     IF ['] reswarn-forward IS resolve-warning THEN
2698 : jwilke 1.103 executed-ghost @ (Theader
2699 : pazsan 1.117 dup >created on dup to created
2700 : pazsan 1.118 2dup takeover-x-semantics
2701 :     there to createhere drop gdoes, ;
2702 : jwilke 1.52
2703 :     : RTCreate ( <name> -- )
2704 :     \ creates a new word with code-field in ram
2705 :     create-forward-warn
2706 :     IF ['] reswarn-forward IS resolve-warning THEN
2707 :     \ make Alias
2708 : jwilke 1.103 executed-ghost @ (THeader
2709 : pazsan 1.118 dup >created on dup to created
2710 : jwilke 1.103 2dup takeover-x-semantics
2711 : jwilke 1.105 there 0 T a, H alias-mask flag!
2712 : jwilke 1.103 \ store poiter to code-field
2713 : jwilke 1.52 switchram T cfalign H
2714 :     there swap T ! H
2715 :     there tlastcfa !
2716 : pazsan 1.118 there to createhere drop gdoes, ;
2717 : anton 1.1
2718 :     : Build: ( -- [xt] [colon-sys] )
2719 : jwilke 1.52 :noname postpone TCreate ;
2720 :    
2721 :     : BuildSmart: ( -- [xt] [colon-sys] )
2722 :     :noname
2723 : jwilke 1.53 [ T has? rom H [IF] ]
2724 : jwilke 1.52 postpone RTCreate
2725 :     [ [ELSE] ]
2726 :     postpone TCreate
2727 :     [ [THEN] ] ;
2728 : anton 1.1
2729 : jwilke 1.108 : ;Build
2730 : pazsan 1.118 postpone create-resolve postpone ; built >exec ! ; immediate
2731 :    
2732 :     : ;Build-immediate
2733 :     postpone create-resolve-immediate
2734 :     postpone ; built >exec ! ; immediate
2735 : jwilke 1.108
2736 : anton 1.1 : gdoes> ( ghost -- addr flag )
2737 : jwilke 1.110 executed-ghost @ g>body ;
2738 : anton 1.1
2739 :     \ DO: ;DO 11may93jaw
2740 :    
2741 : jwilke 1.108 : do:ghost! ( ghost -- ) built >do:ghost ! ;
2742 :     : doexec! ( xt -- ) built >do:ghost @ >exec ! ;
2743 :    
2744 :     : DO: ( -- [xt] [colon-sys] )
2745 :     here ghostheader do:ghost!
2746 : jwilke 1.110 :noname postpone gdoes> ;
2747 : anton 1.1
2748 : jwilke 1.108 : by: ( -- [xt] [colon-sys] ) \ name
2749 :     Ghost do:ghost!
2750 : jwilke 1.110 :noname postpone gdoes> ;
2751 : pazsan 1.42
2752 : jwilke 1.108 : ;DO ( [xt] [colon-sys] -- )
2753 :     postpone ; doexec! ; immediate
2754 : anton 1.1
2755 : jwilke 1.109 : by ( -- ) \ Name
2756 : jwilke 1.108 Ghost >do:ghost @ do:ghost! ;
2757 : jwilke 1.107
2758 : jwilke 1.109 : compile: ( --[xt] [colon-sys] )
2759 : jwilke 1.107 \G defines a compile time action for created words
2760 :     \G by this builder
2761 :     :noname ;
2762 :    
2763 : jwilke 1.109 : ;compile ( [xt] [colon-sys] -- )
2764 :     postpone ; built >do:ghost @ >comp ! ; immediate
2765 : jwilke 1.107
2766 : anton 1.1 \ Variables and Constants 05dec92py
2767 :    
2768 : jwilke 1.108 Builder (Constant)
2769 :     Build: ( n -- ) ;Build
2770 : jwilke 1.103 by: :docon ( target-body-addr -- n ) T @ H ;DO
2771 : jwilke 1.52
2772 : jwilke 1.108 Builder Constant
2773 :     Build: ( n -- ) T , H ;Build
2774 : jwilke 1.52 by (Constant)
2775 :    
2776 : jwilke 1.108 Builder AConstant
2777 :     Build: ( n -- ) T A, H ;Build
2778 : jwilke 1.52 by (Constant)
2779 :    
2780 : jwilke 1.108 Builder 2Constant
2781 :     Build: ( d -- ) T , , H ;Build
2782 : jwilke 1.52 DO: ( ghost -- d ) T dup cell+ @ swap @ H ;DO
2783 :    
2784 : jwilke 1.108 Builder Create
2785 :     BuildSmart: ;Build
2786 : jwilke 1.103 by: :dovar ( target-body-addr -- addr ) ;DO
2787 : anton 1.1
2788 : jwilke 1.108 Builder Variable
2789 : jwilke 1.53 T has? rom H [IF]
2790 : jwilke 1.108 Build: ( -- ) T here 0 A, H switchram T align here swap ! 0 , H ( switchrom ) ;Build
2791 : jwilke 1.52 by (Constant)
2792 :     [ELSE]
2793 : jwilke 1.108 Build: T 0 , H ;Build
2794 : anton 1.1 by Create
2795 : jwilke 1.52 [THEN]
2796 : anton 1.1
2797 : jwilke 1.108 Builder 2Variable
2798 : jwilke 1.53 T has? rom H [IF]
2799 : jwilke 1.108 Build: ( -- ) T here 0 A, H switchram T align here swap ! 0 , 0 , H ( switchrom ) ;Build
2800 : pazsan 1.54 by (Constant)
2801 :     [ELSE]
2802 : jwilke 1.108 Build: T 0 , 0 , H ;Build
2803 : pazsan 1.54 by Create
2804 :     [THEN]
2805 :    
2806 : jwilke 1.108 Builder AVariable
2807 : pazsan 1.54 T has? rom H [IF]
2808 : jwilke 1.108 Build: ( -- ) T here 0 A, H switchram T align here swap ! 0 A, H ( switchrom ) ;Build
2809 : jwilke 1.52 by (Constant)
2810 :     [ELSE]
2811 : jwilke 1.108 Build: T 0 A, H ;Build
2812 : anton 1.1 by Create
2813 : jwilke 1.52 [THEN]
2814 : anton 1.1
2815 : pazsan 1.3 \ User variables 04may94py
2816 :    
2817 : jwilke 1.139 : tup@ user-region >rstart @ ;
2818 :    
2819 :     \ Variable tup 0 tup !
2820 :     \ Variable tudp 0 tudp !
2821 : jwilke 1.78
2822 : pazsan 1.3 : u, ( n -- udp )
2823 : jwilke 1.139 current-region >r user-region activate
2824 :     X here swap X , tup@ -
2825 :     r> activate ;
2826 : jwilke 1.78
2827 : pazsan 1.3 : au, ( n -- udp )
2828 : jwilke 1.139 current-region >r user-region activate
2829 :     X here swap X a, tup@ -
2830 :     r> activate ;
2831 :    
2832 :     T has? no-userspace H [IF]
2833 :    
2834 :     : buildby
2835 :     ghost >exec @ built >exec ! ;
2836 :    
2837 :     Builder User
2838 :     buildby Variable
2839 :     by Variable
2840 :    
2841 :     Builder 2User
2842 :     buildby 2Variable
2843 :     by 2Variable
2844 :    
2845 :     Builder AUser
2846 :     buildby AVariable
2847 :     by AVariable
2848 :    
2849 :     [ELSE]
2850 : jwilke 1.78
2851 : jwilke 1.108 Builder User
2852 :     Build: 0 u, X , ;Build
2853 : jwilke 1.139 by: :douser ( ghost -- up-addr ) X @ tup@ + ;DO
2854 : anton 1.1
2855 : jwilke 1.108 Builder 2User
2856 :     Build: 0 u, X , 0 u, drop ;Build
2857 : pazsan 1.3 by User
2858 : anton 1.1
2859 : jwilke 1.108 Builder AUser
2860 :     Build: 0 au, X , ;Build
2861 : pazsan 1.3 by User
2862 : anton 1.1
2863 : jwilke 1.139 [THEN]
2864 :    
2865 : jwilke 1.108 Builder (Value)
2866 :     Build: ( n -- ) ;Build
2867 :     by: :docon ( target-body-addr -- n ) T @ H ;DO
2868 :    
2869 : anton 1.1 Builder Value
2870 : jwilke 1.108 BuildSmart: T , H ;Build
2871 :     by (Value)
2872 : anton 1.1
2873 : pazsan 1.32 Builder AValue
2874 : jwilke 1.108 BuildSmart: T A, H ;Build
2875 :     by (Value)
2876 : pazsan 1.32
2877 : jwilke 1.103 Defer texecute
2878 :    
2879 : jwilke 1.108 Builder Defer
2880 :     BuildSmart: ( -- ) [T'] noop T A, H ;Build
2881 : jwilke 1.103 by: :dodefer ( ghost -- ) X @ texecute ;DO
2882 : pazsan 1.37
2883 : jwilke 1.108 Builder interpret/compile:
2884 : pazsan 1.118 Build: ( inter comp -- ) swap T A, A, H ;Build-immediate
2885 : pazsan 1.37 DO: ( ghost -- ) ABORT" CROSS: Don't execute" ;DO
2886 : pazsan 1.24
2887 :     \ Sturctures 23feb95py
2888 :    
2889 :     : nalign ( addr1 n -- addr2 )
2890 :     \ addr2 is the aligned version of addr1 wrt the alignment size n
2891 :     1- tuck + swap invert and ;
2892 : jwilke 1.109
2893 : pazsan 1.24
2894 : jwilke 1.108 Builder (Field)
2895 :     Build: ;Build
2896 : pazsan 1.44 by: :dofield T @ H + ;DO
2897 :    
2898 : jwilke 1.108 Builder Field
2899 : anton 1.51 Build: ( align1 offset1 align size "name" -- align2 offset2 )
2900 :     rot dup T , H ( align1 align size offset1 )
2901 : jwilke 1.108 + >r nalign r> ;Build
2902 : pazsan 1.44 by (Field)
2903 : pazsan 1.24
2904 : jwilke 1.109 >TARGET
2905 : anton 1.51 : struct T 1 chars 0 H ;
2906 : pazsan 1.24 : end-struct T 2Constant H ;
2907 :    
2908 : jwilke 1.52 : cell% ( n -- size align )
2909 : anton 1.51 T 1 cells H dup ;
2910 : jwilke 1.109 >CROSS
2911 : pazsan 1.88
2912 : jwilke 1.105 \ Input-Methods 01py
2913 : jwilke 1.103
2914 : jwilke 1.108 Builder input-method
2915 :     Build: ( m v -- m' v ) dup T , cell+ H ;Build
2916 : pazsan 1.88 DO: abort" Not in cross mode" ;DO
2917 :    
2918 : jwilke 1.108 Builder input-var
2919 :     Build: ( m v size -- m v' ) over T , H + ;Build
2920 : pazsan 1.88 DO: abort" Not in cross mode" ;DO
2921 : pazsan 1.24
2922 : jwilke 1.108 \ Peephole optimization 05sep01jaw
2923 :    
2924 :     \ this section defines different compilation
2925 :     \ actions for created words
2926 :     \ this will help the peephole optimizer
2927 : jwilke 1.121 \ I (jaw) took this from bernds latest cross-compiler
2928 : jwilke 1.108 \ changes but seperated it from the original
2929 :     \ Builder words. The final plan is to put this
2930 :     \ into a seperate file, together with the peephole
2931 :     \ optimizer for cross
2932 :    
2933 :    
2934 :     T has? peephole H [IF]
2935 :    
2936 : jwilke 1.139 \ .( loading peephole optimization) cr
2937 :    
2938 : jwilke 1.109 >CROSS
2939 : pazsan 1.118
2940 : jwilke 1.109 : (callc) compile call T >body a, H ; ' (callc) plugin-of colon,
2941 : jwilke 1.121 : (callcm) T here 0 a, 0 a, H ; ' (callcm) plugin-of colonmark,
2942 : pazsan 1.118 : (call-res) >tempdp resolved gexecute tempdp> drop ;
2943 :     ' (call-res) plugin-of colon-resolve
2944 : jwilke 1.121 : (pprim) dup 0< IF $4000 - ELSE
2945 :     cr ." wrong usage of (prim) "
2946 :     dup gdiscover IF .ghost ELSE . THEN cr -1 throw THEN
2947 :     T a, H ; ' (pprim) plugin-of prim,
2948 : jwilke 1.109
2949 :     \ if we want this, we have to spilt aconstant
2950 :     \ and constant!!
2951 :     \ Builder (Constant)
2952 :     \ compile: g>body X @ lit, ;compile
2953 : jwilke 1.108
2954 :     Builder (Constant)
2955 : pazsan 1.118 compile: g>body compile lit@ T a, H ;compile
2956 : jwilke 1.108
2957 :     Builder (Value)
2958 : pazsan 1.118 compile: g>body compile lit@ T a, H ;compile
2959 : jwilke 1.108
2960 :     \ this changes also Variable, AVariable and 2Variable
2961 :     Builder Create
2962 : pazsan 1.117 compile: g>body alit, ;compile
2963 : jwilke 1.108
2964 :     Builder User
2965 :     compile: g>body compile useraddr T @ , H ;compile
2966 :    
2967 :     Builder Defer
2968 : pazsan 1.118 compile: g>body compile lit-perform T A, H ;compile
2969 : jwilke 1.102
2970 : jwilke 1.108 Builder (Field)
2971 : pazsan 1.118 compile: g>body T @ H compile lit+ T , H ;compile
2972 : pazsan 1.117
2973 :     Builder interpret/compile:
2974 :     compile: does-resolved ;compile
2975 :    
2976 :     Builder input-method
2977 :     compile: does-resolved ;compile
2978 :    
2979 :     Builder input-var
2980 :     compile: does-resolved ;compile
2981 : jwilke 1.102
2982 : jwilke 1.108 [THEN]
2983 : jwilke 1.103
2984 : jwilke 1.52 \ structural conditionals 17dec92py
2985 :    
2986 :     >CROSS
2987 : jwilke 1.103 : (ncontrols?) ( n -- )
2988 :     \g We expect n open control structures
2989 :     depth over u<=
2990 :     ABORT" CROSS: unstructured, stack underflow"
2991 :     0 ?DO I pick 0=
2992 :     ABORT" CROSS: unstructured"
2993 :     LOOP ; ' (ncontrols?) plugin-of ncontrols?
2994 :    
2995 :     \ : ?struc ( flag -- ) ABORT" CROSS: unstructured " ;
2996 :     \ : sys? ( sys -- sys ) dup 0= ?struc ;
2997 :    
2998 : jwilke 1.52 : >mark ( -- sys ) T here ( dup ." M" hex. ) 0 , H ;
2999 :    
3000 : pazsan 1.133 X has? abranch [IF]
3001 :     : branchoffset ( src dest -- ) drop ;
3002 :     : offset, ( n -- ) X A, ;
3003 :     [ELSE]
3004 :     : branchoffset ( src dest -- ) - tchar / ; \ ?? jaw
3005 :     : offset, ( n -- ) X , ;
3006 :     [THEN]
3007 : jwilke 1.52
3008 : pazsan 1.133 :noname compile branch X here branchoffset offset, ;
3009 : pazsan 1.54 IS branch, ( target-addr -- )
3010 : pazsan 1.133 :noname compile ?branch X here branchoffset offset, ;
3011 : pazsan 1.54 IS ?branch, ( target-addr -- )
3012 : pazsan 1.133 :noname compile branch T here 0 H offset, ;
3013 : pazsan 1.54 IS branchmark, ( -- branchtoken )
3014 : pazsan 1.133 :noname compile ?branch T here 0 H offset, ;
3015 : pazsan 1.54 IS ?branchmark, ( -- branchtoken )
3016 : pazsan 1.133 :noname T here 0 H offset, ;
3017 : pazsan 1.54 IS ?domark, ( -- branchtoken )
3018 : jwilke 1.78 :noname dup X @ ?struc X here over branchoffset swap X ! ;
3019 : pazsan 1.54 IS branchtoresolve, ( branchtoken -- )
3020 : jwilke 1.78 :noname branchto, X here ;
3021 : pazsan 1.54 IS branchtomark, ( -- target-addr )
3022 : jwilke 1.52
3023 :     >TARGET
3024 :    
3025 :     \ Structural Conditionals 12dec92py
3026 :    
3027 : jwilke 1.103 \ CLEANUP Cond: BUT sys? swap ;Cond
3028 :     \ CLEANUP Cond: YET sys? dup ;Cond
3029 : jwilke 1.52
3030 :     >CROSS
3031 :    
3032 : jwilke 1.78 Variable tleavings 0 tleavings !
3033 : jwilke 1.52
3034 : jwilke 1.129 : (done) ( do-addr -- )
3035 :     \G resolve branches of leave and ?leave and ?do
3036 :     \G do-addr is the address of the beginning of our
3037 :     \G loop so we can take care of nested loops
3038 : pazsan 1.54 tleavings @
3039 :     BEGIN dup
3040 :     WHILE
3041 :     >r dup r@ cell+ @ \ address of branch
3042 :     u> 0= \ lower than DO?
3043 :     WHILE
3044 :     r@ 2 cells + @ \ branch token
3045 :     branchtoresolve,
3046 :     r@ @ r> free throw
3047 :     REPEAT r> THEN
3048 :     tleavings ! drop ;
3049 :    
3050 : jwilke 1.53 >TARGET
3051 :    
3052 : jwilke 1.103 \ What for? ANS? JAW Cond: DONE ( addr -- ) (done) ;Cond
3053 : jwilke 1.53
3054 :     >CROSS
3055 : pazsan 1.54 : (leave) ( branchtoken -- )
3056 : jwilke 1.53 3 cells allocate throw >r
3057 :     T here H r@ cell+ !
3058 :     r@ 2 cells + !
3059 :     tleavings @ r@ !
3060 :     r> tleavings ! ;
3061 :     >TARGET
3062 :    
3063 : jwilke 1.103 : (leave,) ( -- )
3064 :     branchmark, (leave) ; ' (leave,) plugin-of leave,
3065 :    
3066 :     : (?leave,) ( -- )
3067 :     compile 0= ?branchmark, (leave) ; ' (?leave,) plugin-of ?leave,
3068 :    
3069 :     Cond: LEAVE leave, ;Cond
3070 :     Cond: ?LEAVE ?leave, ;Cond
3071 : jwilke 1.53
3072 : pazsan 1.54 >CROSS
3073 :     \ !!JW ToDo : Move to general tools section
3074 :    
3075 :     : to1 ( x1 x2 xn n -- addr )
3076 : jwilke 1.103 \G packs n stack elements in am allocated memory region
3077 : pazsan 1.54 dup dup 1+ cells allocate throw dup >r swap 1+
3078 :     0 DO tuck ! cell+ LOOP
3079 :     drop r> ;
3080 : jwilke 1.103
3081 : pazsan 1.54 : 1to ( addr -- x1 x2 xn )
3082 :     \G unpacks the elements saved by to1
3083 :     dup @ swap over cells + swap
3084 :     0 DO dup @ swap 1 cells - LOOP
3085 :     free throw ;
3086 :    
3087 : jwilke 1.129 : loop] ( target-addr -- )
3088 :     branchto,
3089 : pazsan 1.133 dup X here branchoffset offset,
3090 : jwilke 1.129 tcell - (done) ;
3091 : pazsan 1.54
3092 :     : skiploop] ?dup IF branchto, branchtoresolve, THEN ;
3093 :    
3094 :     >TARGET
3095 :    
3096 : jwilke 1.52 \ Structural Conditionals 12dec92py
3097 :    
3098 : jwilke 1.103 : (cs-swap) ( x1 x2 -- x2 x1 )
3099 :     swap ; ' (cs-swap) plugin-of cs-swap
3100 :    
3101 :     : (ahead,) branchmark, ; ' (ahead,) plugin-of ahead,
3102 :    
3103 :     : (if,) ?branchmark, ; ' (if,) plugin-of if,
3104 :    
3105 :     : (then,) branchto, branchtoresolve, ; ' (then,) plugin-of then,
3106 :    
3107 :     : (else,) ( ahead ) branchmark,
3108 :     swap
3109 :     ( then ) branchto, branchtoresolve, ; ' (else,) plugin-of else,
3110 :    
3111 :     : (begin,) branchtomark, ; ' (begin,) plugin-of begin,
3112 :    
3113 :     : (while,) ( if ) ?branchmark,
3114 :     swap ; ' (while,) plugin-of while,
3115 :    
3116 :     : (again,) branch, ; ' (again,) plugin-of again,
3117 :    
3118 :     : (until,) ?branch, ; ' (until,) plugin-of until,
3119 :    
3120 :     : (repeat,) ( again ) branch,
3121 :     ( then ) branchto, branchtoresolve, ; ' (repeat,) plugin-of repeat,
3122 :    
3123 :     : (case,) ( -- n )
3124 :     0 ; ' (case,) plugin-of case,
3125 :    
3126 :     : (of,) ( n -- x1 n )
3127 :     1+ >r
3128 :     compile over compile =
3129 :     if, compile drop r> ; ' (of,) plugin-of of,
3130 :    
3131 :     : (endof,) ( x1 n -- x2 n )
3132 :     >r 1 ncontrols? else, r> ; ' (endof,) plugin-of endof,
3133 :    
3134 :     : (endcase,) ( x1 .. xn n -- )
3135 :     compile drop 0 ?DO 1 ncontrols? then, LOOP ; ' (endcase,) plugin-of endcase,
3136 :    
3137 : jwilke 1.53 >TARGET
3138 : jwilke 1.103 Cond: AHEAD ahead, ;Cond
3139 :     Cond: IF if, ;Cond
3140 :     Cond: THEN 1 ncontrols? then, ;Cond
3141 :     Cond: ENDIF 1 ncontrols? then, ;Cond
3142 :     Cond: ELSE 1 ncontrols? else, ;Cond
3143 :    
3144 :     Cond: BEGIN begin, ;Cond
3145 :     Cond: WHILE 1 ncontrols? while, ;Cond
3146 :     Cond: AGAIN 1 ncontrols? again, ;Cond
3147 :     Cond: UNTIL 1 ncontrols? until, ;Cond
3148 :     Cond: REPEAT 2 ncontrols? repeat, ;Cond
3149 :    
3150 :     Cond: CASE case, ;Cond
3151 :     Cond: OF of, ;Cond
3152 :     Cond: ENDOF endof, ;Cond
3153 :     Cond: ENDCASE endcase, ;Cond
3154 : anton 1.1
3155 :     \ Structural Conditionals 12dec92py
3156 :    
3157 : jwilke 1.103 : (do,) ( -- target-addr )
3158 :     \ ?? i think 0 is too much! jaw
3159 : pazsan 1.54 0 compile (do)
3160 : jwilke 1.103 branchtomark, 2 to1 ; ' (do,) plugin-of do,
3161 : pazsan 1.54
3162 : jwilke 1.103 \ alternative for if no ?do
3163 :     \ : (do,)
3164 : pazsan 1.54 \ compile 2dup compile = compile IF
3165 :     \ compile 2drop compile ELSE
3166 :     \ compile (do) branchtomark, 2 to1 ;
3167 :    
3168 : jwilke 1.103 : (?do,) ( -- target-addr )
3169 : pazsan 1.54 0 compile (?do) ?domark, (leave)
3170 : jwilke 1.103 branchtomark, 2 to1 ; ' (?do,) plugin-of ?do,
3171 :    
3172 :     : (for,) ( -- target-addr )
3173 :     compile (for) branchtomark, ; ' (for,) plugin-of for,
3174 :    
3175 :     : (loop,) ( target-addr -- )
3176 :     1to compile (loop) loop]
3177 :     compile unloop skiploop] ; ' (loop,) plugin-of loop,
3178 :    
3179 :     : (+loop,) ( target-addr -- )
3180 :     1to compile (+loop) loop]
3181 :     compile unloop skiploop] ; ' (+loop,) plugin-of +loop,
3182 :    
3183 :     : (next,)
3184 :     compile (next) loop] compile unloop ; ' (next,) plugin-of next,
3185 :    
3186 :     Cond: DO do, ;Cond
3187 :     Cond: ?DO ?do, ;Cond
3188 :     Cond: FOR for, ;Cond
3189 :    
3190 :     Cond: LOOP 1 ncontrols? loop, ;Cond
3191 :     Cond: +LOOP 1 ncontrols? +loop, ;Cond
3192 :     Cond: NEXT 1 ncontrols? next, ;Cond
3193 : jwilke 1.52
3194 : anton 1.1 \ String words 23feb93py
3195 :    
3196 : jwilke 1.103 : ," [char] " parse ht-string, X align ;
3197 : anton 1.1
3198 : pazsan 1.130 X has? control-rack [IF]
3199 : jwilke 1.103 Cond: ." compile (.") T ," H ;Cond
3200 :     Cond: S" compile (S") T ," H ;Cond
3201 :     Cond: C" compile (C") T ," H ;Cond
3202 :     Cond: ABORT" compile (ABORT") T ," H ;Cond
3203 : pazsan 1.130 [ELSE]
3204 :     Cond: ." '" parse tuck 2>r ahead, there 2r> ht-mem, X align
3205 :     >r then, r> compile ALiteral compile Literal compile type ;Cond
3206 :     Cond: S" '" parse tuck 2>r ahead, there 2r> ht-mem, X align
3207 :     >r then, r> compile ALiteral compile Literal ;Cond
3208 :     Cond: C" ahead, there [char] " parse ht-string, X align
3209 :     >r then, r> compile ALiteral ;Cond
3210 :     Cond: ABORT" if, ahead, there [char] " parse ht-string, X align
3211 :     >r then, r> compile ALiteral compile c(abort") then, ;Cond
3212 :     [THEN]
3213 : anton 1.1
3214 :     Cond: IS T ' >body H compile ALiteral compile ! ;Cond
3215 : pazsan 1.66 : IS T >address ' >body ! H ;
3216 : pazsan 1.9 Cond: TO T ' >body H compile ALiteral compile ! ;Cond
3217 :     : TO T ' >body ! H ;
3218 : anton 1.1
3219 : jwilke 1.52 Cond: defers T ' >body @ compile, H ;Cond
3220 :    
3221 : anton 1.1 \ LINKED ERR" ENV" 2ENV" 18may93jaw
3222 :    
3223 :     \ linked list primitive
3224 : jwilke 1.79 : linked X here over X @ X A, swap X ! ;
3225 : jwilke 1.52 : chained T linked A, H ;
3226 : anton 1.1
3227 :     : err" s" ErrLink linked" evaluate T , H
3228 : jwilke 1.103 [char] " parse ht-string, X align ;
3229 : anton 1.1
3230 :     : env" [char] " parse s" EnvLink linked" evaluate
3231 : jwilke 1.103 ht-string, X align X , ;
3232 : anton 1.1
3233 :     : 2env" [char] " parse s" EnvLink linked" evaluate
3234 : jwilke 1.103 here >r ht-string, X align X , X ,
3235 : anton 1.1 r> dup T c@ H 80 and swap T c! H ;
3236 :    
3237 :     \ compile must be last 22feb93py
3238 :    
3239 : jwilke 1.103 Cond: [compile] ( -- ) \ name
3240 :     \g For immediate words, works even if forward reference
3241 :     bl word gfind 0= ABORT" CROSS: Can't compile"
3242 :     (gexecute) ;Cond
3243 :    
3244 :     Cond: postpone ( -- ) \ name
3245 :     bl word gfind 0= ABORT" CROSS: Can't compile"
3246 :     dup >magic @ <fwd> =
3247 :     ABORT" CROSS: Can't postpone on forward declaration"
3248 :     dup >magic @ <imm> =
3249 :     IF (gexecute)
3250 :     ELSE compile (compile) addr, THEN ;Cond
3251 : pazsan 1.54
3252 : jwilke 1.77 \ save-cross 17mar93py
3253 :    
3254 :     hex
3255 :    
3256 :     >CROSS
3257 : anton 1.131 Create magic s" Gforth3x" here over allot swap move
3258 : jwilke 1.77
3259 :     bigendian 1+ \ strangely, in magic big=0, little=1
3260 :     tcell 1 = 0 and or
3261 :     tcell 2 = 2 and or
3262 :     tcell 4 = 4 and or
3263 :     tcell 8 = 6 and or
3264 :     tchar 1 = 00 and or
3265 :     tchar 2 = 28 and or
3266 :     tchar 4 = 50 and or
3267 :     tchar 8 = 78 and or
3268 :     magic 7 + c!
3269 :    
3270 :     : save-cross ( "image-name" "binary-name" -- )
3271 :     bl parse ." Saving to " 2dup type cr
3272 :     w/o bin create-file throw >r
3273 : jwilke 1.113 s" header" X $has? IF
3274 : anton 1.80 s" #! " r@ write-file throw
3275 :     bl parse r@ write-file throw
3276 :     s" --image-file" r@ write-file throw
3277 : jwilke 1.77 #lf r@ emit-file throw
3278 :     r@ dup file-position throw drop 8 mod 8 swap ( file-id limit index )
3279 :     ?do
3280 :     bl over emit-file throw
3281 :     loop
3282 :     drop
3283 :     magic 8 r@ write-file throw \ write magic
3284 :     ELSE
3285 :     bl parse 2drop
3286 :     THEN
3287 : jwilke 1.139 dictionary >rmem @ there
3288 : jwilke 1.77 r@ write-file throw \ write image
3289 : jwilke 1.113 s" relocate" X $has? IF
3290 : jwilke 1.139 dictionary >rbm @ there 1- tcell>bit rshift 1+
3291 : jwilke 1.77 r@ write-file throw \ write tags
3292 :     THEN
3293 :     r> close-file throw ;
3294 :    
3295 :     : save-region ( addr len -- )
3296 :     bl parse w/o bin create-file throw >r
3297 :     swap >image swap r@ write-file throw
3298 :     r> close-file throw ;
3299 :    
3300 : jwilke 1.110 \ save-asm-region 29aug01jaw
3301 : jwilke 1.103
3302 :     Variable name-ptr
3303 :     Create name-buf 200 chars allot
3304 :     : init-name-buf name-buf name-ptr ! ;
3305 :     : nb, name-ptr @ c! 1 chars name-ptr +! ;
3306 :     : $nb, ( adr len -- ) bounds ?DO I c@ nb, LOOP ;
3307 :     : @nb name-ptr @ name-buf tuck - ;
3308 :    
3309 :     \ stores a usefull string representation of the character
3310 :     \ in the name buffer
3311 :     : name-char, ( c -- )
3312 :     dup 'a 'z 1+ within IF nb, EXIT THEN
3313 :     dup 'A 'Z 1+ within IF $20 + nb, EXIT THEN
3314 :     dup '0 '9 1+ within IF nb, EXIT THEN
3315 :     CASE '+ OF s" _PLUS" $nb, ENDOF
3316 :     '- OF s" _MINUS" $nb, ENDOF
3317 :     '* OF s" _STAR" $nb, ENDOF
3318 :     '/ OF s" _SLASH" $nb, ENDOF
3319 :     '' OF s" _TICK" $nb, ENDOF
3320 :     '( OF s" _OPAREN" $nb, ENDOF
3321 :     ') OF s" _CPAREN" $nb, ENDOF
3322 :     '[ OF s" _OBRACKET" $nb, ENDOF
3323 :     '] OF s" _CBRACKET" $nb, ENDOF
3324 :     '! OF s" _STORE" $nb, ENDOF
3325 :     '@ OF s" _FETCH" $nb, ENDOF
3326 :     '> OF s" _GREATER" $nb, ENDOF
3327 :     '< OF s" _LESS" $nb, ENDOF
3328 :     '= OF s" _EQUAL" $nb, ENDOF
3329 :     '# OF s" _HASH" $nb, ENDOF
3330 :     '? OF s" _QUEST" $nb, ENDOF
3331 :     ': OF s" _COL" $nb, ENDOF
3332 :     '; OF s" _SEMICOL" $nb, ENDOF
3333 :     ', OF s" _COMMA" $nb, ENDOF
3334 :     '. OF s" _DOT" $nb, ENDOF
3335 :     '" OF s" _DQUOT" $nb, ENDOF
3336 :     dup
3337 :     base @ >r hex s>d <# #s 'X hold '_ hold #> $nb, r> base !
3338 :     ENDCASE ;
3339 :    
3340 :     : label-from-ghostname ( ghost -- addr len )
3341 :     dup >ghostname init-name-buf 'L nb, bounds
3342 :     ?DO I c@ name-char, LOOP
3343 :     \ we add the address to a name to make in unique
3344 :     \ because one name may appear more then once
3345 :     \ there are names (e.g. boot) that may be reference from other
3346 :     \ assembler source files, so we declare them as unique
3347 :     \ and don't add the address suffix
3348 :     dup >ghost-flags @ <unique> and 0=
3349 :     IF s" __" $nb, >link @ base @ >r hex 0 <# #s 'L hold #> r> base ! $nb,
3350 :     ELSE drop
3351 :     THEN
3352 :     @nb ;
3353 :    
3354 : jwilke 1.111 \ FIXME why disabled?!
3355 : jwilke 1.103 : label-from-ghostnameXX ( ghost -- addr len )
3356 :     \ same as (label-from-ghostname) but caches generated names
3357 :     dup >asm-name @ ?dup IF nip count EXIT THEN
3358 :     \ dup >r (label-from-ghostname) 2dup
3359 :     align here >r string, align
3360 :     r> r> >asm-name ! ;
3361 :    
3362 :     : primghostdiscover ( xt -- ghost true | xt false )
3363 :     dup 0= IF false EXIT THEN
3364 :     >r last-prim-ghost
3365 :     BEGIN @ dup
3366 :     WHILE dup >asm-dummyaddr @ r@ =
3367 :     IF rdrop true EXIT THEN
3368 :     REPEAT
3369 :     drop r> false ;
3370 :    
3371 :     : gdiscover2 ( xt -- ghost true | xt false )
3372 :     dup taddr>region 0= IF false EXIT THEN
3373 :     dup (>regiontype) @ dup 0= IF drop false EXIT THEN
3374 :     addr-xt-ghost @ dup 0= IF drop false EXIT THEN
3375 :     nip true ;
3376 :     \ dup >ghost-name @ IF nip true ELSE drop false THEN ;
3377 :    
3378 :     \ generates a label name for the target address
3379 :     : generate-label-name ( taddr -- addr len )
3380 :     gdiscover2
3381 :     IF dup >magic @ <do:> =
3382 :     IF >asm-name @ count EXIT THEN
3383 :     label-from-ghostname
3384 :     ELSE
3385 :     primghostdiscover
3386 :     IF >asm-name @ count
3387 :     ELSE base @ >r hex 0 <# #s 'L hold #> r> base !
3388 :     THEN
3389 :     THEN ;
3390 :    
3391 :     Variable outfile-fd
3392 :    
3393 :     : $out ( adr len -- ) outfile-fd @ write-file throw ;
3394 :     : nlout newline $out ;
3395 :     : .ux ( n -- )
3396 :     base @ hex swap 0 <# #S #> $out base ! ;
3397 :    
3398 :     : save-asm-region-part-aligned ( taddr len -- 'taddr 'len )
3399 :     dup cell/ 0
3400 :     ?DO nlout s" .word " $out over @relbit
3401 :     IF over X @ generate-label-name $out
3402 :     ELSE over X @ s" 0x0" $out .ux
3403 :     THEN
3404 :     tcell /string
3405 :     LOOP ;
3406 :    
3407 :     : print-bytes ( taddr len n -- taddr' len' )
3408 :     over min dup 0>
3409 :     IF nlout s" .byte " $out 0
3410 :     ?DO I 0> IF s" , " $out THEN
3411 :     over X c@ s" 0x0" $out .ux 1 /string
3412 :     LOOP
3413 :     THEN ;
3414 :    
3415 :     : save-asm-region-part ( addr len -- )
3416 :     over dup X aligned swap - ?dup
3417 :     IF print-bytes THEN
3418 :     save-asm-region-part-aligned
3419 :     dup dup X aligned swap - ?dup
3420 :     IF 2 pick @relbit ABORT" relocated field splitted"
3421 :     print-bytes
3422 :     THEN
3423 :     2drop ;
3424 :    
3425 :     : print-label ( taddr -- )
3426 :     nlout generate-label-name $out s" :" $out ;
3427 :    
3428 :     : snl-calc ( taddr taddr2 -- )
3429 :     tuck over - ;
3430 :    
3431 :     : skip-nolables ( taddr -- taddr2 taddr len )
3432 :     \G skips memory region where no lables are defined
3433 :     \G starting from taddr+1
3434 :     \G Labels will be introduced for each reference mark
3435 :     \G in addr-refs.
3436 :     \G This word deals with lables at byte addresses as well.
3437 :     \G The main idea is to have an intro part which
3438 :     \G skips until the next cell boundary, the middle part
3439 :     \G which skips whole cells very efficiently and the third
3440 :     \G part which skips the bytes to the label in a cell
3441 :     dup 1+ dup (>regiontype)
3442 :     ( S taddr taddr-realstart type-addr )
3443 :     dup @ dup IF addr-refs @ THEN
3444 :     swap >r
3445 :     over align+ tuck tcell swap - rshift swap 0
3446 : jwilke 1.126 ?DO dup 1 and
3447 : jwilke 1.103 IF drop rdrop snl-calc UNLOOP EXIT THEN
3448 :     2/ swap 1+ swap
3449 :     LOOP
3450 :     drop r> cell+
3451 :     ( S .. taddr2 type-addr ) dup
3452 :     BEGIN dup @ dup IF addr-refs @ THEN 0= WHILE cell+ REPEAT
3453 :     dup >r swap - 1 cells / tcell * + r>
3454 :     ( S .. taddr2+skiplencells type-addr )
3455 :     @ addr-refs @ 1 tcell lshift or
3456 :     BEGIN dup 1 and 0= WHILE swap 1+ swap 2/ REPEAT drop
3457 :     ( S .. taddr2+skiplencells+skiplenbytes )
3458 :     snl-calc ;
3459 :    
3460 :     : insert-label ( taddr -- )
3461 :     dup 0= IF drop EXIT THEN
3462 :     \ ignore everything which points outside our memory regions
3463 :     \ maybe a primitive pointer or whatever
3464 :     dup taddr>region 0= IF drop EXIT THEN
3465 :     dup >r (>regiontype) define-addr-struct addr-refs dup @
3466 :     r> tcell 1- and 1 swap lshift or swap ! ;
3467 :    
3468 :     \ this generates a sorted list of addresses which must be labels
3469 :     \ it scans therefore a whole region
3470 :     : generate-label-list-region ( taddr len -- )
3471 :     BEGIN over @relbit IF over X @ insert-label THEN
3472 :     tcell /string dup 0<
3473 :     UNTIL 2drop ;
3474 :    
3475 :     : generate-label-list ( -- )
3476 :     region-link
3477 :     BEGIN @ dup WHILE
3478 :     dup 0 >rlink - extent
3479 :     ?dup IF generate-label-list-region ELSE drop THEN
3480 :     REPEAT drop ;
3481 :    
3482 :     : create-outfile ( addr len -- )
3483 :     w/o bin create-file throw outfile-fd ! ;
3484 :    
3485 :     : close-outfile ( -- )
3486 :     outfile-fd @ close-file throw ;
3487 :    
3488 :     : (save-asm-region) ( region -- )
3489 :     \ ." label list..."
3490 :     generate-label-list
3491 :     \ ." ok!" cr
3492 :     extent ( S taddr len )
3493 :     over insert-label
3494 :     2dup + dup insert-label >r ( R end-label )
3495 :     ( S taddr len ) drop
3496 :     BEGIN
3497 :     dup print-label
3498 :     dup r@ <> WHILE
3499 :     skip-nolables save-asm-region-part
3500 :     REPEAT drop rdrop ;
3501 :    
3502 :     : lineout ( addr len -- )
3503 :     outfile-fd @ write-line throw ;
3504 :    
3505 :     : save-asm-region ( region adr len -- )
3506 :     create-outfile (save-asm-region) close-outfile ;
3507 :    
3508 : pazsan 1.54 \ \ minimal definitions
3509 :    
3510 : jwilke 1.77 >MINIMAL also minimal
3511 :    
3512 : anton 1.1 \ Usefull words 13feb93py
3513 :    
3514 :     : KB 400 * ;
3515 :    
3516 : pazsan 1.54 \ \ [IF] [ELSE] [THEN] ... 14sep97jaw
3517 :    
3518 :     \ it is useful to define our own structures and not to rely
3519 : jwilke 1.109 \ on the words in the host system
3520 :     \ The words in the host system might be defined with vocabularies
3521 : pazsan 1.54 \ this doesn't work with our self-made compile-loop
3522 :    
3523 :     Create parsed 20 chars allot \ store word we parsed
3524 :    
3525 :     : upcase
3526 :     parsed count bounds
3527 :     ?DO I c@ toupper I c! LOOP ;
3528 :    
3529 :     : [ELSE]
3530 :     1 BEGIN
3531 :     BEGIN bl word count dup WHILE
3532 : jwilke 1.77 comment? 20 umin parsed place upcase parsed count
3533 : anton 1.128 2dup s" [IF]" str= >r
3534 :     2dup s" [IFUNDEF]" str= >r
3535 :     2dup s" [IFDEF]" str= r> or r> or
3536 : pazsan 1.54 IF 2drop 1+
3537 : anton 1.128 ELSE 2dup s" [ELSE]" str=
3538 : pazsan 1.54 IF 2drop 1- dup
3539 :     IF 1+
3540 :     THEN
3541 :     ELSE
3542 : anton 1.128 2dup s" [ENDIF]" str= >r
3543 :     s" [THEN]" str= r> or
3544 : pazsan 1.54 IF 1- THEN
3545 :     THEN
3546 :     THEN
3547 :     ?dup 0= ?EXIT
3548 :     REPEAT
3549 :     2drop refill 0=
3550 :     UNTIL drop ; immediate
3551 :    
3552 :     : [THEN] ( -- ) ; immediate
3553 :    
3554 :     : [ENDIF] ( -- ) ; immediate
3555 :    
3556 :     : [IF] ( flag -- )
3557 :     0= IF postpone [ELSE] THEN ; immediate
3558 :    
3559 :     Cond: [IF] postpone [IF] ;Cond
3560 :     Cond: [THEN] postpone [THEN] ;Cond
3561 :     Cond: [ELSE] postpone [ELSE] ;Cond
3562 :    
3563 : anton 1.1 \ define new [IFDEF] and [IFUNDEF] 20may93jaw
3564 :    
3565 : jwilke 1.77 : defined? tdefined? ;
3566 : pazsan 1.44 : needed? needed? ;
3567 :     : doer? doer? ;
3568 : anton 1.1
3569 : jwilke 1.52 \ we want to use IFDEF on compiler directives (e.g. E?) in the source, too
3570 :    
3571 :     : directive?
3572 : jwilke 1.77 bl word count [ ' target >wordlist ] literal search-wordlist
3573 : jwilke 1.52 dup IF nip THEN ;
3574 :    
3575 :     : [IFDEF] >in @ directive? swap >in !
3576 : jwilke 1.77 0= IF tdefined? ELSE name 2drop true THEN
3577 : jwilke 1.52 postpone [IF] ;
3578 :    
3579 : jwilke 1.77 : [IFUNDEF] tdefined? 0= postpone [IF] ;
3580 : anton 1.1
3581 : pazsan 1.54 Cond: [IFDEF] postpone [IFDEF] ;Cond
3582 :    
3583 :     Cond: [IFUNDEF] postpone [IFUNDEF] ;Cond
3584 :    
3585 : anton 1.1 \ C: \- \+ Conditional Compiling 09jun93jaw
3586 :    
3587 : jwilke 1.77 : C: >in @ tdefined? 0=
3588 :     IF >in ! X :
3589 : anton 1.1 ELSE drop
3590 :     BEGIN bl word dup c@
3591 : anton 1.128 IF count comment? s" ;" str= ?EXIT
3592 : anton 1.1 ELSE refill 0= ABORT" CROSS: Out of Input while C:"
3593 :     THEN
3594 :     AGAIN
3595 :     THEN ;
3596 :    
3597 : jwilke 1.74 : d? d? ;
3598 :    
3599 : jwilke 1.123 : \D ( -- "debugswitch" )
3600 : jwilke 1.74 \G doesn't skip line when debug switch is on
3601 : jwilke 1.123 D? 0= IF postpone \ THEN ;
3602 : jwilke 1.52
3603 : jwilke 1.123 : \- ( -- "wordname" )
3604 : anton 1.48 \G interprets the line if word is not defined
3605 : jwilke 1.123 tdefined? IF postpone \ THEN ;
3606 : anton 1.48
3607 : jwilke 1.123 : \+ ( -- "wordname" )
3608 : anton 1.48 \G interprets the line if word is defined
3609 : jwilke 1.123 tdefined? 0= IF postpone \ THEN ;
3610 :    
3611 :     : \? ( -- "envorinstring" )
3612 :     \G Skip line if environmental variable evaluates to false
3613 :     X has? 0= IF postpone \ THEN ;
3614 : anton 1.1
3615 : anton 1.48 Cond: \- \- ;Cond
3616 :     Cond: \+ \+ ;Cond
3617 : jwilke 1.52 Cond: \D \D ;Cond
3618 : jwilke 1.123 Cond: \? \? ;Cond
3619 : anton 1.48
3620 :     : ?? bl word find IF execute ELSE drop 0 THEN ;
3621 :    
3622 :     : needed:
3623 :     \G defines ghost for words that we want to be compiled
3624 : jwilke 1.103 BEGIN >in @ bl word c@ WHILE >in ! Ghost drop REPEAT drop ;
3625 : anton 1.48
3626 : anton 1.1 \ words that should be in minimal
3627 : jwilke 1.52
3628 :     create s-buffer 50 chars allot
3629 :    
3630 : jwilke 1.77 bigendian Constant bigendian
3631 : anton 1.1
3632 : jwilke 1.52 : here there ;
3633 : jwilke 1.67 : equ constant ;
3634 :     : mark there constant ;
3635 : pazsan 1.54
3636 :     \ compiler directives
3637 : jwilke 1.52 : >ram >ram ;
3638 :     : >rom >rom ;
3639 :     : >auto >auto ;
3640 :     : >tempdp >tempdp ;
3641 :     : tempdp> tempdp> ;
3642 :     : const constflag on ;
3643 : jwilke 1.103
3644 :     : Redefinitions-start
3645 :     \G Starts a redefinition section. Warnings are disabled and
3646 :     \G existing ghosts are reused. This is used in the kernel
3647 :     \G where ( and \ and the like are redefined
3648 :     twarnings off warnings off reuse-ghosts on ;
3649 :    
3650 :     : Redefinitions-end
3651 :     \G Ends a redefinition section. Warnings are enabled again.
3652 :     twarnings on warnings on reuse-ghosts off ;
3653 :    
3654 :     : warnings name 3 =
3655 :     IF twarnings off warnings off ELSE twarnings on warnings on THEN drop ;
3656 : jwilke 1.102
3657 : anton 1.60 : | ;
3658 :     \ : | NoHeaderFlag on ; \ This is broken (damages the last word)
3659 : jwilke 1.52
3660 : anton 1.48 : save-cross save-cross ;
3661 : jwilke 1.52 : save-region save-region ;
3662 :     : tdump swap >image swap dump ;
3663 :    
3664 : anton 1.48 also forth
3665 : jwilke 1.52 [IFDEF] Label : Label defempty? Label ; [THEN]
3666 :     [IFDEF] start-macros : start-macros defempty? start-macros ; [THEN]
3667 : jwilke 1.77 \ [IFDEF] builttag : builttag builttag ; [THEN]
3668 : anton 1.48 previous
3669 :    
3670 : jwilke 1.52 : s" [char] " parse s-buffer place s-buffer count ; \ for environment?
3671 : pazsan 1.43 : + + ;
3672 : jwilke 1.52 : 1+ 1 + ;
3673 :     : 2+ 2 + ;
3674 : pazsan 1.43 : 1- 1- ;
3675 :     : - - ;
3676 : jwilke 1.52 : and and ;
3677 :     : or or ;
3678 : pazsan 1.43 : 2* 2* ;
3679 :     : * * ;
3680 :     : / / ;
3681 :     : dup dup ;
3682 : jwilke 1.139 : ?dup ?dup ;
3683 : pazsan 1.43 : over over ;
3684 :     : swap swap ;
3685 :     : rot rot ;
3686 :     : drop drop ;
3687 : jwilke 1.139 : 2drop 2drop ;
3688 : pazsan 1.43 : = = ;
3689 : jwilke 1.122 : <> <> ;
3690 : pazsan 1.43 : 0= 0= ;
3691 :     : lshift lshift ;
3692 :     : 2/ 2/ ;
3693 : jwilke 1.139 : hex. base @ $10 base ! swap . base ! ;
3694 :     : invert invert ;
3695 : jwilke 1.103 \ : . . ;
3696 : anton 1.1
3697 : jwilke 1.79 : all-words ['] forced? IS skip? ;
3698 : pazsan 1.43 : needed-words ['] needed? IS skip? ;
3699 : jwilke 1.75 : undef-words ['] defined2? IS skip? ;
3700 :     : skipdef skipdef ;
3701 : anton 1.1
3702 : pazsan 1.40 : \ postpone \ ; immediate
3703 : pazsan 1.47 : \G T-\G ; immediate
3704 : pazsan 1.40 : ( postpone ( ; immediate
3705 : anton 1.1 : include bl word count included ;
3706 : jwilke 1.103 : included swap >image swap included ;
3707 : jwilke 1.52 : require require ;
3708 : jwilke 1.103 : needs require ;
3709 : anton 1.1 : .( [char] ) parse type ;
3710 : jwilke 1.139 : ERROR" [char] " parse
3711 :     rot
3712 :     IF cr ." *** " type ." ***" -1 ABORT" CROSS: Target error, see text above"
3713 :     ELSE 2drop
3714 :     THEN ;
3715 : jwilke 1.52 : ." [char] " parse type ;
3716 : anton 1.1 : cr cr ;
3717 :    
3718 : jwilke 1.77 : times 0 ?DO dup X c, LOOP drop ; \ used for space table creation
3719 :    
3720 :     \ only forth also cross also minimal definitions order
3721 : anton 1.1
3722 :     \ cross-compiler words
3723 :    
3724 : jwilke 1.103 : decimal decimal [g'] decimal >exec2 @ ?dup IF EXECUTE THEN ;
3725 :     : hex hex [g'] hex >exec2 @ ?dup IF EXECUTE THEN ;
3726 : anton 1.1
3727 : jwilke 1.77 \ : tudp X tudp ;
3728 :     \ : tup X tup ;
3729 :    
3730 :     : doc-off false to-doc ! ;
3731 :     : doc-on true to-doc ! ;
3732 : pazsan 1.39
3733 : jwilke 1.103 : declareunique ( "name" -- )
3734 : anton 1.127 \ Sets the unique flag for a ghost. The assembler output
3735 :     \ generates labels with the ghostname concatenated with the address
3736 :     \ while cross-compiling. The address is concatenated
3737 :     \ because we have double occurences of the same name.
3738 :     \ If we want to reference the labels from the assembler or C
3739 :     \ code we declare them unique, so the address is skipped.
3740 : jwilke 1.103 Ghost >ghost-flags dup @ <unique> or swap ! ;
3741 :    
3742 :     \ [IFDEF] dbg : dbg dbg ; [THEN]
3743 : pazsan 1.39
3744 : anton 1.1 \ for debugging...
3745 : jwilke 1.103 \ : dbg dbg ;
3746 :     : horder order ;
3747 :     : hwords words ;
3748 :     \ : words also ghosts
3749 :     \ words previous ;
3750 : jwilke 1.105 : .s .s ;
3751 : jwilke 1.122 : depth depth ;
3752 : anton 1.1 : bye bye ;
3753 : pazsan 1.99
3754 : jwilke 1.103 \ dummy
3755 :    
3756 : anton 1.1 \ turnkey direction
3757 :     : H forth ; immediate
3758 :     : T minimal ; immediate
3759 :     : G ghosts ; immediate
3760 :    
3761 :    
3762 :     \ these ones are pefered:
3763 :    
3764 : jwilke 1.74 : unlock previous forth also cross ;
3765 : jwilke 1.52
3766 : jwilke 1.77 \ also minimal
3767 : jwilke 1.103 >cross
3768 :    
3769 :     : turnkey
3770 :     ghosts-wordlist 1 set-order
3771 :     also target definitions
3772 :     also Minimal also ;
3773 :    
3774 :     >minimal
3775 :    
3776 :     : [[+++
3777 :     turnkey unlock ;
3778 : anton 1.1
3779 :     unlock definitions also minimal
3780 : jwilke 1.77
3781 : jwilke 1.103 : lock turnkey ;
3782 :    
3783 :     Defer +++]]-hook
3784 :     : +++]] +++]]-hook lock ;
3785 :    
3786 :     LOCK
3787 : jwilke 1.77 \ load cross compiler extension defined in mach file
3788 :    
3789 :     UNLOCK >CROSS
3790 :    
3791 :     [IFDEF] extend-cross extend-cross [THEN]
3792 :    
3793 :     LOCK

CVS Admin

Powered by ViewCVS 1.0-dev
(Powered by ViewCVS)

ViewCVS and CVS Help