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

CVS Admin

Powered by ViewCVS 1.0-dev
(Powered by ViewCVS)

ViewCVS and CVS Help