[gforth] / gforth / cross.fs  

gforth: gforth/cross.fs


1 : anton 1.1 \ CROSS.FS The Cross-Compiler 06oct92py
2 : anton 1.22 \ $Id: cross.fs,v 1.21 1995/02/02 18:13:02 pazsan Exp $
3 : anton 1.1 \ Idea and implementation: Bernd Paysan (py)
4 : pazsan 1.15 \ Copyright 1992-94 by the GNU Forth Development Group
5 : anton 1.1
6 :     \ Log:
7 :     \ changed in ; [ to state off 12may93jaw
8 :     \ included place +place 12may93jaw
9 :     \ for a created word (variable, constant...)
10 :     \ is now an alias in the target voabulary.
11 :     \ this means it is no longer necessary to
12 :     \ switch between vocabularies for variable
13 :     \ initialization 12may93jaw
14 :     \ discovered error in DOES>
15 :     \ replaced !does with (;code) 16may93jaw
16 :     \ made complete redesign and
17 :     \ introduced two vocs method
18 :     \ to be asure that the right words
19 :     \ are found 08jun93jaw
20 :     \ btw: ! works not with 16 bit
21 :     \ targets 09jun93jaw
22 :     \ added: 2user and value 11jun93jaw
23 :    
24 : pazsan 1.9 \ include other.fs \ ansforth extentions for cross
25 : anton 1.1
26 : pazsan 1.5 : comment? ( c-addr u -- c-addr u )
27 :     2dup s" (" compare 0=
28 :     IF postpone (
29 :     ELSE 2dup s" \" compare 0= IF postpone \ THEN
30 :     THEN ;
31 :    
32 : anton 1.1 decimal
33 :    
34 :     \ Begin CROSS COMPILER:
35 :    
36 :     \ GhostNames 9may93jaw
37 :     \ second name source to search trough list
38 :    
39 :     VARIABLE GhostNames
40 :     0 GhostNames !
41 :     : GhostName ( -- addr )
42 : anton 1.22 here GhostNames @ , GhostNames ! here 0 ,
43 :     bl word count
44 :     \ 2dup type space
45 :     string, cfalign ;
46 : anton 1.1
47 :     hex
48 :    
49 :    
50 :     Vocabulary Cross
51 :     Vocabulary Target
52 :     Vocabulary Ghosts
53 :     VOCABULARY Minimal
54 :     only Forth also Target also also
55 :     definitions Forth
56 :    
57 :     : T previous Cross also Target ; immediate
58 :     : G Ghosts ; immediate
59 :     : H previous Forth also Cross ; immediate
60 :    
61 :     forth definitions
62 :    
63 :     : T previous Cross also Target ; immediate
64 :     : G Ghosts ; immediate
65 :    
66 :     : >cross also Cross definitions previous ;
67 :     : >target also Target definitions previous ;
68 :     : >minimal also Minimal definitions previous ;
69 :    
70 :     H
71 :    
72 :     >CROSS
73 :    
74 :     \ Variables 06oct92py
75 :    
76 :     -1 Constant NIL
77 :     Variable image
78 :     Variable tlast NIL tlast ! \ Last name field
79 :     Variable tlastcfa \ Last code field
80 :     Variable tdoes \ Resolve does> calls
81 :     Variable bit$
82 :     Variable tdp
83 :     : there tdp @ ;
84 :    
85 :     \ Parameter for target systems 06oct92py
86 :    
87 : pazsan 1.13 included
88 : anton 1.1
89 : pazsan 1.19 \ Create additional parameters 19jan95py
90 :    
91 :     T
92 :     cell Constant tcell
93 :     cell<< Constant tcell<<
94 :     cell>bit Constant tcell>bit
95 :     bits/byte Constant tbits/byte
96 :     float Constant tfloat
97 :     1 bits/byte lshift Constant maxbyte
98 :     H
99 :    
100 : anton 1.1 >TARGET
101 :    
102 :     \ Byte ordering and cell size 06oct92py
103 :    
104 : pazsan 1.19 : cell+ tcell + ;
105 :     : cells tcell<< lshift ;
106 : anton 1.1 : chars ;
107 : pazsan 1.19 : floats tfloat * ;
108 : anton 1.6
109 : anton 1.1 >CROSS
110 : pazsan 1.19 : cell/ tcell<< rshift ;
111 : anton 1.1 >TARGET
112 :     20 CONSTANT bl
113 :     -1 Constant NIL
114 :     -2 Constant :docol
115 :     -3 Constant :docon
116 :     -4 Constant :dovar
117 : pazsan 1.3 -5 Constant :douser
118 : anton 1.10 -6 Constant :dodefer
119 :     -7 Constant :dodoes
120 :     -8 Constant :doesjump
121 : anton 1.1
122 :     >CROSS
123 :    
124 : pazsan 1.20 bigendian
125 :     [IF]
126 :     : T! ( n addr -- ) >r s>d r> tcell bounds swap 1-
127 :     DO maxbyte ud/mod rot I c! -1 +LOOP 2drop ;
128 :     : T@ ( addr -- n ) >r 0 0 r> tcell bounds
129 :     DO maxbyte * swap maxbyte um* rot + swap I c@ + swap LOOP d>s ;
130 : pazsan 1.19 [ELSE]
131 : pazsan 1.20 : T! ( n addr -- ) >r s>d r> tcell bounds
132 :     DO maxbyte ud/mod rot I c! LOOP 2drop ;
133 :     : T@ ( addr -- n ) >r 0 0 r> tcell bounds swap 1-
134 :     DO maxbyte * swap maxbyte um* rot + swap I c@ + swap -1 +LOOP d>s ;
135 : anton 1.1 [THEN]
136 :    
137 :     \ Memory initialisation 05dec92py
138 :     \ Fixed bug in else part 11may93jaw
139 :    
140 :     [IFDEF] Memory \ Memory is a bigFORTH feature
141 : pazsan 1.5 also Memory
142 : anton 1.1 : initmem ( var len -- )
143 :     2dup swap handle! >r @ r> erase ;
144 : pazsan 1.5 toss
145 : anton 1.1 [ELSE]
146 :     : initmem ( var len -- )
147 :     tuck allocate abort" CROSS: No memory for target"
148 :     ( len var adr ) dup rot !
149 :     ( len adr ) swap erase ;
150 :     [THEN]
151 :    
152 :     \ MakeKernal 12dec92py
153 :    
154 :     >MINIMAL
155 :     : makekernal ( targetsize -- targetsize )
156 :     bit$ over 1- cell>bit rshift 1+ initmem
157 :     image over initmem tdp off ;
158 :    
159 :     >CROSS
160 :     \ Bit string manipulation 06oct92py
161 :     \ 9may93jaw
162 :     CREATE Bittable 80 c, 40 c, 20 c, 10 c, 8 c, 4 c, 2 c, 1 c,
163 :     : bits ( n -- n ) chars Bittable + c@ ;
164 :    
165 :     : >bit ( addr n -- c-addr mask ) 8 /mod rot + swap bits ;
166 :     : +bit ( addr n -- ) >bit over c@ or swap c! ;
167 : pazsan 1.4 : -bit ( addr n -- ) >bit invert over c@ and swap c! ;
168 : anton 1.1 : relon ( taddr -- ) bit$ @ swap cell/ +bit ;
169 : pazsan 1.4 : reloff ( taddr -- ) bit$ @ swap cell/ -bit ;
170 : anton 1.1
171 :     \ Target memory access 06oct92py
172 :    
173 :     : align+ ( taddr -- rest )
174 :     cell tuck 1- and - [ cell 1- ] Literal and ;
175 : anton 1.22 : cfalign+ ( taddr -- rest )
176 :     \ see kernal.fs:cfaligned
177 :     float tuck 1- and - [ float 1- ] Literal and ;
178 : anton 1.1
179 :     >TARGET
180 :     : aligned ( taddr -- ta-addr ) dup align+ + ;
181 :     \ assumes cell alignment granularity (as GNU C)
182 :    
183 : anton 1.22 : cfaligned ( taddr1 -- taddr2 )
184 :     \ see kernal.fs
185 :     dup cfalign+ + ;
186 :    
187 : anton 1.1 >CROSS
188 :     : >image ( taddr -- absaddr ) image @ + ;
189 :     >TARGET
190 : pazsan 1.19 : @ ( taddr -- w ) >image t@ ;
191 :     : ! ( w taddr -- ) >image t! ;
192 : anton 1.1 : c@ ( taddr -- char ) >image c@ ;
193 :     : c! ( char taddr -- ) >image c! ;
194 : anton 1.7 : 2@ ( taddr -- x1 x2 ) T dup cell+ @ swap @ H ;
195 :     : 2! ( x1 x2 taddr -- ) T swap over ! cell+ ! H ;
196 : anton 1.1
197 :     \ Target compilation primitives 06oct92py
198 :     \ included A! 16may93jaw
199 :    
200 :     : here ( -- there ) there ;
201 :     : allot ( n -- ) tdp +! ;
202 :     : , ( w -- ) T here H cell T allot ! H ;
203 :     : c, ( char -- ) T here 1 allot c! H ;
204 :     : align ( -- ) T here H align+ 0 ?DO bl T c, H LOOP ;
205 : anton 1.22 : cfalign ( -- )
206 :     T here H cfalign+ 0 ?DO bl T c, H LOOP ;
207 : anton 1.1
208 :     : A! dup relon T ! H ;
209 :     : A, ( w -- ) T here H relon T , H ;
210 :    
211 :     >CROSS
212 :    
213 :     \ threading modell 13dec92py
214 :    
215 :     \ generic threading modell
216 :     : docol, ( -- ) :docol T A, 0 , H ;
217 :    
218 :     >TARGET
219 :     : >body ( cfa -- pfa ) T cell+ cell+ H ;
220 :     >CROSS
221 :    
222 : pazsan 1.3 : dodoes, ( -- ) T :doesjump A, 0 , H ;
223 : anton 1.1
224 :     \ Ghost Builder 06oct92py
225 :    
226 :     \ <T T> new version with temp variable 10may93jaw
227 :    
228 :     VARIABLE VocTemp
229 :    
230 :     : <T get-current VocTemp ! also Ghosts definitions ;
231 :     : T> previous VocTemp @ set-current ;
232 :    
233 :     4711 Constant <fwd> 4712 Constant <res>
234 :     4713 Constant <imm>
235 :    
236 :     \ iForth makes only immediate directly after create
237 :     \ make atonce trick! ?
238 :    
239 :     Variable atonce atonce off
240 :    
241 :     : NoExec true ABORT" CROSS: Don't execute ghost" ;
242 :    
243 :     : GhostHeader <fwd> , 0 , ['] NoExec , ;
244 :    
245 :     : >magic ; : >link cell+ ; : >exec cell+ cell+ ;
246 :     : >end 3 cells + ;
247 :    
248 : pazsan 1.11 Variable last-ghost
249 : anton 1.1 : Make-Ghost ( "name" -- ghost )
250 :     >in @ GhostName swap >in !
251 :     <T Create atonce @ IF immediate atonce off THEN
252 :     here tuck swap ! ghostheader T>
253 : pazsan 1.11 DOES> dup last-ghost ! >exec @ execute ;
254 : anton 1.1
255 :     \ ghost words 14oct92py
256 :     \ changed: 10may93py/jaw
257 :    
258 :     : gfind ( string -- ghost true/1 / string false )
259 :     \ searches for string in word-list ghosts
260 :     \ !! wouldn't it be simpler to just use search-wordlist ? ae
261 : pazsan 1.5 dup count [ ' ghosts >body ] ALiteral search-wordlist
262 : pazsan 1.13 dup IF >r >body nip r> THEN ;
263 : anton 1.1
264 :     VARIABLE Already
265 :    
266 :     : ghost ( "name" -- ghost )
267 :     Already off
268 : pazsan 1.13 >in @ bl word gfind IF Already on nip EXIT THEN
269 : anton 1.1 drop >in ! Make-Ghost ;
270 :    
271 :     \ resolve 14oct92py
272 :    
273 :     : resolve-loop ( ghost tcfa -- ghost tcfa )
274 :     >r dup >link @
275 :     BEGIN dup WHILE dup T @ H r@ rot T ! H REPEAT drop r> ;
276 :    
277 :     \ exists 9may93jaw
278 :    
279 :     : exists ( ghost tcfa -- )
280 :     over GhostNames
281 :     BEGIN @ dup
282 :     WHILE 2dup cell+ @ =
283 :     UNTIL
284 : pazsan 1.18 2 cells + count cr ." CROSS: Exists: " type 4 spaces drop
285 : anton 1.1 swap cell+ !
286 :     ELSE true ABORT" CROSS: Ghostnames inconsistent"
287 :     THEN ;
288 :    
289 :     : resolve ( ghost tcfa -- )
290 :     over >magic @ <fwd> <> IF exists EXIT THEN
291 :     resolve-loop over >link ! <res> swap >magic ! ;
292 :    
293 :     \ gexecute ghost, 01nov92py
294 :    
295 :     : do-forward ( ghost -- )
296 :     >link dup @ there rot ! T A, H ;
297 :     : do-resolve ( ghost -- )
298 :     >link @ T A, H ;
299 :    
300 :     : gexecute ( ghost -- ) dup @
301 :     <fwd> = IF do-forward ELSE do-resolve THEN ;
302 :     : ghost, ghost gexecute ;
303 :    
304 :     \ .unresolved 11may93jaw
305 :    
306 :     variable ResolveFlag
307 :    
308 :     \ ?touched 11may93jaw
309 :    
310 :     : ?touched ( ghost -- flag ) dup >magic @ <fwd> = swap >link @
311 :     0 <> and ;
312 :    
313 :     : ?resolved ( ghostname -- )
314 :     dup cell+ @ ?touched
315 :     IF cell+ cell+ count cr type ResolveFlag on ELSE drop THEN ;
316 :    
317 :     >MINIMAL
318 :     : .unresolved ( -- )
319 :     ResolveFlag off cr ." Unresolved: "
320 :     Ghostnames
321 :     BEGIN @ dup
322 :     WHILE dup ?resolved
323 : anton 1.10 REPEAT drop ResolveFlag @
324 :     IF
325 : pazsan 1.11 abort" Unresolved words!"
326 : anton 1.10 ELSE
327 :     ." Nothing!"
328 :     THEN
329 :     cr ;
330 : anton 1.1
331 :     >CROSS
332 :     \ Header states 12dec92py
333 :    
334 :     : flag! ( 8b -- ) tlast @ dup >r T c@ xor r> c! H ;
335 :    
336 :     VARIABLE ^imm
337 :    
338 :     >TARGET
339 :     : immediate 20 flag!
340 : pazsan 1.18 ^imm @ @ dup <imm> = IF drop EXIT THEN
341 : anton 1.1 <res> <> ABORT" CROSS: Cannot immediate a unresolved word"
342 :     <imm> ^imm @ ! ;
343 : pazsan 1.8 : restrict 40 flag! ;
344 : anton 1.1 >CROSS
345 :    
346 :     \ ALIAS2 ansforth conform alias 9may93jaw
347 :    
348 :     : ALIAS2 create here 0 , DOES> @ execute ;
349 :     \ usage:
350 : pazsan 1.18 \ ' <name> alias2 bla !
351 : anton 1.1
352 :     \ Target Header Creation 01nov92py
353 :    
354 :     : string, ( addr count -- )
355 :     dup T c, H bounds DO I c@ T c, H LOOP ;
356 : anton 1.22 : name, ( "name" -- ) bl word count string, T cfalign H ;
357 : anton 1.1 : view, ( -- ) ( dummy ) ;
358 :    
359 :     VARIABLE CreateFlag CreateFlag off
360 :    
361 :     : (Theader ( "name" -- ghost ) T align H view,
362 :     tlast @ dup 0> IF T 1 cells - THEN A, H there tlast !
363 :     >in @ name, >in ! T here H tlastcfa !
364 :     CreateFlag @ IF
365 : pazsan 1.18 >in @ alias2 swap >in ! \ create alias in target
366 :     >in @ ghost swap >in !
367 :     swap also ghosts ' previous swap ! \ tick ghost and store in alias
368 :     CreateFlag off
369 : anton 1.1 ELSE ghost THEN
370 :     dup >magic ^imm ! \ a pointer for immediate
371 :     Already @ IF dup >end tdoes !
372 :     ELSE 0 tdoes ! THEN
373 :     80 flag! ;
374 :    
375 :     VARIABLE ;Resolve 1 cells allot
376 :    
377 : pazsan 1.11 : Theader ( "name" -- ghost )
378 :     (THeader dup there resolve 0 ;Resolve ! ;
379 : anton 1.1
380 :     >TARGET
381 :     : Alias ( cfa -- ) \ name
382 :     (THeader over resolve T A, H 80 flag! ;
383 :     >CROSS
384 :    
385 :     \ Conditionals and Comments 11may93jaw
386 :    
387 :     : ;Cond
388 :     postpone ;
389 :     swap ! ; immediate
390 :    
391 :     : Cond: ( -- ) \ name {code } ;
392 :     atonce on
393 :     ghost
394 :     >exec
395 :     :NONAME ;
396 :    
397 :     : restrict? ( -- )
398 :     \ aborts on interprete state - ae
399 :     state @ 0= ABORT" CROSS: Restricted" ;
400 :    
401 :     : Comment ( -- )
402 :     >in @ atonce on ghost swap >in ! ' swap >exec ! ;
403 :    
404 :     Comment ( Comment \
405 :    
406 :     \ Predefined ghosts 12dec92py
407 :    
408 :     ghost 0= drop
409 :     ghost branch ghost ?branch 2drop
410 :     ghost (do) ghost (?do) 2drop
411 :     ghost (for) drop
412 :     ghost (loop) ghost (+loop) 2drop
413 :     ghost (next) drop
414 : pazsan 1.2 ghost unloop ghost ;S 2drop
415 : anton 1.1 ghost lit ghost (compile) ghost ! 2drop drop
416 :     ghost (;code) ghost noop 2drop
417 :     ghost (.") ghost (S") ghost (ABORT") 2drop drop
418 : pazsan 1.9 ghost '
419 : anton 1.1
420 :     \ compile 10may93jaw
421 :    
422 :     : compile ( -- ) \ name
423 :     restrict?
424 : pazsan 1.13 bl word gfind dup 0= ABORT" CROSS: Can't compile "
425 : anton 1.1 0> ( immediate? )
426 :     IF >exec @ compile,
427 :     ELSE postpone literal postpone gexecute THEN ;
428 :     immediate
429 :    
430 :     >TARGET
431 : pazsan 1.13 : ' ( -- cfa ) bl word gfind 0= ABORT" CROSS: undefined "
432 : anton 1.1 dup >magic @ <fwd> = ABORT" CROSS: forward " >link @ ;
433 :    
434 :     Cond: ['] compile lit ghost gexecute ;Cond
435 : anton 1.14
436 :     Cond: chars ;Cond
437 : anton 1.1
438 :     >CROSS
439 :     \ tLiteral 12dec92py
440 :    
441 :     : lit, ( n -- ) compile lit T , H ;
442 :     : alit, ( n -- ) compile lit T A, H ;
443 :    
444 :     >TARGET
445 :     Cond: Literal ( n -- ) restrict? lit, ;Cond
446 :     Cond: ALiteral ( n -- ) restrict? alit, ;Cond
447 :    
448 :     : Char ( "<char>" -- ) bl word char+ c@ ;
449 :     Cond: [Char] ( "<char>" -- ) restrict? Char lit, ;Cond
450 :    
451 :     >CROSS
452 :     \ Target compiling loop 12dec92py
453 :     \ ">tib trick thrown out 10may93jaw
454 :     \ number? defined at the top 11may93jaw
455 :    
456 :     \ compiled word might leave items on stack!
457 :     : tcom ( in name -- )
458 :     gfind ?dup IF 0> IF nip >exec @ execute
459 :     ELSE nip gexecute THEN EXIT THEN
460 :     number? dup IF 0> IF swap lit, THEN lit, drop
461 :     ELSE 2drop >in !
462 :     ghost gexecute THEN ;
463 :    
464 :     >TARGET
465 :     \ : ; DOES> 13dec92py
466 :     \ ] 9may93py/jaw
467 :    
468 :     : ] state on
469 :     BEGIN
470 : pazsan 1.13 BEGIN >in @ bl word
471 : anton 1.1 dup c@ 0= WHILE 2drop refill 0=
472 :     ABORT" CROSS: End of file while target compiling"
473 :     REPEAT
474 :     tcom
475 :     state @
476 :     0=
477 :     UNTIL ;
478 :    
479 :     \ by the way: defining a second interpreter (a compiler-)loop
480 :     \ is not allowed if a system should be ans conform
481 :    
482 :     : : ( -- colon-sys ) \ Name
483 :     (THeader ;Resolve ! there ;Resolve cell+ !
484 :     docol, depth T ] H ;
485 :    
486 : pazsan 1.2 Cond: EXIT ( -- ) restrict? compile ;S ;Cond
487 : anton 1.6
488 :     Cond: ?EXIT ( -- ) 1 abort" CROSS: using ?exit" ;Cond
489 : pazsan 1.2
490 : anton 1.1 Cond: ; ( -- ) restrict?
491 :     depth ?dup IF 1- <> ABORT" CROSS: Stack changed"
492 :     ELSE true ABORT" CROSS: Stack empty" THEN
493 : pazsan 1.2 compile ;S state off
494 : anton 1.1 ;Resolve @
495 :     IF ;Resolve @ ;Resolve cell+ @ resolve THEN
496 :     ;Cond
497 :     Cond: [ restrict? state off ;Cond
498 :    
499 :     >CROSS
500 :     : !does :dodoes tlastcfa @ tuck T ! cell+ ! H ;
501 :    
502 :     >TARGET
503 :     Cond: DOES> restrict?
504 :     compile (;code) dodoes, tdoes @ ?dup IF @ T here H resolve THEN
505 :     ;Cond
506 :     : DOES> dodoes, T here H !does depth T ] H ;
507 :    
508 :     >CROSS
509 :     \ Creation 01nov92py
510 :    
511 :     \ Builder 11may93jaw
512 :    
513 :     : Builder ( Create do: "name" -- )
514 :     >in @ alias2 swap dup >in ! >r >r
515 :     Make-Ghost rot swap >exec ! ,
516 :     r> r> >in !
517 : pazsan 1.11 also ghosts ' previous swap ! ;
518 :     \ DOES> dup >exec @ execute ;
519 : anton 1.1
520 :     : gdoes, ( ghost -- ) >end @ dup >magic @ <fwd> <>
521 :     IF dup >link @ dup 0< IF T A, 0 , H drop EXIT THEN drop THEN
522 : pazsan 1.4 :dodoes T A, H gexecute T here H cell - reloff ;
523 : anton 1.1
524 : pazsan 1.11 : TCreate ( -- )
525 :     last-ghost @
526 : anton 1.1 CreateFlag on
527 : pazsan 1.11 Theader >r dup gdoes,
528 :     >end @ >exec @ r> >exec ! ;
529 : anton 1.1
530 :     : Build: ( -- [xt] [colon-sys] )
531 :     :noname postpone TCreate ;
532 :    
533 :     : gdoes> ( ghost -- addr flag )
534 : pazsan 1.11 last-ghost @
535 : anton 1.1 state @ IF gexecute true EXIT THEN
536 :     cell+ @ T >body H false ;
537 :    
538 :     \ DO: ;DO 11may93jaw
539 :     \ changed to ?EXIT 10may93jaw
540 :    
541 :     : DO: ( -- addr [xt] [colon-sys] )
542 :     here ghostheader
543 : pazsan 1.11 :noname postpone gdoes> postpone ?EXIT ;
544 : anton 1.1
545 :     : ;DO ( addr [xt] [colon-sys] -- )
546 :     postpone ; ( S addr xt )
547 :     over >exec ! ; immediate
548 :    
549 :     : by ( -- addr ) \ Name
550 :     ghost >end @ ;
551 :    
552 :     >TARGET
553 :     \ Variables and Constants 05dec92py
554 :    
555 :     Build: ;
556 :     DO: ( ghost -- addr ) ;DO
557 :     Builder Create
558 :     by Create :dovar resolve
559 :    
560 :     Build: T 0 , H ;
561 :     by Create
562 :     Builder Variable
563 :    
564 :     Build: T 0 A, H ;
565 :     by Create
566 :     Builder AVariable
567 :    
568 : pazsan 1.3 \ User variables 04may94py
569 :    
570 :     >CROSS
571 :     Variable tup 0 tup !
572 :     Variable tudp 0 tudp !
573 :     : u, ( n -- udp )
574 :     tup @ tudp @ + T ! H
575 : pazsan 1.19 tudp @ dup T cell+ H tudp ! ;
576 : pazsan 1.3 : au, ( n -- udp )
577 :     tup @ tudp @ + T A! H
578 : pazsan 1.19 tudp @ dup T cell+ H tudp ! ;
579 : pazsan 1.3 >TARGET
580 :    
581 :     Build: T 0 u, , H ;
582 :     DO: ( ghost -- up-addr ) T @ H tup @ + ;DO
583 : anton 1.1 Builder User
584 : pazsan 1.3 by User :douser resolve
585 : anton 1.1
586 : pazsan 1.3 Build: T 0 u, , 0 u, drop H ;
587 :     by User
588 : anton 1.1 Builder 2User
589 :    
590 : pazsan 1.3 Build: T 0 au, , H ;
591 :     by User
592 : anton 1.1 Builder AUser
593 :    
594 :     Build: ( n -- ) T , H ;
595 :     DO: ( ghost -- n ) T @ H ;DO
596 :     Builder Constant
597 :     by Constant :docon resolve
598 :    
599 :     Build: ( n -- ) T A, H ;
600 :     by Constant
601 :     Builder AConstant
602 :    
603 :     Build: T 0 , H ;
604 :     by Constant
605 :     Builder Value
606 :    
607 :     Build: ( -- ) compile noop ;
608 :     DO: ( ghost -- ) ABORT" CROSS: Don't execute" ;DO
609 :     Builder Defer
610 : anton 1.10 by Defer :dodefer resolve
611 : anton 1.1
612 :     \ structural conditionals 17dec92py
613 :    
614 :     >CROSS
615 :     : ?struc ( flag -- ) ABORT" CROSS: unstructured " ;
616 :     : sys? ( sys -- sys ) dup 0= ?struc ;
617 :     : >mark ( -- sys ) T here 0 , H ;
618 :     : >resolve ( sys -- ) T here over - swap ! H ;
619 :     : <resolve ( sys -- ) T here - , H ;
620 :     >TARGET
621 :    
622 :     \ Structural Conditionals 12dec92py
623 :    
624 :     Cond: BUT restrict? sys? swap ;Cond
625 :     Cond: YET restrict? sys? dup ;Cond
626 :    
627 :     >CROSS
628 :     Variable tleavings
629 :     >TARGET
630 :    
631 :     Cond: DONE ( addr -- ) restrict? tleavings @
632 :     BEGIN 2dup u> 0= WHILE dup T @ H swap >resolve REPEAT
633 :     tleavings ! drop ;Cond
634 :    
635 :     >CROSS
636 :     : (leave T here H tleavings @ T , H tleavings ! ;
637 :     >TARGET
638 :    
639 :     Cond: LEAVE restrict? compile branch (leave ;Cond
640 :     Cond: ?LEAVE restrict? compile 0= compile ?branch (leave ;Cond
641 :    
642 :     \ Structural Conditionals 12dec92py
643 :    
644 :     Cond: AHEAD restrict? compile branch >mark ;Cond
645 :     Cond: IF restrict? compile ?branch >mark ;Cond
646 :     Cond: THEN restrict? sys? dup T @ H ?struc >resolve ;Cond
647 :     Cond: ELSE restrict? sys? compile AHEAD swap compile THEN ;Cond
648 :    
649 :     Cond: BEGIN restrict? T here H ;Cond
650 :     Cond: WHILE restrict? sys? compile IF swap ;Cond
651 :     Cond: AGAIN restrict? sys? compile branch <resolve ;Cond
652 :     Cond: UNTIL restrict? sys? compile ?branch <resolve ;Cond
653 :     Cond: REPEAT restrict? over 0= ?struc compile AGAIN compile THEN ;Cond
654 :    
655 :     \ Structural Conditionals 12dec92py
656 :    
657 :     Cond: DO restrict? compile (do) T here H ;Cond
658 :     Cond: ?DO restrict? compile (?do) (leave T here H ;Cond
659 :     Cond: FOR restrict? compile (for) T here H ;Cond
660 :    
661 :     >CROSS
662 :     : loop] dup <resolve cell - compile DONE compile unloop ;
663 :     >TARGET
664 :    
665 :     Cond: LOOP restrict? sys? compile (loop) loop] ;Cond
666 :     Cond: +LOOP restrict? sys? compile (+loop) loop] ;Cond
667 :     Cond: NEXT restrict? sys? compile (next) loop] ;Cond
668 :    
669 :     \ String words 23feb93py
670 :    
671 :     : ," [char] " parse string, T align H ;
672 :    
673 :     Cond: ." restrict? compile (.") T ," H ;Cond
674 :     Cond: S" restrict? compile (S") T ," H ;Cond
675 :     Cond: ABORT" restrict? compile (ABORT") T ," H ;Cond
676 :    
677 :     Cond: IS T ' >body H compile ALiteral compile ! ;Cond
678 :     : IS T ' >body ! H ;
679 : pazsan 1.9 Cond: TO T ' >body H compile ALiteral compile ! ;Cond
680 :     : TO T ' >body ! H ;
681 : anton 1.1
682 :     \ LINKED ERR" ENV" 2ENV" 18may93jaw
683 :    
684 :     \ linked list primitive
685 :     : linked T here over @ A, swap ! H ;
686 :    
687 :     : err" s" ErrLink linked" evaluate T , H
688 :     [char] " parse string, T align H ;
689 :    
690 :     : env" [char] " parse s" EnvLink linked" evaluate
691 :     string, T align , H ;
692 :    
693 :     : 2env" [char] " parse s" EnvLink linked" evaluate
694 :     here >r string, T align , , H
695 :     r> dup T c@ H 80 and swap T c! H ;
696 :    
697 :     \ compile must be last 22feb93py
698 :    
699 :     Cond: compile ( -- ) restrict? \ name
700 : pazsan 1.13 bl word gfind dup 0= ABORT" CROSS: Can't compile"
701 : anton 1.1 0> IF gexecute
702 :     ELSE dup >magic @ <imm> =
703 :     IF gexecute
704 :     ELSE compile (compile) gexecute THEN THEN ;Cond
705 :    
706 :     Cond: postpone ( -- ) restrict? \ name
707 : pazsan 1.13 bl word gfind dup 0= ABORT" CROSS: Can't compile"
708 : anton 1.1 0> IF gexecute
709 :     ELSE dup >magic @ <imm> =
710 :     IF gexecute
711 :     ELSE compile (compile) gexecute THEN THEN ;Cond
712 :    
713 :     >MINIMAL
714 :     also minimal
715 :     \ Usefull words 13feb93py
716 :    
717 :     : KB 400 * ;
718 :    
719 :     \ define new [IFDEF] and [IFUNDEF] 20may93jaw
720 :    
721 : pazsan 1.13 : there? bl word gfind IF >magic @ <fwd> <> ELSE drop false THEN ;
722 : anton 1.1
723 :     : [IFDEF] there? postpone [IF] ;
724 :     : [IFUNDEF] there? 0= postpone [IF] ;
725 :    
726 :     \ C: \- \+ Conditional Compiling 09jun93jaw
727 :    
728 :     : C: >in @ there? 0=
729 :     IF >in ! T : H
730 :     ELSE drop
731 :     BEGIN bl word dup c@
732 :     IF count comment? s" ;" compare 0= ?EXIT
733 :     ELSE refill 0= ABORT" CROSS: Out of Input while C:"
734 :     THEN
735 :     AGAIN
736 :     THEN ;
737 :    
738 :     also minimal
739 :    
740 :     : \- there? IF postpone \ THEN ;
741 :     : \+ there? 0= IF postpone \ THEN ;
742 :    
743 :     : [IF] postpone [IF] ;
744 :     : [THEN] postpone [THEN] ;
745 :     : [ELSE] postpone [ELSE] ;
746 :    
747 :     Cond: [IF] [IF] ;Cond
748 :     Cond: [IFDEF] [IFDEF] ;Cond
749 :     Cond: [IFUNDEF] [IFUNDEF] ;Cond
750 :     Cond: [THEN] [THEN] ;Cond
751 :     Cond: [ELSE] [ELSE] ;Cond
752 :    
753 :     \ save-cross 17mar93py
754 :    
755 :     \ i'm not interested in bigforth features this time 10may93jaw
756 :     \ [IFDEF] file
757 :     \ also file
758 :     \ [THEN]
759 :     \ included throw after create-file 11may93jaw
760 :    
761 : anton 1.12 bigendian Constant bigendian
762 : anton 1.1
763 :     : save-cross ( "name" -- )
764 :     bl parse ." Saving to " 2dup type
765 :     w/o bin create-file throw >r
766 : pazsan 1.16 s" gforth00" r@ write-file throw \ write magic
767 :     image @ there r@ write-file throw \ write image
768 :     bit$ @ there 1- cell>bit rshift 1+
769 :     r@ write-file throw \ write tags
770 : anton 1.1 r> close-file throw ;
771 :    
772 :     \ words that should be in minimal
773 :    
774 :     : + + ; : 1- 1- ;
775 :     : - - ; : 2* 2* ;
776 : pazsan 1.11 : * * ; : / / ;
777 : anton 1.1 : dup dup ; : over over ;
778 :     : swap swap ; : rot rot ;
779 : pazsan 1.19 : drop drop ; : = = ;
780 : pazsan 1.13 : lshift lshift ; : 2/ 2/ ;
781 : pazsan 1.19 : . . ;
782 : pazsan 1.13 cell constant cell
783 : anton 1.1
784 :     \ include bug5.fs
785 :     \ only forth also minimal definitions
786 :    
787 :     : \ postpone \ ;
788 :     : ( postpone ( ;
789 :     : include bl word count included ;
790 :     : .( [char] ) parse type ;
791 :     : cr cr ;
792 :    
793 :     : times 0 ?DO dup T c, H LOOP drop ; \ used for space table creation
794 :     only forth also minimal definitions
795 :    
796 :     \ cross-compiler words
797 :    
798 :     : decimal decimal ;
799 :     : hex hex ;
800 :    
801 : pazsan 1.3 : tudp T tudp H ;
802 :     : tup T tup H ; minimal
803 : anton 1.1
804 :     \ for debugging...
805 :     : order order ;
806 :     : words words ;
807 :     : .s .s ;
808 :    
809 :     : bye bye ;
810 :    
811 :     \ turnkey direction
812 :     : H forth ; immediate
813 :     : T minimal ; immediate
814 :     : G ghosts ; immediate
815 :    
816 :     : turnkey 0 set-order also Target definitions
817 :     also Minimal also ;
818 :    
819 :     \ these ones are pefered:
820 :    
821 :     : lock turnkey ;
822 :     : unlock forth also cross ;
823 :    
824 :     unlock definitions also minimal
825 :     : lock lock ;
826 :     lock

CVS Admin

Powered by ViewCVS 1.0-dev
(Powered by ViewCVS)

ViewCVS and CVS Help