[gforth] / gforth / cross.fs  

gforth: gforth/cross.fs


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

CVS Admin

Powered by ViewCVS 1.0-dev
(Powered by ViewCVS)

ViewCVS and CVS Help