[gforth] / gforth / prims2x.fs  

gforth: gforth/prims2x.fs


1 : anton 1.16 \ converts primitives to, e.g., C code
2 :    
3 : anton 1.47 \ Copyright (C) 1995,1996,1997,1998,2000 Free Software Foundation, Inc.
4 : anton 1.16
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 : anton 1.48 \ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
20 : anton 1.16
21 :    
22 : anton 1.71 \ This is not very nice (hard limits, no checking, assumes 1 chars = 1).
23 :     \ And it grew even worse when it aged.
24 : anton 1.1
25 :     \ Optimizations:
26 :     \ superfluous stores are removed. GCC removes the superfluous loads by itself
27 :     \ TOS and FTOS can be kept in register( variable)s.
28 :     \
29 :     \ Problems:
30 :     \ The TOS optimization is somewhat hairy. The problems by example:
31 :     \ 1) dup ( w -- w w ): w=TOS; sp-=1; sp[1]=w; TOS=w;
32 :     \ The store is not superfluous although the earlier opt. would think so
33 :     \ Alternatively: sp[0]=TOS; w=TOS; sp-=1; TOS=w;
34 :     \ 2) ( -- .. ): sp[0] = TOS; ... /* This additional store is necessary */
35 :     \ 3) ( .. -- ): ... TOS = sp[0]; /* as well as this load */
36 :     \ 4) ( -- ): /* but here they are unnecessary */
37 :     \ 5) Words that call NEXT themselves have to be done very carefully.
38 :     \
39 :     \ To do:
40 : pazsan 1.8 \ add the store optimization for doubles
41 : anton 1.1 \ regarding problem 1 above: It would be better (for over) to implement
42 :     \ the alternative
43 :    
44 : pazsan 1.3 warnings off
45 :    
46 : jwilke 1.39 [IFUNDEF] vocabulary \ we are executed just with kernel image
47 :     \ load the rest that is needed
48 :     \ (require fails because this file is needed from a
49 :     \ different directory with the wordlibraries)
50 :     include ./search.fs
51 :     include ./extend.fs
52 : anton 1.40 [THEN]
53 : pazsan 1.76 include ./stuff.fs
54 : anton 1.40
55 :     [IFUNDEF] environment?
56 : jwilke 1.39 include ./environ.fs
57 :     [THEN]
58 : pazsan 1.25
59 : anton 1.49 : struct% struct ; \ struct is redefined in gray
60 :    
61 : jwilke 1.39 include ./gray.fs
62 : anton 1.1
63 : anton 1.69 32 constant max-effect \ number of things on one side of a stack effect
64 : anton 1.71 4 constant max-stacks \ the max. number of stacks (including inst-stream).
65 : anton 1.1 255 constant maxchar
66 :     maxchar 1+ constant eof-char
67 : anton 1.17 #tab constant tab-char
68 :     #lf constant nl-char
69 : anton 1.1
70 : anton 1.18 variable rawinput \ pointer to next character to be scanned
71 :     variable endrawinput \ pointer to the end of the input (the char after the last)
72 :     variable cookedinput \ pointer to the next char to be parsed
73 : anton 1.17 variable line \ line number of char pointed to by input
74 : anton 1.65 variable line-start \ pointer to start of current line (for error messages)
75 :     0 line !
76 : anton 1.17 2variable filename \ filename of original input file
77 :     0 0 filename 2!
78 : pazsan 1.25 2variable f-comment
79 :     0 0 f-comment 2!
80 : anton 1.17 variable skipsynclines \ are sync lines ("#line ...") invisible to the parser?
81 :     skipsynclines on
82 : anton 1.1
83 : anton 1.72 : th ( addr1 n -- addr2 )
84 :     cells + ;
85 :    
86 :     : holds ( addr u -- )
87 :     \ like HOLD, but for a string
88 :     tuck + swap 0 +do
89 :     1- dup c@ hold
90 :     loop
91 :     drop ;
92 : anton 1.71
93 : anton 1.1 : start ( -- addr )
94 : anton 1.18 cookedinput @ ;
95 : anton 1.1
96 :     : end ( addr -- addr u )
97 : anton 1.18 cookedinput @ over - ;
98 : anton 1.1
99 : anton 1.71 : print-error-line ( -- )
100 :     \ print the current line and position
101 :     line-start @ endrawinput @ over - 2dup nl-char scan drop nip ( start end )
102 :     over - type cr
103 :     line-start @ rawinput @ over - typewhite ." ^" cr ;
104 :    
105 :     : ?print-error { f addr u -- }
106 :     f ?not? if
107 :     outfile-id >r try
108 :     stderr to outfile-id
109 :     filename 2@ type ." :" line @ 0 .r ." : " addr u type cr
110 :     print-error-line
111 :     0
112 :     recover endtry
113 :     r> to outfile-id throw
114 :     abort
115 :     endif ;
116 :    
117 : anton 1.63 : quote ( -- )
118 :     [char] " emit ;
119 :    
120 : anton 1.72 variable output \ xt ( -- ) of output word for simple primitives
121 :     variable output-combined \ xt ( -- ) of output word for combined primitives
122 : anton 1.1
123 :     : printprim ( -- )
124 :     output @ execute ;
125 :    
126 : anton 1.49 struct%
127 : anton 1.71 cell% field stack-number \ the number of this stack
128 : anton 1.49 cell% 2* field stack-pointer \ stackpointer name
129 : anton 1.74 cell% field stack-type \ name for default type of stack items
130 : anton 1.49 cell% 2* field stack-cast \ cast string for assignments to stack elements
131 : anton 1.53 cell% field stack-in-index-xt \ ( in-size item -- in-index )
132 : anton 1.49 end-struct stack%
133 :    
134 : anton 1.53 struct%
135 :     cell% 2* field item-name \ name, excluding stack prefixes
136 :     cell% field item-stack \ descriptor for the stack used, 0 is default
137 :     cell% field item-type \ descriptor for the item type
138 :     cell% field item-offset \ offset in stack items, 0 for the deepest element
139 : anton 1.66 cell% field item-first \ true if this is the first occurence of the item
140 : anton 1.53 end-struct item%
141 :    
142 :     struct%
143 :     cell% 2* field type-c-name
144 :     cell% field type-stack \ default stack
145 :     cell% field type-size \ size of type in stack items
146 :     cell% field type-fetch \ xt of fetch code generator ( item -- )
147 :     cell% field type-store \ xt of store code generator ( item -- )
148 :     end-struct type%
149 :    
150 : anton 1.72 variable next-stack-number 0 next-stack-number !
151 :     create stacks max-stacks cells allot \ array of stacks
152 :    
153 : anton 1.53 : stack-in-index ( in-size item -- in-index )
154 :     item-offset @ - 1- ;
155 :    
156 :     : inst-in-index ( in-size item -- in-index )
157 :     nip dup item-offset @ swap item-type @ type-size @ + 1- ;
158 :    
159 : anton 1.74 : make-stack ( addr-ptr u1 type addr-cast u2 "stack-name" -- )
160 : anton 1.49 create stack% %allot >r
161 : anton 1.72 r@ stacks next-stack-number @ th !
162 : anton 1.71 next-stack-number @ r@ stack-number ! 1 next-stack-number +!
163 : anton 1.49 save-mem r@ stack-cast 2!
164 : anton 1.74 r@ stack-type !
165 : anton 1.53 save-mem r@ stack-pointer 2!
166 :     ['] stack-in-index r> stack-in-index-xt ! ;
167 : anton 1.49
168 :     \ stack items
169 :    
170 :     : init-item ( addr u addr1 -- )
171 :     \ initialize item at addr1 with name addr u
172 :     \ !! remove stack prefix
173 :     dup item% %size erase
174 :     item-name 2! ;
175 :    
176 : anton 1.64 : map-items { addr end xt -- }
177 :     \ perform xt for all items in array addr...end
178 :     end addr ?do
179 :     i xt execute
180 :     item% %size +loop ;
181 :    
182 : anton 1.77 \ types
183 :    
184 :     : print-type-prefix ( type -- )
185 :     body> >head name>string type ;
186 :    
187 : anton 1.49 \ various variables for storing stuff of one primitive
188 : anton 1.1
189 : anton 1.69 struct%
190 :     cell% 2* field prim-name
191 :     cell% 2* field prim-wordset
192 :     cell% 2* field prim-c-name
193 :     cell% 2* field prim-doc
194 :     cell% 2* field prim-c-code
195 :     cell% 2* field prim-forth-code
196 :     cell% 2* field prim-stack-string
197 : anton 1.75 cell% field prim-items-wordlist \ unique items
198 : anton 1.69 item% max-effect * field prim-effect-in
199 :     item% max-effect * field prim-effect-out
200 :     cell% field prim-effect-in-end
201 :     cell% field prim-effect-out-end
202 : anton 1.71 cell% max-stacks * field prim-stacks-in \ number of in items per stack
203 :     cell% max-stacks * field prim-stacks-out \ number of out items per stack
204 : anton 1.69 end-struct prim%
205 :    
206 : anton 1.70 : make-prim ( -- prim )
207 :     prim% %alloc { p }
208 :     s" " p prim-doc 2! s" " p prim-forth-code 2! s" " p prim-wordset 2!
209 :     p ;
210 :    
211 : anton 1.79 0 value prim \ in combined prims either combined or a part
212 :     0 value combined \ in combined prims the combined prim
213 :     variable in-part \ true if processing a part
214 :     in-part off
215 :    
216 :     1000 constant max-combined
217 :     create combined-prims max-combined cells allot
218 :     variable num-combined
219 :    
220 :     create current-depth max-stacks cells allot
221 :     create max-depth max-stacks cells allot
222 :     create min-depth max-stacks cells allot
223 : anton 1.69
224 : anton 1.71 wordlist constant primitives
225 :    
226 :     : create-prim ( prim -- )
227 :     get-current >r
228 :     primitives set-current
229 :     dup prim-name 2@ nextname constant
230 :     r> set-current ;
231 :    
232 :     : stack-in ( stack -- addr )
233 :     \ address of number of stack items in effect in
234 :     stack-number @ cells prim prim-stacks-in + ;
235 :    
236 :     : stack-out ( stack -- addr )
237 :     \ address of number of stack items in effect out
238 :     stack-number @ cells prim prim-stacks-out + ;
239 :    
240 : anton 1.69 \ global vars
241 : anton 1.17 variable c-line
242 :     2variable c-filename
243 :     variable name-line
244 :     2variable name-filename
245 :     2variable last-name-filename
246 : pazsan 1.30 Variable function-number 0 function-number !
247 : anton 1.1
248 :     \ a few more set ops
249 :    
250 :     : bit-equivalent ( w1 w2 -- w3 )
251 :     xor invert ;
252 :    
253 :     : complement ( set1 -- set2 )
254 :     empty ['] bit-equivalent binary-set-operation ;
255 :    
256 :     \ types
257 :    
258 : anton 1.79
259 :     : normal-stack-access ( n stack -- )
260 : anton 1.49 stack-pointer 2@ type
261 :     dup
262 :     if
263 :     ." [" 0 .r ." ]"
264 :     else
265 :     drop ." TOS"
266 :     endif ;
267 : anton 1.1
268 : anton 1.79 : part-stack-access { n stack -- }
269 :     \ print _<stack><x>, x=maxdepth-currentdepth-n-1
270 :     ." _" stack stack-pointer 2@ type
271 :     stack stack-number @ { stack# }
272 :     combined prim-stacks-in stack# th @ assert( dup max-depth stack# th @ = )
273 :     current-depth stack# th @ - n - 1-
274 :     0 .r ;
275 :    
276 :     : stack-access ( n stack -- )
277 :     \ print a stack access at index n of stack
278 :     in-part @ if
279 :     part-stack-access
280 :     else
281 :     normal-stack-access
282 :     endif ;
283 :    
284 : anton 1.53 : item-in-index { item -- n }
285 : anton 1.49 \ n is the index of item (in the in-effect)
286 : anton 1.53 item item-stack @ dup >r stack-in @ ( in-size r:stack )
287 :     item r> stack-in-index-xt @ execute ;
288 : anton 1.1
289 : anton 1.78 : item-stack-type-name ( item -- addr u )
290 :     item-stack @ stack-type @ type-c-name 2@ ;
291 :    
292 : anton 1.1 : fetch-single ( item -- )
293 : anton 1.49 \ fetch a single stack item from its stack
294 : anton 1.1 >r
295 : pazsan 1.8 r@ item-name 2@ type
296 : anton 1.78 ." = vm_" r@ item-stack-type-name type
297 : anton 1.77 ." 2" r@ item-type @ print-type-prefix ." ("
298 : anton 1.49 r@ item-in-index r@ item-stack @ stack-access
299 : anton 1.77 ." );" cr
300 : anton 1.1 rdrop ;
301 :    
302 :     : fetch-double ( item -- )
303 : anton 1.49 \ fetch a double stack item from its stack
304 : anton 1.1 >r
305 : anton 1.78 ." vm_two"
306 :     r@ item-stack-type-name type ." 2"
307 :     r@ item-type @ print-type-prefix ." ("
308 : anton 1.20 r@ item-name 2@ type ." , "
309 : anton 1.61 r@ item-in-index r@ item-stack @ 2dup ." (Cell)" stack-access
310 :     ." , " -1 under+ ." (Cell)" stack-access
311 : anton 1.20 ." );" cr
312 : anton 1.1 rdrop ;
313 :    
314 : anton 1.49 : same-as-in? ( item -- f )
315 :     \ f is true iff the offset and stack of item is the same as on input
316 : anton 1.1 >r
317 : anton 1.74 r@ item-first @ if
318 :     rdrop false exit
319 :     endif
320 : anton 1.75 r@ item-name 2@ prim prim-items-wordlist @ search-wordlist 0= abort" bug"
321 : anton 1.1 execute @
322 :     dup r@ =
323 :     if \ item first appeared in output
324 :     drop false
325 :     else
326 : anton 1.49 dup item-stack @ r@ item-stack @ =
327 :     swap item-offset @ r@ item-offset @ = and
328 : anton 1.1 endif
329 :     rdrop ;
330 :    
331 : anton 1.49 : item-out-index ( item -- n )
332 :     \ n is the index of item (in the in-effect)
333 :     >r r@ item-stack @ stack-out @ r> item-offset @ - 1- ;
334 : pazsan 1.31
335 : anton 1.1 : really-store-single ( item -- )
336 :     >r
337 : anton 1.77 r@ item-out-index r@ item-stack @ stack-access ." = vm_"
338 :     r@ item-type @ print-type-prefix ." 2"
339 : anton 1.78 r@ item-stack-type-name type ." ("
340 : anton 1.77 r@ item-name 2@ type ." );"
341 : anton 1.1 rdrop ;
342 :    
343 :     : store-single ( item -- )
344 :     >r
345 : anton 1.49 r@ same-as-in?
346 : anton 1.1 if
347 : anton 1.49 r@ item-in-index 0= r@ item-out-index 0= xor
348 : anton 1.1 if
349 : anton 1.49 ." IF_" r@ item-stack @ stack-pointer 2@ type
350 :     ." TOS(" r@ really-store-single ." );" cr
351 : anton 1.1 endif
352 :     else
353 :     r@ really-store-single cr
354 :     endif
355 :     rdrop ;
356 :    
357 :     : store-double ( item -- )
358 :     \ !! store optimization is not performed, because it is not yet needed
359 :     >r
360 : anton 1.78 ." vm_"
361 :     r@ item-type @ print-type-prefix ." 2two"
362 :     r@ item-stack-type-name type ." ("
363 :     r@ item-name 2@ type ." , "
364 : anton 1.49 r@ item-out-index r@ item-stack @ 2dup stack-access
365 :     ." , " -1 under+ stack-access
366 : anton 1.20 ." );" cr
367 : anton 1.1 rdrop ;
368 :    
369 : anton 1.54 : single ( -- xt1 xt2 n )
370 :     ['] fetch-single ['] store-single 1 ;
371 : anton 1.1
372 : anton 1.54 : double ( -- xt1 xt2 n )
373 :     ['] fetch-double ['] store-double 2 ;
374 : anton 1.1
375 :     : s, ( addr u -- )
376 :     \ allocate a string
377 :     here swap dup allot move ;
378 :    
379 : anton 1.50 wordlist constant prefixes
380 :    
381 :     : declare ( addr "name" -- )
382 :     \ remember that there is a stack item at addr called name
383 :     create , ;
384 :    
385 :     : !default ( w addr -- )
386 :     dup @ if
387 :     2drop \ leave nonzero alone
388 :     else
389 :     !
390 :     endif ;
391 :    
392 :     : create-type { addr u xt1 xt2 n stack -- } ( "prefix" -- )
393 : anton 1.49 \ describes a type
394 :     \ addr u specifies the C type name
395 :     \ stack effect entries of the type start with prefix
396 :     create type% %allot >r
397 :     addr u save-mem r@ type-c-name 2!
398 :     xt1 r@ type-fetch !
399 :     xt2 r@ type-store !
400 :     n r@ type-size !
401 :     stack r@ type-stack !
402 :     rdrop ;
403 : anton 1.1
404 : anton 1.54 : type-prefix ( xt1 xt2 n stack "prefix" -- )
405 : anton 1.50 create-type
406 :     does> ( item -- )
407 :     \ initialize item
408 :     { item typ }
409 :     typ item item-type !
410 :     typ type-stack @ item item-stack !default
411 : anton 1.75 item item-name 2@ prim prim-items-wordlist @ search-wordlist 0= if
412 : anton 1.66 item item-name 2@ nextname item declare
413 :     item item-first on
414 :     \ typ type-c-name 2@ type space type ." ;" cr
415 : anton 1.50 else
416 :     drop
417 : anton 1.66 item item-first off
418 : anton 1.50 endif ;
419 :    
420 :     : execute-prefix ( item addr1 u1 -- )
421 :     \ execute the word ( item -- ) associated with the longest prefix
422 :     \ of addr1 u1
423 :     0 swap ?do
424 :     dup i prefixes search-wordlist
425 :     if \ ok, we have the type ( item addr1 xt )
426 :     nip execute
427 :     UNLOOP EXIT
428 :     endif
429 :     -1 s+loop
430 :     \ we did not find a type, abort
431 :     true abort" unknown prefix" ;
432 : anton 1.1
433 :     : declaration ( item -- )
434 : anton 1.50 dup item-name 2@ execute-prefix ;
435 : anton 1.1
436 : anton 1.64 : declaration-list ( addr1 addr2 -- )
437 :     ['] declaration map-items ;
438 :    
439 :     : declarations ( -- )
440 : anton 1.75 wordlist dup prim prim-items-wordlist ! set-current
441 : anton 1.69 prim prim-effect-in prim prim-effect-in-end @ declaration-list
442 :     prim prim-effect-out prim prim-effect-out-end @ declaration-list ;
443 : anton 1.64
444 : anton 1.66 : print-declaration { item -- }
445 :     item item-first @ if
446 :     item item-type @ type-c-name 2@ type space
447 :     item item-name 2@ type ." ;" cr
448 :     endif ;
449 :    
450 :     : print-declarations ( -- )
451 : anton 1.69 prim prim-effect-in prim prim-effect-in-end @ ['] print-declaration map-items
452 :     prim prim-effect-out prim prim-effect-out-end @ ['] print-declaration map-items ;
453 : anton 1.66
454 : anton 1.51 : stack-prefix ( stack "prefix" -- )
455 :     name tuck nextname create ( stack length ) 2,
456 :     does> ( item -- )
457 :     2@ { item stack prefix-length }
458 :     item item-name 2@ prefix-length /string item item-name 2!
459 :     stack item item-stack !
460 :     item declaration ;
461 : anton 1.73
462 : anton 1.74 \ types pointed to by stacks for use in combined prims
463 :     s" Cell" single 0 create-type cell-type
464 :     s" Float" single 0 create-type float-type
465 :    
466 :     s" sp" save-mem cell-type s" (Cell)" make-stack data-stack
467 : anton 1.77 s" fp" save-mem float-type s" " make-stack fp-stack
468 :     s" rp" save-mem cell-type s" (Cell)" make-stack return-stack
469 : anton 1.74 s" IP" save-mem cell-type s" error don't use # on results" make-stack inst-stream
470 : anton 1.73 ' inst-in-index inst-stream stack-in-index-xt !
471 :     \ !! initialize stack-in and stack-out
472 : anton 1.1
473 :     \ offset computation
474 :     \ the leftmost (i.e. deepest) item has offset 0
475 :     \ the rightmost item has the highest offset
476 :    
477 : anton 1.49 : compute-offset { item xt -- }
478 :     \ xt specifies in/out; update stack-in/out and set item-offset
479 :     item item-type @ type-size @
480 :     item item-stack @ xt execute dup @ >r +!
481 :     r> item item-offset ! ;
482 :    
483 : anton 1.64 : compute-offset-in ( addr1 addr2 -- )
484 :     ['] stack-in compute-offset ;
485 :    
486 :     : compute-offset-out ( addr1 addr2 -- )
487 :     ['] stack-out compute-offset ;
488 : anton 1.49
489 :     : clear-stack { -- }
490 :     dup stack-in off stack-out off ;
491 : anton 1.1
492 :     : compute-offsets ( -- )
493 : anton 1.51 data-stack clear-stack fp-stack clear-stack return-stack clear-stack
494 : anton 1.53 inst-stream clear-stack
495 : anton 1.69 prim prim-effect-in prim prim-effect-in-end @ ['] compute-offset-in map-items
496 :     prim prim-effect-out prim prim-effect-out-end @ ['] compute-offset-out map-items
497 : anton 1.53 inst-stream stack-out @ 0<> abort" # can only be on the input side" ;
498 : anton 1.49
499 :     : flush-a-tos { stack -- }
500 :     stack stack-out @ 0<> stack stack-in @ 0= and
501 :     if
502 :     ." IF_" stack stack-pointer 2@ 2dup type ." TOS("
503 :     2dup type ." [0] = " type ." TOS);" cr
504 :     endif ;
505 : anton 1.1
506 :     : flush-tos ( -- )
507 : anton 1.51 data-stack flush-a-tos
508 :     fp-stack flush-a-tos
509 :     return-stack flush-a-tos ;
510 : anton 1.49
511 :     : fill-a-tos { stack -- }
512 :     stack stack-out @ 0= stack stack-in @ 0<> and
513 :     if
514 :     ." IF_" stack stack-pointer 2@ 2dup type ." TOS("
515 :     2dup type ." TOS = " type ." [0]);" cr
516 :     endif ;
517 : anton 1.1
518 :     : fill-tos ( -- )
519 : anton 1.53 \ !! inst-stream for prefetching?
520 : anton 1.51 fp-stack fill-a-tos
521 :     data-stack fill-a-tos
522 :     return-stack fill-a-tos ;
523 : anton 1.49
524 :     : fetch ( addr -- )
525 : anton 1.72 dup item-type @ type-fetch @ execute ;
526 : anton 1.1
527 :     : fetches ( -- )
528 : anton 1.69 prim prim-effect-in prim prim-effect-in-end @ ['] fetch map-items ;
529 : anton 1.49
530 :     : stack-pointer-update { stack -- }
531 :     \ stack grow downwards
532 :     stack stack-in @ stack stack-out @ -
533 :     ?dup-if \ this check is not necessary, gcc would do this for us
534 :     stack stack-pointer 2@ type ." += " 0 .r ." ;" cr
535 :     endif ;
536 : anton 1.1
537 : anton 1.55 : inst-pointer-update ( -- )
538 :     inst-stream stack-in @ ?dup-if
539 :     ." INC_IP(" 0 .r ." );" cr
540 :     endif ;
541 :    
542 : anton 1.1 : stack-pointer-updates ( -- )
543 : anton 1.55 inst-pointer-update
544 : anton 1.51 data-stack stack-pointer-update
545 :     fp-stack stack-pointer-update
546 :     return-stack stack-pointer-update ;
547 : anton 1.1
548 :     : store ( item -- )
549 :     \ f is true if the item should be stored
550 :     \ f is false if the store is probably not necessary
551 : anton 1.49 dup item-type @ type-store @ execute ;
552 : anton 1.1
553 :     : stores ( -- )
554 : anton 1.69 prim prim-effect-out prim prim-effect-out-end @ ['] store map-items ;
555 : pazsan 1.8
556 : anton 1.52 : output-c-tail ( -- )
557 :     \ the final part of the generated C code
558 :     ." NEXT_P1;" cr
559 :     stores
560 :     fill-tos
561 :     ." NEXT_P2;" cr ;
562 :    
563 :     : type-c ( c-addr u -- )
564 :     \ like TYPE, but replaces "TAIL;" with tail code
565 :     begin ( c-addr1 u1 )
566 :     2dup s" TAIL;" search
567 :     while ( c-addr1 u1 c-addr3 u3 )
568 :     2dup 2>r drop nip over - type
569 :     output-c-tail
570 :     2r> 5 /string
571 :     \ !! resync #line missing
572 :     repeat
573 :     2drop type ;
574 : anton 1.63
575 :     : print-debug-arg { item -- }
576 :     ." fputs(" quote space item item-name 2@ type ." =" quote ." , vm_out); "
577 :     ." printarg_" item item-type @ print-type-prefix
578 :     ." (" item item-name 2@ type ." );" cr ;
579 :    
580 :     : print-debug-args ( -- )
581 :     ." #ifdef VM_DEBUG" cr
582 :     ." if (vm_debug) {" cr
583 : anton 1.69 prim prim-effect-in prim prim-effect-in-end @ ['] print-debug-arg map-items
584 : anton 1.63 ." fputc('\n', vm_out);" cr
585 :     ." }" cr
586 :     ." #endif" cr ;
587 : anton 1.72
588 :     : print-entry ( -- )
589 :     ." I_" prim prim-c-name 2@ type ." :" ;
590 : anton 1.63
591 : jwilke 1.43 : output-c ( -- )
592 : anton 1.72 print-entry ." /* " prim prim-name 2@ type ." ( " prim prim-stack-string 2@ type ." ) */" cr
593 : anton 1.69 ." /* " prim prim-doc 2@ type ." */" cr
594 :     ." NAME(" quote prim prim-name 2@ type quote ." )" cr \ debugging
595 : anton 1.1 ." {" cr
596 :     ." DEF_CA" cr
597 : anton 1.66 print-declarations
598 : anton 1.13 ." NEXT_P0;" cr
599 :     flush-tos
600 : anton 1.1 fetches
601 : anton 1.63 print-debug-args
602 : anton 1.13 stack-pointer-updates
603 : anton 1.1 ." {" cr
604 : anton 1.63 ." #line " c-line @ . quote c-filename 2@ type quote cr
605 : anton 1.69 prim prim-c-code 2@ type-c
606 : anton 1.1 ." }" cr
607 : anton 1.52 output-c-tail
608 : anton 1.1 ." }" cr
609 :     cr
610 :     ;
611 :    
612 : anton 1.56 : disasm-arg { item -- }
613 :     item item-stack @ inst-stream = if
614 : anton 1.63 ." fputc(' ', vm_out); "
615 :     ." printarg_" item item-type @ print-type-prefix
616 :     ." ((" item item-type @ type-c-name 2@ type ." )"
617 :     ." ip[" item item-offset @ 1+ 0 .r ." ]);" cr
618 : anton 1.56 endif ;
619 :    
620 :     : disasm-args ( -- )
621 : anton 1.69 prim prim-effect-in prim prim-effect-in-end @ ['] disasm-arg map-items ;
622 : anton 1.56
623 :     : output-disasm ( -- )
624 :     \ generate code for disassembling VM instructions
625 :     ." if (ip[0] == prim[" function-number @ 0 .r ." ]) {" cr
626 : anton 1.69 ." fputs(" quote prim prim-name 2@ type quote ." , vm_out);" cr
627 : anton 1.56 disasm-args
628 :     ." ip += " inst-stream stack-in @ 1+ 0 .r ." ;" cr
629 : anton 1.68 ." } else " ;
630 : anton 1.56
631 : anton 1.60 : gen-arg-parm { item -- }
632 :     item item-stack @ inst-stream = if
633 :     ." , " item item-type @ type-c-name 2@ type space
634 :     item item-name 2@ type
635 :     endif ;
636 :    
637 :     : gen-args-parm ( -- )
638 : anton 1.69 prim prim-effect-in prim prim-effect-in-end @ ['] gen-arg-parm map-items ;
639 : anton 1.60
640 :     : gen-arg-gen { item -- }
641 :     item item-stack @ inst-stream = if
642 :     ." genarg_" item item-type @ print-type-prefix
643 :     ." (ctp, " item item-name 2@ type ." );" cr
644 :     endif ;
645 :    
646 :     : gen-args-gen ( -- )
647 : anton 1.69 prim prim-effect-in prim prim-effect-in-end @ ['] gen-arg-gen map-items ;
648 : anton 1.60
649 :     : output-gen ( -- )
650 :     \ generate C code for generating VM instructions
651 : anton 1.69 ." void gen_" prim prim-c-name 2@ type ." (Inst **ctp" gen-args-parm ." )" cr
652 : anton 1.60 ." {" cr
653 :     ." gen_inst(ctp, vm_prim[" function-number @ 0 .r ." ]);" cr
654 :     gen-args-gen
655 : anton 1.68 ." }" cr ;
656 : anton 1.60
657 : anton 1.49 : stack-used? { stack -- f }
658 :     stack stack-in @ stack stack-out @ or 0<> ;
659 : jwilke 1.44
660 : pazsan 1.30 : output-funclabel ( -- )
661 : anton 1.69 ." &I_" prim prim-c-name 2@ type ." ," cr ;
662 : pazsan 1.30
663 :     : output-forthname ( -- )
664 : anton 1.69 '" emit prim prim-name 2@ type '" emit ." ," cr ;
665 : pazsan 1.30
666 :     : output-c-func ( -- )
667 : jwilke 1.44 \ used for word libraries
668 : anton 1.69 ." Cell * I_" prim prim-c-name 2@ type ." (Cell *SP, Cell **FP) /* " prim prim-name 2@ type
669 :     ." ( " prim prim-stack-string 2@ type ." ) */" cr
670 :     ." /* " prim prim-doc 2@ type ." */" cr
671 :     ." NAME(" quote prim prim-name 2@ type quote ." )" cr
672 : pazsan 1.30 \ debugging
673 :     ." {" cr
674 : anton 1.66 print-declarations
675 : anton 1.53 inst-stream stack-used? IF ." Cell *ip=IP;" cr THEN
676 : anton 1.51 data-stack stack-used? IF ." Cell *sp=SP;" cr THEN
677 :     fp-stack stack-used? IF ." Cell *fp=*FP;" cr THEN
678 :     return-stack stack-used? IF ." Cell *rp=*RP;" cr THEN
679 : pazsan 1.30 flush-tos
680 :     fetches
681 :     stack-pointer-updates
682 : anton 1.49 fp-stack stack-used? IF ." *FP=fp;" cr THEN
683 : pazsan 1.30 ." {" cr
684 : anton 1.63 ." #line " c-line @ . quote c-filename 2@ type quote cr
685 : anton 1.69 prim prim-c-code 2@ type
686 : pazsan 1.30 ." }" cr
687 :     stores
688 :     fill-tos
689 : jwilke 1.44 ." return (sp);" cr
690 : pazsan 1.30 ." }" cr
691 :     cr ;
692 :    
693 : jwilke 1.43 : output-label ( -- )
694 : anton 1.69 ." (Label)&&I_" prim prim-c-name 2@ type ." ," cr ;
695 : anton 1.1
696 : jwilke 1.43 : output-alias ( -- )
697 : anton 1.69 ( primitive-number @ . ." alias " ) ." Primitive " prim prim-name 2@ type cr ;
698 : anton 1.1
699 : jwilke 1.43 : output-forth ( -- )
700 : anton 1.69 prim prim-forth-code @ 0=
701 : pazsan 1.30 IF \ output-alias
702 : jwilke 1.28 \ this is bad for ec: an alias is compiled if tho word does not exist!
703 :     \ JAW
704 : anton 1.69 ELSE ." : " prim prim-name 2@ type ." ( "
705 :     prim prim-stack-string 2@ type ." )" cr
706 :     prim prim-forth-code 2@ type cr
707 : pazsan 1.30 THEN ;
708 : anton 1.10
709 : anton 1.17 : output-tag-file ( -- )
710 :     name-filename 2@ last-name-filename 2@ compare if
711 :     name-filename 2@ last-name-filename 2!
712 :     #ff emit cr
713 :     name-filename 2@ type
714 :     ." ,0" cr
715 :     endif ;
716 :    
717 :     : output-tag ( -- )
718 :     output-tag-file
719 : anton 1.69 prim prim-name 2@ 1+ type
720 : anton 1.17 127 emit
721 : anton 1.69 space prim prim-name 2@ type space
722 : anton 1.17 1 emit
723 :     name-line @ 0 .r
724 :     ." ,0" cr ;
725 :    
726 : anton 1.10 [IFDEF] documentation
727 :     : register-doc ( -- )
728 :     get-current documentation set-current
729 : anton 1.69 prim prim-name 2@ nextname create
730 :     prim prim-name 2@ 2,
731 :     prim prim-stack-string 2@ condition-stack-effect 2,
732 :     prim prim-wordset 2@ 2,
733 :     prim prim-c-name 2@ condition-pronounciation 2,
734 :     prim prim-doc 2@ 2,
735 : anton 1.10 set-current ;
736 :     [THEN]
737 : anton 1.67
738 :    
739 : anton 1.69 \ combining instructions
740 :    
741 :     \ The input should look like this:
742 :    
743 :     \ lit_+ = lit +
744 :    
745 :     \ The output should look like this:
746 :    
747 :     \ I_lit_+:
748 :     \ {
749 :     \ DEF_CA
750 :     \ Cell _x_ip0;
751 :     \ Cell _x_sp0;
752 :     \ Cell _x_sp1;
753 :     \ NEXT_P0;
754 :     \ _x_ip0 = (Cell) IPTOS;
755 :     \ _x_sp0 = (Cell) spTOS;
756 :     \ INC_IP(1);
757 :     \ /* sp += 0; */
758 :     \ /* lit ( #w -- w ) */
759 :     \ /* */
760 :     \ NAME("lit")
761 :     \ {
762 :     \ Cell w;
763 :     \ w = (Cell) _x_ip0;
764 :     \ #ifdef VM_DEBUG
765 :     \ if (vm_debug) {
766 :     \ fputs(" w=", vm_out); printarg_w (w);
767 :     \ fputc('\n', vm_out);
768 :     \ }
769 :     \ #endif
770 :     \ {
771 :     \ #line 136 "./prim"
772 :     \ }
773 :     \ _x_sp1 = (Cell)w;
774 :     \ }
775 :     \ I_plus: /* + ( n1 n2 -- n ) */
776 :     \ /* */
777 :     \ NAME("+")
778 :     \ {
779 :     \ DEF_CA
780 :     \ Cell n1;
781 :     \ Cell n2;
782 :     \ Cell n;
783 :     \ NEXT_P0;
784 :     \ n1 = (Cell) _x_sp0;
785 :     \ n2 = (Cell) _x_sp1;
786 :     \ #ifdef VM_DEBUG
787 :     \ if (vm_debug) {
788 :     \ fputs(" n1=", vm_out); printarg_n (n1);
789 :     \ fputs(" n2=", vm_out); printarg_n (n2);
790 :     \ fputc('\n', vm_out);
791 :     \ }
792 :     \ #endif
793 :     \ {
794 :     \ #line 516 "./prim"
795 :     \ n = n1+n2;
796 :     \ }
797 :     \ NEXT_P1;
798 :     \ _x_sp0 = (Cell)n;
799 :     \ NEXT_P2;
800 :     \ }
801 :     \ NEXT_P1;
802 :     \ spTOS = (Cell)_x_sp0;
803 :     \ NEXT_P2;
804 :    
805 : anton 1.71 : init-combined ( -- )
806 : anton 1.79 prim to combined
807 : anton 1.71 0 num-combined !
808 :     current-depth max-stacks cells erase
809 : anton 1.72 max-depth max-stacks cells erase
810 :     min-depth max-stacks cells erase
811 :     prim prim-effect-in prim prim-effect-in-end !
812 :     prim prim-effect-out prim prim-effect-out-end ! ;
813 : anton 1.71
814 :     : max! ( n addr -- )
815 :     tuck @ max swap ! ;
816 :    
817 : anton 1.72 : min! ( n addr -- )
818 :     tuck @ min swap ! ;
819 :    
820 : anton 1.71 : add-depths { p -- }
821 :     \ combine stack effect of p with *-depths
822 :     max-stacks 0 ?do
823 : anton 1.72 current-depth i th @
824 :     p prim-stacks-in i th @ +
825 :     dup max-depth i th max!
826 :     p prim-stacks-out i th @ -
827 :     dup min-depth i th min!
828 :     current-depth i th !
829 : anton 1.71 loop ;
830 :    
831 :     : add-prim ( addr u -- )
832 :     \ add primitive given by "addr u" to combined-prims
833 :     primitives search-wordlist s" unknown primitive" ?print-error
834 :     execute { p }
835 : anton 1.72 p combined-prims num-combined @ th !
836 : anton 1.71 1 num-combined +!
837 :     p add-depths ;
838 :    
839 :     : compute-effects { q -- }
840 :     \ compute the stack effects of q from the depths
841 :     max-stacks 0 ?do
842 : anton 1.72 max-depth i th @ dup
843 :     q prim-stacks-in i th !
844 :     current-depth i th @ -
845 :     q prim-stacks-out i th !
846 :     loop ;
847 :    
848 :     : make-effect-items { stack# items effect-endp -- }
849 :     \ effect-endp points to a pointer to the end of the current item-array
850 :     \ and has to be updated
851 :     stacks stack# th @ { stack }
852 :     items 0 +do
853 :     effect-endp @ { item }
854 :     i 0 <# #s stack stack-pointer 2@ holds [char] _ hold #> save-mem
855 :     item item-name 2!
856 :     stack item item-stack !
857 : anton 1.74 stack stack-type @ item item-type !
858 : anton 1.72 i item item-offset !
859 :     item item-first on
860 :     item% %size effect-endp +!
861 :     loop ;
862 :    
863 :     : init-effects { q -- }
864 :     \ initialize effects field for FETCHES and STORES
865 :     max-stacks 0 ?do
866 :     i q prim-stacks-in i th @ q prim-effect-in-end make-effect-items
867 :     i q prim-stacks-out i th @ q prim-effect-out-end make-effect-items
868 : anton 1.71 loop ;
869 :    
870 :     : process-combined ( -- )
871 : anton 1.72 prim compute-effects
872 :     prim init-effects
873 :     output-combined perform ;
874 :    
875 :     \ C output
876 :    
877 :     : print-item { n stack -- }
878 :     \ print nth stack item name
879 : anton 1.79 stack stack-type @ type-c-name 2@ type space
880 :     ." _" stack stack-pointer 2@ type n 0 .r ;
881 : anton 1.72
882 :     : print-declarations-combined ( -- )
883 :     max-stacks 0 ?do
884 :     max-depth i th @ min-depth i th @ - 0 +do
885 :     i stacks j th @ print-item ." ;" cr
886 :     loop
887 :     loop ;
888 : anton 1.79
889 :     : part-fetches ( -- )
890 :     fetches ;
891 :    
892 :     : part-output-c-tail ( -- )
893 :     output-c-tail ;
894 :    
895 :     : output-part ( p -- )
896 :     to prim
897 :     ." /* " prim prim-name 2@ type ." ( " prim prim-stack-string 2@ type ." ) */" cr
898 :     ." NAME(" quote prim prim-name 2@ type quote ." )" cr \ debugging
899 :     ." {" cr
900 :     print-declarations
901 :     part-fetches
902 :     print-debug-args
903 :     prim add-depths \ !! right place?
904 :     ." {" cr
905 :     ." #line " c-line @ . quote c-filename 2@ type quote cr
906 :     prim prim-c-code 2@ type-c \ !! deal with TAIL
907 :     ." }" cr
908 :     part-output-c-tail
909 :     ." }" cr ;
910 :    
911 : anton 1.74 : output-parts ( -- )
912 : anton 1.79 prim >r in-part on
913 :     current-depth max-stacks cells erase
914 : anton 1.74 num-combined @ 0 +do
915 : anton 1.79 combined-prims i th @ output-part
916 : anton 1.74 loop
917 : anton 1.79 in-part off
918 : anton 1.74 r> to prim ;
919 :    
920 : anton 1.72 : output-c-combined ( -- )
921 :     print-entry cr
922 : anton 1.74 \ debugging messages just in parts
923 : anton 1.72 ." {" cr
924 :     ." DEF_CA" cr
925 :     print-declarations-combined
926 :     ." NEXT_P0;" cr
927 :     flush-tos
928 :     fetches
929 : anton 1.74 \ print-debug-args
930 :     stack-pointer-updates
931 :     output-parts
932 :     output-c-tail
933 :     ." }" cr
934 :     cr ;
935 : anton 1.72
936 :     : output-forth-combined ( -- )
937 :     ;
938 : anton 1.69
939 : anton 1.67 \ the parser
940 :    
941 :     eof-char max-member \ the whole character set + EOF
942 :    
943 :     : getinput ( -- n )
944 :     rawinput @ endrawinput @ =
945 :     if
946 :     eof-char
947 :     else
948 :     cookedinput @ c@
949 :     endif ;
950 :    
951 :     :noname ( n -- )
952 :     dup bl > if
953 :     emit space
954 :     else
955 :     .
956 :     endif ;
957 :     print-token !
958 :    
959 :     : testchar? ( set -- f )
960 :     getinput member? ;
961 :     ' testchar? test-vector !
962 :    
963 :     : checksyncline ( -- )
964 :     \ when input points to a newline, check if the next line is a
965 :     \ sync line. If it is, perform the appropriate actions.
966 :     rawinput @ >r
967 :     s" #line " r@ over compare 0<> if
968 :     rdrop 1 line +! EXIT
969 :     endif
970 :     0. r> 6 chars + 20 >number drop >r drop line ! r> ( c-addr )
971 :     dup c@ bl = if
972 :     char+ dup c@ [char] " <> abort" sync line syntax"
973 :     char+ dup 100 [char] " scan drop swap 2dup - save-mem filename 2!
974 :     char+
975 :     endif
976 :     dup c@ nl-char <> abort" sync line syntax"
977 :     skipsynclines @ if
978 :     dup char+ rawinput !
979 :     rawinput @ c@ cookedinput @ c!
980 :     endif
981 :     drop ;
982 :    
983 :     : ?nextchar ( f -- )
984 : anton 1.71 s" syntax error, wrong char" ?print-error
985 : anton 1.67 rawinput @ endrawinput @ <> if
986 :     rawinput @ c@
987 :     1 chars rawinput +!
988 :     1 chars cookedinput +!
989 :     nl-char = if
990 :     checksyncline
991 :     rawinput @ line-start !
992 :     endif
993 :     rawinput @ c@ cookedinput @ c!
994 :     endif ;
995 :    
996 :     : charclass ( set "name" -- )
997 :     ['] ?nextchar terminal ;
998 :    
999 :     : .. ( c1 c2 -- set )
1000 :     ( creates a set that includes the characters c, c1<=c<=c2 )
1001 :     empty copy-set
1002 :     swap 1+ rot do
1003 :     i over add-member
1004 :     loop ;
1005 :    
1006 :     : ` ( -- terminal ) ( use: ` c )
1007 :     ( creates anonymous terminal for the character c )
1008 :     char singleton ['] ?nextchar make-terminal ;
1009 :    
1010 :     char a char z .. char A char Z .. union char _ singleton union charclass letter
1011 :     char 0 char 9 .. charclass digit
1012 :     bl singleton tab-char over add-member charclass white
1013 :     nl-char singleton eof-char over add-member complement charclass nonl
1014 :     nl-char singleton eof-char over add-member
1015 :     char : over add-member complement charclass nocolonnl
1016 :     bl 1+ maxchar .. char \ singleton complement intersection
1017 :     charclass nowhitebq
1018 :     bl 1+ maxchar .. charclass nowhite
1019 :     char " singleton eof-char over add-member complement charclass noquote
1020 :     nl-char singleton charclass nl
1021 :     eof-char singleton charclass eof
1022 : anton 1.79 nl-char singleton eof-char over add-member charclass nleof
1023 : anton 1.67
1024 :     (( letter (( letter || digit )) **
1025 :     )) <- c-ident ( -- )
1026 :    
1027 :     (( ` # ?? (( letter || digit || ` : )) **
1028 :     )) <- stack-ident ( -- )
1029 :    
1030 :     (( nowhitebq nowhite ** ))
1031 :     <- forth-ident ( -- )
1032 :    
1033 :     Variable forth-flag
1034 :     Variable c-flag
1035 :    
1036 :     (( (( ` e || ` E )) {{ start }} nonl **
1037 :     {{ end evaluate }}
1038 :     )) <- eval-comment ( ... -- ... )
1039 :    
1040 :     (( (( ` f || ` F )) {{ start }} nonl **
1041 :     {{ end forth-flag @ IF type cr ELSE 2drop THEN }}
1042 :     )) <- forth-comment ( -- )
1043 :    
1044 :     (( (( ` c || ` C )) {{ start }} nonl **
1045 :     {{ end c-flag @ IF type cr ELSE 2drop THEN }}
1046 :     )) <- c-comment ( -- )
1047 :    
1048 :     (( ` - nonl ** {{
1049 :     forth-flag @ IF ." [ELSE]" cr THEN
1050 :     c-flag @ IF ." #else" cr THEN }}
1051 :     )) <- else-comment
1052 :    
1053 :     (( ` + {{ start }} nonl ** {{ end
1054 :     dup
1055 :     IF c-flag @
1056 :     IF ." #ifdef HAS_" bounds ?DO I c@ toupper emit LOOP cr
1057 :     THEN
1058 :     forth-flag @
1059 :     IF ." has? " type ." [IF]" cr THEN
1060 :     ELSE 2drop
1061 :     c-flag @ IF ." #endif" cr THEN
1062 :     forth-flag @ IF ." [THEN]" cr THEN
1063 :     THEN }}
1064 :     )) <- if-comment
1065 :    
1066 :     (( (( eval-comment || forth-comment || c-comment || else-comment || if-comment )) ?? nonl ** )) <- comment-body
1067 :    
1068 : anton 1.79 (( ` \ comment-body nleof )) <- comment ( -- )
1069 : anton 1.67
1070 :     (( {{ start }} stack-ident {{ end 2 pick init-item item% %size + }} white ** )) **
1071 :     <- stack-items
1072 :    
1073 : anton 1.69 (( {{ prim prim-effect-in }} stack-items {{ prim prim-effect-in-end ! }}
1074 : anton 1.67 ` - ` - white **
1075 : anton 1.69 {{ prim prim-effect-out }} stack-items {{ prim prim-effect-out-end ! }}
1076 : anton 1.67 )) <- stack-effect ( -- )
1077 :    
1078 : anton 1.71 (( {{ prim create-prim }}
1079 : anton 1.69 ` ( white ** {{ start }} stack-effect {{ end prim prim-stack-string 2! }} ` ) white **
1080 :     (( {{ start }} forth-ident {{ end prim prim-wordset 2! }} white **
1081 :     (( {{ start }} c-ident {{ end prim prim-c-name 2! }} )) ??
1082 : anton 1.79 )) ?? nleof
1083 :     (( ` " ` " {{ start }} (( noquote ++ ` " )) ++ {{ end 1- prim prim-doc 2! }} ` " white ** nleof )) ??
1084 :     {{ skipsynclines off line @ c-line ! filename 2@ c-filename 2! start }} (( nocolonnl nonl ** nleof white ** )) ** {{ end prim prim-c-code 2! skipsynclines on }}
1085 :     (( ` : white ** nleof
1086 :     {{ start }} (( nonl ++ nleof white ** )) ++ {{ end prim prim-forth-code 2! }}
1087 : anton 1.68 )) ?? {{ declarations compute-offsets printprim 1 function-number +! }}
1088 : anton 1.79 nleof
1089 : anton 1.69 )) <- simple-primitive ( -- )
1090 :    
1091 : anton 1.71 (( {{ init-combined }}
1092 :     ` = (( white ++ {{ start }} forth-ident {{ end add-prim }} )) ++
1093 : anton 1.79 nleof {{ process-combined }}
1094 : anton 1.69 )) <- combined-primitive
1095 :    
1096 : anton 1.79 (( {{ make-prim to prim 0 to combined
1097 : anton 1.69 line @ name-line ! filename 2@ name-filename 2!
1098 :     start }} forth-ident {{ end 2dup prim prim-name 2! prim prim-c-name 2! }} white ++
1099 :     (( simple-primitive || combined-primitive ))
1100 : anton 1.67 )) <- primitive ( -- )
1101 :    
1102 :     (( (( comment || primitive || nl white ** )) ** eof ))
1103 :     parser primitives2something
1104 :     warnings @ [IF]
1105 :     .( parser generated ok ) cr
1106 :     [THEN]
1107 :    
1108 : anton 1.69 : primfilter ( addr u -- )
1109 :     \ process the string at addr u
1110 :     over dup rawinput ! dup line-start ! cookedinput !
1111 :     + endrawinput !
1112 :     checksyncline
1113 :     primitives2something ;
1114 : pazsan 1.8
1115 : anton 1.72 : process-file ( addr u xt-simple x-combined -- )
1116 :     output-combined ! output !
1117 : anton 1.61 save-mem 2dup filename 2!
1118 : anton 1.69 slurp-file
1119 : anton 1.17 warnings @ if
1120 :     ." ------------ CUT HERE -------------" cr endif
1121 : anton 1.69 primfilter ;
1122 : pazsan 1.30
1123 : anton 1.72 \ : process ( xt -- )
1124 :     \ bl word count rot
1125 :     \ process-file ;

CVS Admin

Powered by ViewCVS 1.0-dev
(Powered by ViewCVS)

ViewCVS and CVS Help