[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 :     \ Copyright (C) 1995 Free Software Foundation, Inc.
5 :    
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 :     \ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 : anton 1.1
22 :     \ Log:
23 :     \ changed in ; [ to state off 12may93jaw
24 :     \ included place +place 12may93jaw
25 :     \ for a created word (variable, constant...)
26 :     \ is now an alias in the target voabulary.
27 :     \ this means it is no longer necessary to
28 :     \ switch between vocabularies for variable
29 :     \ initialization 12may93jaw
30 :     \ discovered error in DOES>
31 :     \ replaced !does with (;code) 16may93jaw
32 :     \ made complete redesign and
33 :     \ introduced two vocs method
34 :     \ to be asure that the right words
35 :     \ are found 08jun93jaw
36 :     \ btw: ! works not with 16 bit
37 :     \ targets 09jun93jaw
38 :     \ added: 2user and value 11jun93jaw
39 :    
40 : anton 1.48 \ needed? works better now!!! 01mar97jaw
41 :     \ mach file is only loaded into target
42 :     \ cell corrected
43 : jwilke 1.52 \ romable extansions 27apr97-5jun97jaw
44 : anton 1.48
45 :    
46 : jwilke 1.52 hex \ the defualt base for the cross-compiler is hex !!
47 :     Warnings off
48 :    
49 :     \ words that are generaly useful
50 :    
51 :     : >wordlist ( vocabulary-xt -- wordlist-struct )
52 :     also execute get-order swap >r 1- set-order r> ;
53 :    
54 :     : umax 2dup u< IF swap THEN drop ;
55 :     : umin 2dup u> IF swap THEN drop ;
56 : anton 1.1
57 : pazsan 1.23 : string, ( c-addr u -- )
58 :     \ puts down string as cstring
59 :     dup c, here swap chars dup allot move ;
60 : pazsan 1.5
61 : jwilke 1.52 : SetValue ( n -- <name> )
62 :     \G Same behaviour as "Value" when the <name> is not defined
63 :     \G Same behaviour as "to" when <name> is defined
64 :     \G SetValue searches in the current vocabulary
65 :     save-input bl word >r restore-input throw r> count
66 :     get-current search-wordlist
67 :     IF bl word drop >body ! ELSE Value THEN ;
68 :    
69 :     : DefaultValue ( n -- <name> )
70 :     \G Same behaviour as "Value" when the <name> is not defined
71 :     \G SetValue searches in the current vocabulary
72 :     save-input bl word >r restore-input throw r> count
73 :     get-current search-wordlist
74 :     IF bl word drop drop drop ELSE Value THEN ;
75 : anton 1.1
76 :     hex
77 :    
78 :     Vocabulary Cross
79 :     Vocabulary Target
80 :     Vocabulary Ghosts
81 :     VOCABULARY Minimal
82 :     only Forth also Target also also
83 :     definitions Forth
84 :    
85 :     : T previous Cross also Target ; immediate
86 :     : G Ghosts ; immediate
87 :     : H previous Forth also Cross ; immediate
88 :    
89 :     forth definitions
90 :    
91 :     : T previous Cross also Target ; immediate
92 :     : G Ghosts ; immediate
93 :    
94 :     : >cross also Cross definitions previous ;
95 :     : >target also Target definitions previous ;
96 :     : >minimal also Minimal definitions previous ;
97 :    
98 :     H
99 :    
100 :     >CROSS
101 :    
102 : jwilke 1.52 \ 1 Constant Cross-Flag \ to check whether assembler compiler plug-ins are
103 :     \ for cross-compiling
104 :     \ No! we use "[IFUNDEF]" there to find out whether we are target compiling!!!
105 :    
106 :     : comment? ( c-addr u -- c-addr u )
107 :     2dup s" (" compare 0=
108 :     IF postpone (
109 :     ELSE 2dup s" \" compare 0= IF postpone \ THEN
110 :     THEN ;
111 :    
112 :     \ Begin CROSS COMPILER:
113 :    
114 :    
115 :    
116 :     \ \ -------------------- Error Handling 05aug97jaw
117 :    
118 :     \ Flags
119 :    
120 :     also forth definitions \ these values may be predefined before
121 :     \ the cross-compiler is loaded
122 :    
123 :     false DefaultValue stack-warn \ check on empty stack at any definition
124 :     false DefaultValue create-forward-warn \ warn on forward declaration of created words
125 :    
126 :     [IFUNDEF] DebugMaskSrouce Variable DebugMaskSource 0 DebugMaskSource ! [THEN]
127 :     [IFUNDEF] DebugMaskCross Variable DebugMaskCross 0 DebugMaskCross ! [THEN]
128 :    
129 :     previous >CROSS
130 :    
131 : jwilke 1.53 : .dec
132 :     base @ decimal swap . base ! ;
133 :    
134 : jwilke 1.52 : .sourcepos
135 :     cr sourcefilename type ." :"
136 : jwilke 1.53 sourceline# .dec ;
137 : jwilke 1.52
138 :     : warnhead
139 :     \G display error-message head
140 :     \G perhaps with linenumber and filename
141 :     .sourcepos ." Warning: " ;
142 :    
143 :     : empty? depth IF .sourcepos ." Stack not empty!" THEN ;
144 :    
145 :     stack-warn [IF]
146 :     : defempty? empty? ;
147 :     [ELSE]
148 :     : defempty? ; immediate
149 :     [THEN]
150 :    
151 :    
152 :     \ \ GhostNames Ghosts 9may93jaw
153 :    
154 :     \ second name source to search trough list
155 :    
156 :     VARIABLE GhostNames
157 :     0 GhostNames !
158 :    
159 :     : GhostName ( -- addr )
160 :     here GhostNames @ , GhostNames ! here 0 ,
161 :     bl word count
162 :     \ 2dup type space
163 :     string, \ !! cfalign ?
164 :     align ;
165 :    
166 :     \ Ghost Builder 06oct92py
167 :    
168 :     \ <T T> new version with temp variable 10may93jaw
169 :    
170 :     VARIABLE VocTemp
171 :    
172 :     : <T get-current VocTemp ! also Ghosts definitions ;
173 :     : T> previous VocTemp @ set-current ;
174 :    
175 :     hex
176 :     4711 Constant <fwd> 4712 Constant <res>
177 :     4713 Constant <imm> 4714 Constant <do:>
178 :    
179 :     \ iForth makes only immediate directly after create
180 :     \ make atonce trick! ?
181 :    
182 :     Variable atonce atonce off
183 :    
184 :     : NoExec true ABORT" CROSS: Don't execute ghost" ;
185 :    
186 :     : GhostHeader <fwd> , 0 , ['] NoExec , ;
187 :    
188 :     : >magic ; \ type of ghost
189 :     : >link cell+ ; \ pointer where ghost is in target, or if unresolved
190 :     \ points to the where we have to resolve (linked-list)
191 :     : >exec cell+ cell+ ; \ execution symantics (while target compiling) of ghost
192 :     : >end 3 cells + ; \ room for additional tags
193 :     \ for builder (create, variable...) words the
194 :     \ execution symantics of words built are placed here
195 :    
196 :     Variable executed-ghost \ last executed ghost, needed in tcreate and gdoes>
197 :     Variable last-ghost \ last ghost that is created
198 :     Variable last-header-ghost \ last ghost definitions with header
199 :    
200 :     : Make-Ghost ( "name" -- ghost )
201 :     >in @ GhostName swap >in !
202 :     <T Create atonce @ IF immediate atonce off THEN
203 :     here tuck swap ! ghostheader T>
204 :     dup last-ghost !
205 :     DOES> dup executed-ghost ! >exec @ execute ;
206 :    
207 :     \ ghost words 14oct92py
208 :     \ changed: 10may93py/jaw
209 :    
210 :     : gfind ( string -- ghost true/1 / string false )
211 :     \ searches for string in word-list ghosts
212 :     dup count [ ' ghosts >wordlist ] ALiteral search-wordlist
213 :     dup IF >r >body nip r> THEN ;
214 :    
215 :     : gdiscover ( xt -- ghost true | xt false )
216 :     GhostNames
217 :     BEGIN @ dup
218 :     WHILE 2dup
219 :     cell+ @ dup >magic @ <fwd> <>
220 :     >r >link @ = r> and
221 :     IF cell+ @ nip true EXIT THEN
222 :     REPEAT
223 :     drop false ;
224 :    
225 :     VARIABLE Already
226 :    
227 :     : ghost ( "name" -- ghost )
228 :     Already off
229 :     >in @ bl word gfind IF Already on nip EXIT THEN
230 :     drop >in ! Make-Ghost ;
231 :    
232 :     : >ghostname ( ghost -- adr len )
233 :     GhostNames
234 :     BEGIN @ dup
235 :     WHILE 2dup cell+ @ =
236 :     UNTIL nip 2 cells + count
237 :     ELSE 2drop true abort" CROSS: Ghostnames inconsistent"
238 :     THEN ;
239 :    
240 :     ' >ghostname ALIAS @name
241 :    
242 :     : forward? ( ghost -- flag )
243 :     >magic @ <fwd> = ;
244 :    
245 :     \ Predefined ghosts 12dec92py
246 :    
247 :     ghost 0= drop
248 :     ghost branch ghost ?branch 2drop
249 :     ghost (do) ghost (?do) 2drop
250 :     ghost (for) drop
251 :     ghost (loop) ghost (+loop) 2drop
252 :     ghost (next) drop
253 :     ghost unloop ghost ;S 2drop
254 :     ghost lit ghost (compile) ghost ! 2drop drop
255 :     ghost (does>) ghost noop 2drop
256 :     ghost (.") ghost (S") ghost (ABORT") 2drop drop
257 :     ghost ' drop
258 :     ghost :docol ghost :doesjump ghost :dodoes 2drop drop
259 :     ghost over ghost = ghost drop 2drop drop
260 :     ghost - drop
261 :    
262 :     \ \ Parameter for target systems 06oct92py
263 :    
264 :     \ we define it ans like...
265 :     wordlist Constant target-environment
266 :    
267 :     VARIABLE env-current \ save information of current dictionary to restore with environ>
268 :    
269 :     : >ENVIRON get-current env-current ! target-environment set-current ;
270 :     : ENVIRON> env-current @ set-current ;
271 : pazsan 1.43
272 : anton 1.48 >TARGET
273 : pazsan 1.43
274 : jwilke 1.52 : environment?
275 :     target-environment search-wordlist
276 :     IF execute true ELSE false THEN ;
277 :    
278 :     : e? name T environment? H 0= ABORT" environment variable not defined!" ;
279 :    
280 : jwilke 1.53 : has? name T environment? H
281 :     IF \ environment variable is present, return its value
282 :     ELSE \ environment variable is not present, return false
283 :     \ !! JAW abort is just for testing
284 :     false true ABORT" arg"
285 :     THEN ;
286 : jwilke 1.52
287 :     : $has? T environment? H IF ELSE false THEN ;
288 : anton 1.48
289 : jwilke 1.52 >ENVIRON
290 : jwilke 1.53 false SetValue ionly
291 :     true SetValue cross
292 : jwilke 1.52 >TARGET
293 :    
294 :     mach-file count included hex
295 : pazsan 1.43
296 : jwilke 1.53 >ENVIRON
297 :    
298 :     s" interpreter" T environment? H 0= ?dup nip [IF] true Value interpreter [THEN]
299 :     s" ITC" T environment? H 0= ?dup nip [IF] true SetValue ITC [THEN]
300 :     s" rom" T environment? H 0= ?dup nip [IF] false Value rom [THEN]
301 :    
302 : jwilke 1.52 >TARGET
303 : jwilke 1.53 s" relocate" T environment? H
304 :     [IF] SetValue NIL
305 :     [ELSE] >ENVIRON T NIL H SetValue relocate
306 :     [THEN]
307 : pazsan 1.43
308 :     >CROSS
309 :    
310 : jwilke 1.52 \ \ Create additional parameters 19jan95py
311 : pazsan 1.19
312 :     T
313 : anton 1.48 NIL Constant TNIL
314 : pazsan 1.19 cell Constant tcell
315 :     cell<< Constant tcell<<
316 :     cell>bit Constant tcell>bit
317 :     bits/byte Constant tbits/byte
318 :     float Constant tfloat
319 :     1 bits/byte lshift Constant maxbyte
320 :     H
321 :    
322 : anton 1.48 \ Variables 06oct92py
323 :    
324 :     Variable image
325 :     Variable tlast TNIL tlast ! \ Last name field
326 :     Variable tlastcfa \ Last code field
327 :     Variable tdoes \ Resolve does> calls
328 :     Variable bit$
329 : jwilke 1.52
330 :     \ statistics 10jun97jaw
331 :    
332 :     Variable headers-named 0 headers-named !
333 :     Variable user-vars 0 user-vars !
334 :    
335 :     \ Memory initialisation 05dec92py
336 :    
337 :     [IFDEF] Memory \ Memory is a bigFORTH feature
338 :     also Memory
339 :     : initmem ( var len -- )
340 :     2dup swap handle! >r @ r> erase ;
341 :     toss
342 :     [ELSE]
343 :     : initmem ( var len -- )
344 :     tuck allocate abort" CROSS: No memory for target"
345 :     ( len var adr ) dup rot !
346 :     ( len adr ) swap erase ;
347 :     [THEN]
348 :    
349 :     \ MakeKernal 12dec92py
350 :    
351 :     : makekernel ( targetsize -- targetsize )
352 :     bit$ over 1- tcell>bit rshift 1+ initmem
353 :     image over initmem ;
354 :    
355 :     >MINIMAL
356 :     : makekernel makekernel ;
357 :    
358 :    
359 :     >CROSS
360 :    
361 :     \ memregion.fs
362 :    
363 :    
364 :     Variable last-defined-region \ pointer to last defined region
365 :     Variable region-link \ linked list with all regions
366 :     Variable mirrored-link \ linked list for mirrored regions
367 :     0 dup mirrored-link ! region-link !
368 :    
369 :    
370 :     : >rdp 2 cells + ;
371 :     : >rlen cell+ ;
372 :     : >rstart ;
373 :    
374 :    
375 :     : region ( addr len -- ) \G create a new region
376 :     \ check whether predefined region exists
377 :     save-input bl word find >r >r restore-input throw r> r> 0=
378 :     IF \ make region
379 :     drop
380 :     save-input create restore-input throw
381 :     here last-defined-region !
382 :     over ( startaddr ) , ( length ) , ( dp ) ,
383 :     region-link linked name string,
384 :     ELSE \ store new parameters in region
385 :     bl word drop
386 :     >body >r r@ last-defined-region !
387 :     r@ cell+ ! dup r@ ! r> 2 cells + !
388 :     THEN ;
389 :    
390 :     : borders ( region -- startaddr endaddr ) \G returns lower and upper region border
391 :     dup @ swap cell+ @ over + ;
392 :    
393 :     : extent ( region -- startaddr len ) \G returns the really used area
394 :     dup @ swap 2 cells + @ over - ;
395 :    
396 :     : area ( region -- startaddr totallen ) \G returns the total area
397 :     dup @ swap cell+ @ ;
398 :    
399 :     : mirrored \G mark a region as mirrored
400 :     mirrored-link
401 :     linked last-defined-region @ , ;
402 :    
403 :     : .addr
404 :     base @ >r hex
405 :     tcell 2 u>
406 :     IF s>d <# # # # # '. hold # # # # #> type
407 :     ELSE s>d <# # # # # # #> type
408 :     THEN r> base ! ;
409 :    
410 :     : .regions \G display region statistic
411 :    
412 :     \ we want to list the regions in the right order
413 :     \ so first collect all regions on stack
414 :     0 region-link @
415 :     BEGIN dup WHILE dup @ REPEAT drop
416 :     BEGIN dup
417 :     WHILE cr 3 cells - >r
418 :     r@ 4 cells + count tuck type
419 :     12 swap - 0 max spaces space
420 :     ." Start: " r@ @ dup .addr space
421 :     ." End: " r@ 1 cells + @ + .addr space
422 :     ." DP: " r> 2 cells + @ .addr
423 :     REPEAT drop
424 : jwilke 1.53 s" rom" T $has? H 0= ?EXIT
425 : jwilke 1.52 cr ." Mirrored:"
426 :     mirrored-link @
427 :     BEGIN dup
428 :     WHILE space dup cell+ @ 4 cells + count type @
429 :     REPEAT drop cr
430 :     ;
431 :    
432 :     \ -------- predefined regions
433 :    
434 :     0 0 region address-space
435 :     \ total memory addressed and used by the target system
436 :    
437 :     0 0 region dictionary
438 :     \ rom area for the compiler
439 :    
440 : jwilke 1.53 T has? rom H
441 : jwilke 1.52 [IF]
442 :     0 0 region ram-dictionary mirrored
443 :     \ ram area for the compiler
444 :     [ELSE]
445 :     ' dictionary ALIAS ram-dictionary
446 :     [THEN]
447 :    
448 :     0 0 region return-stack
449 :    
450 :     0 0 region data-stack
451 :    
452 :     0 0 region tib-region
453 :    
454 :     ' dictionary ALIAS rom-dictionary
455 :    
456 :    
457 :     : setup-target ( -- ) \G initialize targets memory space
458 : jwilke 1.53 s" rom" T $has? H
459 : jwilke 1.52 IF \ check for ram and rom...
460 :     address-space area nip
461 :     ram-dictionary area nip
462 :     rom-dictionary area nip
463 :     and and 0=
464 :     ABORT" CROSS: define address-space, rom- , ram-dictionary, with rom-support!"
465 :     THEN
466 :     address-space area nip
467 :     IF
468 :     address-space area
469 :     ELSE
470 :     dictionary area
471 :     THEN
472 :     dup 0=
473 :     ABORT" CROSS: define at least address-space or dictionary!!"
474 :     + makekernel drop ;
475 :    
476 :     \ switched tdp for rom support 03jun97jaw
477 :    
478 :     \ second value is here to store some maximal value for statistics
479 :     \ tempdp is also embedded here but has nothing to do with rom support
480 :     \ (needs switched dp)
481 :    
482 :     variable tempdp 0 , \ temporary dp for resolving
483 :     variable tempdp-save
484 :    
485 :     0 [IF]
486 :     variable romdp 0 , \ Dictionary-Pointer for ramarea
487 :     variable ramdp 0 , \ Dictionary-Pointer for romarea
488 :    
489 :     \
490 :     variable sramdp \ start of ram-area for forth
491 :     variable sromdp \ start of rom-area for forth
492 :    
493 :     [THEN]
494 :    
495 :    
496 :     0 value tdp
497 :     variable fixed \ flag: true: no automatic switching
498 :     \ false: switching is done automatically
499 :    
500 :     \ Switch-Policy:
501 :     \
502 :     \ a header is always compiled into rom
503 :     \ after a created word (create and variable) compilation goes to ram
504 :     \
505 :     \ Be careful: If you want to make the data behind create into rom
506 :     \ you have to put >rom before create!
507 :    
508 :     variable constflag constflag off
509 :    
510 :     : (switchram)
511 : jwilke 1.53 fixed @ ?EXIT s" rom" T $has? H 0= ?EXIT
512 : jwilke 1.52 ram-dictionary >rdp to tdp ;
513 :    
514 :     : switchram
515 :     constflag @
516 :     IF constflag off ELSE (switchram) THEN ;
517 :    
518 :     : switchrom
519 :     fixed @ ?EXIT rom-dictionary >rdp to tdp ;
520 :    
521 :     : >tempdp ( addr -- )
522 :     tdp tempdp-save ! tempdp to tdp tdp ! ;
523 :     : tempdp> ( -- )
524 :     tempdp-save @ to tdp ;
525 :    
526 :     : >ram fixed off (switchram) fixed on ;
527 :     : >rom fixed off switchrom fixed on ;
528 :     : >auto fixed off switchrom ;
529 :    
530 :    
531 :    
532 :     \ : romstart dup sromdp ! romdp ! ;
533 :     \ : ramstart dup sramdp ! ramdp ! ;
534 :    
535 :     \ default compilation goed to rom
536 :     \ when romable support is off, only the rom switch is used (!!)
537 :     >auto
538 :    
539 : anton 1.48 : there tdp @ ;
540 :    
541 : jwilke 1.52 >TARGET
542 : anton 1.48
543 : jwilke 1.52 \ \ Target Memory Handling
544 : anton 1.1
545 :     \ Byte ordering and cell size 06oct92py
546 :    
547 : pazsan 1.19 : cell+ tcell + ;
548 :     : cells tcell<< lshift ;
549 : anton 1.1 : chars ;
550 : anton 1.48 : char+ 1 + ;
551 : pazsan 1.19 : floats tfloat * ;
552 : anton 1.6
553 : anton 1.1 >CROSS
554 : pazsan 1.19 : cell/ tcell<< rshift ;
555 : anton 1.1 >TARGET
556 :     20 CONSTANT bl
557 : jwilke 1.52 \ TNIL Constant NIL
558 : anton 1.1
559 :     >CROSS
560 :    
561 : pazsan 1.20 bigendian
562 :     [IF]
563 : jwilke 1.52 : S! ( n addr -- ) >r s>d r> tcell bounds swap 1-
564 : pazsan 1.20 DO maxbyte ud/mod rot I c! -1 +LOOP 2drop ;
565 : jwilke 1.52 : S@ ( addr -- n ) >r 0 0 r> tcell bounds
566 : pazsan 1.20 DO maxbyte * swap maxbyte um* rot + swap I c@ + swap LOOP d>s ;
567 : pazsan 1.19 [ELSE]
568 : jwilke 1.52 : S! ( n addr -- ) >r s>d r> tcell bounds
569 : pazsan 1.20 DO maxbyte ud/mod rot I c! LOOP 2drop ;
570 : jwilke 1.52 : S@ ( addr -- n ) >r 0 0 r> tcell bounds swap 1-
571 : pazsan 1.20 DO maxbyte * swap maxbyte um* rot + swap I c@ + swap -1 +LOOP d>s ;
572 : anton 1.1 [THEN]
573 :    
574 :     >CROSS
575 :     \ Bit string manipulation 06oct92py
576 :     \ 9may93jaw
577 :     CREATE Bittable 80 c, 40 c, 20 c, 10 c, 8 c, 4 c, 2 c, 1 c,
578 :     : bits ( n -- n ) chars Bittable + c@ ;
579 :    
580 :     : >bit ( addr n -- c-addr mask ) 8 /mod rot + swap bits ;
581 :     : +bit ( addr n -- ) >bit over c@ or swap c! ;
582 : pazsan 1.4 : -bit ( addr n -- ) >bit invert over c@ and swap c! ;
583 : anton 1.1 : relon ( taddr -- ) bit$ @ swap cell/ +bit ;
584 : pazsan 1.4 : reloff ( taddr -- ) bit$ @ swap cell/ -bit ;
585 : anton 1.1
586 :     \ Target memory access 06oct92py
587 :    
588 :     : align+ ( taddr -- rest )
589 : anton 1.48 tcell tuck 1- and - [ tcell 1- ] Literal and ;
590 : anton 1.22 : cfalign+ ( taddr -- rest )
591 : pazsan 1.39 \ see kernel.fs:cfaligned
592 : pazsan 1.43 /maxalign tuck 1- and - [ /maxalign 1- ] Literal and ;
593 : anton 1.1
594 :     >TARGET
595 :     : aligned ( taddr -- ta-addr ) dup align+ + ;
596 :     \ assumes cell alignment granularity (as GNU C)
597 :    
598 : anton 1.22 : cfaligned ( taddr1 -- taddr2 )
599 : pazsan 1.39 \ see kernel.fs
600 : anton 1.22 dup cfalign+ + ;
601 :    
602 : anton 1.1 >CROSS
603 :     : >image ( taddr -- absaddr ) image @ + ;
604 :     >TARGET
605 : jwilke 1.52 : @ ( taddr -- w ) >image S@ ;
606 :     : ! ( w taddr -- ) >image S! ;
607 : anton 1.1 : c@ ( taddr -- char ) >image c@ ;
608 :     : c! ( char taddr -- ) >image c! ;
609 : anton 1.7 : 2@ ( taddr -- x1 x2 ) T dup cell+ @ swap @ H ;
610 :     : 2! ( x1 x2 taddr -- ) T swap over ! cell+ ! H ;
611 : anton 1.1
612 :     \ Target compilation primitives 06oct92py
613 :     \ included A! 16may93jaw
614 :    
615 :     : here ( -- there ) there ;
616 :     : allot ( n -- ) tdp +! ;
617 : jwilke 1.52 : , ( w -- ) T here H tcell T allot ! H T here drop H ;
618 : anton 1.1 : c, ( char -- ) T here 1 allot c! H ;
619 :     : align ( -- ) T here H align+ 0 ?DO bl T c, H LOOP ;
620 : anton 1.22 : cfalign ( -- )
621 :     T here H cfalign+ 0 ?DO bl T c, H LOOP ;
622 : anton 1.1
623 :     : A! dup relon T ! H ;
624 :     : A, ( w -- ) T here H relon T , H ;
625 :    
626 :     >CROSS
627 :    
628 : jwilke 1.52 : tcmove ( source dest len -- )
629 :     \G cmove in target memory
630 :     bounds
631 :     ?DO dup T c@ H I T c! H 1+
632 :     LOOP drop ;
633 : anton 1.1
634 :     >TARGET
635 : jwilke 1.52 H also Forth definitions \ ." asm: " order
636 : anton 1.1
637 : jwilke 1.52 : X also target bl word find
638 :     IF state @ IF compile,
639 :     ELSE execute THEN
640 :     ELSE previous ABORT" Cross: access method not supported!"
641 :     THEN
642 :     previous ; immediate
643 : anton 1.1
644 : jwilke 1.52 [IFDEF] asm-include asm-include [THEN] hex
645 : anton 1.1
646 : jwilke 1.52 previous
647 :     >CROSS H
648 : anton 1.1
649 : jwilke 1.52 \ \ -------------------- Compiler Plug Ins 01aug97jaw
650 : anton 1.1
651 : jwilke 1.52 Defer lit, ( n -- )
652 :     Defer alit, ( n -- )
653 :     Defer branch, ( target-addr -- )
654 :     Defer ?branch, ( target-addr -- )
655 :     Defer branchmark, ( -- branch-addr )
656 :     Defer ?branchmark, ( -- branch-addr )
657 :     Defer branchto,
658 :     Defer branchtoresolve, ( branch-addr -- )
659 :     Defer branchfrom, ( -- )
660 :     Defer branchtomark, ( -- target-addr )
661 :     Defer colon, ( tcfa -- ) \ compiles call to tcfa at current position
662 :     Defer colon-resolve ( tcfa addr -- )
663 :     Defer addr-resolve ( target-addr addr -- )
664 : anton 1.1
665 : jwilke 1.52 [IFUNDEF] ca>native
666 :     defer ca>native
667 :     [THEN]
668 : anton 1.1
669 : jwilke 1.52 >TARGET
670 :     DEFER >body \ we need the system >body
671 :     \ and the target >body
672 :     >CROSS
673 :     T 2 cells H VALUE xt>body
674 :     DEFER doprim,
675 :     DEFER docol, \ compiles start of definition and doer
676 :     DEFER doer,
677 :     DEFER fini, \ compiles end of definition ;s
678 :     DEFER doeshandler,
679 :     DEFER dodoes,
680 :    
681 :     DEFER ]comp \ starts compilation
682 :     DEFER comp[ \ ends compilation
683 :    
684 :     : (cc) T a, H ; ' (cc) IS colon,
685 :     : (cr) >tempdp ]comp colon, comp[ tempdp> ; ' (cr) IS colon-resolve
686 :     : (ar) T ! H ; ' (ar) IS addr-resolve
687 : anton 1.1
688 : jwilke 1.52 >TARGET
689 :     : compile, colon, ;
690 :     >CROSS
691 : anton 1.1
692 : jwilke 1.53 \ file loading
693 :    
694 :     Variable filelist 0 filelist !
695 :     0 Value loadfile
696 :    
697 :     0 [IF] \ !! JAW WIP
698 : anton 1.1
699 : jwilke 1.53 : add-included-file ( adr len -- )
700 :     dup 2 cells + allocate throw >r
701 :     r@ 1 cells + dup TO loadfile place
702 :     filelist @ r@ !
703 :     r> filelist ! ;
704 :    
705 :     : included? ( c-addr u -- f )
706 :     filelist
707 :     BEGIN @ dup
708 :     WHILE >r r@ 1 cells + count compare 0=
709 :     IF rdrop 2drop true EXIT THEN
710 :     r>
711 :     REPEAT
712 :     2drop drop false ;
713 :    
714 :     : included
715 :     cr ." Including: " 2dup type ." ..."
716 :     2dup add-included-file included ;
717 :    
718 :     : include bl word count included ;
719 :    
720 :     : require bl word count included ;
721 :    
722 :     [THEN]
723 : anton 1.1
724 : jwilke 1.52 \ resolve structure
725 : anton 1.1
726 : jwilke 1.52 : >next ; \ link to next field
727 :     : >tag cell+ ; \ indecates type of reference: 0: call, 1: address
728 : jwilke 1.53 : >taddr cell+ cell+ ;
729 : jwilke 1.52 : >ghost 3 cells + ;
730 : jwilke 1.53 : >file 4 cells + ;
731 :     : >line 5 cells + ;
732 : anton 1.48
733 : jwilke 1.52 : refered ( ghost tag -- )
734 : jwilke 1.53 \G creates a resolve structure
735 : jwilke 1.52 swap >r here r@ >link @ , r@ >link ! ( tag ) ,
736 : jwilke 1.53 T here aligned H , r> drop last-header-ghost @ ,
737 :     loadfile , sourceline# ,
738 :     ;
739 : anton 1.48
740 : jwilke 1.52 Defer resolve-warning
741 : anton 1.1
742 : jwilke 1.52 : reswarn-test ( ghost res-struct -- ghost res-struct )
743 :     over cr ." Resolving " >ghostname type dup ." in " >ghost @ >ghostname type ;
744 : anton 1.1
745 : jwilke 1.52 : reswarn-forward ( ghost res-struct -- ghost res-struct )
746 :     over warnhead >ghostname type dup ." is referenced in "
747 :     >ghost @ >ghostname type ;
748 : anton 1.1
749 : jwilke 1.52 \ ' reswarn-test IS resolve-warning
750 :    
751 : anton 1.1 \ resolve 14oct92py
752 :    
753 : jwilke 1.52 : resolve-loop ( ghost tcfa -- ghost tcfa )
754 :     >r dup >link
755 :     BEGIN @ dup WHILE
756 :     resolve-warning
757 :     r@ over >taddr @
758 :     2 pick >tag @
759 :     IF addr-resolve
760 :     ELSE colon-resolve
761 :     THEN
762 :     REPEAT drop r> ;
763 :    
764 :     \ : resolve-loop ( ghost tcfa -- ghost tcfa )
765 :     \ >r dup >link @
766 :     \ BEGIN dup WHILE dup T @ H r@ rot T ! H REPEAT drop r> ;
767 : anton 1.1
768 :     \ exists 9may93jaw
769 :    
770 : jwilke 1.52 Variable TWarnings
771 :     TWarnings on
772 :     Variable Exists-Warnings
773 :     Exists-Warnings on
774 :    
775 : anton 1.1 : exists ( ghost tcfa -- )
776 :     over GhostNames
777 :     BEGIN @ dup
778 :     WHILE 2dup cell+ @ =
779 :     UNTIL
780 : jwilke 1.52 2 cells + count
781 :     TWarnings @ Exists-Warnings @ and
782 :     IF warnhead type ." exists"
783 :     ELSE 2drop THEN
784 :     drop swap >link !
785 : pazsan 1.24 ELSE true abort" CROSS: Ghostnames inconsistent "
786 : anton 1.1 THEN ;
787 :    
788 :     : resolve ( ghost tcfa -- )
789 : jwilke 1.52 \ resolve referencies to ghost with tcfa
790 :     over forward? 0= IF exists EXIT THEN
791 :     resolve-loop over >link ! <res> swap >magic !
792 :     ['] noop IS resolve-warning
793 :     ;
794 : anton 1.1
795 :     \ gexecute ghost, 01nov92py
796 :    
797 : jwilke 1.52 : is-forward ( ghost -- )
798 :     \ >link dup @ there rot ! T A, H ;
799 :     0 refered -1 colon, ;
800 :    
801 :     : is-resolved ( ghost -- )
802 :     >link @ colon, ; \ compile-call
803 :    
804 :     : gexecute ( ghost -- )
805 :     dup @ <fwd> = IF is-forward ELSE is-resolved THEN ;
806 :    
807 :     : addr, ( ghost -- )
808 :     dup @ <fwd> = IF 1 refered 0 T a, H ELSE >link @ T a, H THEN ;
809 :    
810 :     \ !! : ghost, ghost gexecute ;
811 : anton 1.1
812 :     \ .unresolved 11may93jaw
813 :    
814 :     variable ResolveFlag
815 :    
816 :     \ ?touched 11may93jaw
817 :    
818 : jwilke 1.52 : ?touched ( ghost -- flag ) dup forward? swap >link @
819 : anton 1.1 0 <> and ;
820 :    
821 : jwilke 1.53 : .forwarddefs ( ghost -- )
822 :     ." appeared in:"
823 :     >link
824 :     BEGIN @ dup
825 :     WHILE cr 5 spaces
826 :     dup >ghost @ >ghostname type
827 :     ." file " dup >file @ ?dup IF count type ELSE ." CON" THEN
828 :     ." line " dup >line @ .dec
829 :     REPEAT
830 :     drop ;
831 :    
832 : anton 1.1 : ?resolved ( ghostname -- )
833 :     dup cell+ @ ?touched
834 : jwilke 1.53 IF dup
835 :     cell+ cell+ count cr type ResolveFlag on
836 :     cell+ @ .forwarddefs
837 :     ELSE drop
838 :     THEN ;
839 : anton 1.1
840 :     >MINIMAL
841 :     : .unresolved ( -- )
842 :     ResolveFlag off cr ." Unresolved: "
843 :     Ghostnames
844 :     BEGIN @ dup
845 :     WHILE dup ?resolved
846 : anton 1.10 REPEAT drop ResolveFlag @
847 :     IF
848 : anton 1.48 -1 abort" Unresolved words!"
849 : anton 1.10 ELSE
850 :     ." Nothing!"
851 :     THEN
852 :     cr ;
853 : anton 1.1
854 : jwilke 1.52 : .stats
855 :     base @ >r decimal
856 :     cr ." named Headers: " headers-named @ .
857 :     r> base ! ;
858 :    
859 : anton 1.1 >CROSS
860 :     \ Header states 12dec92py
861 :    
862 :     : flag! ( 8b -- ) tlast @ dup >r T c@ xor r> c! H ;
863 :    
864 :     VARIABLE ^imm
865 :    
866 :     >TARGET
867 : anton 1.36 : immediate 40 flag!
868 : pazsan 1.18 ^imm @ @ dup <imm> = IF drop EXIT THEN
869 : anton 1.1 <res> <> ABORT" CROSS: Cannot immediate a unresolved word"
870 :     <imm> ^imm @ ! ;
871 : anton 1.36 : restrict 20 flag! ;
872 : jwilke 1.52
873 :     : isdoer <do:> last-header-ghost @ >magic ! ;
874 : anton 1.1 >CROSS
875 :    
876 :     \ ALIAS2 ansforth conform alias 9may93jaw
877 :    
878 :     : ALIAS2 create here 0 , DOES> @ execute ;
879 :     \ usage:
880 : pazsan 1.18 \ ' <name> alias2 bla !
881 : anton 1.1
882 :     \ Target Header Creation 01nov92py
883 :    
884 : jwilke 1.52 >TARGET
885 : anton 1.1 : string, ( addr count -- )
886 : pazsan 1.28 dup T c, H bounds ?DO I c@ T c, H LOOP ;
887 : jwilke 1.52 : name, ( "name" -- ) bl word count T string, cfalign H ;
888 : anton 1.1 : view, ( -- ) ( dummy ) ;
889 : jwilke 1.52 >CROSS
890 : anton 1.1
891 : pazsan 1.25 \ Target Document Creation (goes to crossdoc.fd) 05jul95py
892 :    
893 : anton 1.48 s" doc/crossdoc.fd" r/w create-file throw value doc-file-id
894 : pazsan 1.25 \ contains the file-id of the documentation file
895 :    
896 : pazsan 1.40 : T-\G ( -- )
897 : pazsan 1.25 source >in @ /string doc-file-id write-line throw
898 : pazsan 1.40 postpone \ ;
899 : pazsan 1.25
900 : pazsan 1.39 Variable to-doc to-doc on
901 : pazsan 1.25
902 :     : cross-doc-entry ( -- )
903 :     to-doc @ tlast @ 0<> and \ not an anonymous (i.e. noname) header
904 :     IF
905 :     s" " doc-file-id write-line throw
906 :     s" make-doc " doc-file-id write-file throw
907 :     tlast @ >image count $1F and doc-file-id write-file throw
908 :     >in @
909 :     [char] ( parse 2drop
910 :     [char] ) parse doc-file-id write-file throw
911 :     s" )" doc-file-id write-file throw
912 :     [char] \ parse 2drop
913 : pazsan 1.40 T-\G
914 : pazsan 1.25 >in !
915 : pazsan 1.39 THEN ;
916 : pazsan 1.25
917 : pazsan 1.28 \ Target TAGS creation
918 :    
919 : pazsan 1.39 s" kernel.TAGS" r/w create-file throw value tag-file-id
920 : pazsan 1.28 \ contains the file-id of the tags file
921 :    
922 :     Create tag-beg 2 c, 7F c, bl c,
923 :     Create tag-end 2 c, bl c, 01 c,
924 :     Create tag-bof 1 c, 0C c,
925 :    
926 :     2variable last-loadfilename 0 0 last-loadfilename 2!
927 :    
928 :     : put-load-file-name ( -- )
929 :     loadfilename 2@ last-loadfilename 2@ d<>
930 :     IF
931 :     tag-bof count tag-file-id write-line throw
932 : anton 1.31 sourcefilename 2dup
933 : pazsan 1.28 tag-file-id write-file throw
934 :     last-loadfilename 2!
935 :     s" ,0" tag-file-id write-line throw
936 :     THEN ;
937 :    
938 :     : cross-tag-entry ( -- )
939 :     tlast @ 0<> \ not an anonymous (i.e. noname) header
940 :     IF
941 :     put-load-file-name
942 :     source >in @ min tag-file-id write-file throw
943 :     tag-beg count tag-file-id write-file throw
944 :     tlast @ >image count $1F and tag-file-id write-file throw
945 :     tag-end count tag-file-id write-file throw
946 : anton 1.31 base @ decimal sourceline# 0 <# #s #> tag-file-id write-file throw
947 : pazsan 1.28 \ >in @ 0 <# #s [char] , hold #> tag-file-id write-line throw
948 :     s" ,0" tag-file-id write-line throw
949 :     base !
950 :     THEN ;
951 :    
952 : pazsan 1.43 \ Check for words
953 :    
954 :     Defer skip? ' false IS skip?
955 :    
956 :     : defined? ( -- flag ) \ name
957 : jwilke 1.52 ghost forward? 0= ;
958 : pazsan 1.43
959 :     : needed? ( -- flag ) \ name
960 : anton 1.48 \G returns a false flag when
961 :     \G a word is not defined
962 :     \G a forward reference exists
963 :     \G so the definition is not skipped!
964 :     bl word gfind
965 : jwilke 1.52 IF dup forward?
966 : anton 1.48 nip
967 :     0=
968 :     ELSE drop true THEN ;
969 : pazsan 1.43
970 : pazsan 1.44 : doer? ( -- flag ) \ name
971 :     ghost >magic @ <do:> = ;
972 :    
973 : pazsan 1.43 : skip-defs ( -- )
974 :     BEGIN refill WHILE source -trailing nip 0= UNTIL THEN ;
975 :    
976 : pazsan 1.28 \ Target header creation
977 :    
978 : jwilke 1.52
979 : anton 1.1 VARIABLE CreateFlag CreateFlag off
980 :    
981 : jwilke 1.52 : 0.r ( n1 n2 -- ) 0 swap <# 0 ?DO # LOOP #> type ;
982 :     : .sym
983 :     bounds
984 :     DO I c@ dup
985 :     CASE '/ OF drop ." \/" ENDOF
986 :     '\ OF drop ." \\" ENDOF
987 :     dup OF emit ENDOF
988 :     ENDCASE
989 :     LOOP ;
990 :    
991 : pazsan 1.43 : (Theader ( "name" -- ghost )
992 :     \ >in @ bl word count type 2 spaces >in !
993 : jwilke 1.52 \ wordheaders will always be compiled to rom
994 :     switchrom
995 : pazsan 1.43 T align H view,
996 : anton 1.1 tlast @ dup 0> IF T 1 cells - THEN A, H there tlast !
997 : jwilke 1.52 1 headers-named +! \ Statistic
998 :     >in @ T name, H >in ! T here H tlastcfa !
999 :     \ Symbol table
1000 :     \ >in @ cr ." sym:s/CFA=" there 4 0.r ." /" bl word count .sym ." /g" cr >in !
1001 : anton 1.1 CreateFlag @ IF
1002 : pazsan 1.18 >in @ alias2 swap >in ! \ create alias in target
1003 :     >in @ ghost swap >in !
1004 :     swap also ghosts ' previous swap ! \ tick ghost and store in alias
1005 :     CreateFlag off
1006 : anton 1.1 ELSE ghost THEN
1007 : jwilke 1.52 dup Last-Header-Ghost !
1008 : anton 1.1 dup >magic ^imm ! \ a pointer for immediate
1009 :     Already @ IF dup >end tdoes !
1010 :     ELSE 0 tdoes ! THEN
1011 : pazsan 1.25 80 flag!
1012 : pazsan 1.28 cross-doc-entry cross-tag-entry ;
1013 : anton 1.1
1014 :     VARIABLE ;Resolve 1 cells allot
1015 : jwilke 1.52 \ this is the resolver information from ":"
1016 :     \ resolving is done by ";"
1017 : anton 1.1
1018 : pazsan 1.11 : Theader ( "name" -- ghost )
1019 :     (THeader dup there resolve 0 ;Resolve ! ;
1020 : anton 1.1
1021 :     >TARGET
1022 :     : Alias ( cfa -- ) \ name
1023 : pazsan 1.43 >in @ skip? IF 2drop EXIT THEN >in !
1024 : jwilke 1.53 dup 0< s" prims" T $has? H 0= and
1025 : pazsan 1.43 IF
1026 : jwilke 1.53 .sourcepos ." needs prim: " >in @ bl word count type >in ! cr
1027 : pazsan 1.43 THEN
1028 :     (THeader over resolve T A, H 80 flag! ;
1029 : pazsan 1.42 : Alias: ( cfa -- ) \ name
1030 : pazsan 1.43 >in @ skip? IF 2drop EXIT THEN >in !
1031 : jwilke 1.53 dup 0< s" prims" T $has? H 0= and
1032 : pazsan 1.43 IF
1033 : jwilke 1.53 .sourcepos ." needs doer: " >in @ bl word count type >in ! cr
1034 : pazsan 1.43 THEN
1035 :     ghost tuck swap resolve <do:> swap >magic ! ;
1036 : anton 1.1 >CROSS
1037 :    
1038 :     \ Conditionals and Comments 11may93jaw
1039 :    
1040 :     : ;Cond
1041 :     postpone ;
1042 :     swap ! ; immediate
1043 :    
1044 :     : Cond: ( -- ) \ name {code } ;
1045 :     atonce on
1046 :     ghost
1047 :     >exec
1048 :     :NONAME ;
1049 :    
1050 :     : restrict? ( -- )
1051 :     \ aborts on interprete state - ae
1052 :     state @ 0= ABORT" CROSS: Restricted" ;
1053 :    
1054 :     : Comment ( -- )
1055 :     >in @ atonce on ghost swap >in ! ' swap >exec ! ;
1056 :    
1057 :     Comment ( Comment \
1058 :    
1059 :     \ compile 10may93jaw
1060 :    
1061 :     : compile ( -- ) \ name
1062 :     restrict?
1063 : pazsan 1.13 bl word gfind dup 0= ABORT" CROSS: Can't compile "
1064 : anton 1.1 0> ( immediate? )
1065 :     IF >exec @ compile,
1066 :     ELSE postpone literal postpone gexecute THEN ;
1067 :     immediate
1068 :    
1069 : jwilke 1.52 : [G']
1070 :     \G ticks a ghost and returns its address
1071 :     bl word gfind 0= ABORT" CROSS: Ghost don't exists"
1072 :     state @
1073 :     IF postpone literal
1074 :     THEN ; immediate
1075 :    
1076 :     : ghost>cfa
1077 :     dup forward? ABORT" CROSS: forward " >link @ ;
1078 :    
1079 :     >TARGET
1080 :    
1081 :     : ' ( -- cfa )
1082 :     \ returns the target-cfa of a ghost
1083 :     bl word gfind 0= ABORT" CROSS: Ghost don't exists"
1084 :     ghost>cfa ;
1085 :    
1086 :     Cond: ['] T ' H alit, ;Cond
1087 :    
1088 :     >CROSS
1089 :    
1090 :     : [T']
1091 :     \ returns the target-cfa of a ghost, or compiles it as literal
1092 :     postpone [G'] state @ IF postpone ghost>cfa ELSE ghost>cfa THEN ; immediate
1093 : pazsan 1.42
1094 : jwilke 1.52 \ \ threading modell 13dec92py
1095 :     \ modularized 14jun97jaw
1096 :    
1097 :     : fillcfa ( usedcells -- )
1098 :     T cells H xt>body swap - 0 ?DO 0 T c, H LOOP ;
1099 :    
1100 :     : (>body) ( cfa -- pfa ) xt>body + ; ' (>body) T IS >body H
1101 :    
1102 :     : (doer,) ( ghost -- ) ]comp gexecute comp[ 1 fillcfa ; ' (doer,) IS doer,
1103 :    
1104 :     : (docol,) ( -- ) [G'] :docol doer, ; ' (docol,) IS docol,
1105 :    
1106 :     : (doprim,) ( -- )
1107 :     there xt>body + ca>native T a, H 1 fillcfa ; ' (doprim,) IS doprim,
1108 :    
1109 :     : (doeshandler,) ( -- )
1110 :     T cfalign H compile :doesjump T 0 , H ; ' (doeshandler,) IS doeshandler,
1111 :    
1112 :     : (dodoes,) ( does-action-ghost -- )
1113 :     ]comp [G'] :dodoes gexecute comp[
1114 :     addr,
1115 :     T here H tcell - reloff 2 fillcfa ; ' (dodoes,) IS dodoes,
1116 :    
1117 :     : (lit,) ( n -- ) compile lit T , H ; ' (lit,) IS lit,
1118 :    
1119 :     : (alit,) ( n -- ) lit, T here cell - H relon ; ' (alit,) IS alit,
1120 :    
1121 :     : (fini,) compile ;s ; ' (fini,) IS fini,
1122 : pazsan 1.42
1123 : pazsan 1.43 [IFUNDEF] (code)
1124 :     Defer (code)
1125 :     Defer (end-code)
1126 :     [THEN]
1127 :    
1128 : anton 1.1 >TARGET
1129 : pazsan 1.43 : Code
1130 : jwilke 1.52 defempty?
1131 : anton 1.48 (THeader there resolve
1132 : jwilke 1.53 [ T e? prims H 0= [IF] T e? ITC H [ELSE] true [THEN] ] [IF]
1133 : jwilke 1.52 doprim,
1134 : anton 1.48 [THEN]
1135 :     depth (code) ;
1136 : pazsan 1.43
1137 :     : Code:
1138 : jwilke 1.52 defempty?
1139 : anton 1.48 ghost dup there ca>native resolve <do:> swap >magic !
1140 : pazsan 1.43 depth (code) ;
1141 :    
1142 :     : end-code
1143 : jwilke 1.52 (end-code)
1144 : pazsan 1.43 depth ?dup IF 1- <> ABORT" CROSS: Stack changed"
1145 :     ELSE true ABORT" CROSS: Stack empty" THEN
1146 : jwilke 1.52 ;
1147 : anton 1.14
1148 :     Cond: chars ;Cond
1149 : anton 1.1
1150 :     >CROSS
1151 : jwilke 1.52
1152 : anton 1.1 \ tLiteral 12dec92py
1153 :    
1154 :     >TARGET
1155 : pazsan 1.40 Cond: \G T-\G ;Cond
1156 :    
1157 : anton 1.1 Cond: Literal ( n -- ) restrict? lit, ;Cond
1158 :     Cond: ALiteral ( n -- ) restrict? alit, ;Cond
1159 :    
1160 :     : Char ( "<char>" -- ) bl word char+ c@ ;
1161 :     Cond: [Char] ( "<char>" -- ) restrict? Char lit, ;Cond
1162 :    
1163 : pazsan 1.43 \ some special literals 27jan97jaw
1164 :    
1165 : jwilke 1.52 \ !! Known Bug: Special Literals and plug-ins work only correct
1166 :     \ on 16 and 32 Bit Targets and 32 Bit Hosts!
1167 :    
1168 : pazsan 1.43 Cond: MAXU
1169 : jwilke 1.52 restrict?
1170 :     tcell 1 cells u>
1171 :     IF compile lit tcell 0 ?DO FF T c, H LOOP
1172 :     ELSE $ffffffff lit, THEN
1173 :     ;Cond
1174 : pazsan 1.43
1175 :     Cond: MINI
1176 : jwilke 1.52 restrict?
1177 :     tcell 1 cells u>
1178 :     IF compile lit bigendian
1179 :     IF 80 T c, H tcell 1 ?DO 0 T c, H LOOP
1180 :     ELSE tcell 1 ?DO 0 T c, H LOOP 80 T c, H
1181 :     THEN
1182 :     ELSE tcell 2 = IF $8000 ELSE $80000000 THEN lit, THEN
1183 :     ;Cond
1184 : pazsan 1.43
1185 :     Cond: MAXI
1186 : jwilke 1.52 restrict?
1187 :     tcell 1 cells u>
1188 :     IF compile lit bigendian
1189 :     IF 7F T c, H tcell 1 ?DO FF T c, H LOOP
1190 :     ELSE tcell 1 ?DO FF T c, H LOOP 7F T c, H
1191 :     THEN
1192 :     ELSE tcell 2 = IF $7fff ELSE $7fffffff THEN lit, THEN
1193 : pazsan 1.43 ;Cond
1194 :    
1195 : anton 1.1 >CROSS
1196 :     \ Target compiling loop 12dec92py
1197 :     \ ">tib trick thrown out 10may93jaw
1198 :     \ number? defined at the top 11may93jaw
1199 :    
1200 :     \ compiled word might leave items on stack!
1201 :     : tcom ( in name -- )
1202 :     gfind ?dup IF 0> IF nip >exec @ execute
1203 :     ELSE nip gexecute THEN EXIT THEN
1204 :     number? dup IF 0> IF swap lit, THEN lit, drop
1205 :     ELSE 2drop >in !
1206 :     ghost gexecute THEN ;
1207 :    
1208 :     >TARGET
1209 :     \ : ; DOES> 13dec92py
1210 :     \ ] 9may93py/jaw
1211 :    
1212 :     : ] state on
1213 :     BEGIN
1214 : pazsan 1.13 BEGIN >in @ bl word
1215 : anton 1.1 dup c@ 0= WHILE 2drop refill 0=
1216 :     ABORT" CROSS: End of file while target compiling"
1217 :     REPEAT
1218 :     tcom
1219 :     state @
1220 :     0=
1221 :     UNTIL ;
1222 :    
1223 :     \ by the way: defining a second interpreter (a compiler-)loop
1224 :     \ is not allowed if a system should be ans conform
1225 :    
1226 :     : : ( -- colon-sys ) \ Name
1227 : jwilke 1.52 defempty?
1228 :     constflag off \ don't let this flag work over colon defs
1229 :     \ just to go sure nothing unwanted happens
1230 : pazsan 1.43 >in @ skip? IF drop skip-defs EXIT THEN >in !
1231 : anton 1.1 (THeader ;Resolve ! there ;Resolve cell+ !
1232 : jwilke 1.52 docol, ]comp depth T ] H ;
1233 : anton 1.1
1234 : pazsan 1.37 : :noname ( -- colon-sys )
1235 : jwilke 1.52 T cfalign H there docol, 0 ;Resolve ! depth T ] H ;
1236 : pazsan 1.37
1237 : pazsan 1.2 Cond: EXIT ( -- ) restrict? compile ;S ;Cond
1238 : anton 1.6
1239 :     Cond: ?EXIT ( -- ) 1 abort" CROSS: using ?exit" ;Cond
1240 : pazsan 1.2
1241 : jwilke 1.52 >CROSS
1242 :     : LastXT ;Resolve @ 0= abort" CROSS: no definition for LastXT"
1243 :     ;Resolve cell+ @ ;
1244 :    
1245 :     >TARGET
1246 :    
1247 :     Cond: recurse ( -- ) Last-Ghost @ gexecute ;Cond
1248 :    
1249 : anton 1.1 Cond: ; ( -- ) restrict?
1250 :     depth ?dup IF 1- <> ABORT" CROSS: Stack changed"
1251 :     ELSE true ABORT" CROSS: Stack empty" THEN
1252 : jwilke 1.52 fini,
1253 :     comp[
1254 :     state off
1255 : anton 1.1 ;Resolve @
1256 :     IF ;Resolve @ ;Resolve cell+ @ resolve THEN
1257 :     ;Cond
1258 :     Cond: [ restrict? state off ;Cond
1259 :    
1260 :     >CROSS
1261 : jwilke 1.52 : !does ( does-action -- )
1262 :     \ !! zusammenziehen und dodoes, machen!
1263 : pazsan 1.42 tlastcfa @ dup there >r tdp ! compile :dodoes r> tdp ! T cell+ ! H ;
1264 : jwilke 1.52 \ !! geht so nicht, da dodoes, ghost will!
1265 :     \ tlastcfa @ >tempdp dodoes, tempdp> ;
1266 : anton 1.1
1267 :     >TARGET
1268 :     Cond: DOES> restrict?
1269 : jwilke 1.52 compile (does>) doeshandler,
1270 :     \ resolve words made by builders
1271 :     tdoes @ ?dup IF @ T here H resolve THEN
1272 : anton 1.1 ;Cond
1273 : jwilke 1.52 : DOES> switchrom doeshandler, T here H !does depth T ] H ;
1274 : anton 1.1
1275 :     >CROSS
1276 :     \ Creation 01nov92py
1277 :    
1278 :     \ Builder 11may93jaw
1279 :    
1280 : jwilke 1.52 : Builder ( Create-xt do:-xt "name" -- )
1281 :     \ builds up a builder in current vocabulary
1282 :     \ create-xt is executed when word is interpreted
1283 :     \ do:-xt is executet when the created word from builder is executed
1284 :     \ for do:-xt an additional entry after the normal ghost-enrys is used
1285 :    
1286 : anton 1.1 >in @ alias2 swap dup >in ! >r >r
1287 :     Make-Ghost rot swap >exec ! ,
1288 :     r> r> >in !
1289 : pazsan 1.11 also ghosts ' previous swap ! ;
1290 :     \ DOES> dup >exec @ execute ;
1291 : anton 1.1
1292 : jwilke 1.52 : gdoes, ( ghost -- )
1293 :     \ makes the codefield for a word that is built
1294 :     >end @ dup forward? 0=
1295 :     IF
1296 : pazsan 1.42 dup >magic @ <do:> =
1297 : jwilke 1.52 IF doer, EXIT THEN
1298 :     THEN
1299 :     \ compile :dodoes gexecute
1300 :     \ T here H tcell - reloff
1301 :     dodoes,
1302 :     ;
1303 : anton 1.1
1304 : jwilke 1.52 : TCreate ( <name> -- )
1305 :     executed-ghost @
1306 : anton 1.1 CreateFlag on
1307 : jwilke 1.52 create-forward-warn
1308 :     IF ['] reswarn-forward IS resolve-warning THEN
1309 : pazsan 1.11 Theader >r dup gdoes,
1310 : jwilke 1.52 \ stores execution symantic in the built word
1311 :     >end @ >exec @ r> >exec ! ;
1312 :    
1313 :     : RTCreate ( <name> -- )
1314 :     \ creates a new word with code-field in ram
1315 :     executed-ghost @
1316 :     CreateFlag on
1317 :     create-forward-warn
1318 :     IF ['] reswarn-forward IS resolve-warning THEN
1319 :     \ make Alias
1320 :     (THeader there 0 T a, H 80 flag! ( S executed-ghost new-ghost )
1321 :     \ store poiter to code-field
1322 :     switchram T cfalign H
1323 :     there swap T ! H
1324 :     there tlastcfa !
1325 :     dup there resolve 0 ;Resolve !
1326 :     >r dup gdoes,
1327 : pazsan 1.11 >end @ >exec @ r> >exec ! ;
1328 : anton 1.1
1329 :     : Build: ( -- [xt] [colon-sys] )
1330 : jwilke 1.52 :noname postpone TCreate ;
1331 :    
1332 :     : BuildSmart: ( -- [xt] [colon-sys] )
1333 :     :noname
1334 : jwilke 1.53 [ T has? rom H [IF] ]
1335 : jwilke 1.52 postpone RTCreate
1336 :     [ [ELSE] ]
1337 :     postpone TCreate
1338 :     [ [THEN] ] ;
1339 : anton 1.1
1340 :     : gdoes> ( ghost -- addr flag )
1341 : jwilke 1.52 executed-ghost @
1342 : anton 1.1 state @ IF gexecute true EXIT THEN
1343 : jwilke 1.52 >link @ T >body H false ;
1344 : anton 1.1
1345 :     \ DO: ;DO 11may93jaw
1346 :     \ changed to ?EXIT 10may93jaw
1347 :    
1348 :     : DO: ( -- addr [xt] [colon-sys] )
1349 :     here ghostheader
1350 : pazsan 1.11 :noname postpone gdoes> postpone ?EXIT ;
1351 : anton 1.1
1352 : pazsan 1.42 : by: ( -- addr [xt] [colon-sys] ) \ name
1353 :     ghost
1354 :     :noname postpone gdoes> postpone ?EXIT ;
1355 :    
1356 : jwilke 1.52 : ;DO ( addr [xt] [colon-sys] -- addr )
1357 : anton 1.1 postpone ; ( S addr xt )
1358 :     over >exec ! ; immediate
1359 :    
1360 :     : by ( -- addr ) \ Name
1361 :     ghost >end @ ;
1362 :    
1363 :     >TARGET
1364 :     \ Variables and Constants 05dec92py
1365 :    
1366 : jwilke 1.52 Build: ( n -- ) ;
1367 :     by: :docon ( ghost -- n ) T @ H ;DO
1368 :     Builder (Constant)
1369 :    
1370 :     Build: ( n -- ) T , H ;
1371 :     by (Constant)
1372 :     Builder Constant
1373 :    
1374 :     Build: ( n -- ) T A, H ;
1375 :     by (Constant)
1376 :     Builder AConstant
1377 :    
1378 :     Build: ( d -- ) T , , H ;
1379 :     DO: ( ghost -- d ) T dup cell+ @ swap @ H ;DO
1380 :     Builder 2Constant
1381 :    
1382 :     BuildSmart: ;
1383 : pazsan 1.42 by: :dovar ( ghost -- addr ) ;DO
1384 : anton 1.1 Builder Create
1385 :    
1386 : jwilke 1.53 T has? rom H [IF]
1387 : jwilke 1.52 Build: ( n -- ) T here 0 , H switchram T align here swap ! 0 , H ( switchrom ) ;
1388 :     by (Constant)
1389 :     Builder Variable
1390 :     [ELSE]
1391 : anton 1.1 Build: T 0 , H ;
1392 :     by Create
1393 :     Builder Variable
1394 : jwilke 1.52 [THEN]
1395 : anton 1.1
1396 : jwilke 1.53 T has? rom H [IF]
1397 : jwilke 1.52 Build: ( n -- ) T here 0 , H switchram T align here swap ! 0 , H ( switchrom ) ;
1398 :     by (Constant)
1399 :     Builder AVariable
1400 :     [ELSE]
1401 : anton 1.1 Build: T 0 A, H ;
1402 :     by Create
1403 :     Builder AVariable
1404 : jwilke 1.52 [THEN]
1405 : anton 1.1
1406 : pazsan 1.3 \ User variables 04may94py
1407 :    
1408 :     >CROSS
1409 :     Variable tup 0 tup !
1410 :     Variable tudp 0 tudp !
1411 :     : u, ( n -- udp )
1412 :     tup @ tudp @ + T ! H
1413 : pazsan 1.19 tudp @ dup T cell+ H tudp ! ;
1414 : pazsan 1.3 : au, ( n -- udp )
1415 :     tup @ tudp @ + T A! H
1416 : pazsan 1.19 tudp @ dup T cell+ H tudp ! ;
1417 : pazsan 1.3 >TARGET
1418 :    
1419 :     Build: T 0 u, , H ;
1420 : pazsan 1.42 by: :douser ( ghost -- up-addr ) T @ H tup @ + ;DO
1421 : anton 1.1 Builder User
1422 :    
1423 : pazsan 1.3 Build: T 0 u, , 0 u, drop H ;
1424 :     by User
1425 : anton 1.1 Builder 2User
1426 :    
1427 : pazsan 1.3 Build: T 0 au, , H ;
1428 :     by User
1429 : anton 1.1 Builder AUser
1430 :    
1431 : jwilke 1.52 BuildSmart: T , H ;
1432 : pazsan 1.44 by (Constant)
1433 : anton 1.1 Builder Value
1434 :    
1435 : jwilke 1.52 BuildSmart: T A, H ;
1436 : pazsan 1.44 by (Constant)
1437 : pazsan 1.32 Builder AValue
1438 :    
1439 : jwilke 1.52 BuildSmart: ( -- ) [T'] noop T A, H ;
1440 : pazsan 1.42 by: :dodefer ( ghost -- ) ABORT" CROSS: Don't execute" ;DO
1441 : anton 1.1 Builder Defer
1442 : pazsan 1.37
1443 : jwilke 1.52 BuildSmart: ( inter comp -- ) swap T immediate A, A, H ;
1444 : pazsan 1.37 DO: ( ghost -- ) ABORT" CROSS: Don't execute" ;DO
1445 : anton 1.38 Builder interpret/compile:
1446 : pazsan 1.24
1447 :     \ Sturctures 23feb95py
1448 :    
1449 :     >CROSS
1450 :     : nalign ( addr1 n -- addr2 )
1451 :     \ addr2 is the aligned version of addr1 wrt the alignment size n
1452 :     1- tuck + swap invert and ;
1453 :     >TARGET
1454 :    
1455 : pazsan 1.44 Build: ;
1456 :     by: :dofield T @ H + ;DO
1457 :     Builder (Field)
1458 :    
1459 : anton 1.51 Build: ( align1 offset1 align size "name" -- align2 offset2 )
1460 :     rot dup T , H ( align1 align size offset1 )
1461 :     + >r nalign r> ;
1462 : pazsan 1.44 by (Field)
1463 : pazsan 1.24 Builder Field
1464 :    
1465 : anton 1.51 : struct T 1 chars 0 H ;
1466 : pazsan 1.24 : end-struct T 2Constant H ;
1467 :    
1468 : jwilke 1.52 : cell% ( n -- size align )
1469 : anton 1.51 T 1 cells H dup ;
1470 : pazsan 1.24
1471 :     \ ' 2Constant Alias2 end-struct
1472 :     \ 0 1 T Chars H 2Constant struct
1473 : anton 1.1
1474 : jwilke 1.52 0 [IF]
1475 :    
1476 : anton 1.1 \ structural conditionals 17dec92py
1477 :    
1478 :     >CROSS
1479 :     : ?struc ( flag -- ) ABORT" CROSS: unstructured " ;
1480 :     : sys? ( sys -- sys ) dup 0= ?struc ;
1481 : jwilke 1.52 : >mark ( -- sys ) T here ( dup ." M" hex. ) 0 , H ;
1482 :    
1483 :     : branchoffset ( src dest -- ) - ;
1484 :     : >resolve ( sys -- ) T here ( dup ." >" hex. ) over branchoffset swap ! H ;
1485 :     : <resolve ( sys -- ) T here ( dup ." <" hex. ) branchoffset , H ;
1486 : anton 1.1 >TARGET
1487 :    
1488 :     \ Structural Conditionals 12dec92py
1489 :    
1490 :     Cond: BUT restrict? sys? swap ;Cond
1491 :     Cond: YET restrict? sys? dup ;Cond
1492 :    
1493 :     >CROSS
1494 :     Variable tleavings
1495 :     >TARGET
1496 :    
1497 :     Cond: DONE ( addr -- ) restrict? tleavings @
1498 :     BEGIN 2dup u> 0= WHILE dup T @ H swap >resolve REPEAT
1499 :     tleavings ! drop ;Cond
1500 :    
1501 :     >CROSS
1502 :     : (leave T here H tleavings @ T , H tleavings ! ;
1503 :     >TARGET
1504 :    
1505 :     Cond: LEAVE restrict? compile branch (leave ;Cond
1506 :     Cond: ?LEAVE restrict? compile 0= compile ?branch (leave ;Cond
1507 :    
1508 :     \ Structural Conditionals 12dec92py
1509 :    
1510 :     Cond: AHEAD restrict? compile branch >mark ;Cond
1511 :     Cond: IF restrict? compile ?branch >mark ;Cond
1512 : jwilke 1.52 Cond: THEN restrict? sys? branchto, dup T @ H ?struc >resolve ;Cond
1513 : anton 1.1 Cond: ELSE restrict? sys? compile AHEAD swap compile THEN ;Cond
1514 :    
1515 : jwilke 1.52 Cond: BEGIN restrict? T branchto, here ( dup ." B" hex. ) H ;Cond
1516 : anton 1.1 Cond: WHILE restrict? sys? compile IF swap ;Cond
1517 :     Cond: AGAIN restrict? sys? compile branch <resolve ;Cond
1518 :     Cond: UNTIL restrict? sys? compile ?branch <resolve ;Cond
1519 :     Cond: REPEAT restrict? over 0= ?struc compile AGAIN compile THEN ;Cond
1520 : pazsan 1.45
1521 :     Cond: CASE restrict? 0 ;Cond
1522 : jwilke 1.52 Cond: OF restrict? 1+ >r compile over compile =
1523 :     compile IF compile drop r> ;Cond
1524 :     Cond: ENDOF restrict? >r compile ELSE r> ;Cond
1525 :     Cond: ENDCASE restrict? compile drop 0 ?DO compile THEN LOOP ;Cond
1526 :    
1527 :     \ Structural Conditionals 12dec92py
1528 :    
1529 :     Cond: DO restrict? compile (do) T here H ;Cond
1530 :     Cond: ?DO restrict? compile (?do) T (leave here H ;Cond
1531 :     Cond: FOR restrict? compile (for) T here H ;Cond
1532 :    
1533 :     >CROSS
1534 :     : loop] dup <resolve tcell - compile DONE compile unloop ;
1535 :     >TARGET
1536 :    
1537 :     Cond: LOOP restrict? sys? compile (loop) loop] ;Cond
1538 :     Cond: +LOOP restrict? sys? compile (+loop) loop] ;Cond
1539 :     Cond: NEXT restrict? sys? compile (next) loop] ;Cond
1540 :    
1541 :     [ELSE]
1542 :    
1543 :     \ structural conditionals 17dec92py
1544 :    
1545 :     >CROSS
1546 :     : ?struc ( flag -- ) ABORT" CROSS: unstructured " ;
1547 :     : sys? ( sys -- sys ) dup 0= ?struc ;
1548 :     : >mark ( -- sys ) T here ( dup ." M" hex. ) 0 , H ;
1549 :    
1550 :     : branchoffset ( src dest -- ) - ;
1551 :    
1552 :     : >resolve ( sys -- ) T here ( dup ." >" hex. ) over branchoffset swap ! H ;
1553 :    
1554 :     : <resolve ( sys -- ) T here ( dup ." <" hex. ) branchoffset , H ;
1555 :    
1556 :     :noname compile branch T here branchoffset , H ; IS branch,
1557 :     :noname compile ?branch T here branchoffset , H ; IS ?branch,
1558 :     :noname compile branch T here 0 , H ; IS branchmark,
1559 :     :noname compile ?branch T here 0 , H ; IS ?branchmark,
1560 :     :noname dup T @ H ?struc T here over branchoffset swap ! H ; IS branchtoresolve,
1561 :     :noname branchto, T here H ; IS branchtomark,
1562 :    
1563 :     >TARGET
1564 :    
1565 :     \ Structural Conditionals 12dec92py
1566 :    
1567 :     Cond: BUT restrict? sys? swap ;Cond
1568 :     Cond: YET restrict? sys? dup ;Cond
1569 :    
1570 : jwilke 1.53 1 [IF]
1571 : jwilke 1.52 >CROSS
1572 :     Variable tleavings
1573 :     >TARGET
1574 :    
1575 :     Cond: DONE ( addr -- ) restrict? tleavings @
1576 :     BEGIN 2dup u> 0= WHILE dup T @ H swap >resolve REPEAT
1577 :     tleavings ! drop ;Cond
1578 :    
1579 :     >CROSS
1580 :     : (leave T here H tleavings @ T , H tleavings ! ;
1581 :     >TARGET
1582 :    
1583 :     Cond: LEAVE restrict? compile branch (leave ;Cond
1584 :     Cond: ?LEAVE restrict? compile 0= compile ?branch (leave ;Cond
1585 :    
1586 : jwilke 1.53 [ELSE]
1587 :     \ !! This is WIP
1588 :     \ The problem is (?DO)!
1589 :     \ perhaps we need a plug-in for (?DO)
1590 :    
1591 :     >CROSS
1592 :     Variable tleavings 0 tleavings !
1593 :     >TARGET
1594 :    
1595 :     Cond: DONE ( addr -- )
1596 :     restrict? tleavings @
1597 :     BEGIN dup
1598 :     WHILE >r dup r@ cell+ @ \ address of branch
1599 :     u> 0= \ lower than DO?
1600 :     WHILE r@ 2 cells + @ \ branch token
1601 :     branchtoresolve,
1602 :     r@ @ r> free throw
1603 :     REPEAT drop r>
1604 :     THEN
1605 :     tleavings ! drop ;Cond
1606 :    
1607 :     >CROSS
1608 :     : (leave ( branchtoken -- )
1609 :     3 cells allocate throw >r
1610 :     T here H r@ cell+ !
1611 :     r@ 2 cells + !
1612 :     tleavings @ r@ !
1613 :     r> tleavings ! ;
1614 :     >TARGET
1615 :    
1616 :     Cond: LEAVE restrict? branchmark, (leave ;Cond
1617 :     Cond: ?LEAVE restrict? compile 0= ?branchmark, (leave ;Cond
1618 :    
1619 :     [THEN]
1620 :    
1621 : jwilke 1.52 \ Structural Conditionals 12dec92py
1622 :    
1623 : jwilke 1.53 >TARGET
1624 : jwilke 1.52 Cond: AHEAD restrict? branchmark, ;Cond
1625 :     Cond: IF restrict? ?branchmark, ;Cond
1626 :     Cond: THEN restrict? sys? branchto, branchtoresolve, ;Cond
1627 :     Cond: ELSE restrict? sys? compile AHEAD swap compile THEN ;Cond
1628 :    
1629 :     Cond: BEGIN restrict? branchtomark, ;Cond
1630 :     Cond: WHILE restrict? sys? compile IF swap ;Cond
1631 :     Cond: AGAIN restrict? sys? branch, ;Cond
1632 :     Cond: UNTIL restrict? sys? ?branch, ;Cond
1633 :     Cond: REPEAT restrict? over 0= ?struc compile AGAIN compile THEN ;Cond
1634 :    
1635 :     Cond: CASE restrict? 0 ;Cond
1636 :     Cond: OF restrict? 1+ >r compile over compile =
1637 :     compile IF compile drop r> ;Cond
1638 : pazsan 1.45 Cond: ENDOF restrict? >r compile ELSE r> ;Cond
1639 :     Cond: ENDCASE restrict? compile drop 0 ?DO compile THEN LOOP ;Cond
1640 : anton 1.1
1641 :     \ Structural Conditionals 12dec92py
1642 :    
1643 :     Cond: DO restrict? compile (do) T here H ;Cond
1644 : anton 1.48 Cond: ?DO restrict? compile (?do) T (leave here H ;Cond
1645 : anton 1.1 Cond: FOR restrict? compile (for) T here H ;Cond
1646 :    
1647 :     >CROSS
1648 : jwilke 1.53 : loop] branchto, dup <resolve tcell - compile DONE compile unloop ;
1649 : anton 1.1 >TARGET
1650 :    
1651 :     Cond: LOOP restrict? sys? compile (loop) loop] ;Cond
1652 :     Cond: +LOOP restrict? sys? compile (+loop) loop] ;Cond
1653 :     Cond: NEXT restrict? sys? compile (next) loop] ;Cond
1654 :    
1655 : jwilke 1.52 [THEN]
1656 :    
1657 : anton 1.1 \ String words 23feb93py
1658 :    
1659 : jwilke 1.52 : ," [char] " parse T string, align H ;
1660 : anton 1.1
1661 :     Cond: ." restrict? compile (.") T ," H ;Cond
1662 :     Cond: S" restrict? compile (S") T ," H ;Cond
1663 :     Cond: ABORT" restrict? compile (ABORT") T ," H ;Cond
1664 :    
1665 :     Cond: IS T ' >body H compile ALiteral compile ! ;Cond
1666 :     : IS T ' >body ! H ;
1667 : pazsan 1.9 Cond: TO T ' >body H compile ALiteral compile ! ;Cond
1668 :     : TO T ' >body ! H ;
1669 : anton 1.1
1670 : jwilke 1.52 Cond: defers T ' >body @ compile, H ;Cond
1671 :     : on T -1 swap ! H ;
1672 :     : off T 0 swap ! H ;
1673 :    
1674 : anton 1.1 \ LINKED ERR" ENV" 2ENV" 18may93jaw
1675 :    
1676 :     \ linked list primitive
1677 :     : linked T here over @ A, swap ! H ;
1678 : jwilke 1.52 : chained T linked A, H ;
1679 : anton 1.1
1680 :     : err" s" ErrLink linked" evaluate T , H
1681 : jwilke 1.52 [char] " parse T string, align H ;
1682 : anton 1.1
1683 :     : env" [char] " parse s" EnvLink linked" evaluate
1684 : jwilke 1.52 T string, align , H ;
1685 : anton 1.1
1686 :     : 2env" [char] " parse s" EnvLink linked" evaluate
1687 : jwilke 1.52 here >r T string, align , , H
1688 : anton 1.1 r> dup T c@ H 80 and swap T c! H ;
1689 :    
1690 :     \ compile must be last 22feb93py
1691 :    
1692 :     Cond: compile ( -- ) restrict? \ name
1693 : pazsan 1.13 bl word gfind dup 0= ABORT" CROSS: Can't compile"
1694 : anton 1.1 0> IF gexecute
1695 :     ELSE dup >magic @ <imm> =
1696 :     IF gexecute
1697 :     ELSE compile (compile) gexecute THEN THEN ;Cond
1698 :    
1699 :     Cond: postpone ( -- ) restrict? \ name
1700 : pazsan 1.13 bl word gfind dup 0= ABORT" CROSS: Can't compile"
1701 : anton 1.1 0> IF gexecute
1702 :     ELSE dup >magic @ <imm> =
1703 :     IF gexecute
1704 :     ELSE compile (compile) gexecute THEN THEN ;Cond
1705 :    
1706 :     >MINIMAL
1707 :     also minimal
1708 :     \ Usefull words 13feb93py
1709 :    
1710 :     : KB 400 * ;
1711 :    
1712 :     \ define new [IFDEF] and [IFUNDEF] 20may93jaw
1713 :    
1714 : pazsan 1.43 : defined? defined? ;
1715 : pazsan 1.44 : needed? needed? ;
1716 :     : doer? doer? ;
1717 : anton 1.1
1718 : jwilke 1.52 \ we want to use IFDEF on compiler directives (e.g. E?) in the source, too
1719 :    
1720 :     : directive?
1721 :     bl word count [ ' target >wordlist ] aliteral search-wordlist
1722 :     dup IF nip THEN ;
1723 :    
1724 :     : [IFDEF] >in @ directive? swap >in !
1725 :     0= IF defined? ELSE name 2drop true THEN
1726 :     postpone [IF] ;
1727 :    
1728 : pazsan 1.43 : [IFUNDEF] defined? 0= postpone [IF] ;
1729 : anton 1.1
1730 :     \ C: \- \+ Conditional Compiling 09jun93jaw
1731 :    
1732 : pazsan 1.43 : C: >in @ defined? 0=
1733 : anton 1.1 IF >in ! T : H
1734 :     ELSE drop
1735 :     BEGIN bl word dup c@
1736 :     IF count comment? s" ;" compare 0= ?EXIT
1737 :     ELSE refill 0= ABORT" CROSS: Out of Input while C:"
1738 :     THEN
1739 :     AGAIN
1740 :     THEN ;
1741 :    
1742 :     also minimal
1743 :    
1744 : jwilke 1.52 \G doesn't skip line when bit is set in debugmask
1745 :     : \D name evaluate debugmasksource @ and 0= IF postpone \ THEN ;
1746 :    
1747 : anton 1.48 \G interprets the line if word is not defined
1748 : pazsan 1.43 : \- defined? IF postpone \ THEN ;
1749 : anton 1.48
1750 :     \G interprets the line if word is defined
1751 : pazsan 1.43 : \+ defined? 0= IF postpone \ THEN ;
1752 : anton 1.1
1753 : anton 1.48 Cond: \- \- ;Cond
1754 :     Cond: \+ \+ ;Cond
1755 : jwilke 1.52 Cond: \D \D ;Cond
1756 : anton 1.48
1757 :     : ?? bl word find IF execute ELSE drop 0 THEN ;
1758 :    
1759 :     : needed:
1760 :     \G defines ghost for words that we want to be compiled
1761 :     BEGIN >in @ bl word c@ WHILE >in ! ghost drop REPEAT drop ;
1762 :    
1763 : anton 1.1 : [IF] postpone [IF] ;
1764 :     : [THEN] postpone [THEN] ;
1765 :     : [ELSE] postpone [ELSE] ;
1766 :    
1767 :     Cond: [IF] [IF] ;Cond
1768 :     Cond: [IFDEF] [IFDEF] ;Cond
1769 :     Cond: [IFUNDEF] [IFUNDEF] ;Cond
1770 :     Cond: [THEN] [THEN] ;Cond
1771 :     Cond: [ELSE] [ELSE] ;Cond
1772 :    
1773 : anton 1.48 previous
1774 :    
1775 : anton 1.1 \ save-cross 17mar93py
1776 :    
1777 : anton 1.48 >CROSS
1778 : anton 1.34 Create magic s" Gforth10" here over allot swap move
1779 : pazsan 1.26
1780 : anton 1.48 char 1 bigendian + tcell + magic 7 + c!
1781 : pazsan 1.26
1782 : anton 1.34 : save-cross ( "image-name" "binary-name" -- )
1783 :     bl parse ." Saving to " 2dup type cr
1784 : anton 1.1 w/o bin create-file throw >r
1785 : anton 1.48 TNIL IF
1786 : pazsan 1.43 s" #! " r@ write-file throw
1787 :     bl parse r@ write-file throw
1788 :     s" -i" r@ write-file throw
1789 :     #lf r@ emit-file throw
1790 :     r@ dup file-position throw drop 8 mod 8 swap ( file-id limit index )
1791 :     ?do
1792 :     bl over emit-file throw
1793 :     loop
1794 :     drop
1795 :     magic 8 r@ write-file throw \ write magic
1796 :     ELSE
1797 :     bl parse 2drop
1798 :     THEN
1799 : jwilke 1.52 image @ there
1800 :     r@ write-file throw \ write image
1801 : anton 1.48 TNIL IF
1802 :     bit$ @ there 1- tcell>bit rshift 1+
1803 : pazsan 1.16 r@ write-file throw \ write tags
1804 : pazsan 1.43 THEN
1805 : anton 1.1 r> close-file throw ;
1806 :    
1807 : jwilke 1.52 : save-region ( addr len -- )
1808 :     bl parse w/o bin create-file throw >r
1809 :     swap image @ + swap r@ write-file throw
1810 :     r> close-file throw ;
1811 :    
1812 : anton 1.1 \ words that should be in minimal
1813 : jwilke 1.52
1814 :     create s-buffer 50 chars allot
1815 :    
1816 : anton 1.48 >MINIMAL
1817 :     also minimal
1818 : anton 1.1
1819 : anton 1.48 bigendian Constant bigendian
1820 : jwilke 1.52 : here there ;
1821 :     : >ram >ram ;
1822 :     : >rom >rom ;
1823 :     : >auto >auto ;
1824 :     : >tempdp >tempdp ;
1825 :     : tempdp> tempdp> ;
1826 :     : const constflag on ;
1827 :     : warnings name 3 = 0= twarnings ! drop ;
1828 :    
1829 :    
1830 : anton 1.48 : save-cross save-cross ;
1831 : jwilke 1.52 : save-region save-region ;
1832 :     : tdump swap >image swap dump ;
1833 :    
1834 : anton 1.48 also forth
1835 : jwilke 1.52 [IFDEF] Label : Label defempty? Label ; [THEN]
1836 :     [IFDEF] start-macros : start-macros defempty? start-macros ; [THEN]
1837 :     [IFDEF] builttag : builttag builttag ; [THEN]
1838 : anton 1.48 previous
1839 :    
1840 : jwilke 1.52 : s" [char] " parse s-buffer place s-buffer count ; \ for environment?
1841 : pazsan 1.43 : + + ;
1842 : jwilke 1.52 : 1+ 1 + ;
1843 :     : 2+ 2 + ;
1844 : pazsan 1.43 : or or ;
1845 :     : 1- 1- ;
1846 :     : - - ;
1847 : jwilke 1.52 : and and ;
1848 :     : or or ;
1849 : pazsan 1.43 : 2* 2* ;
1850 :     : * * ;
1851 :     : / / ;
1852 :     : dup dup ;
1853 :     : over over ;
1854 :     : swap swap ;
1855 :     : rot rot ;
1856 :     : drop drop ;
1857 :     : = = ;
1858 :     : 0= 0= ;
1859 :     : lshift lshift ;
1860 :     : 2/ 2/ ;
1861 : pazsan 1.19 : . . ;
1862 : anton 1.1
1863 : pazsan 1.43 : all-words ['] false IS skip? ;
1864 :     : needed-words ['] needed? IS skip? ;
1865 :     : undef-words ['] defined? IS skip? ;
1866 : anton 1.1
1867 : pazsan 1.40 : \ postpone \ ; immediate
1868 : pazsan 1.47 : \G T-\G ; immediate
1869 : pazsan 1.40 : ( postpone ( ; immediate
1870 : anton 1.1 : include bl word count included ;
1871 : jwilke 1.52 : require require ;
1872 : anton 1.1 : .( [char] ) parse type ;
1873 : jwilke 1.52 : ." [char] " parse type ;
1874 : anton 1.1 : cr cr ;
1875 :    
1876 :     : times 0 ?DO dup T c, H LOOP drop ; \ used for space table creation
1877 :     only forth also minimal definitions
1878 :    
1879 :     \ cross-compiler words
1880 :    
1881 :     : decimal decimal ;
1882 :     : hex hex ;
1883 :    
1884 : pazsan 1.3 : tudp T tudp H ;
1885 : pazsan 1.39 : tup T tup H ;
1886 :    
1887 :     : doc-off false T to-doc H ! ;
1888 :     : doc-on true T to-doc H ! ;
1889 : jwilke 1.52 [IFDEF] dbg : dbg dbg ; [THEN]
1890 : pazsan 1.39
1891 :     minimal
1892 : anton 1.1
1893 :     \ for debugging...
1894 :     : order order ;
1895 : jwilke 1.52 : hwords words ;
1896 :     : words also ghosts words previous ;
1897 : anton 1.1 : .s .s ;
1898 :     : bye bye ;
1899 :    
1900 :     \ turnkey direction
1901 :     : H forth ; immediate
1902 :     : T minimal ; immediate
1903 :     : G ghosts ; immediate
1904 :    
1905 :     : turnkey 0 set-order also Target definitions
1906 :     also Minimal also ;
1907 :    
1908 :     \ these ones are pefered:
1909 :    
1910 :     : lock turnkey ;
1911 :     : unlock forth also cross ;
1912 : jwilke 1.52
1913 :     : [[ also unlock ;
1914 :     : ]] previous previous ;
1915 : anton 1.1
1916 :     unlock definitions also minimal
1917 :     : lock lock ;
1918 :     lock

CVS Admin

Powered by ViewCVS 1.0-dev
(Powered by ViewCVS)

ViewCVS and CVS Help