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