[gforth] / gforth / kernel / int.fs  

gforth: gforth/kernel/int.fs


1 : pazsan 1.1 \ definitions needed for interpreter only
2 :    
3 : anton 1.11 \ Copyright (C) 1995,1996,1997,1998 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 : pazsan 1.1 \ \ Revision-Log
22 :    
23 :     \ put in seperate file 14sep97jaw
24 :    
25 :     \ \ input stream primitives 23feb93py
26 :    
27 :     : tib ( -- c-addr ) \ core-ext
28 :     \ obsolescent
29 :     >tib @ ;
30 :    
31 :     Defer source ( -- addr count ) \ core
32 :     \ used by dodefer:, must be defer
33 :    
34 :     : (source) ( -- addr count )
35 :     tib #tib @ ;
36 :     ' (source) IS source
37 :    
38 :     : (word) ( addr1 n1 char -- addr2 n2 )
39 :     dup >r skip 2dup r> scan nip - ;
40 :    
41 :     \ (word) should fold white spaces
42 :     \ this is what (parse-white) does
43 :    
44 :     \ word parse 23feb93py
45 :    
46 : anton 1.3 : sword ( char -- addr len ) \ gforth
47 :     \G parses like @code{word}, but the output is like @code{parse} output
48 :     \ this word was called PARSE-WORD until 0.3.0, but Open Firmware and
49 :     \ dpANS6 A.6.2.2008 have a word with that name that behaves
50 :     \ differently (like NAME).
51 : pazsan 1.1 source 2dup >r >r >in @ over min /string
52 :     rot dup bl = IF drop (parse-white) ELSE (word) THEN
53 :     2dup + r> - 1+ r> min >in ! ;
54 :    
55 :     : word ( char -- addr ) \ core
56 : anton 1.3 sword here place bl here count + c! here ;
57 : pazsan 1.1
58 :     : parse ( char -- addr len ) \ core-ext
59 :     >r source >in @ over min /string over swap r> scan >r
60 :     over - dup r> IF 1+ THEN >in +! ;
61 :    
62 :     \ name 13feb93py
63 :    
64 :     [IFUNDEF] (name) \ name might be a primitive
65 :    
66 :     : (name) ( -- c-addr count )
67 :     source 2dup >r >r >in @ /string (parse-white)
68 :     2dup + r> - 1+ r> min >in ! ;
69 :     \ name count ;
70 :     [THEN]
71 :    
72 :     : name-too-short? ( c-addr u -- c-addr u )
73 :     dup 0= -&16 and throw ;
74 :    
75 :     : name-too-long? ( c-addr u -- c-addr u )
76 :     dup $1F u> -&19 and throw ;
77 :    
78 :     \ \ Number parsing 23feb93py
79 :    
80 :     \ number? number 23feb93py
81 :    
82 :     hex
83 :     const Create bases 10 , 2 , A , 100 ,
84 :     \ 16 2 10 character
85 :    
86 : anton 1.18 \ !! protect BASE saving wrapper against exceptions
87 : pazsan 1.1 : getbase ( addr u -- addr' u' )
88 :     over c@ [char] $ - dup 4 u<
89 :     IF
90 :     cells bases + @ base ! 1 /string
91 :     ELSE
92 :     drop
93 :     THEN ;
94 :    
95 : pazsan 1.20 : sign? ( addr u -- addr u flag )
96 : pazsan 1.1 over c@ '- = dup >r
97 :     IF
98 :     1 /string
99 :     THEN
100 : pazsan 1.20 r> ;
101 :    
102 :     : s>unumber? ( addr u -- ud flag )
103 :     0. 2swap
104 : anton 1.18 BEGIN ( d addr len )
105 : pazsan 1.1 dup >r >number dup
106 : anton 1.18 WHILE \ there are characters left
107 : pazsan 1.1 dup r> -
108 : anton 1.18 WHILE \ the last >number parsed something
109 :     dup 1- dpl ! over c@ [char] . =
110 :     WHILE \ the current char is '.'
111 : pazsan 1.1 1 /string
112 : anton 1.18 REPEAT THEN \ there are unparseable characters left
113 : pazsan 1.20 rdrop 2drop false
114 :     ELSE
115 :     rdrop 2drop true
116 :     THEN ;
117 :    
118 :     \ ouch, this is complicated; there must be a simpler way - anton
119 :     : s>number? ( addr len -- d f )
120 :     \ converts string addr len into d, flag indicates success
121 :     base @ >r dpl on sign? >r getbase
122 :     s>unumber?
123 :     0= IF
124 :     false
125 : anton 1.18 ELSE \ no characters left, all ok
126 : pazsan 1.20 r>
127 : pazsan 1.1 IF
128 :     dnegate
129 :     THEN
130 : anton 1.18 true
131 : pazsan 1.1 THEN
132 :     r> base ! ;
133 :    
134 : anton 1.18 : s>number ( addr len -- d )
135 :     \ don't use this, there is no way to tell success
136 :     s>number? drop ;
137 :    
138 : pazsan 1.1 : snumber? ( c-addr u -- 0 / n -1 / d 0> )
139 : anton 1.18 s>number? 0=
140 : pazsan 1.1 IF
141 :     2drop false EXIT
142 :     THEN
143 : anton 1.18 dpl @ dup 0< IF
144 : pazsan 1.1 nip
145 : anton 1.18 ELSE
146 :     1+
147 : pazsan 1.1 THEN ;
148 :    
149 :     : number? ( string -- string 0 / n -1 / d 0> )
150 :     dup >r count snumber? dup if
151 :     rdrop
152 :     else
153 :     r> swap
154 :     then ;
155 :    
156 :     : number ( string -- d )
157 :     number? ?dup 0= abort" ?" 0<
158 :     IF
159 :     s>d
160 :     THEN ;
161 :    
162 :     \ \ Comments ( \ \G
163 :    
164 :     : ( ( compilation 'ccc<close-paren>' -- ; run-time -- ) \ core,file paren
165 : crook 1.17 \G ** this will not get annotated. The alias in glocals.fs will instead **
166 : pazsan 1.1 [char] ) parse 2drop ; immediate
167 :    
168 : crook 1.17 : \ ( -- ) \ core-ext,block-ext backslash
169 :     \G ** this will not get annotated. The alias in glocals.fs will instead **
170 : pazsan 1.12 [ has? file [IF] ]
171 : pazsan 1.1 blk @
172 :     IF
173 :     >in @ c/l / 1+ c/l * >in !
174 :     EXIT
175 :     THEN
176 : pazsan 1.12 [ [THEN] ]
177 : pazsan 1.1 source >in ! drop ; immediate
178 :    
179 : crook 1.19 : \G ( -- ) \ gforth backslash-gee
180 :     \G Equivalent to @code{\} but used as a tag to annotate definition
181 :     \G comments into documentation.
182 : pazsan 1.1 POSTPONE \ ; immediate
183 :    
184 :     \ \ object oriented search list 17mar93py
185 :    
186 :     \ word list structure:
187 :    
188 :     struct
189 :     cell% field find-method \ xt: ( c_addr u wid -- nt )
190 :     cell% field reveal-method \ xt: ( nt wid -- ) \ used by dofield:, must be field
191 :     cell% field rehash-method \ xt: ( wid -- ) \ re-initializes a "search-data" (hashtables)
192 :     cell% field hash-method \ xt: ( wid -- ) \ initializes ""
193 :     \ \ !! what else
194 :     end-struct wordlist-map-struct
195 :    
196 :     struct
197 : pazsan 1.6 cell% field wordlist-map \ pointer to a wordlist-map-struct
198 : anton 1.13 cell% field wordlist-id \ linked list of words (for WORDS etc.)
199 : pazsan 1.1 cell% field wordlist-link \ link field to other wordlists
200 : anton 1.13 cell% field wordlist-extend \ wordlist extensions (eg bucket offset)
201 : pazsan 1.1 end-struct wordlist-struct
202 :    
203 :     : f83find ( addr len wordlist -- nt / false )
204 : pazsan 1.6 wordlist-id @ (f83find) ;
205 : pazsan 1.1
206 :     : initvoc ( wid -- )
207 :     dup wordlist-map @ hash-method perform ;
208 :    
209 :     \ Search list table: find reveal
210 :     Create f83search ( -- wordlist-map )
211 :     ' f83find A, ' drop A, ' drop A, ' drop A,
212 :    
213 : pazsan 1.6 here G f83search T A, NIL A, NIL A, NIL A,
214 : pazsan 1.1 AValue forth-wordlist \ variable, will be redefined by search.fs
215 :    
216 :     AVariable lookup forth-wordlist lookup !
217 :     \ !! last is user and lookup?! jaw
218 :     AVariable current ( -- addr ) \ gforth
219 : crook 1.17 \G VARIABLE: holds the wid of the current compilation word list.
220 : pazsan 1.1 AVariable voclink forth-wordlist wordlist-link voclink !
221 : crook 1.17 lookup AValue context ( -- addr ) \ gforth
222 :     \G VALUE: @code{context} @code{@@} is the wid of the word list at the
223 :     \G top of the search order stack.
224 : pazsan 1.1
225 :     forth-wordlist current !
226 :    
227 :     \ \ header, finding, ticks 17dec92py
228 :    
229 :     $80 constant alias-mask \ set when the word is not an alias!
230 :     $40 constant immediate-mask
231 :     $20 constant restrict-mask
232 :    
233 :     \ higher level parts of find
234 :    
235 :     : flag-sign ( f -- 1|-1 )
236 :     \ true becomes 1, false -1
237 :     0= 2* 1+ ;
238 :    
239 :     : compile-only-error ( ... -- )
240 :     -&14 throw ;
241 :    
242 :     : (cfa>int) ( cfa -- xt )
243 :     [ has? compiler [IF] ]
244 :     dup interpret/compile?
245 :     if
246 :     interpret/compile-int @
247 :     then
248 :     [ [THEN] ] ;
249 :    
250 :     : (x>int) ( cfa b -- xt )
251 :     \ get interpretation semantics of name
252 :     restrict-mask and
253 :     if
254 :     drop ['] compile-only-error
255 :     else
256 :     (cfa>int)
257 :     then ;
258 :    
259 :     : name>string ( nt -- addr count ) \ gforth head-to-string
260 :     \g @var{addr count} is the name of the word represented by @var{nt}.
261 :     cell+ count $1F and ;
262 :    
263 :     : ((name>)) ( nfa -- cfa )
264 :     name>string + cfaligned ;
265 :    
266 :     : (name>x) ( nfa -- cfa b )
267 :     \ cfa is an intermediate cfa and b is the flags byte of nfa
268 :     dup ((name>))
269 :     swap cell+ c@ dup alias-mask and 0=
270 :     IF
271 :     swap @ swap
272 :     THEN ;
273 :    
274 :     : name>int ( nt -- xt ) \ gforth
275 :     \G @var{xt} represents the interpretation semantics of the word
276 :     \G @var{nt}. Produces @code{' compile-only-error} if
277 :     \G @var{nt} is compile-only.
278 :     (name>x) (x>int) ;
279 :    
280 :     : name?int ( nt -- xt ) \ gforth
281 :     \G Like name>int, but throws an error if compile-only.
282 :     (name>x) restrict-mask and
283 :     if
284 :     compile-only-error \ does not return
285 :     then
286 :     (cfa>int) ;
287 :    
288 :     : (name>comp) ( nt -- w +-1 ) \ gforth
289 :     \G @var{w xt} is the compilation token for the word @var{nt}.
290 :     (name>x) >r
291 :     [ has? compiler [IF] ]
292 :     dup interpret/compile?
293 :     if
294 :     interpret/compile-comp @
295 :     then
296 :     [ [THEN] ]
297 :     r> immediate-mask and flag-sign
298 :     ;
299 :    
300 :     : (name>intn) ( nfa -- xt +-1 )
301 :     (name>x) tuck (x>int) ( b xt )
302 :     swap immediate-mask and flag-sign ;
303 :    
304 : anton 1.14 : head? ( addr -- f )
305 :     \G heuristic check whether addr is a name token; may deliver false
306 :     \G positives; addr must be a valid address
307 :     \ we follow the link fields and check for plausibility; two
308 :     \ iterations should catch most false addresses: on the first
309 :     \ iteration, we may get an xt, on the second a code address (or
310 :     \ some code), which is typically not in the dictionary.
311 :     2 0 do
312 :     dup @ dup
313 :     if ( addr addr1 )
314 :     dup rot forthstart within
315 :     if \ addr1 is outside forthstart..addr, not a head
316 :     drop false unloop exit
317 :     then ( addr1 )
318 :     else \ 0 in the link field, no further checks
319 :     2drop true unloop exit
320 :     then
321 :     loop
322 :     \ in dubio pro:
323 :     drop true ;
324 :    
325 : pazsan 1.1 const Create ??? 0 , 3 c, char ? c, char ? c, char ? c,
326 :     \ ??? is used by dovar:, must be created/:dovar
327 :    
328 : anton 1.14 : >head ( cfa -- nt ) \ gforth to-head
329 :     $21 cell do ( cfa )
330 :     dup i - count $9F and + cfaligned over alias-mask + =
331 :     if ( cfa )
332 :     dup i - cell - dup head?
333 :     if
334 :     nip unloop exit
335 :     then
336 :     drop
337 :     then
338 :     cell +loop
339 :     drop ??? ( wouldn't 0 be better? ) ;
340 : pazsan 1.1
341 :     ' >head ALIAS >name
342 :    
343 :     : body> 0 >body - ;
344 :    
345 :     : (search-wordlist) ( addr count wid -- nt / false )
346 :     dup wordlist-map @ find-method perform ;
347 :    
348 : crook 1.17 : search-wordlist ( c-addr count wid -- 0 / xt +-1 ) \ search
349 :     \G Search the word list identified by wid
350 :     \G for the definition named by the string at c-addr count.
351 :     \G If the definition is not found, return 0. If the definition
352 :     \G is found return 1 (if the definition is immediate) or -1
353 :     \G (if the definition is not immediate) together with the xt.
354 :     \G The xt returned represents the interpretation semantics.
355 : pazsan 1.1 (search-wordlist) dup if
356 :     (name>intn)
357 :     then ;
358 :    
359 :     : find-name ( c-addr u -- nt/0 ) \ gforth
360 :     \g Find the name @var{c-addr u} in the current search
361 :     \g order. Return its nt, if found, otherwise 0.
362 :     lookup @ (search-wordlist) ;
363 :    
364 :     : sfind ( c-addr u -- 0 / xt +-1 ) \ gforth-obsolete
365 :     find-name dup
366 :     if ( nt )
367 :     state @
368 :     if
369 :     (name>comp)
370 :     else
371 :     (name>intn)
372 :     then
373 :     then ;
374 :    
375 :     : find ( c-addr -- xt +-1 / c-addr 0 ) \ core,search
376 : crook 1.17 \G Search all word lists in the current search order
377 :     \G for the definition named by the counted string at c-addr.
378 :     \G If the definition is not found, return 0. If the definition
379 :     \G is found return 1 (if the definition is immediate) or -1
380 :     \G (if the definition is not immediate) together with the xt.
381 : pazsan 1.1 dup count sfind dup
382 :     if
383 :     rot drop
384 :     then ;
385 :    
386 :     \ ticks
387 :    
388 :     : (') ( "name" -- nt ) \ gforth
389 :     name find-name dup 0=
390 :     IF
391 :     drop -&13 bounce
392 :     THEN ;
393 :    
394 :     : ' ( "name" -- xt ) \ core tick
395 :     \g @var{xt} represents @var{name}'s interpretation
396 :     \g semantics. Performs @code{-14 throw} if the word has no
397 :     \g interpretation semantics.
398 :     (') name?int ;
399 :    
400 :     \ \ the interpreter loop mar92py
401 :    
402 :     \ interpret 10mar92py
403 :    
404 :     Defer parser
405 :     Defer name ( -- c-addr count ) \ gforth
406 :     \ get the next word from the input buffer
407 :     ' (name) IS name
408 :     Defer compiler-notfound ( c-addr count -- )
409 :     Defer interpreter-notfound ( c-addr count -- )
410 :    
411 :     : no.extensions ( addr u -- )
412 :     2drop -&13 bounce ;
413 :     ' no.extensions IS compiler-notfound
414 :     ' no.extensions IS interpreter-notfound
415 :    
416 :     : interpret ( ?? -- ?? ) \ gforth
417 :     \ interpret/compile the (rest of the) input buffer
418 :     BEGIN
419 :     ?stack name dup
420 :     WHILE
421 :     parser
422 :     REPEAT
423 :     2drop ;
424 :    
425 :     \ interpreter 30apr92py
426 :    
427 :     \ not the most efficient implementations of interpreter and compiler
428 : pazsan 1.12 | : interpreter ( c-addr u -- )
429 : pazsan 1.1 2dup find-name dup
430 :     if
431 :     nip nip name>int execute
432 :     else
433 :     drop
434 :     2dup 2>r snumber?
435 :     IF
436 :     2rdrop
437 :     ELSE
438 :     2r> interpreter-notfound
439 :     THEN
440 :     then ;
441 :    
442 :     ' interpreter IS parser
443 :    
444 :     \ \ Query Evaluate 07apr93py
445 :    
446 :     has? file 0= [IF]
447 : pazsan 1.12 : sourceline# ( -- n ) 1 ;
448 : pazsan 1.1 [THEN]
449 :    
450 :     : refill ( -- flag ) \ core-ext,block-ext,file-ext
451 : pazsan 1.12 [ has? file [IF] ]
452 :     blk @ IF 1 blk +! true 0 >in ! EXIT THEN
453 :     [ [THEN] ]
454 :     tib /line
455 :     [ has? file [IF] ]
456 :     loadfile @ ?dup
457 :     IF read-line throw
458 :     ELSE
459 :     [ [THEN] ]
460 :     sourceline# 0< IF 2drop false EXIT THEN
461 :     accept true
462 :     [ has? file [IF] ]
463 :     THEN
464 :     1 loadline +!
465 :     [ [THEN] ]
466 :     swap #tib ! 0 >in ! ;
467 : pazsan 1.1
468 :     : query ( -- ) \ core-ext
469 :     \G obsolescent
470 : pazsan 1.12 [ has? file [IF] ]
471 :     blk off loadfile off
472 :     [ [THEN] ]
473 : pazsan 1.1 tib /line accept #tib ! 0 >in ! ;
474 :    
475 :     \ save-mem extend-mem
476 :    
477 :     has? os [IF]
478 :     : save-mem ( addr1 u -- addr2 u ) \ gforth
479 :     \g copy a memory block into a newly allocated region in the heap
480 :     swap >r
481 :     dup allocate throw
482 :     swap 2dup r> -rot move ;
483 :    
484 :     : extend-mem ( addr1 u1 u -- addr addr2 u2 )
485 :     \ extend memory block allocated from the heap by u aus
486 :     \ the (possibly reallocated piece is addr2 u2, the extension is at addr
487 :     over >r + dup >r resize throw
488 :     r> over r> + -rot ;
489 :     [THEN]
490 :    
491 :     \ EVALUATE 17may93jaw
492 :    
493 :     has? file 0= [IF]
494 :     : push-file ( -- ) r>
495 : pazsan 1.12 tibstack @ >r >tib @ >r #tib @ >r
496 : pazsan 1.1 >tib @ tibstack @ = IF r@ tibstack +! THEN
497 :     tibstack @ >tib ! >in @ >r >r ;
498 :    
499 :     : pop-file ( throw-code -- throw-code )
500 :     r>
501 : pazsan 1.12 r> >in ! r> #tib ! r> >tib ! r> tibstack ! >r ;
502 : pazsan 1.1 [THEN]
503 :    
504 :     : evaluate ( c-addr len -- ) \ core,block
505 :     push-file #tib ! >tib !
506 : pazsan 1.12 >in off
507 :     [ has? file [IF] ]
508 :     blk off loadfile off -1 loadline !
509 :     [ [THEN] ]
510 : pazsan 1.1 ['] interpret catch
511 :     pop-file throw ;
512 :    
513 :     \ \ Quit 13feb93py
514 :    
515 :     Defer 'quit
516 :    
517 :     Defer .status
518 :    
519 :     : prompt state @ IF ." compiled" EXIT THEN ." ok" ;
520 :    
521 :     : (Query) ( -- )
522 : pazsan 1.12 [ has? file [IF] ]
523 :     loadfile off blk off loadline off
524 :     [ [THEN] ]
525 :     refill drop ;
526 : pazsan 1.1
527 :     : (quit) BEGIN .status cr (query) interpret prompt AGAIN ;
528 :    
529 :     ' (quit) IS 'quit
530 :    
531 :     \ \ DOERROR (DOERROR) 13jun93jaw
532 :    
533 :     8 Constant max-errors
534 :     Variable error-stack 0 error-stack !
535 :     max-errors 6 * cells allot
536 :     \ format of one cell:
537 :     \ source ( addr u )
538 :     \ >in
539 :     \ line-number
540 :     \ Loadfilename ( addr u )
541 :    
542 :     : dec. ( n -- ) \ gforth
543 : crook 1.17 \G Display n as a signed decimal number, followed by a space.
544 : pazsan 1.1 base @ decimal swap . base ! ;
545 :    
546 :     : hex. ( u -- ) \ gforth
547 : crook 1.17 \G Display u as an unsigned hex number, prefixed with a "$" and
548 :     \G followed by a space.
549 : pazsan 1.1 '$ emit base @ swap hex u. base ! ;
550 :    
551 :     : typewhite ( addr u -- ) \ gforth
552 :     \ like type, but white space is printed instead of the characters
553 :     bounds ?do
554 :     i c@ #tab = if \ check for tab
555 :     #tab
556 :     else
557 :     bl
558 :     then
559 :     emit
560 :     loop ;
561 :    
562 :     DEFER DOERROR
563 : anton 1.15 Defer dobacktrace ( -- )
564 :     ' noop IS dobacktrace
565 : pazsan 1.1
566 :     : .error-frame ( addr1 u1 n1 n2 addr2 u2 -- )
567 :     cr error-stack @
568 :     IF
569 :     ." in file included from "
570 :     type ." :" dec. drop 2drop
571 :     ELSE
572 :     type ." :" dec.
573 :     cr dup 2over type cr drop
574 :     nip -trailing 1- ( line-start index2 )
575 :     0 >r BEGIN
576 :     2dup + c@ bl > WHILE
577 :     r> 1+ >r 1- dup 0< UNTIL THEN 1+
578 :     ( line-start index1 )
579 :     typewhite
580 :     r> 1 max 0 ?do \ we want at least one "^", even if the length is 0
581 :     [char] ^ emit
582 :     loop
583 :     THEN
584 :     ;
585 :    
586 :     : (DoError) ( throw-code -- )
587 :     [ has? os [IF] ]
588 : pazsan 1.8 >stderr
589 : pazsan 1.1 [ [THEN] ]
590 :     sourceline# IF
591 : pazsan 1.8 source >in @ sourceline# 0 0 .error-frame
592 : pazsan 1.1 THEN
593 :     error-stack @ 0 ?DO
594 :     -1 error-stack +!
595 :     error-stack dup @ 6 * cells + cell+
596 :     6 cells bounds DO
597 :     I @
598 :     cell +LOOP
599 :     .error-frame
600 :     LOOP
601 :     dup -2 =
602 :     IF
603 :     "error @ ?dup
604 :     IF
605 :     cr count type
606 :     THEN
607 :     drop
608 :     ELSE
609 :     .error
610 :     THEN
611 : anton 1.15 dobacktrace
612 : pazsan 1.8 normal-dp dpp ! ;
613 : pazsan 1.1
614 :     ' (DoError) IS DoError
615 :    
616 :     : quit ( ?? -- ?? ) \ core
617 : anton 1.5 rp0 @ rp! handler off clear-tibstack >tib @ >r
618 : pazsan 1.1 BEGIN
619 :     [ has? compiler [IF] ]
620 :     postpone [
621 :     [ [THEN] ]
622 :     ['] 'quit CATCH dup
623 :     WHILE
624 :     DoError r@ >tib ! r@ tibstack !
625 :     REPEAT
626 :     drop r> >tib ! ;
627 :    
628 :     \ \ Cold Boot 13feb93py
629 :    
630 :     : (bootmessage)
631 :     ." GForth " version-string type
632 : anton 1.11 ." , Copyright (C) 1998 Free Software Foundation, Inc." cr
633 : pazsan 1.1 ." GForth comes with ABSOLUTELY NO WARRANTY; for details type `license'"
634 :     [ has? os [IF] ]
635 :     cr ." Type `bye' to exit"
636 :     [ [THEN] ] ;
637 :    
638 :     defer bootmessage
639 :     defer process-args
640 :    
641 :     ' (bootmessage) IS bootmessage
642 :    
643 : anton 1.10 Defer 'cold ( -- ) \ gforth tick-cold
644 : pazsan 1.1 \ hook (deferred word) for things to do right before interpreting the
645 :     \ command-line arguments
646 :     ' noop IS 'cold
647 :    
648 : anton 1.2 include ../chains.fs
649 : pazsan 1.1
650 :     Variable init8
651 :    
652 :     : cold ( -- ) \ gforth
653 :     [ has? file [IF] ]
654 :     pathstring 2@ fpath only-path
655 :     init-included-files
656 :     [ [THEN] ]
657 :     'cold
658 :     init8 chainperform
659 :     [ has? file [IF] ]
660 : pazsan 1.8 process-args
661 : pazsan 1.12 loadline off
662 : pazsan 1.1 [ [THEN] ]
663 :     bootmessage
664 : pazsan 1.12 quit ;
665 : pazsan 1.1
666 : anton 1.5 : clear-tibstack ( -- )
667 :     [ has? glocals [IF] ]
668 :     lp@ forthstart 7 cells + @ -
669 :     [ [ELSE] ]
670 :     [ has? os [IF] ]
671 : pazsan 1.8 r0 @ forthstart 6 cells + @ -
672 : anton 1.5 [ [ELSE] ]
673 : pazsan 1.16 sp@ $10 cells +
674 : anton 1.5 [ [THEN] ]
675 :     [ [THEN] ]
676 :     dup >tib ! tibstack ! #tib off >in off ;
677 :    
678 : pazsan 1.1 : boot ( path **argv argc -- )
679 :     main-task up!
680 :     [ has? os [IF] ]
681 :     stdout TO outfile-id
682 : pazsan 1.7 stdin TO infile-id
683 : pazsan 1.1 \ !! [ [THEN] ]
684 :     \ !! [ has? file [IF] ]
685 :     argc ! argv ! pathstring 2!
686 :     [ [THEN] ]
687 :     sp@ sp0 !
688 : anton 1.5 clear-tibstack
689 : pazsan 1.1 rp@ rp0 !
690 :     [ has? floating [IF] ]
691 :     fp@ fp0 !
692 :     [ [THEN] ]
693 : pazsan 1.8 ['] cold catch DoError cr
694 : pazsan 1.1 [ has? os [IF] ]
695 :     bye
696 :     [ [THEN] ]
697 :     ;
698 :    
699 :     has? os [IF]
700 :     : bye ( -- ) \ tools-ext
701 :     [ has? file [IF] ]
702 :     script? 0= IF cr THEN
703 :     [ [ELSE] ]
704 :     cr
705 :     [ [THEN] ]
706 :     0 (bye) ;
707 :     [THEN]
708 :    
709 :     \ **argv may be scanned by the C starter to get some important
710 :     \ information, as -display and -geometry for an X client FORTH
711 :     \ or space and stackspace overrides
712 :    
713 :     \ 0 arg contains, however, the name of the program.
714 :    

CVS Admin

Powered by ViewCVS 1.0-dev
(Powered by ViewCVS)

ViewCVS and CVS Help