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

CVS Admin

Powered by ViewCVS 1.0-dev
(Powered by ViewCVS)

ViewCVS and CVS Help