[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 :     previous >CROSS
122 :    
123 : jwilke 1.53 : .dec
124 :     base @ decimal swap . base ! ;
125 :    
126 : jwilke 1.52 : .sourcepos
127 :     cr sourcefilename type ." :"
128 : jwilke 1.53 sourceline# .dec ;
129 : jwilke 1.52
130 :     : warnhead
131 :     \G display error-message head
132 :     \G perhaps with linenumber and filename
133 :     .sourcepos ." Warning: " ;
134 :    
135 :     : empty? depth IF .sourcepos ." Stack not empty!" THEN ;
136 :    
137 :     stack-warn [IF]
138 :     : defempty? empty? ;
139 :     [ELSE]
140 :     : defempty? ; immediate
141 :     [THEN]
142 :    
143 : jwilke 1.74 \ debugging
144 : jwilke 1.52
145 : jwilke 1.74 0 [IF]
146 :    
147 :     This implements debugflags for the cross compiler and the compiled
148 :     images. It works identical to the has-flags in the environment.
149 :     The debugflags are defined in a vocabluary. If the word exists and
150 :     its value is true, the flag is switched on.
151 :    
152 :     [THEN]
153 :    
154 :     Vocabulary debugflags \ debug flags for cross
155 :     also debugflags get-order over
156 :     Constant debugflags-wl
157 :     set-order previous
158 :    
159 :     : DebugFlag
160 :     get-current >r debugflags-wl set-current
161 :     SetValue
162 :     r> set-current ;
163 :    
164 :     : Debug? ( adr u -- flag )
165 :     \G return true if debug flag is defined or switched on
166 :     debugflags-wl search-wordlist
167 :     IF EXECUTE
168 :     ELSE false THEN ;
169 :    
170 :     : D? ( <name> -- flag )
171 :     \G return true if debug flag is defined or switched on
172 :     \G while compiling we do not return the current value but
173 :     bl word count debug? ;
174 :    
175 :     : [d?]
176 :     \G compile the value-xt so the debug flag can be switched
177 :     \G the flag must exist!
178 :     bl word count debugflags-wl search-wordlist
179 :     IF compile,
180 :     ELSE -1 ABORT" unknown debug flag"
181 :     \ POSTPONE false
182 :     THEN ; immediate
183 : pazsan 1.54
184 : jwilke 1.52 \ \ GhostNames Ghosts 9may93jaw
185 :    
186 :     \ second name source to search trough list
187 :    
188 :     VARIABLE GhostNames
189 :     0 GhostNames !
190 :    
191 :     : GhostName ( -- addr )
192 :     here GhostNames @ , GhostNames ! here 0 ,
193 :     bl word count
194 :     \ 2dup type space
195 :     string, \ !! cfalign ?
196 :     align ;
197 :    
198 :     \ Ghost Builder 06oct92py
199 :    
200 :     \ <T T> new version with temp variable 10may93jaw
201 :    
202 :     VARIABLE VocTemp
203 :    
204 :     : <T get-current VocTemp ! also Ghosts definitions ;
205 :     : T> previous VocTemp @ set-current ;
206 :    
207 :     hex
208 :     4711 Constant <fwd> 4712 Constant <res>
209 :     4713 Constant <imm> 4714 Constant <do:>
210 : jwilke 1.75 4715 Constant <skip>
211 : jwilke 1.52
212 :     \ iForth makes only immediate directly after create
213 :     \ make atonce trick! ?
214 :    
215 :     Variable atonce atonce off
216 :    
217 : jwilke 1.76 : NoExec true ABORT" CROSS: Don't execute ghost, or immediate target word" ;
218 : jwilke 1.52
219 :     : GhostHeader <fwd> , 0 , ['] NoExec , ;
220 :    
221 :     : >magic ; \ type of ghost
222 :     : >link cell+ ; \ pointer where ghost is in target, or if unresolved
223 :     \ points to the where we have to resolve (linked-list)
224 :     : >exec cell+ cell+ ; \ execution symantics (while target compiling) of ghost
225 :     : >end 3 cells + ; \ room for additional tags
226 :     \ for builder (create, variable...) words the
227 :     \ execution symantics of words built are placed here
228 :    
229 :     Variable executed-ghost \ last executed ghost, needed in tcreate and gdoes>
230 :     Variable last-ghost \ last ghost that is created
231 :     Variable last-header-ghost \ last ghost definitions with header
232 :    
233 :     : Make-Ghost ( "name" -- ghost )
234 :     >in @ GhostName swap >in !
235 :     <T Create atonce @ IF immediate atonce off THEN
236 :     here tuck swap ! ghostheader T>
237 :     dup last-ghost !
238 :     DOES> dup executed-ghost ! >exec @ execute ;
239 :    
240 :     \ ghost words 14oct92py
241 :     \ changed: 10may93py/jaw
242 :    
243 :     : gfind ( string -- ghost true/1 / string false )
244 :     \ searches for string in word-list ghosts
245 :     dup count [ ' ghosts >wordlist ] ALiteral search-wordlist
246 :     dup IF >r >body nip r> THEN ;
247 :    
248 :     : gdiscover ( xt -- ghost true | xt false )
249 :     GhostNames
250 :     BEGIN @ dup
251 :     WHILE 2dup
252 :     cell+ @ dup >magic @ <fwd> <>
253 :     >r >link @ = r> and
254 :     IF cell+ @ nip true EXIT THEN
255 :     REPEAT
256 :     drop false ;
257 :    
258 :     VARIABLE Already
259 :    
260 :     : ghost ( "name" -- ghost )
261 :     Already off
262 : jwilke 1.76 >in @ bl word gfind IF atonce off Already on nip EXIT THEN
263 : jwilke 1.52 drop >in ! Make-Ghost ;
264 :    
265 :     : >ghostname ( ghost -- adr len )
266 :     GhostNames
267 :     BEGIN @ dup
268 :     WHILE 2dup cell+ @ =
269 :     UNTIL nip 2 cells + count
270 : pazsan 1.54 ELSE 2drop
271 :     \ true abort" CROSS: Ghostnames inconsistent"
272 :     s" ?!?!?!"
273 : jwilke 1.52 THEN ;
274 :    
275 :     ' >ghostname ALIAS @name
276 :    
277 :     : forward? ( ghost -- flag )
278 :     >magic @ <fwd> = ;
279 :    
280 : jwilke 1.75 : undefined? ( ghost -- flag )
281 :     >magic @ dup <fwd> = swap <skip> = or ;
282 :    
283 : jwilke 1.52 \ Predefined ghosts 12dec92py
284 :    
285 :     ghost 0= drop
286 :     ghost branch ghost ?branch 2drop
287 :     ghost (do) ghost (?do) 2drop
288 :     ghost (for) drop
289 :     ghost (loop) ghost (+loop) 2drop
290 :     ghost (next) drop
291 :     ghost unloop ghost ;S 2drop
292 :     ghost lit ghost (compile) ghost ! 2drop drop
293 :     ghost (does>) ghost noop 2drop
294 :     ghost (.") ghost (S") ghost (ABORT") 2drop drop
295 :     ghost ' drop
296 :     ghost :docol ghost :doesjump ghost :dodoes 2drop drop
297 : pazsan 1.54 ghost :dovar drop
298 : jwilke 1.52 ghost over ghost = ghost drop 2drop drop
299 :     ghost - drop
300 : pazsan 1.54 ghost 2drop drop
301 :     ghost 2dup drop
302 : jwilke 1.52
303 :     \ \ Parameter for target systems 06oct92py
304 :    
305 :     \ we define it ans like...
306 :     wordlist Constant target-environment
307 :    
308 :     VARIABLE env-current \ save information of current dictionary to restore with environ>
309 :    
310 :     : >ENVIRON get-current env-current ! target-environment set-current ;
311 :     : ENVIRON> env-current @ set-current ;
312 : pazsan 1.43
313 : anton 1.48 >TARGET
314 : pazsan 1.43
315 : jwilke 1.67 : environment? ( adr len -- [ x ] true | false )
316 : jwilke 1.52 target-environment search-wordlist
317 :     IF execute true ELSE false THEN ;
318 :    
319 : jwilke 1.67 : e? bl word count T environment? H 0= ABORT" environment variable not defined!" ;
320 : jwilke 1.52
321 : jwilke 1.67 : has? bl word count T environment? H
322 : jwilke 1.53 IF \ environment variable is present, return its value
323 :     ELSE \ environment variable is not present, return false
324 : jwilke 1.75 false \ debug true ABORT" arg"
325 : jwilke 1.53 THEN ;
326 : jwilke 1.52
327 :     : $has? T environment? H IF ELSE false THEN ;
328 : anton 1.48
329 : pazsan 1.54 >ENVIRON get-order get-current swap 1+ set-order
330 :     true SetValue compiler
331 : jwilke 1.53 true SetValue cross
332 : pazsan 1.54 true SetValue standard-threading
333 :     >TARGET previous
334 : jwilke 1.52
335 : pazsan 1.59
336 : jwilke 1.52 mach-file count included hex
337 : pazsan 1.43
338 : jwilke 1.53 >ENVIRON
339 :    
340 : pazsan 1.54 T has? ec H
341 :     [IF]
342 :     false DefaultValue relocate
343 :     false DefaultValue file
344 :     false DefaultValue OS
345 :     false DefaultValue prims
346 :     false DefaultValue floating
347 :     false DefaultValue glocals
348 :     false DefaultValue dcomps
349 :     false DefaultValue hash
350 :     false DefaultValue xconds
351 :     false DefaultValue header
352 :     [THEN]
353 :    
354 :     true DefaultValue interpreter
355 :     true DefaultValue ITC
356 :     false DefaultValue rom
357 : jwilke 1.73 true DefaultValue standardthreading
358 : jwilke 1.53
359 : jwilke 1.52 >TARGET
360 : jwilke 1.53 s" relocate" T environment? H
361 :     [IF] SetValue NIL
362 :     [ELSE] >ENVIRON T NIL H SetValue relocate
363 :     [THEN]
364 : pazsan 1.43
365 :     >CROSS
366 :    
367 : jwilke 1.52 \ \ Create additional parameters 19jan95py
368 : pazsan 1.19
369 : jwilke 1.71 \ currently cross only works for host machines with address-unit-bits
370 :     \ eual to 8 because of s! and sc!
371 :     \ but I start to query the environment just to modularize a little bit
372 :    
373 :     : check-address-unit-bits ( -- )
374 :     \ s" ADDRESS-UNIT-BITS" environment?
375 :     \ IF 8 <> ELSE true THEN
376 :     \ ABORT" ADDRESS-UNIT-BITS unknown or not equal to 8!"
377 :    
378 :     \ shit, this doesn't work because environment? is only defined for
379 :     \ gforth.fi and not kernl???.fi
380 :     ;
381 :    
382 :     check-address-unit-bits
383 :     8 Constant bits/byte \ we define: byte is address-unit
384 :    
385 :     1 bits/byte lshift Constant maxbyte
386 : jwilke 1.67 \ this sets byte size for the target machine, an (probably right guess) jaw
387 :    
388 : pazsan 1.19 T
389 : jwilke 1.71 NIL Constant TNIL
390 :     cell Constant tcell
391 :     cell<< Constant tcell<<
392 :     cell>bit Constant tcell>bit
393 :     bits/char Constant tbits/char
394 :     bits/char H bits/byte T /
395 :     Constant tchar
396 :     float Constant tfloat
397 :     1 bits/char lshift Constant tmaxchar
398 :     [IFUNDEF] bits/byte
399 :     8 Constant tbits/byte
400 :     [ELSE]
401 :     bits/byte Constant tbits/byte
402 :     [THEN]
403 : pazsan 1.19 H
404 : jwilke 1.71 tbits/byte bits/byte / Constant tbyte
405 :    
406 : pazsan 1.19
407 : anton 1.48 \ Variables 06oct92py
408 :    
409 :     Variable image
410 :     Variable tlast TNIL tlast ! \ Last name field
411 :     Variable tlastcfa \ Last code field
412 :     Variable tdoes \ Resolve does> calls
413 :     Variable bit$
414 : jwilke 1.52
415 :     \ statistics 10jun97jaw
416 :    
417 :     Variable headers-named 0 headers-named !
418 :     Variable user-vars 0 user-vars !
419 :    
420 : jwilke 1.67 : target>bitmask-size ( u1 -- u2 )
421 :     1- tcell>bit rshift 1+ ;
422 :    
423 :     : allocatetarget ( size --- adr )
424 :     dup allocate ABORT" CROSS: No memory for target"
425 :     swap over swap erase ;
426 : jwilke 1.52
427 : pazsan 1.54 \ \ memregion.fs
428 : jwilke 1.52
429 :    
430 :     Variable last-defined-region \ pointer to last defined region
431 :     Variable region-link \ linked list with all regions
432 :     Variable mirrored-link \ linked list for mirrored regions
433 :     0 dup mirrored-link ! region-link !
434 :    
435 :    
436 : jwilke 1.67 : >rname 6 cells + ;
437 :     : >rbm 5 cells + ;
438 :     : >rmem 4 cells + ;
439 :     : >rlink 3 cells + ;
440 : jwilke 1.52 : >rdp 2 cells + ;
441 :     : >rlen cell+ ;
442 :     : >rstart ;
443 :    
444 :    
445 :     : region ( addr len -- ) \G create a new region
446 :     \ check whether predefined region exists
447 :     save-input bl word find >r >r restore-input throw r> r> 0=
448 :     IF \ make region
449 :     drop
450 :     save-input create restore-input throw
451 :     here last-defined-region !
452 :     over ( startaddr ) , ( length ) , ( dp ) ,
453 : jwilke 1.67 region-link linked 0 , 0 , bl word count string,
454 : jwilke 1.52 ELSE \ store new parameters in region
455 :     bl word drop
456 :     >body >r r@ last-defined-region !
457 : jwilke 1.67 r@ >rlen ! dup r@ >rstart ! r> >rdp !
458 : jwilke 1.52 THEN ;
459 :    
460 :     : borders ( region -- startaddr endaddr ) \G returns lower and upper region border
461 : jwilke 1.67 dup >rstart @ swap >rlen @ over + ;
462 : jwilke 1.52
463 :     : extent ( region -- startaddr len ) \G returns the really used area
464 : jwilke 1.67 dup >rstart @ swap >rdp @ over - ;
465 : jwilke 1.52
466 :     : area ( region -- startaddr totallen ) \G returns the total area
467 : jwilke 1.67 dup >rstart swap >rlen @ ;
468 : jwilke 1.52
469 :     : mirrored \G mark a region as mirrored
470 :     mirrored-link
471 : jwilke 1.68 align linked last-defined-region @ , ;
472 : jwilke 1.52
473 : jwilke 1.67 : .addr ( u -- )
474 :     \G prints a 16 or 32 Bit nice hex value
475 : jwilke 1.52 base @ >r hex
476 :     tcell 2 u>
477 :     IF s>d <# # # # # '. hold # # # # #> type
478 :     ELSE s>d <# # # # # # #> type
479 :     THEN r> base ! ;
480 :    
481 :     : .regions \G display region statistic
482 :    
483 :     \ we want to list the regions in the right order
484 :     \ so first collect all regions on stack
485 :     0 region-link @
486 :     BEGIN dup WHILE dup @ REPEAT drop
487 :     BEGIN dup
488 : jwilke 1.67 WHILE cr
489 :     0 >rlink - >r
490 :     r@ >rname count tuck type
491 : jwilke 1.52 12 swap - 0 max spaces space
492 : jwilke 1.67 ." Start: " r@ >rstart @ dup .addr space
493 :     ." End: " r@ >rlen @ + .addr space
494 :     ." DP: " r> >rdp @ .addr
495 : jwilke 1.52 REPEAT drop
496 : jwilke 1.53 s" rom" T $has? H 0= ?EXIT
497 : jwilke 1.52 cr ." Mirrored:"
498 :     mirrored-link @
499 :     BEGIN dup
500 : jwilke 1.67 WHILE space dup cell+ @ >rname count type @
501 : jwilke 1.52 REPEAT drop cr
502 :     ;
503 :    
504 :     \ -------- predefined regions
505 :    
506 :     0 0 region address-space
507 :     \ total memory addressed and used by the target system
508 :    
509 :     0 0 region dictionary
510 :     \ rom area for the compiler
511 :    
512 : jwilke 1.53 T has? rom H
513 : jwilke 1.52 [IF]
514 :     0 0 region ram-dictionary mirrored
515 :     \ ram area for the compiler
516 :     [ELSE]
517 :     ' dictionary ALIAS ram-dictionary
518 :     [THEN]
519 :    
520 :     0 0 region return-stack
521 :    
522 :     0 0 region data-stack
523 :    
524 :     0 0 region tib-region
525 :    
526 :     ' dictionary ALIAS rom-dictionary
527 :    
528 :    
529 :     : setup-target ( -- ) \G initialize targets memory space
530 : jwilke 1.53 s" rom" T $has? H
531 : jwilke 1.52 IF \ check for ram and rom...
532 : jwilke 1.72 \ address-space area nip 0<>
533 : jwilke 1.67 ram-dictionary area nip 0<>
534 :     rom-dictionary area nip 0<>
535 : jwilke 1.72 and 0=
536 : jwilke 1.52 ABORT" CROSS: define address-space, rom- , ram-dictionary, with rom-support!"
537 :     THEN
538 :     address-space area nip
539 :     IF
540 :     address-space area
541 :     ELSE
542 :     dictionary area
543 :     THEN
544 : jwilke 1.67 nip 0=
545 : jwilke 1.52 ABORT" CROSS: define at least address-space or dictionary!!"
546 : jwilke 1.67
547 :     \ allocate target for each region
548 :     region-link
549 :     BEGIN @ dup
550 :     WHILE dup
551 :     0 >rlink - >r
552 :     r@ >rlen @
553 :     IF \ allocate mem
554 :     r@ >rlen @ dup
555 :    
556 :     allocatetarget dup image !
557 :     r@ >rmem !
558 :    
559 :     target>bitmask-size allocatetarget
560 : jwilke 1.72 dup bit$ !
561 : jwilke 1.67 r> >rbm !
562 :    
563 :     ELSE r> drop THEN
564 : jwilke 1.72 REPEAT drop ;
565 :    
566 :     \ MakeKernal 22feb99jaw
567 :    
568 :     : makekernel ( targetsize -- targetsize )
569 :     dup dictionary >rlen ! setup-target ;
570 :    
571 :     >MINIMAL
572 :     : makekernel makekernel ;
573 :     >CROSS
574 : jwilke 1.52
575 : pazsan 1.54 \ \ switched tdp for rom support 03jun97jaw
576 : jwilke 1.52
577 :     \ second value is here to store some maximal value for statistics
578 :     \ tempdp is also embedded here but has nothing to do with rom support
579 :     \ (needs switched dp)
580 :    
581 :     variable tempdp 0 , \ temporary dp for resolving
582 :     variable tempdp-save
583 :    
584 :     0 [IF]
585 :     variable romdp 0 , \ Dictionary-Pointer for ramarea
586 :     variable ramdp 0 , \ Dictionary-Pointer for romarea
587 :    
588 :     \
589 :     variable sramdp \ start of ram-area for forth
590 :     variable sromdp \ start of rom-area for forth
591 :    
592 :     [THEN]
593 :    
594 :    
595 :     0 value tdp
596 :     variable fixed \ flag: true: no automatic switching
597 :     \ false: switching is done automatically
598 :    
599 :     \ Switch-Policy:
600 :     \
601 :     \ a header is always compiled into rom
602 :     \ after a created word (create and variable) compilation goes to ram
603 :     \
604 :     \ Be careful: If you want to make the data behind create into rom
605 :     \ you have to put >rom before create!
606 :    
607 :     variable constflag constflag off
608 :    
609 : jwilke 1.67 : activate ( region -- )
610 :     \G next code goes to this region
611 :     >rdp to tdp ;
612 :    
613 : jwilke 1.52 : (switchram)
614 : jwilke 1.53 fixed @ ?EXIT s" rom" T $has? H 0= ?EXIT
615 : jwilke 1.67 ram-dictionary activate ;
616 : jwilke 1.52
617 :     : switchram
618 :     constflag @
619 :     IF constflag off ELSE (switchram) THEN ;
620 :    
621 :     : switchrom
622 : jwilke 1.67 fixed @ ?EXIT rom-dictionary activate ;
623 : jwilke 1.52
624 :     : >tempdp ( addr -- )
625 :     tdp tempdp-save ! tempdp to tdp tdp ! ;
626 :     : tempdp> ( -- )
627 :     tempdp-save @ to tdp ;
628 :    
629 :     : >ram fixed off (switchram) fixed on ;
630 :     : >rom fixed off switchrom fixed on ;
631 :     : >auto fixed off switchrom ;
632 :    
633 :    
634 :    
635 :     \ : romstart dup sromdp ! romdp ! ;
636 :     \ : ramstart dup sramdp ! ramdp ! ;
637 :    
638 : jwilke 1.67 \ default compilation goes to rom
639 : jwilke 1.52 \ when romable support is off, only the rom switch is used (!!)
640 :     >auto
641 :    
642 : anton 1.48 : there tdp @ ;
643 :    
644 : jwilke 1.52 >TARGET
645 : anton 1.48
646 : jwilke 1.52 \ \ Target Memory Handling
647 : anton 1.1
648 :     \ Byte ordering and cell size 06oct92py
649 :    
650 : pazsan 1.19 : cell+ tcell + ;
651 :     : cells tcell<< lshift ;
652 : jwilke 1.71 : chars tchar * ;
653 :     : char+ tchar + ;
654 : pazsan 1.19 : floats tfloat * ;
655 : anton 1.6
656 : anton 1.1 >CROSS
657 : pazsan 1.19 : cell/ tcell<< rshift ;
658 : anton 1.1 >TARGET
659 :     20 CONSTANT bl
660 : jwilke 1.52 \ TNIL Constant NIL
661 : anton 1.1
662 :     >CROSS
663 :    
664 : pazsan 1.20 bigendian
665 :     [IF]
666 : jwilke 1.52 : S! ( n addr -- ) >r s>d r> tcell bounds swap 1-
667 : pazsan 1.20 DO maxbyte ud/mod rot I c! -1 +LOOP 2drop ;
668 : jwilke 1.52 : S@ ( addr -- n ) >r 0 0 r> tcell bounds
669 : pazsan 1.20 DO maxbyte * swap maxbyte um* rot + swap I c@ + swap LOOP d>s ;
670 : pazsan 1.57 : Sc! ( n addr -- ) >r s>d r> tchar bounds swap 1-
671 :     DO maxbyte ud/mod rot I c! -1 +LOOP 2drop ;
672 :     : Sc@ ( addr -- n ) >r 0 0 r> tchar bounds
673 :     DO maxbyte * swap maxbyte um* rot + swap I c@ + swap LOOP d>s ;
674 : pazsan 1.19 [ELSE]
675 : jwilke 1.52 : S! ( n addr -- ) >r s>d r> tcell bounds
676 : pazsan 1.20 DO maxbyte ud/mod rot I c! LOOP 2drop ;
677 : jwilke 1.52 : S@ ( addr -- n ) >r 0 0 r> tcell bounds swap 1-
678 : pazsan 1.20 DO maxbyte * swap maxbyte um* rot + swap I c@ + swap -1 +LOOP d>s ;
679 : pazsan 1.57 : Sc! ( n addr -- ) >r s>d r> tchar bounds
680 :     DO maxbyte ud/mod rot I c! LOOP 2drop ;
681 :     : Sc@ ( addr -- n ) >r 0 0 r> tchar bounds swap 1-
682 :     DO maxbyte * swap maxbyte um* rot + swap I c@ + swap -1 +LOOP d>s ;
683 : anton 1.1 [THEN]
684 :    
685 : jwilke 1.67 : taddr>region ( taddr -- region | 0 )
686 :     \G finds for a target-address the correct region
687 :     \G returns 0 if taddr is not in range of a target memory region
688 :     region-link
689 :     BEGIN @ dup
690 :     WHILE dup >r
691 :     0 >rlink - >r
692 :     r@ >rlen @
693 :     IF dup r@ borders within
694 :     IF r> r> drop nip EXIT THEN
695 :     THEN
696 :     r> drop
697 :     r>
698 :     REPEAT
699 :     2drop 0 ;
700 :    
701 :     : (>regionimage) ( taddr -- 'taddr )
702 :     dup
703 :     \ find region we want to address
704 :     taddr>region dup 0= ABORT" Address out of range!"
705 :     >r
706 :     \ calculate offset in region
707 :     r@ >rstart @ -
708 :     \ add regions real address in our memory
709 :     r> >rmem @ + ;
710 :    
711 : anton 1.1 \ Bit string manipulation 06oct92py
712 :     \ 9may93jaw
713 :     CREATE Bittable 80 c, 40 c, 20 c, 10 c, 8 c, 4 c, 2 c, 1 c,
714 :     : bits ( n -- n ) chars Bittable + c@ ;
715 :    
716 :     : >bit ( addr n -- c-addr mask ) 8 /mod rot + swap bits ;
717 :     : +bit ( addr n -- ) >bit over c@ or swap c! ;
718 : pazsan 1.4 : -bit ( addr n -- ) >bit invert over c@ and swap c! ;
719 : jwilke 1.67
720 :     : (relon) ( taddr -- ) bit$ @ swap cell/ +bit ;
721 :     : (reloff) ( taddr -- ) bit$ @ swap cell/ -bit ;
722 :    
723 :     : (>image) ( taddr -- absaddr ) image @ + ;
724 :    
725 :     DEFER >image
726 :     DEFER relon
727 :     DEFER reloff
728 :     DEFER correcter
729 :    
730 :     T has? relocate H
731 :     [IF]
732 :     ' (relon) IS relon
733 :     ' (reloff) IS reloff
734 :     ' (>image) IS >image
735 :     [ELSE]
736 :     ' drop IS relon
737 :     ' drop IS reloff
738 : jwilke 1.68 ' (>regionimage) IS >image
739 : jwilke 1.67 [THEN]
740 : anton 1.1
741 :     \ Target memory access 06oct92py
742 :    
743 :     : align+ ( taddr -- rest )
744 : anton 1.48 tcell tuck 1- and - [ tcell 1- ] Literal and ;
745 : anton 1.22 : cfalign+ ( taddr -- rest )
746 : pazsan 1.39 \ see kernel.fs:cfaligned
747 : pazsan 1.43 /maxalign tuck 1- and - [ /maxalign 1- ] Literal and ;
748 : anton 1.1
749 :     >TARGET
750 :     : aligned ( taddr -- ta-addr ) dup align+ + ;
751 :     \ assumes cell alignment granularity (as GNU C)
752 :    
753 : anton 1.22 : cfaligned ( taddr1 -- taddr2 )
754 : pazsan 1.39 \ see kernel.fs
755 : anton 1.22 dup cfalign+ + ;
756 :    
757 : jwilke 1.52 : @ ( taddr -- w ) >image S@ ;
758 :     : ! ( w taddr -- ) >image S! ;
759 : pazsan 1.57 : c@ ( taddr -- char ) >image Sc@ ;
760 :     : c! ( char taddr -- ) >image Sc! ;
761 : anton 1.7 : 2@ ( taddr -- x1 x2 ) T dup cell+ @ swap @ H ;
762 :     : 2! ( x1 x2 taddr -- ) T swap over ! cell+ ! H ;
763 : anton 1.1
764 :     \ Target compilation primitives 06oct92py
765 :     \ included A! 16may93jaw
766 :    
767 :     : here ( -- there ) there ;
768 :     : allot ( n -- ) tdp +! ;
769 : jwilke 1.52 : , ( w -- ) T here H tcell T allot ! H T here drop H ;
770 : pazsan 1.57 : c, ( char -- ) T here tchar allot c! H ;
771 : jwilke 1.67 : align ( -- ) T here H align+ 0 ?DO bl T c, tchar H +LOOP ;
772 : anton 1.22 : cfalign ( -- )
773 : pazsan 1.59 T here H cfalign+ 0 ?DO bl T c, tchar H +LOOP ;
774 : anton 1.1
775 : jwilke 1.71 : >address dup 0>= IF tbyte / THEN ; \ ?? jaw
776 : pazsan 1.59 : A! swap >address swap dup relon T ! H ;
777 :     : A, ( w -- ) >address T here H relon T , H ;
778 : anton 1.1
779 :     >CROSS
780 :    
781 : jwilke 1.52 : tcmove ( source dest len -- )
782 :     \G cmove in target memory
783 : pazsan 1.57 tchar * bounds
784 : jwilke 1.52 ?DO dup T c@ H I T c! H 1+
785 : pazsan 1.57 tchar +LOOP drop ;
786 : anton 1.1
787 : jwilke 1.67 \ \ Load Assembler
788 :    
789 : anton 1.1 >TARGET
790 : jwilke 1.74 H also Forth definitions
791 : anton 1.1
792 : jwilke 1.52 : X also target bl word find
793 :     IF state @ IF compile,
794 :     ELSE execute THEN
795 :     ELSE previous ABORT" Cross: access method not supported!"
796 :     THEN
797 :     previous ; immediate
798 : anton 1.1
799 : jwilke 1.52 [IFDEF] asm-include asm-include [THEN] hex
800 : anton 1.1
801 : jwilke 1.52 previous
802 :     >CROSS H
803 : anton 1.1
804 : jwilke 1.52 \ \ -------------------- Compiler Plug Ins 01aug97jaw
805 : anton 1.1
806 : pazsan 1.54 \ Compiler States
807 :    
808 :     Variable comp-state
809 :     0 Constant interpreting
810 :     1 Constant compiling
811 :     2 Constant resolving
812 :     3 Constant assembling
813 :    
814 : jwilke 1.52 Defer lit, ( n -- )
815 :     Defer alit, ( n -- )
816 : pazsan 1.54
817 :     Defer branch, ( target-addr -- ) \ compiles a branch
818 :     Defer ?branch, ( target-addr -- ) \ compiles a ?branch
819 :     Defer branchmark, ( -- branch-addr ) \ reserves room for a branch
820 :     Defer ?branchmark, ( -- branch-addr ) \ reserves room for a ?branch
821 :     Defer ?domark, ( -- branch-addr ) \ reserves room for a ?do branch
822 :     Defer branchto, ( -- ) \ actual program position is target of a branch (do e.g. alignment)
823 :     Defer branchtoresolve, ( branch-addr -- ) \ resolves a forward reference from branchmark
824 :     Defer branchfrom, ( -- ) \ ?!
825 :     Defer branchtomark, ( -- target-addr ) \ marks a branch destination
826 :    
827 : jwilke 1.52 Defer colon, ( tcfa -- ) \ compiles call to tcfa at current position
828 : pazsan 1.54 Defer colonmark, ( -- addr ) \ marks a colon call
829 : jwilke 1.52 Defer colon-resolve ( tcfa addr -- )
830 : pazsan 1.54
831 : jwilke 1.52 Defer addr-resolve ( target-addr addr -- )
832 : pazsan 1.54 Defer doer-resolve ( ghost res-pnt target-addr addr -- ghost res-pnt )
833 :    
834 :     Defer do, ( -- do-token )
835 :     Defer ?do, ( -- ?do-token )
836 :     Defer for, ( -- for-token )
837 :     Defer loop, ( do-token / ?do-token -- )
838 :     Defer +loop, ( do-token / ?do-token -- )
839 :     Defer next, ( for-token )
840 : anton 1.1
841 : jwilke 1.52 [IFUNDEF] ca>native
842 :     defer ca>native
843 :     [THEN]
844 : anton 1.1
845 : jwilke 1.52 >TARGET
846 :     DEFER >body \ we need the system >body
847 :     \ and the target >body
848 :     >CROSS
849 :     T 2 cells H VALUE xt>body
850 : pazsan 1.54 DEFER doprim, \ compiles start of a primitive
851 :     DEFER docol, \ compiles start of a colon definition
852 : jwilke 1.52 DEFER doer,
853 :     DEFER fini, \ compiles end of definition ;s
854 :     DEFER doeshandler,
855 :     DEFER dodoes,
856 :    
857 :     DEFER ]comp \ starts compilation
858 :     DEFER comp[ \ ends compilation
859 :    
860 : pazsan 1.54 : (cc) T a, H ; ' (cc) IS colon,
861 :    
862 :     : (cr) >tempdp ]comp colon, comp[ tempdp> ; ' (cr) IS colon-resolve
863 :     : (ar) T ! H ; ' (ar) IS addr-resolve
864 :     : (dr) ( ghost res-pnt target-addr addr )
865 :     >tempdp drop over
866 :     dup >magic @ <do:> =
867 :     IF doer,
868 :     ELSE dodoes,
869 :     THEN
870 :     tempdp> ; ' (dr) IS doer-resolve
871 :    
872 :     : (cm) ( -- addr )
873 :     T here align H
874 :     -1 colon, ; ' (cm) IS colonmark,
875 : anton 1.1
876 : jwilke 1.52 >TARGET
877 :     : compile, colon, ;
878 :     >CROSS
879 : anton 1.1
880 : jwilke 1.53 \ file loading
881 :    
882 : pazsan 1.54 : >fl-id 1 cells + ;
883 :     : >fl-name 2 cells + ;
884 :    
885 : jwilke 1.53 Variable filelist 0 filelist !
886 : jwilke 1.67 Create NoFile ," #load-file#"
887 : pazsan 1.54 0 Value filemem
888 : jwilke 1.67 : loadfile FileMem ?dup IF >fl-name ELSE NoFile THEN ;
889 : jwilke 1.53
890 : pazsan 1.54 1 [IF] \ !! JAW WIP
891 : anton 1.1
892 : jwilke 1.53 : add-included-file ( adr len -- )
893 : pazsan 1.54 dup char+ >fl-name allocate throw >r
894 :     r@ >fl-name place
895 : jwilke 1.53 filelist @ r@ !
896 : pazsan 1.54 r> dup filelist ! to FileMem
897 :     ;
898 : jwilke 1.53
899 :     : included? ( c-addr u -- f )
900 :     filelist
901 :     BEGIN @ dup
902 :     WHILE >r r@ 1 cells + count compare 0=
903 :     IF rdrop 2drop true EXIT THEN
904 :     r>
905 :     REPEAT
906 :     2drop drop false ;
907 :    
908 : jwilke 1.74 false DebugFlag showincludedfiles
909 :    
910 : jwilke 1.53 : included
911 : jwilke 1.74 [d?] showincludedfiles
912 :     IF cr ." Including: " 2dup type ." ..." THEN
913 : pazsan 1.54 FileMem >r
914 :     2dup add-included-file included
915 :     r> to FileMem ;
916 : jwilke 1.53
917 :     : include bl word count included ;
918 :    
919 :     : require bl word count included ;
920 :    
921 :     [THEN]
922 : anton 1.1
923 : jwilke 1.52 \ resolve structure
924 : anton 1.1
925 : jwilke 1.52 : >next ; \ link to next field
926 : pazsan 1.54 : >tag cell+ ; \ indecates type of reference: 0: call, 1: address, 2: doer
927 : jwilke 1.53 : >taddr cell+ cell+ ;
928 : jwilke 1.52 : >ghost 3 cells + ;
929 : jwilke 1.53 : >file 4 cells + ;
930 :     : >line 5 cells + ;
931 : anton 1.48
932 : pazsan 1.54 : (refered) ( ghost addr tag -- )
933 :     \G creates a reference to ghost at address taddr
934 :     rot >r here r@ >link @ , r> >link !
935 :     ( taddr tag ) ,
936 :     ( taddr ) ,
937 :     last-header-ghost @ ,
938 :     loadfile ,
939 :     sourceline# ,
940 :     ;
941 :    
942 : jwilke 1.52 : refered ( ghost tag -- )
943 : jwilke 1.53 \G creates a resolve structure
944 : pazsan 1.54 T here aligned H swap (refered)
945 :     ;
946 :    
947 :     : killref ( addr ghost -- )
948 :     \G kills a forward reference to ghost at position addr
949 :     \G this is used to eleminate a :dovar refence after making a DOES>
950 :     dup >magic @ <fwd> <> IF 2drop EXIT THEN
951 :     swap >r >link
952 :     BEGIN dup @ dup ( addr last this )
953 :     WHILE dup >taddr @ r@ =
954 :     IF @ over !
955 :     ELSE nip THEN
956 :     REPEAT rdrop 2drop
957 : jwilke 1.53 ;
958 : anton 1.48
959 : jwilke 1.52 Defer resolve-warning
960 : anton 1.1
961 : jwilke 1.52 : reswarn-test ( ghost res-struct -- ghost res-struct )
962 :     over cr ." Resolving " >ghostname type dup ." in " >ghost @ >ghostname type ;
963 : anton 1.1
964 : jwilke 1.52 : reswarn-forward ( ghost res-struct -- ghost res-struct )
965 :     over warnhead >ghostname type dup ." is referenced in "
966 :     >ghost @ >ghostname type ;
967 : anton 1.1
968 : jwilke 1.52 \ ' reswarn-test IS resolve-warning
969 :    
970 : anton 1.1 \ resolve 14oct92py
971 :    
972 : pazsan 1.54 : resolve-loop ( ghost resolve-list tcfa -- )
973 :     >r
974 :     BEGIN dup WHILE
975 :     \ dup >tag @ 2 = IF reswarn-forward THEN
976 :     resolve-warning
977 :     r@ over >taddr @
978 :     2 pick >tag @
979 :     CASE 0 OF colon-resolve ENDOF
980 :     1 OF addr-resolve ENDOF
981 :     2 OF doer-resolve ENDOF
982 :     ENDCASE
983 :     @ \ next list element
984 :     REPEAT 2drop rdrop
985 :     ;
986 : jwilke 1.52
987 :     \ : resolve-loop ( ghost tcfa -- ghost tcfa )
988 :     \ >r dup >link @
989 :     \ BEGIN dup WHILE dup T @ H r@ rot T ! H REPEAT drop r> ;
990 : anton 1.1
991 :     \ exists 9may93jaw
992 :    
993 : jwilke 1.52 Variable TWarnings
994 :     TWarnings on
995 :     Variable Exists-Warnings
996 :     Exists-Warnings on
997 :    
998 : anton 1.1 : exists ( ghost tcfa -- )
999 :     over GhostNames
1000 :     BEGIN @ dup
1001 :     WHILE 2dup cell+ @ =
1002 :     UNTIL
1003 : jwilke 1.52 2 cells + count
1004 :     TWarnings @ Exists-Warnings @ and
1005 :     IF warnhead type ." exists"
1006 :     ELSE 2drop THEN
1007 :     drop swap >link !
1008 : pazsan 1.24 ELSE true abort" CROSS: Ghostnames inconsistent "
1009 : anton 1.1 THEN ;
1010 :    
1011 :     : resolve ( ghost tcfa -- )
1012 : pazsan 1.54 \G resolve referencies to ghost with tcfa
1013 :     \ is ghost resolved?, second resolve means another definition with the
1014 :     \ same name
1015 : jwilke 1.75 over undefined? 0= IF exists EXIT THEN
1016 : pazsan 1.54 \ get linked-list
1017 :     swap >r r@ >link @ swap \ ( list tcfa R: ghost )
1018 :     \ mark ghost as resolved
1019 :     dup r@ >link ! <res> r@ >magic !
1020 :     \ loop through forward referencies
1021 :     r> -rot
1022 :     comp-state @ >r Resolving comp-state !
1023 :     resolve-loop
1024 :     r> comp-state !
1025 :    
1026 :     ['] noop IS resolve-warning
1027 : jwilke 1.52 ;
1028 : anton 1.1
1029 :     \ gexecute ghost, 01nov92py
1030 :    
1031 : jwilke 1.52 : is-forward ( ghost -- )
1032 : pazsan 1.54 colonmark, 0 (refered) ; \ compile space for call
1033 : jwilke 1.52
1034 :     : is-resolved ( ghost -- )
1035 :     >link @ colon, ; \ compile-call
1036 :    
1037 :     : gexecute ( ghost -- )
1038 :     dup @ <fwd> = IF is-forward ELSE is-resolved THEN ;
1039 :    
1040 :     : addr, ( ghost -- )
1041 :     dup @ <fwd> = IF 1 refered 0 T a, H ELSE >link @ T a, H THEN ;
1042 :    
1043 :     \ !! : ghost, ghost gexecute ;
1044 : anton 1.1
1045 :     \ .unresolved 11may93jaw
1046 :    
1047 :     variable ResolveFlag
1048 :    
1049 :     \ ?touched 11may93jaw
1050 :    
1051 : jwilke 1.52 : ?touched ( ghost -- flag ) dup forward? swap >link @
1052 : anton 1.1 0 <> and ;
1053 :    
1054 : jwilke 1.53 : .forwarddefs ( ghost -- )
1055 :     ." appeared in:"
1056 :     >link
1057 :     BEGIN @ dup
1058 :     WHILE cr 5 spaces
1059 :     dup >ghost @ >ghostname type
1060 :     ." file " dup >file @ ?dup IF count type ELSE ." CON" THEN
1061 :     ." line " dup >line @ .dec
1062 :     REPEAT
1063 :     drop ;
1064 :    
1065 : anton 1.1 : ?resolved ( ghostname -- )
1066 :     dup cell+ @ ?touched
1067 : jwilke 1.53 IF dup
1068 :     cell+ cell+ count cr type ResolveFlag on
1069 :     cell+ @ .forwarddefs
1070 :     ELSE drop
1071 :     THEN ;
1072 : anton 1.1
1073 :     >MINIMAL
1074 :     : .unresolved ( -- )
1075 :     ResolveFlag off cr ." Unresolved: "
1076 :     Ghostnames
1077 :     BEGIN @ dup
1078 :     WHILE dup ?resolved
1079 : anton 1.10 REPEAT drop ResolveFlag @
1080 :     IF
1081 : anton 1.48 -1 abort" Unresolved words!"
1082 : anton 1.10 ELSE
1083 :     ." Nothing!"
1084 :     THEN
1085 :     cr ;
1086 : anton 1.1
1087 : jwilke 1.52 : .stats
1088 :     base @ >r decimal
1089 :     cr ." named Headers: " headers-named @ .
1090 :     r> base ! ;
1091 :    
1092 : anton 1.1 >CROSS
1093 :     \ Header states 12dec92py
1094 :    
1095 :     : flag! ( 8b -- ) tlast @ dup >r T c@ xor r> c! H ;
1096 :    
1097 :     VARIABLE ^imm
1098 :    
1099 :     >TARGET
1100 : anton 1.36 : immediate 40 flag!
1101 : pazsan 1.18 ^imm @ @ dup <imm> = IF drop EXIT THEN
1102 : anton 1.1 <res> <> ABORT" CROSS: Cannot immediate a unresolved word"
1103 :     <imm> ^imm @ ! ;
1104 : anton 1.36 : restrict 20 flag! ;
1105 : jwilke 1.52
1106 : pazsan 1.54 : isdoer
1107 :     \G define a forth word as doer, this makes obviously only sence on
1108 :     \G forth processors such as the PSC1000
1109 :     <do:> last-header-ghost @ >magic ! ;
1110 : anton 1.1 >CROSS
1111 :    
1112 :     \ ALIAS2 ansforth conform alias 9may93jaw
1113 :    
1114 :     : ALIAS2 create here 0 , DOES> @ execute ;
1115 :     \ usage:
1116 : pazsan 1.18 \ ' <name> alias2 bla !
1117 : anton 1.1
1118 :     \ Target Header Creation 01nov92py
1119 :    
1120 : jwilke 1.52 >TARGET
1121 : anton 1.1 : string, ( addr count -- )
1122 : pazsan 1.28 dup T c, H bounds ?DO I c@ T c, H LOOP ;
1123 : jwilke 1.52 : name, ( "name" -- ) bl word count T string, cfalign H ;
1124 : anton 1.1 : view, ( -- ) ( dummy ) ;
1125 : jwilke 1.52 >CROSS
1126 : anton 1.1
1127 : pazsan 1.25 \ Target Document Creation (goes to crossdoc.fd) 05jul95py
1128 :    
1129 : pazsan 1.55 s" ./doc/crossdoc.fd" r/w create-file throw value doc-file-id
1130 : pazsan 1.25 \ contains the file-id of the documentation file
1131 :    
1132 : pazsan 1.40 : T-\G ( -- )
1133 : pazsan 1.25 source >in @ /string doc-file-id write-line throw
1134 : pazsan 1.40 postpone \ ;
1135 : pazsan 1.25
1136 : pazsan 1.39 Variable to-doc to-doc on
1137 : pazsan 1.25
1138 :     : cross-doc-entry ( -- )
1139 :     to-doc @ tlast @ 0<> and \ not an anonymous (i.e. noname) header
1140 :     IF
1141 :     s" " doc-file-id write-line throw
1142 :     s" make-doc " doc-file-id write-file throw
1143 :     tlast @ >image count $1F and doc-file-id write-file throw
1144 :     >in @
1145 :     [char] ( parse 2drop
1146 :     [char] ) parse doc-file-id write-file throw
1147 :     s" )" doc-file-id write-file throw
1148 :     [char] \ parse 2drop
1149 : pazsan 1.40 T-\G
1150 : pazsan 1.25 >in !
1151 : pazsan 1.39 THEN ;
1152 : pazsan 1.25
1153 : pazsan 1.28 \ Target TAGS creation
1154 :    
1155 : pazsan 1.39 s" kernel.TAGS" r/w create-file throw value tag-file-id
1156 : pazsan 1.28 \ contains the file-id of the tags file
1157 :    
1158 :     Create tag-beg 2 c, 7F c, bl c,
1159 :     Create tag-end 2 c, bl c, 01 c,
1160 :     Create tag-bof 1 c, 0C c,
1161 :    
1162 :     2variable last-loadfilename 0 0 last-loadfilename 2!
1163 :    
1164 :     : put-load-file-name ( -- )
1165 :     loadfilename 2@ last-loadfilename 2@ d<>
1166 :     IF
1167 :     tag-bof count tag-file-id write-line throw
1168 : anton 1.31 sourcefilename 2dup
1169 : pazsan 1.28 tag-file-id write-file throw
1170 :     last-loadfilename 2!
1171 :     s" ,0" tag-file-id write-line throw
1172 :     THEN ;
1173 :    
1174 :     : cross-tag-entry ( -- )
1175 :     tlast @ 0<> \ not an anonymous (i.e. noname) header
1176 :     IF
1177 :     put-load-file-name
1178 :     source >in @ min tag-file-id write-file throw
1179 :     tag-beg count tag-file-id write-file throw
1180 :     tlast @ >image count $1F and tag-file-id write-file throw
1181 :     tag-end count tag-file-id write-file throw
1182 : anton 1.31 base @ decimal sourceline# 0 <# #s #> tag-file-id write-file throw
1183 : pazsan 1.28 \ >in @ 0 <# #s [char] , hold #> tag-file-id write-line throw
1184 :     s" ,0" tag-file-id write-line throw
1185 :     base !
1186 :     THEN ;
1187 :    
1188 : pazsan 1.43 \ Check for words
1189 :    
1190 :     Defer skip? ' false IS skip?
1191 :    
1192 : jwilke 1.75 : skipdef ( <name> -- )
1193 :     \G skip definition of an undefined word in undef-words mode
1194 :     ghost dup forward?
1195 :     IF >magic <skip> swap !
1196 :     ELSE drop THEN ;
1197 :    
1198 : pazsan 1.43 : defined? ( -- flag ) \ name
1199 : jwilke 1.75 ghost undefined? 0= ;
1200 :    
1201 :     : defined2? ( -- flag ) \ name
1202 :     \G return true for anything else than forward, even for <skip>
1203 :     \G that's what we want
1204 : jwilke 1.52 ghost forward? 0= ;
1205 : pazsan 1.43
1206 :     : needed? ( -- flag ) \ name
1207 : anton 1.48 \G returns a false flag when
1208 :     \G a word is not defined
1209 :     \G a forward reference exists
1210 :     \G so the definition is not skipped!
1211 :     bl word gfind
1212 : jwilke 1.75 IF dup undefined?
1213 : anton 1.48 nip
1214 :     0=
1215 :     ELSE drop true THEN ;
1216 : pazsan 1.43
1217 : pazsan 1.44 : doer? ( -- flag ) \ name
1218 :     ghost >magic @ <do:> = ;
1219 :    
1220 : pazsan 1.43 : skip-defs ( -- )
1221 :     BEGIN refill WHILE source -trailing nip 0= UNTIL THEN ;
1222 :    
1223 : pazsan 1.28 \ Target header creation
1224 :    
1225 : pazsan 1.54 Variable CreateFlag
1226 :     CreateFlag off
1227 : jwilke 1.52
1228 : pazsan 1.54 Variable NoHeaderFlag
1229 :     NoHeaderFlag off
1230 : anton 1.1
1231 : pazsan 1.54 : 0.r ( n1 n2 -- )
1232 :     base @ >r hex
1233 :     0 swap <# 0 ?DO # LOOP #> type
1234 :     r> base ! ;
1235 : jwilke 1.52 : .sym
1236 :     bounds
1237 :     DO I c@ dup
1238 :     CASE '/ OF drop ." \/" ENDOF
1239 :     '\ OF drop ." \\" ENDOF
1240 :     dup OF emit ENDOF
1241 :     ENDCASE
1242 : pazsan 1.54 LOOP ;
1243 : jwilke 1.52
1244 : pazsan 1.43 : (Theader ( "name" -- ghost )
1245 : pazsan 1.54 \ >in @ bl word count type 2 spaces >in !
1246 :     \ wordheaders will always be compiled to rom
1247 :     switchrom
1248 :     \ build header in target
1249 :     NoHeaderFlag @
1250 :     IF NoHeaderFlag off
1251 :     ELSE
1252 :     T align H view,
1253 : pazsan 1.59 tlast @ dup 0> IF T 1 cells - H THEN T A, H there tlast !
1254 : pazsan 1.54 1 headers-named +! \ Statistic
1255 :     >in @ T name, H >in !
1256 :     THEN
1257 :     T cfalign here H tlastcfa !
1258 :     \ Symbol table
1259 :     \ >in @ cr ." sym:s/CFA=" there 4 0.r ." /" bl word count .sym ." /g" cr >in !
1260 :     CreateFlag @
1261 : jwilke 1.76 IF \ for a created word we need also a definition in target
1262 :     \ to execute the created word while compile time
1263 :     \ dont mind if a alias is defined twice
1264 :     Warnings @ >r Warnings off
1265 : pazsan 1.54 >in @ alias2 swap >in ! \ create alias in target
1266 : jwilke 1.76 r> Warnings !
1267 : pazsan 1.54 >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