[gforth] / gforth / prims2x.fs  

gforth: gforth/prims2x.fs


1 : anton 1.16 \ converts primitives to, e.g., C code
2 :    
3 :     \ Copyright (C) 1995 Free Software Foundation, Inc.
4 :    
5 :     \ This file is part of Gforth.
6 :    
7 :     \ Gforth is free software; you can redistribute it and/or
8 :     \ modify it under the terms of the GNU General Public License
9 :     \ as published by the Free Software Foundation; either version 2
10 :     \ of the License, or (at your option) any later version.
11 :    
12 :     \ This program is distributed in the hope that it will be useful,
13 :     \ but WITHOUT ANY WARRANTY; without even the implied warranty of
14 :     \ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 :     \ GNU General Public License for more details.
16 :    
17 :     \ You should have received a copy of the GNU General Public License
18 :     \ along with this program; if not, write to the Free Software
19 :     \ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 :    
21 :    
22 : anton 1.1 \ This is not very nice (hard limits, no checking, assumes 1 chars = 1)
23 :    
24 :     \ Optimizations:
25 :     \ superfluous stores are removed. GCC removes the superfluous loads by itself
26 :     \ TOS and FTOS can be kept in register( variable)s.
27 :     \
28 :     \ Problems:
29 :     \ The TOS optimization is somewhat hairy. The problems by example:
30 :     \ 1) dup ( w -- w w ): w=TOS; sp-=1; sp[1]=w; TOS=w;
31 :     \ The store is not superfluous although the earlier opt. would think so
32 :     \ Alternatively: sp[0]=TOS; w=TOS; sp-=1; TOS=w;
33 :     \ 2) ( -- .. ): sp[0] = TOS; ... /* This additional store is necessary */
34 :     \ 3) ( .. -- ): ... TOS = sp[0]; /* as well as this load */
35 :     \ 4) ( -- ): /* but here they are unnecessary */
36 :     \ 5) Words that call NEXT themselves have to be done very carefully.
37 :     \
38 :     \ To do:
39 : pazsan 1.8 \ add the store optimization for doubles
40 : anton 1.1 \ regarding problem 1 above: It would be better (for over) to implement
41 :     \ the alternative
42 :    
43 : pazsan 1.3 warnings off
44 :    
45 : pazsan 1.25 include extend.fs
46 :    
47 : anton 1.24 \ require interpretation.fs
48 : anton 1.18 require debugging.fs
49 : pazsan 1.11 [IFUNDEF] vocabulary include search-order.fs [THEN]
50 :     [IFUNDEF] environment? include environ.fs [THEN]
51 : anton 1.1 include gray.fs
52 :    
53 :     100 constant max-effect \ number of things on one side of a stack effect
54 :     255 constant maxchar
55 :     maxchar 1+ constant eof-char
56 : anton 1.17 #tab constant tab-char
57 :     #lf constant nl-char
58 : anton 1.1
59 :     : read-whole-file ( c-addr1 file-id -- c-addr2 )
60 :     \ reads the contents of the file file-id puts it into memory at c-addr1
61 :     \ c-addr2 is the first address after the file block
62 : anton 1.23 >r dup $7fffffff r> read-file throw + ;
63 : anton 1.1
64 : anton 1.18 variable rawinput \ pointer to next character to be scanned
65 :     variable endrawinput \ pointer to the end of the input (the char after the last)
66 :     variable cookedinput \ pointer to the next char to be parsed
67 : anton 1.17 variable line \ line number of char pointed to by input
68 :     1 line !
69 :     2variable filename \ filename of original input file
70 :     0 0 filename 2!
71 : pazsan 1.25 2variable f-comment
72 :     0 0 f-comment 2!
73 : anton 1.17 variable skipsynclines \ are sync lines ("#line ...") invisible to the parser?
74 :     skipsynclines on
75 : anton 1.1
76 : pazsan 1.26 Variable flush-comment flush-comment off
77 :    
78 :     : ?flush-comment
79 :     flush-comment @ 0= ?EXIT
80 :     f-comment 2@ nip
81 :     IF cr f-comment 2@ 2 /string type 0 0 f-comment 2! THEN ;
82 :    
83 : anton 1.1 : start ( -- addr )
84 : anton 1.18 cookedinput @ ;
85 : anton 1.1
86 :     : end ( addr -- addr u )
87 : anton 1.18 cookedinput @ over - ;
88 : anton 1.1
89 :     variable output \ xt ( -- ) of output word
90 :    
91 :     : printprim ( -- )
92 :     output @ execute ;
93 :    
94 :     : field
95 :     <builds-field ( n1 n2 -- n3 )
96 :     does> ( addr1 -- addr2 )
97 :     @ + ;
98 :    
99 :     : const-field
100 :     <builds-field ( n1 n2 -- n3 )
101 :     does> ( addr -- w )
102 :     @ + @ ;
103 :    
104 :     struct
105 :     2 cells field item-name
106 :     cell field item-d-offset
107 :     cell field item-f-offset
108 :     cell field item-type
109 :     constant item-descr
110 :    
111 :     2variable forth-name
112 :     2variable wordset
113 :     2variable c-name
114 :     2variable doc
115 :     2variable c-code
116 :     2variable forth-code
117 :     2variable stack-string
118 :     create effect-in max-effect item-descr * allot
119 :     create effect-out max-effect item-descr * allot
120 :     variable effect-in-end ( pointer )
121 :     variable effect-out-end ( pointer )
122 :     2variable effect-in-size
123 :     2variable effect-out-size
124 : anton 1.17 variable c-line
125 :     2variable c-filename
126 :     variable name-line
127 :     2variable name-filename
128 :     2variable last-name-filename
129 : anton 1.1
130 : pazsan 1.14 variable primitive-number -10 primitive-number !
131 : anton 1.1
132 :     \ for several reasons stack items of a word are stored in a wordlist
133 :     \ since neither forget nor marker are implemented yet, we make a new
134 :     \ wordlist for every word and store it in the variable items
135 :     variable items
136 :    
137 :     \ a few more set ops
138 :    
139 :     : bit-equivalent ( w1 w2 -- w3 )
140 :     xor invert ;
141 :    
142 :     : complement ( set1 -- set2 )
143 :     empty ['] bit-equivalent binary-set-operation ;
144 :    
145 :     \ the parser
146 :    
147 :     eof-char max-member \ the whole character set + EOF
148 :    
149 :     : getinput ( -- n )
150 : anton 1.18 rawinput @ endrawinput @ =
151 : anton 1.1 if
152 : anton 1.18 eof-char
153 : anton 1.1 else
154 : anton 1.18 cookedinput @ c@
155 : anton 1.1 endif ;
156 :    
157 :     :noname ( n -- )
158 :     dup bl > if
159 :     emit space
160 :     else
161 :     .
162 :     endif ;
163 :     print-token !
164 :    
165 :     : testchar? ( set -- f )
166 :     getinput member? ;
167 :     ' testchar? test-vector !
168 :    
169 : anton 1.17 : checksyncline ( -- )
170 :     \ when input points to a newline, check if the next line is a
171 :     \ sync line. If it is, perform the appropriate actions.
172 : anton 1.18 rawinput @ >r
173 : anton 1.17 s" #line " r@ over compare 0<> if
174 :     rdrop 1 line +! EXIT
175 :     endif
176 :     0. r> 6 chars + 20 >number drop >r drop line ! r> ( c-addr )
177 :     dup c@ bl = if
178 :     char+ dup c@ [char] " <> abort" sync line syntax"
179 : anton 1.24 char+ dup 100 [char] " scan drop swap 2dup - save-mem filename 2!
180 : anton 1.17 char+
181 :     endif
182 :     dup c@ nl-char <> abort" sync line syntax"
183 :     skipsynclines @ if
184 : anton 1.18 dup char+ rawinput !
185 :     rawinput @ c@ cookedinput @ c!
186 : anton 1.17 endif
187 :     drop ;
188 :    
189 : anton 1.1 : ?nextchar ( f -- )
190 : anton 1.17 ?not? if
191 : anton 1.18 filename 2@ type ." :" line @ 0 .r ." : syntax error, wrong char:"
192 : anton 1.17 getinput . cr
193 : anton 1.18 rawinput @ endrawinput @ over - 100 min type cr
194 : anton 1.17 abort
195 :     endif
196 : anton 1.18 rawinput @ endrawinput @ <> if
197 :     rawinput @ c@
198 :     1 chars rawinput +!
199 :     1 chars cookedinput +!
200 : anton 1.17 nl-char = if
201 :     checksyncline
202 :     endif
203 : anton 1.18 rawinput @ c@ cookedinput @ c!
204 : anton 1.17 endif ;
205 : anton 1.1
206 :     : charclass ( set "name" -- )
207 :     ['] ?nextchar terminal ;
208 :    
209 :     : .. ( c1 c2 -- set )
210 :     ( creates a set that includes the characters c, c1<=c<=c2 )
211 :     empty copy-set
212 :     swap 1+ rot do
213 :     i over add-member
214 :     loop ;
215 :    
216 :     : ` ( -- terminal ) ( use: ` c )
217 :     ( creates anonymous terminal for the character c )
218 : anton 1.21 char singleton ['] ?nextchar make-terminal ;
219 : anton 1.1
220 :     char a char z .. char A char Z .. union char _ singleton union charclass letter
221 :     char 0 char 9 .. charclass digit
222 :     bl singleton charclass blank
223 :     tab-char singleton charclass tab
224 :     nl-char singleton eof-char over add-member complement charclass nonl
225 :     nl-char singleton eof-char over add-member char : over add-member complement charclass nocolonnl
226 :     bl 1+ maxchar .. charclass nowhite
227 :     char " singleton eof-char over add-member complement charclass noquote
228 :     nl-char singleton charclass nl
229 :     eof-char singleton charclass eof
230 :    
231 :    
232 :     (( letter (( letter || digit )) **
233 :     )) <- c-name ( -- )
234 :    
235 :     nowhite ++
236 :     <- name ( -- )
237 :    
238 : pazsan 1.26 (( {{ ?flush-comment start }} ` \ nonl ** nl {{ end
239 : pazsan 1.25 2dup 2 min s" \+" compare 0= IF f-comment 2! ELSE 2drop THEN }}
240 : anton 1.1 )) <- comment ( -- )
241 :    
242 :     (( {{ effect-in }} (( {{ start }} c-name {{ end 2 pick item-name 2! item-descr + }} blank ** )) ** {{ effect-in-end ! }}
243 :     ` - ` - blank **
244 :     {{ effect-out }} (( {{ start }} c-name {{ end 2 pick item-name 2! item-descr + }} blank ** )) ** {{ effect-out-end ! }}
245 :     )) <- stack-effect ( -- )
246 :    
247 :     (( {{ s" " doc 2! s" " forth-code 2! }}
248 :     (( comment || nl )) **
249 : anton 1.17 (( {{ line @ name-line ! filename 2@ name-filename 2! }}
250 :     {{ start }} name {{ end 2dup forth-name 2! c-name 2! }} tab ++
251 : anton 1.1 {{ start }} stack-effect {{ end stack-string 2! }} tab ++
252 :     {{ start }} name {{ end wordset 2! }} tab **
253 :     (( {{ start }} c-name {{ end c-name 2! }} )) ?? nl
254 :     ))
255 :     (( ` " ` " {{ start }} (( noquote ++ ` " )) ++ {{ end 1- doc 2! }} ` " nl )) ??
256 : anton 1.18 {{ skipsynclines off line @ c-line ! filename 2@ c-filename 2! start }} (( nocolonnl nonl ** nl )) ** {{ end c-code 2! skipsynclines on }}
257 : anton 1.1 (( ` : nl
258 :     {{ start }} (( nonl ++ nl )) ++ {{ end forth-code 2! }}
259 :     )) ??
260 :     (( nl || eof ))
261 :     )) <- primitive ( -- )
262 :    
263 :     (( (( primitive {{ printprim }} )) ** eof ))
264 :     parser primitives2something
265 : pazsan 1.3 warnings @ [IF]
266 : anton 1.1 .( parser generated ok ) cr
267 : pazsan 1.3 [THEN]
268 : anton 1.1
269 :     : primfilter ( file-id xt -- )
270 :     \ fileid is for the input file, xt ( -- ) is for the output word
271 :     output !
272 : anton 1.18 here dup rawinput ! cookedinput !
273 : anton 1.1 here swap read-whole-file
274 : anton 1.18 dup endrawinput !
275 : anton 1.1 here - allot
276 : pazsan 1.2 align
277 : anton 1.17 checksyncline
278 : anton 1.18 \ begin
279 :     \ getinput dup eof-char = ?EXIT emit true ?nextchar
280 :     \ again ;
281 : anton 1.1 primitives2something ;
282 :    
283 :     \ types
284 :    
285 :     struct
286 :     2 cells field type-c-name
287 :     cell const-field type-d-size
288 :     cell const-field type-f-size
289 :     cell const-field type-fetch-handler
290 :     cell const-field type-store-handler
291 :     constant type-description
292 :    
293 :     : data-stack-access ( n1 n2 n3 -- )
294 :     \ n1 is the offset of the accessed item, n2, n3 are effect-*-size
295 :     drop swap - 1- dup
296 :     if
297 : pazsan 1.2 ." sp[" 0 .r ." ]"
298 : anton 1.1 else
299 :     drop ." TOS"
300 :     endif ;
301 :    
302 :     : fp-stack-access ( n1 n2 n3 -- )
303 :     \ n1 is the offset of the accessed item, n2, n3 are effect-*-size
304 :     nip swap - 1- dup
305 :     if
306 : pazsan 1.2 ." fp[" 0 .r ." ]"
307 : anton 1.1 else
308 :     drop ." FTOS"
309 :     endif ;
310 :    
311 :     : fetch-single ( item -- )
312 :     >r
313 : pazsan 1.8 r@ item-name 2@ type
314 :     ." = ("
315 : anton 1.1 r@ item-type @ type-c-name 2@ type ." ) "
316 :     r@ item-d-offset @ effect-in-size 2@ data-stack-access ." ;" cr
317 :     rdrop ;
318 :    
319 :     : fetch-double ( item -- )
320 :     >r
321 : anton 1.20 ." FETCH_DCELL("
322 :     r@ item-name 2@ type ." , "
323 : anton 1.1 r@ item-d-offset @ dup effect-in-size 2@ data-stack-access
324 : anton 1.20 ." , " 1+ effect-in-size 2@ data-stack-access
325 :     ." );" cr
326 : anton 1.1 rdrop ;
327 :    
328 :     : fetch-float ( item -- )
329 :     >r
330 : pazsan 1.8 r@ item-name 2@ type
331 :     ." = "
332 : anton 1.1 \ ." (" r@ item-type @ type-c-name 2@ type ." ) "
333 :     r@ item-f-offset @ effect-in-size 2@ fp-stack-access ." ;" cr
334 :     rdrop ;
335 :    
336 :     : d-same-as-in? ( item -- f )
337 :     \ f is true iff the offset of item is the same as on input
338 :     >r
339 :     r@ item-name 2@ items @ search-wordlist 0=
340 : pazsan 1.8 abort" bug"
341 : anton 1.1 execute @
342 :     dup r@ =
343 :     if \ item first appeared in output
344 :     drop false
345 :     else
346 :     item-d-offset @ r@ item-d-offset @ =
347 :     endif
348 :     rdrop ;
349 :    
350 :     : is-in-tos? ( item -- f )
351 :     \ true if item has the same offset as the input TOS
352 :     item-d-offset @ 1+ effect-in-size 2@ drop = ;
353 :    
354 :     : really-store-single ( item -- )
355 :     >r
356 :     r@ item-d-offset @ effect-out-size 2@ data-stack-access ." = (Cell)"
357 :     r@ item-name 2@ type ." ;"
358 :     rdrop ;
359 :    
360 :     : store-single ( item -- )
361 :     >r
362 :     r@ d-same-as-in?
363 :     if
364 :     r@ is-in-tos?
365 :     if
366 :     ." IF_TOS(" r@ really-store-single ." );" cr
367 :     endif
368 :     else
369 :     r@ really-store-single cr
370 :     endif
371 :     rdrop ;
372 :    
373 :     : store-double ( item -- )
374 :     \ !! store optimization is not performed, because it is not yet needed
375 :     >r
376 : anton 1.20 ." STORE_DCELL(" r@ item-name 2@ type ." , "
377 :     r@ item-d-offset @ dup effect-out-size 2@ data-stack-access
378 :     ." , " 1+ effect-out-size 2@ data-stack-access
379 :     ." );" cr
380 : anton 1.1 rdrop ;
381 :    
382 :     : f-same-as-in? ( item -- f )
383 :     \ f is true iff the offset of item is the same as on input
384 :     >r
385 :     r@ item-name 2@ items @ search-wordlist 0=
386 : pazsan 1.8 abort" bug"
387 : anton 1.1 execute @
388 :     dup r@ =
389 :     if \ item first appeared in output
390 :     drop false
391 :     else
392 :     item-f-offset @ r@ item-f-offset @ =
393 :     endif
394 :     rdrop ;
395 :    
396 :     : is-in-ftos? ( item -- f )
397 :     \ true if item has the same offset as the input TOS
398 :     item-f-offset @ 1+ effect-in-size 2@ nip = ;
399 :    
400 :     : really-store-float ( item -- )
401 :     >r
402 :     r@ item-f-offset @ effect-out-size 2@ fp-stack-access ." = "
403 :     r@ item-name 2@ type ." ;"
404 :     rdrop ;
405 :    
406 :     : store-float ( item -- )
407 :     >r
408 :     r@ f-same-as-in?
409 :     if
410 :     r@ is-in-ftos?
411 :     if
412 :     ." IF_FTOS(" r@ really-store-float ." );" cr
413 :     endif
414 :     else
415 :     r@ really-store-float cr
416 :     endif
417 :     rdrop ;
418 :    
419 : anton 1.10 : single-type ( -- xt1 xt2 n1 n2 )
420 : anton 1.1 ['] fetch-single ['] store-single 1 0 ;
421 :    
422 : anton 1.10 : double-type ( -- xt1 xt2 n1 n2 )
423 : anton 1.1 ['] fetch-double ['] store-double 2 0 ;
424 :    
425 : anton 1.10 : float-type ( -- xt1 xt2 n1 n2 )
426 : anton 1.1 ['] fetch-float ['] store-float 0 1 ;
427 :    
428 :     : s, ( addr u -- )
429 :     \ allocate a string
430 :     here swap dup allot move ;
431 :    
432 :     : starts-with ( addr u xt1 xt2 n1 n2 "prefix" -- )
433 :     \ describes a type
434 :     \ addr u specifies the C type name
435 :     \ n1 is the size of the type on the data stack
436 :     \ n2 is the size of the type on the FP stack
437 :     \ stack effect entries of the type start with prefix
438 :     >r >r >r >r
439 :     dup >r here >r s,
440 :     create
441 :     r> r> 2,
442 :     r> r> r> , r> , swap , , ;
443 :    
444 :     wordlist constant types
445 :     get-current
446 :     types set-current
447 :    
448 :     s" Bool" single-type starts-with f
449 :     s" Char" single-type starts-with c
450 :     s" Cell" single-type starts-with n
451 :     s" Cell" single-type starts-with w
452 :     s" UCell" single-type starts-with u
453 :     s" DCell" double-type starts-with d
454 :     s" UDCell" double-type starts-with ud
455 :     s" Float" float-type starts-with r
456 :     s" Cell *" single-type starts-with a_
457 :     s" Char *" single-type starts-with c_
458 :     s" Float *" single-type starts-with f_
459 :     s" DFloat *" single-type starts-with df_
460 :     s" SFloat *" single-type starts-with sf_
461 :     s" Xt" single-type starts-with xt
462 :     s" WID" single-type starts-with wid
463 :     s" F83Name *" single-type starts-with f83name
464 :    
465 :     set-current
466 :    
467 :     : get-type ( addr1 u1 -- type-descr )
468 :     \ get the type of the name in addr1 u1
469 :     \ type-descr is a pointer to a type-descriptor
470 :     0 swap ?do
471 :     dup i types search-wordlist
472 :     if \ ok, we have the type ( addr1 xt )
473 :     execute nip
474 :     UNLOOP EXIT
475 :     endif
476 : anton 1.9 -1 s+loop
477 : anton 1.1 \ we did not find a type, abort
478 : pazsan 1.8 true abort" unknown type prefix" ;
479 : anton 1.1
480 :     : declare ( addr "name" -- )
481 :     \ remember that there is a stack item at addr called name
482 :     create , ;
483 :    
484 :     : declaration ( item -- )
485 :     dup item-name 2@ items @ search-wordlist
486 :     if \ already declared ( item xt )
487 :     execute @ item-type @ swap item-type !
488 :     else ( addr )
489 :     dup item-name 2@ nextname dup declare ( addr )
490 :     dup >r item-name 2@ 2dup get-type ( addr1 u type-descr )
491 :     dup r> item-type ! ( addr1 u type-descr )
492 :     type-c-name 2@ type space type ." ;" cr
493 :     endif ;
494 :    
495 :     : declaration-list ( addr1 addr2 -- )
496 :     swap ?do
497 :     i declaration
498 :     item-descr +loop ;
499 :    
500 : pazsan 1.8 : fetch ( addr -- )
501 :     dup item-type @ type-fetch-handler execute ;
502 :    
503 : anton 1.1 : declarations ( -- )
504 :     wordlist dup items ! set-current
505 :     effect-in effect-in-end @ declaration-list
506 :     effect-out effect-out-end @ declaration-list ;
507 :    
508 :     \ offset computation
509 :     \ the leftmost (i.e. deepest) item has offset 0
510 :     \ the rightmost item has the highest offset
511 :    
512 :     : compute-offset ( n1 n2 item -- n3 n4 )
513 :     \ n1, n3 are data-stack-offsets
514 :     \ n2, n4 are the fp-stack-offsets
515 :     >r
516 :     swap dup r@ item-d-offset !
517 :     r@ item-type @ type-d-size +
518 :     swap dup r@ item-f-offset !
519 :     r@ item-type @ type-f-size +
520 :     rdrop ;
521 :    
522 :     : compute-list ( addr1 addr2 -- n1 n2 )
523 :     \ n1, n2 are the final offsets
524 :     0 0 2swap swap ?do
525 :     i compute-offset
526 :     item-descr +loop ;
527 :    
528 :     : compute-offsets ( -- )
529 :     effect-in effect-in-end @ compute-list effect-in-size 2!
530 :     effect-out effect-out-end @ compute-list effect-out-size 2! ;
531 :    
532 :     : flush-tos ( -- )
533 :     effect-in-size 2@ effect-out-size 2@
534 :     0<> rot 0= and
535 :     if
536 : anton 1.13 ." IF_FTOS(fp[0] = FTOS);" cr
537 :     endif
538 : anton 1.1 0<> swap 0= and
539 :     if
540 : anton 1.13 ." IF_TOS(sp[0] = TOS);" cr
541 :     endif ;
542 : anton 1.1
543 :     : fill-tos ( -- )
544 :     effect-in-size 2@ effect-out-size 2@
545 :     0= rot 0<> and
546 :     if
547 :     ." IF_FTOS(FTOS = fp[0]);" cr
548 :     endif
549 :     0= swap 0<> and
550 :     if
551 :     ." IF_TOS(TOS = sp[0]);" cr
552 :     endif ;
553 :    
554 :     : fetches ( -- )
555 :     effect-in-end @ effect-in ?do
556 :     i fetch
557 :     item-descr +loop ;
558 :    
559 :     : stack-pointer-updates ( -- )
560 : pazsan 1.8 \ we need not check if an update is a noop; gcc does this for us
561 : anton 1.1 effect-in-size 2@
562 :     effect-out-size 2@
563 :     rot swap - ( d-in d-out f-diff )
564 :     rot rot - ( f-diff d-diff )
565 : pazsan 1.2 ?dup IF ." sp += " 0 .r ." ;" cr THEN
566 :     ?dup IF ." fp += " 0 .r ." ;" cr THEN ;
567 : anton 1.1
568 :     : store ( item -- )
569 :     \ f is true if the item should be stored
570 :     \ f is false if the store is probably not necessary
571 :     dup item-type @ type-store-handler execute ;
572 :    
573 :     : stores ( -- )
574 :     effect-out-end @ effect-out ?do
575 :     i store
576 :     item-descr +loop ;
577 :    
578 : pazsan 1.8 : .stack-list ( start end -- )
579 :     swap ?do
580 :     i item-name 2@ type space
581 :     item-descr +loop ;
582 :    
583 : anton 1.1 : output-c ( -- )
584 : pazsan 1.2 ." I_" c-name 2@ type ." : /* " forth-name 2@ type ." ( " stack-string 2@ type ." ) */" cr
585 : anton 1.1 ." /* " doc 2@ type ." */" cr
586 : anton 1.13 ." NAME(" [char] " emit forth-name 2@ type [char] " emit ." )" cr \ debugging
587 : anton 1.1 ." {" cr
588 :     ." DEF_CA" cr
589 :     declarations
590 :     compute-offsets \ for everything else
591 : anton 1.13 ." NEXT_P0;" cr
592 :     flush-tos
593 : anton 1.1 fetches
594 : anton 1.13 stack-pointer-updates
595 : anton 1.1 ." {" cr
596 : anton 1.17 ." #line " c-line @ . [char] " emit c-filename 2@ type [char] " emit cr
597 : anton 1.1 c-code 2@ type
598 :     ." }" cr
599 :     ." NEXT_P1;" cr
600 :     stores
601 :     fill-tos
602 : anton 1.9 ." NEXT_P2;" cr
603 : anton 1.1 ." }" cr
604 :     cr
605 :     ;
606 :    
607 :     : output-label ( -- )
608 :     ." &&I_" c-name 2@ type ." ," cr ;
609 :    
610 : pazsan 1.26 : output-alias ( -- ) flush-comment on
611 :     ?flush-comment
612 : anton 1.1 primitive-number @ . ." alias " forth-name 2@ type cr
613 :     -1 primitive-number +! ;
614 :    
615 : pazsan 1.26 : output-forth ( -- ) flush-comment on
616 :     ?flush-comment
617 : pazsan 1.8 forth-code @ 0=
618 :     IF output-alias
619 :     ELSE ." : " forth-name 2@ type ." ( "
620 :     effect-in effect-in-end @ .stack-list ." -- "
621 :     effect-out effect-out-end @ .stack-list ." )" cr
622 :     forth-code 2@ type cr
623 :     -1 primitive-number +!
624 : anton 1.10 THEN ;
625 :    
626 : anton 1.17 : output-tag-file ( -- )
627 :     name-filename 2@ last-name-filename 2@ compare if
628 :     name-filename 2@ last-name-filename 2!
629 :     #ff emit cr
630 :     name-filename 2@ type
631 :     ." ,0" cr
632 :     endif ;
633 :    
634 :     : output-tag ( -- )
635 :     output-tag-file
636 :     forth-name 2@ 1+ type
637 :     127 emit
638 :     space forth-name 2@ type space
639 :     1 emit
640 :     name-line @ 0 .r
641 :     ." ,0" cr ;
642 :    
643 : anton 1.10 [IFDEF] documentation
644 :     : register-doc ( -- )
645 :     get-current documentation set-current
646 :     forth-name 2@ nextname create
647 :     forth-name 2@ 2,
648 : anton 1.15 stack-string 2@ condition-stack-effect 2,
649 : anton 1.10 wordset 2@ 2,
650 : anton 1.15 c-name 2@ condition-pronounciation 2,
651 : anton 1.10 doc 2@ 2,
652 :     set-current ;
653 :     [THEN]
654 : pazsan 1.8
655 : anton 1.1 : process-file ( addr u xt -- )
656 : anton 1.17 >r
657 :     2dup filename 2!
658 :     r/o open-file abort" cannot open file"
659 :     warnings @ if
660 :     ." ------------ CUT HERE -------------" cr endif
661 :     r> primfilter ;
662 : pazsan 1.5

CVS Admin

Powered by ViewCVS 1.0-dev
(Powered by ViewCVS)

ViewCVS and CVS Help