Annotation of gforth/kernel/int.fs, revision 1.142
1.1 pazsan 1: \ definitions needed for interpreter only
2:
1.123 anton 3: \ Copyright (C) 1995-2000,2004,2005 Free Software Foundation, Inc.
1.11 anton 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
1.63 anton 19: \ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
1.11 anton 20:
1.1 pazsan 21: \ \ Revision-Log
22:
23: \ put in seperate file 14sep97jaw
24:
25: \ \ input stream primitives 23feb93py
26:
1.33 jwilke 27: require ./basics.fs \ bounds decimal hex ...
28: require ./io.fs \ type ...
29: require ./nio.fs \ . <# ...
30: require ./errore.fs \ .error ...
1.50 anton 31: require kernel/version.fs \ version-string
1.33 jwilke 32: require ./../chains.fs
33:
1.64 pazsan 34: has? new-input 0= [IF]
1.43 crook 35: : tib ( -- c-addr ) \ core-ext t-i-b
1.40 crook 36: \G @i{c-addr} is the address of the Terminal Input Buffer.
1.29 crook 37: \G OBSOLESCENT: @code{source} superceeds the function of this word.
1.1 pazsan 38: >tib @ ;
39:
1.29 crook 40: Defer source ( -- c-addr u ) \ core
1.1 pazsan 41: \ used by dodefer:, must be defer
1.40 crook 42: \G @i{c-addr} is the address of the input buffer and @i{u} is the
1.29 crook 43: \G number of characters in it.
1.1 pazsan 44:
1.29 crook 45: : (source) ( -- c-addr u )
1.1 pazsan 46: tib #tib @ ;
47: ' (source) IS source
1.64 pazsan 48: [THEN]
1.1 pazsan 49:
50: : (word) ( addr1 n1 char -- addr2 n2 )
51: dup >r skip 2dup r> scan nip - ;
52:
53: \ (word) should fold white spaces
54: \ this is what (parse-white) does
55:
56: \ word parse 23feb93py
57:
1.130 anton 58: : sword ( char -- addr len ) \ gforth-obsolete s-word
59: \G Parses like @code{word}, but the output is like @code{parse} output.
60: \G @xref{core-idef}.
61: \ this word was called PARSE-WORD until 0.3.0, but Open Firmware and
62: \ dpANS6 A.6.2.2008 have a word with that name that behaves
63: \ differently (like NAME).
64: source 2dup >r >r >in @ over min /string
65: rot dup bl = IF
66: drop (parse-white)
67: ELSE
68: (word)
69: THEN
1.138 pazsan 70: [ has? new-input [IF] ]
1.132 anton 71: 2dup input-lexeme!
1.138 pazsan 72: [ [THEN] ]
1.130 anton 73: 2dup + r> - 1+ r> min >in ! ;
1.1 pazsan 74:
1.29 crook 75: : word ( char "<chars>ccc<char>-- c-addr ) \ core
1.40 crook 76: \G Skip leading delimiters. Parse @i{ccc}, delimited by
77: \G @i{char}, in the parse area. @i{c-addr} is the address of a
1.29 crook 78: \G transient region containing the parsed string in
1.40 crook 79: \G counted-string format. If the parse area was empty or
1.29 crook 80: \G contained no characters other than delimiters, the resulting
81: \G string has zero length. A program may replace characters within
82: \G the counted string. OBSOLESCENT: the counted string has a
83: \G trailing space that is not included in its length.
84: sword here place bl here count + c! here ;
85:
86: : parse ( char "ccc<char>" -- c-addr u ) \ core-ext
1.80 anton 87: \G Parse @i{ccc}, delimited by @i{char}, in the parse
88: \G area. @i{c-addr u} specifies the parsed string within the
89: \G parse area. If the parse area was empty, @i{u} is 0.
1.132 anton 90: >r source >in @ over min /string ( c-addr1 u1 )
1.130 anton 91: over swap r> scan >r
1.132 anton 92: over - dup r> IF 1+ THEN >in +!
1.138 pazsan 93: [ has? new-input [IF] ]
94: 2dup input-lexeme!
95: [ [THEN] ] ;
1.1 pazsan 96:
97: \ name 13feb93py
98:
99: [IFUNDEF] (name) \ name might be a primitive
100:
1.40 crook 101: : (name) ( -- c-addr count ) \ gforth
1.1 pazsan 102: source 2dup >r >r >in @ /string (parse-white)
1.138 pazsan 103: [ has? new-input [IF] ]
1.132 anton 104: 2dup input-lexeme!
1.138 pazsan 105: [ [THEN] ]
1.1 pazsan 106: 2dup + r> - 1+ r> min >in ! ;
107: \ name count ;
108: [THEN]
109:
110: : name-too-short? ( c-addr u -- c-addr u )
111: dup 0= -&16 and throw ;
112:
113: : name-too-long? ( c-addr u -- c-addr u )
1.67 anton 114: dup lcount-mask u> -&19 and throw ;
1.1 pazsan 115:
116: \ \ Number parsing 23feb93py
117:
118: \ number? number 23feb93py
119:
120: hex
1.110 anton 121: const Create bases 0A , 10 , 2 , 0A ,
1.109 anton 122: \ 10 16 2 10
1.1 pazsan 123:
1.18 anton 124: \ !! protect BASE saving wrapper against exceptions
1.1 pazsan 125: : getbase ( addr u -- addr' u' )
1.108 anton 126: 2dup s" 0x" string-prefix? >r
127: 2dup s" 0X" string-prefix? r> or
1.117 anton 128: base @ &34 < and if
1.108 anton 129: hex 2 /string
130: endif
1.109 anton 131: over c@ [char] # - dup 4 u<
1.1 pazsan 132: IF
133: cells bases + @ base ! 1 /string
134: ELSE
135: drop
136: THEN ;
137:
1.124 anton 138: : sign? ( addr u -- addr1 u1 flag )
1.33 jwilke 139: over c@ [char] - = dup >r
1.1 pazsan 140: IF
141: 1 /string
142: THEN
1.20 pazsan 143: r> ;
144:
1.109 anton 145: : s'>unumber? ( addr u -- ud flag )
146: \ convert string "C" or "C'" to character code
147: dup 0= if
148: false exit
149: endif
1.116 anton 150: x@+/string 0 s" '" 2rot string-prefix? ;
1.109 anton 151:
1.124 anton 152: : s>unumber? ( addr u -- ud flag ) \ gforth
1.125 anton 153: \G converts string addr u into ud, flag indicates success
1.121 anton 154: dpl on
1.109 anton 155: over c@ '' = if
156: 1 /string s'>unumber? exit
157: endif
1.121 anton 158: base @ >r getbase
1.20 pazsan 159: 0. 2swap
1.18 anton 160: BEGIN ( d addr len )
1.1 pazsan 161: dup >r >number dup
1.18 anton 162: WHILE \ there are characters left
1.1 pazsan 163: dup r> -
1.18 anton 164: WHILE \ the last >number parsed something
165: dup 1- dpl ! over c@ [char] . =
166: WHILE \ the current char is '.'
1.1 pazsan 167: 1 /string
1.18 anton 168: REPEAT THEN \ there are unparseable characters left
1.21 pazsan 169: 2drop false
1.20 pazsan 170: ELSE
171: rdrop 2drop true
1.21 pazsan 172: THEN
173: r> base ! ;
1.20 pazsan 174:
175: \ ouch, this is complicated; there must be a simpler way - anton
1.125 anton 176: : s>number? ( addr u -- d f ) \ gforth
177: \G converts string addr u into d, flag indicates success
1.21 pazsan 178: sign? >r
1.20 pazsan 179: s>unumber?
180: 0= IF
1.21 pazsan 181: rdrop false
1.18 anton 182: ELSE \ no characters left, all ok
1.20 pazsan 183: r>
1.1 pazsan 184: IF
185: dnegate
186: THEN
1.18 anton 187: true
1.21 pazsan 188: THEN ;
1.1 pazsan 189:
1.18 anton 190: : s>number ( addr len -- d )
191: \ don't use this, there is no way to tell success
192: s>number? drop ;
193:
1.1 pazsan 194: : snumber? ( c-addr u -- 0 / n -1 / d 0> )
1.18 anton 195: s>number? 0=
1.1 pazsan 196: IF
197: 2drop false EXIT
198: THEN
1.18 anton 199: dpl @ dup 0< IF
1.1 pazsan 200: nip
1.18 anton 201: ELSE
202: 1+
1.1 pazsan 203: THEN ;
204:
205: : number? ( string -- string 0 / n -1 / d 0> )
206: dup >r count snumber? dup if
207: rdrop
208: else
209: r> swap
210: then ;
211:
212: : number ( string -- d )
213: number? ?dup 0= abort" ?" 0<
214: IF
215: s>d
216: THEN ;
217:
218: \ \ Comments ( \ \G
219:
1.29 crook 220: : ( ( compilation 'ccc<close-paren>' -- ; run-time -- ) \ thisone- core,file paren
1.17 crook 221: \G ** this will not get annotated. The alias in glocals.fs will instead **
1.29 crook 222: \G It does not work to use "wordset-" prefix since this file is glossed
223: \G by cross.fs which doesn't have the same functionalty as makedoc.fs
1.1 pazsan 224: [char] ) parse 2drop ; immediate
225:
1.51 anton 226: : \ ( compilation 'ccc<newline>' -- ; run-time -- ) \ thisone- core-ext,block-ext backslash
1.29 crook 227: \G ** this will not get annotated. The alias in glocals.fs will instead **
228: \G It does not work to use "wordset-" prefix since this file is glossed
229: \G by cross.fs which doesn't have the same functionalty as makedoc.fs
1.12 pazsan 230: [ has? file [IF] ]
1.1 pazsan 231: blk @
232: IF
233: >in @ c/l / 1+ c/l * >in !
234: EXIT
235: THEN
1.12 pazsan 236: [ [THEN] ]
1.1 pazsan 237: source >in ! drop ; immediate
238:
1.51 anton 239: : \G ( compilation 'ccc<newline>' -- ; run-time -- ) \ gforth backslash-gee
1.19 crook 240: \G Equivalent to @code{\} but used as a tag to annotate definition
241: \G comments into documentation.
1.1 pazsan 242: POSTPONE \ ; immediate
243:
1.139 pazsan 244: has? ec [IF]
245: AVariable forth-wordlist
1.140 pazsan 246: AVariable current forth-wordlist current !
247: ' current alias context
1.139 pazsan 248: | ' (f83find) alias (search-wordlist) ( addr len wid -- nt / false )
249: : find-name ( c-addr u -- nt | 0 ) \ gforth
250: \g Find the name @i{c-addr u} in the current search
251: \g order. Return its @i{nt}, if found, otherwise 0.
252: context @ (search-wordlist) ;
253: [ELSE]
1.1 pazsan 254: \ \ object oriented search list 17mar93py
255:
256: \ word list structure:
257:
258: struct
259: cell% field find-method \ xt: ( c_addr u wid -- nt )
260: cell% field reveal-method \ xt: ( nt wid -- ) \ used by dofield:, must be field
261: cell% field rehash-method \ xt: ( wid -- ) \ re-initializes a "search-data" (hashtables)
262: cell% field hash-method \ xt: ( wid -- ) \ initializes ""
263: \ \ !! what else
264: end-struct wordlist-map-struct
265:
266: struct
1.6 pazsan 267: cell% field wordlist-map \ pointer to a wordlist-map-struct
1.13 anton 268: cell% field wordlist-id \ linked list of words (for WORDS etc.)
1.1 pazsan 269: cell% field wordlist-link \ link field to other wordlists
1.13 anton 270: cell% field wordlist-extend \ wordlist extensions (eg bucket offset)
1.1 pazsan 271: end-struct wordlist-struct
272:
1.103 pazsan 273: has? f83headerstring [IF]
274: : f83find ( addr len wordlist -- nt / false )
275: wordlist-id @ (f83find) ;
276: [ELSE]
1.1 pazsan 277: : f83find ( addr len wordlist -- nt / false )
1.67 anton 278: wordlist-id @ (listlfind) ;
1.103 pazsan 279: [THEN]
1.1 pazsan 280:
281: : initvoc ( wid -- )
282: dup wordlist-map @ hash-method perform ;
283:
284: \ Search list table: find reveal
285: Create f83search ( -- wordlist-map )
286: ' f83find A, ' drop A, ' drop A, ' drop A,
287:
1.6 pazsan 288: here G f83search T A, NIL A, NIL A, NIL A,
1.1 pazsan 289: AValue forth-wordlist \ variable, will be redefined by search.fs
290:
291: AVariable lookup forth-wordlist lookup !
292: \ !! last is user and lookup?! jaw
293: AVariable current ( -- addr ) \ gforth
1.43 crook 294: \G @code{Variable} -- holds the @i{wid} of the compilation word list.
1.1 pazsan 295: AVariable voclink forth-wordlist wordlist-link voclink !
1.38 anton 296: \ lookup AValue context ( -- addr ) \ gforth
297: Defer context ( -- addr ) \ gforth
1.43 crook 298: \G @code{context} @code{@@} is the @i{wid} of the word list at the
299: \G top of the search order.
1.1 pazsan 300:
1.38 anton 301: ' lookup is context
1.1 pazsan 302: forth-wordlist current !
303:
1.139 pazsan 304: : (search-wordlist) ( addr count wid -- nt | false )
305: dup wordlist-map @ find-method perform ;
306:
307: : search-wordlist ( c-addr count wid -- 0 | xt +-1 ) \ search
308: \G Search the word list identified by @i{wid} for the definition
309: \G named by the string at @i{c-addr count}. If the definition is
310: \G not found, return 0. If the definition is found return 1 (if
311: \G the definition is immediate) or -1 (if the definition is not
312: \G immediate) together with the @i{xt}. In Gforth, the @i{xt}
313: \G returned represents the interpretation semantics. ANS Forth
314: \G does not specify clearly what @i{xt} represents.
315: (search-wordlist) dup if
316: (name>intn)
317: then ;
318:
319: : find-name ( c-addr u -- nt | 0 ) \ gforth
320: \g Find the name @i{c-addr u} in the current search
321: \g order. Return its @i{nt}, if found, otherwise 0.
322: lookup @ (search-wordlist) ;
323: [THEN]
324:
1.1 pazsan 325: \ \ header, finding, ticks 17dec92py
326:
1.69 pazsan 327: \ The constants are defined as 32 bits, but then erased
328: \ and overwritten by the right ones
1.67 anton 329:
1.103 pazsan 330: has? f83headerstring [IF]
331: \ to save space, Gforth EC limits words to 31 characters
332: $80 constant alias-mask
333: $40 constant immediate-mask
334: $20 constant restrict-mask
335: $1f constant lcount-mask
336: [ELSE]
1.67 anton 337: $80000000 constant alias-mask
1.69 pazsan 338: 1 bits/char 1 - lshift
339: -1 cells allot bigendian [IF] c, 0 1 cells 1- times
340: [ELSE] 0 1 cells 1- times c, [THEN]
1.67 anton 341: $40000000 constant immediate-mask
1.69 pazsan 342: 1 bits/char 2 - lshift
343: -1 cells allot bigendian [IF] c, 0 1 cells 1- times
344: [ELSE] 0 1 cells 1- times c, [THEN]
1.67 anton 345: $20000000 constant restrict-mask
1.69 pazsan 346: 1 bits/char 3 - lshift
347: -1 cells allot bigendian [IF] c, 0 1 cells 1- times
348: [ELSE] 0 1 cells 1- times c, [THEN]
1.67 anton 349: $1fffffff constant lcount-mask
1.69 pazsan 350: 1 bits/char 3 - lshift 1 -
1.71 pazsan 351: -1 cells allot bigendian [IF] c, -1 1 cells 1- times
352: [ELSE] -1 1 cells 1- times c, [THEN]
1.103 pazsan 353: [THEN]
1.1 pazsan 354:
355: \ higher level parts of find
356:
357: : flag-sign ( f -- 1|-1 )
358: \ true becomes 1, false -1
359: 0= 2* 1+ ;
360:
1.79 anton 361: : ticking-compile-only-error ( ... -- )
362: -&2048 throw ;
1.1 pazsan 363:
1.93 anton 364: : compile-only-error ( ... -- )
365: -&14 throw ;
366:
1.1 pazsan 367: : (cfa>int) ( cfa -- xt )
368: [ has? compiler [IF] ]
369: dup interpret/compile?
370: if
371: interpret/compile-int @
372: then
373: [ [THEN] ] ;
374:
1.67 anton 375: : (x>int) ( cfa w -- xt )
1.1 pazsan 376: \ get interpretation semantics of name
1.141 pazsan 377: restrict-mask and [ has? rom [IF] ] 0= [ [THEN] ]
1.1 pazsan 378: if
1.93 anton 379: drop ['] compile-only-error
1.1 pazsan 380: else
381: (cfa>int)
382: then ;
383:
1.103 pazsan 384: has? f83headerstring [IF]
385: : name>string ( nt -- addr count ) \ gforth head-to-string
386: \g @i{addr count} is the name of the word represented by @i{nt}.
387: cell+ count lcount-mask and ;
388:
389: : ((name>)) ( nfa -- cfa )
390: name>string + cfaligned ;
391:
392: : (name>x) ( nfa -- cfa w )
393: \ cfa is an intermediate cfa and w is the flags cell of nfa
394: dup ((name>))
395: swap cell+ c@ dup alias-mask and 0=
396: IF
397: swap @ swap
398: THEN ;
399: [ELSE]
1.1 pazsan 400: : name>string ( nt -- addr count ) \ gforth head-to-string
1.40 crook 401: \g @i{addr count} is the name of the word represented by @i{nt}.
1.67 anton 402: cell+ dup cell+ swap @ lcount-mask and ;
1.1 pazsan 403:
404: : ((name>)) ( nfa -- cfa )
405: name>string + cfaligned ;
406:
1.67 anton 407: : (name>x) ( nfa -- cfa w )
408: \ cfa is an intermediate cfa and w is the flags cell of nfa
1.1 pazsan 409: dup ((name>))
1.67 anton 410: swap cell+ @ dup alias-mask and 0=
1.1 pazsan 411: IF
412: swap @ swap
413: THEN ;
1.103 pazsan 414: [THEN]
1.1 pazsan 415:
416: : name>int ( nt -- xt ) \ gforth
1.31 crook 417: \G @i{xt} represents the interpretation semantics of the word
418: \G @i{nt}. If @i{nt} has no interpretation semantics (i.e. is
419: \G @code{compile-only}), @i{xt} is the execution token for
1.79 anton 420: \G @code{ticking-compile-only-error}, which performs @code{-2048 throw}.
1.1 pazsan 421: (name>x) (x>int) ;
422:
423: : name?int ( nt -- xt ) \ gforth
1.79 anton 424: \G Like @code{name>int}, but perform @code{-2048 throw} if @i{nt}
1.31 crook 425: \G has no interpretation semantics.
1.141 pazsan 426: (name>x) restrict-mask and [ has? rom [IF] ] 0= [ [THEN] ]
1.1 pazsan 427: if
1.79 anton 428: ticking-compile-only-error \ does not return
1.1 pazsan 429: then
430: (cfa>int) ;
431:
432: : (name>comp) ( nt -- w +-1 ) \ gforth
1.31 crook 433: \G @i{w xt} is the compilation token for the word @i{nt}.
1.1 pazsan 434: (name>x) >r
435: [ has? compiler [IF] ]
436: dup interpret/compile?
437: if
438: interpret/compile-comp @
439: then
440: [ [THEN] ]
1.141 pazsan 441: r> immediate-mask and [ has? rom [IF] ] 0= [ [THEN] ] flag-sign
1.1 pazsan 442: ;
443:
444: : (name>intn) ( nfa -- xt +-1 )
1.67 anton 445: (name>x) tuck (x>int) ( w xt )
1.141 pazsan 446: swap immediate-mask and [ has? rom [IF] ] 0= [ [THEN] ] flag-sign ;
1.1 pazsan 447:
1.72 pazsan 448: const Create ??? 0 , 3 , char ? c, char ? c, char ? c,
1.30 jwilke 449: \ ??? is used by dovar:, must be created/:dovar
450:
451: [IFDEF] forthstart
452: \ if we have a forthstart we can define head? with it
453: \ otherwise leave out the head? check
454:
1.14 anton 455: : head? ( addr -- f )
1.82 anton 456: \G heuristic check whether addr is a name token; may deliver false
457: \G positives; addr must be a valid address; returns 1 for
458: \G particularly unsafe positives
1.14 anton 459: \ we follow the link fields and check for plausibility; two
460: \ iterations should catch most false addresses: on the first
461: \ iteration, we may get an xt, on the second a code address (or
462: \ some code), which is typically not in the dictionary.
1.82 anton 463: \ we added a third iteration for working with code and ;code words.
464: 3 0 do
1.41 anton 465: dup dup aligned <> if \ protect @ against unaligned accesses
466: drop false unloop exit
467: then
1.14 anton 468: dup @ dup
469: if ( addr addr1 )
470: dup rot forthstart within
471: if \ addr1 is outside forthstart..addr, not a head
472: drop false unloop exit
473: then ( addr1 )
474: else \ 0 in the link field, no further checks
1.81 anton 475: 2drop 1 unloop exit \ this is very unsure, so return 1
1.14 anton 476: then
477: loop
478: \ in dubio pro:
479: drop true ;
480:
1.48 anton 481: : >head-noprim ( cfa -- nt ) \ gforth to-head-noprim
1.97 anton 482: \ also heuristic
483: dup forthstart - max-name-length @ float+ cell+ min cell max cell ?do ( cfa )
1.70 pazsan 484: dup i - dup @ [ alias-mask lcount-mask or ] literal
485: [ 1 bits/char 3 - lshift 1 - 1 bits/char 1 - lshift or
1.71 pazsan 486: -1 cells allot bigendian [IF] c, -1 1 cells 1- times
487: [ELSE] -1 1 cells 1- times c, [THEN] ]
1.70 pazsan 488: and ( cfa len|alias )
1.97 anton 489: swap + cell+ cfaligned over alias-mask + =
1.14 anton 490: if ( cfa )
491: dup i - cell - dup head?
492: if
493: nip unloop exit
494: then
495: drop
496: then
497: cell +loop
498: drop ??? ( wouldn't 0 be better? ) ;
1.1 pazsan 499:
1.30 jwilke 500: [ELSE]
501:
1.48 anton 502: : >head-noprim ( cfa -- nt ) \ gforth to-head-noprim
1.45 pazsan 503: $25 cell do ( cfa )
1.70 pazsan 504: dup i - dup @ [ alias-mask lcount-mask or ] literal
505: [ 1 bits/char 3 - lshift 1 - 1 bits/char 1 - lshift or
1.71 pazsan 506: -1 cells allot bigendian [IF] c, -1 1 cells 1- times
507: [ELSE] -1 1 cells 1- times c, [THEN] ]
1.70 pazsan 508: and ( cfa len|alias )
1.67 anton 509: swap + cell + cfaligned over alias-mask + =
1.30 jwilke 510: if ( cfa ) i - cell - unloop exit
511: then
512: cell +loop
513: drop ??? ( wouldn't 0 be better? ) ;
514:
515: [THEN]
1.1 pazsan 516:
1.83 anton 517: cell% 2* 0 0 field >body ( xt -- a_addr ) \ core
518: \G Get the address of the body of the word represented by @i{xt} (the
519: \G address of the word's data field).
520: drop drop
521:
522: cell% -2 * 0 0 field body> ( xt -- a_addr )
1.84 anton 523: drop drop
524:
525: has? standardthreading has? compiler and [IF]
526:
527: ' @ alias >code-address ( xt -- c_addr ) \ gforth
528: \G @i{c-addr} is the code address of the word @i{xt}.
529:
530: : >does-code ( xt -- a_addr ) \ gforth
531: \G If @i{xt} is the execution token of a child of a @code{DOES>} word,
532: \G @i{a-addr} is the start of the Forth code after the @code{DOES>};
533: \G Otherwise @i{a-addr} is 0.
534: dup @ dodoes: = if
535: cell+ @
536: else
537: drop 0
538: endif ;
539:
1.142 ! pazsan 540: has? flash [IF] ' flash! [ELSE] ' ! [THEN]
! 541: alias code-address! ( c_addr xt -- ) \ gforth
1.85 anton 542: \G Create a code field with code address @i{c-addr} at @i{xt}.
543:
544: : does-code! ( a_addr xt -- ) \ gforth
545: \G Create a code field at @i{xt} for a child of a @code{DOES>}-word;
546: \G @i{a-addr} is the start of the Forth code after @code{DOES>}.
1.142 ! pazsan 547: [ has? flash [IF] ]
! 548: dodoes: over flash! cell+ flash!
! 549: [ [ELSE] ]
! 550: dodoes: over ! cell+ !
! 551: [ [THEN] ] ;
1.85 anton 552:
1.86 anton 553: ' drop alias does-handler! ( a_addr -- ) \ gforth
554: \G Create a @code{DOES>}-handler at address @i{a-addr}. Normally,
555: \G @i{a-addr} points just behind a @code{DOES>}.
556:
1.85 anton 557: 2 cells constant /does-handler ( -- n ) \ gforth
558: \G The size of a @code{DOES>}-handler (includes possible padding).
559:
1.84 anton 560: [THEN]
1.1 pazsan 561:
562: : sfind ( c-addr u -- 0 / xt +-1 ) \ gforth-obsolete
563: find-name dup
564: if ( nt )
565: state @
566: if
567: (name>comp)
568: else
569: (name>intn)
570: then
571: then ;
572:
1.31 crook 573: : find ( c-addr -- xt +-1 | c-addr 0 ) \ core,search
1.53 anton 574: \G Search all word lists in the current search order for the
575: \G definition named by the counted string at @i{c-addr}. If the
576: \G definition is not found, return 0. If the definition is found
577: \G return 1 (if the definition has non-default compilation
578: \G semantics) or -1 (if the definition has default compilation
579: \G semantics). The @i{xt} returned in interpret state represents
580: \G the interpretation semantics. The @i{xt} returned in compile
581: \G state represented either the compilation semantics (for
582: \G non-default compilation semantics) or the run-time semantics
583: \G that the compilation semantics would @code{compile,} (for
584: \G default compilation semantics). The ANS Forth standard does
585: \G not specify clearly what the returned @i{xt} represents (and
586: \G also talks about immediacy instead of non-default compilation
587: \G semantics), so this word is questionable in portable programs.
588: \G If non-portability is ok, @code{find-name} and friends are
589: \G better (@pxref{Name token}).
1.1 pazsan 590: dup count sfind dup
591: if
592: rot drop
593: then ;
594:
1.34 jwilke 595: \ ticks in interpreter
1.1 pazsan 596:
597: : (') ( "name" -- nt ) \ gforth
1.139 pazsan 598: parse-name name-too-short?
1.28 anton 599: find-name dup 0=
1.1 pazsan 600: IF
1.42 anton 601: drop -&13 throw
1.1 pazsan 602: THEN ;
603:
604: : ' ( "name" -- xt ) \ core tick
1.31 crook 605: \g @i{xt} represents @i{name}'s interpretation
606: \g semantics. Perform @code{-14 throw} if the word has no
1.1 pazsan 607: \g interpretation semantics.
608: (') name?int ;
1.34 jwilke 609:
610: has? compiler 0= [IF] \ interpreter only version of IS and TO
611:
612: : IS ' >body ! ;
613: ' IS Alias TO
614:
615: [THEN]
1.1 pazsan 616:
617: \ \ the interpreter loop mar92py
618:
619: \ interpret 10mar92py
620:
1.120 anton 621: Defer parser1 ( c-addr u -- ... xt)
622: \ "... xt" is the action to be performed by the text-interpretation of c-addr u
623:
624: : parser ( c-addr u -- ... )
625: \ text-interpret the word/number c-addr u, possibly producing a number
626: parser1 execute ;
627:
1.139 pazsan 628: has? ec [IF]
629: ' (name) Alias parse-name
1.140 pazsan 630: : no.extensions 2drop -&13 throw ;
1.139 pazsan 631: ' no.extensions Alias compiler-notfound1
632: ' no.extensions Alias interpreter-notfound1
633: [ELSE]
1.119 anton 634: Defer parse-name ( "name" -- c-addr u ) \ gforth
1.55 anton 635: \G Get the next word from the input buffer
1.119 anton 636: ' (name) IS parse-name
1.77 anton 637:
1.119 anton 638: ' parse-name alias parse-word ( -- c-addr u ) \ gforth-obsolete
639: \G old name for @code{parse-name}
640:
641: ' parse-name alias name ( -- c-addr u ) \ gforth-obsolete
642: \G old name for @code{parse-name}
643:
1.120 anton 644: Defer compiler-notfound1 ( c-addr count -- ... xt )
645: Defer interpreter-notfound1 ( c-addr count -- ... xt )
1.1 pazsan 646:
647: : no.extensions ( addr u -- )
1.42 anton 648: 2drop -&13 throw ;
1.120 anton 649: ' no.extensions IS compiler-notfound1
650: ' no.extensions IS interpreter-notfound1
1.1 pazsan 651:
1.106 anton 652: Defer before-word ( -- ) \ gforth
653: \ called before the text interpreter parses the next word
654: ' noop IS before-word
1.139 pazsan 655: [THEN]
1.106 anton 656:
1.66 anton 657: : interpret1 ( ... -- ... )
1.33 jwilke 658: [ has? backtrace [IF] ]
1.24 anton 659: rp@ backtrace-rp0 !
1.33 jwilke 660: [ [THEN] ]
1.1 pazsan 661: BEGIN
1.139 pazsan 662: ?stack [ has? EC 0= [IF] ] before-word [ [THEN] ] parse-name dup
1.1 pazsan 663: WHILE
1.120 anton 664: parser1 execute
1.1 pazsan 665: REPEAT
1.66 anton 666: 2drop ;
667:
668: : interpret ( ?? -- ?? ) \ gforth
669: \ interpret/compile the (rest of the) input buffer
670: [ has? backtrace [IF] ]
671: backtrace-rp0 @ >r
672: [ [THEN] ]
673: ['] interpret1 catch
1.65 anton 674: [ has? backtrace [IF] ]
675: r> backtrace-rp0 !
1.66 anton 676: [ [THEN] ]
677: throw ;
1.1 pazsan 678:
679: \ interpreter 30apr92py
680:
681: \ not the most efficient implementations of interpreter and compiler
1.120 anton 682: : interpreter1 ( c-addr u -- ... xt )
1.1 pazsan 683: 2dup find-name dup
684: if
1.120 anton 685: nip nip name>int
1.1 pazsan 686: else
687: drop
688: 2dup 2>r snumber?
689: IF
1.120 anton 690: 2rdrop ['] noop
1.1 pazsan 691: ELSE
1.120 anton 692: 2r> interpreter-notfound1
1.1 pazsan 693: THEN
694: then ;
695:
1.120 anton 696: ' interpreter1 IS parser1
1.1 pazsan 697:
698: \ \ Query Evaluate 07apr93py
699:
700: has? file 0= [IF]
1.12 pazsan 701: : sourceline# ( -- n ) 1 ;
1.61 pazsan 702: [ELSE]
1.64 pazsan 703: has? new-input 0= [IF]
1.58 pazsan 704: Variable #fill-bytes
705: \G number of bytes read via (read-line) by the last refill
1.61 pazsan 706: [THEN]
1.64 pazsan 707: [THEN]
1.58 pazsan 708:
1.64 pazsan 709: has? new-input 0= [IF]
1.138 pazsan 710: : input-start-line ( -- ) >in off ;
1.1 pazsan 711: : refill ( -- flag ) \ core-ext,block-ext,file-ext
1.29 crook 712: \G Attempt to fill the input buffer from the input source. When
713: \G the input source is the user input device, attempt to receive
714: \G input into the terminal input device. If successful, make the
715: \G result the input buffer, set @code{>IN} to 0 and return true;
716: \G otherwise return false. When the input source is a block, add 1
717: \G to the value of @code{BLK} to make the next block the input
718: \G source and current input buffer, and set @code{>IN} to 0;
719: \G return true if the new value of @code{BLK} is a valid block
720: \G number, false otherwise. When the input source is a text file,
721: \G attempt to read the next line from the file. If successful,
722: \G make the result the current input buffer, set @code{>IN} to 0
723: \G and return true; otherwise, return false. A successful result
724: \G includes receipt of a line containing 0 characters.
1.12 pazsan 725: [ has? file [IF] ]
1.138 pazsan 726: blk @ IF 1 blk +! true EXIT THEN
1.12 pazsan 727: [ [THEN] ]
728: tib /line
729: [ has? file [IF] ]
730: loadfile @ ?dup
1.59 pazsan 731: IF (read-line) throw #fill-bytes !
1.12 pazsan 732: ELSE
733: [ [THEN] ]
734: sourceline# 0< IF 2drop false EXIT THEN
735: accept true
736: [ has? file [IF] ]
737: THEN
738: 1 loadline +!
739: [ [THEN] ]
1.138 pazsan 740: swap #tib !
741: input-start-line ;
1.1 pazsan 742:
743: : query ( -- ) \ core-ext
1.29 crook 744: \G Make the user input device the input source. Receive input into
745: \G the Terminal Input Buffer. Set @code{>IN} to zero. OBSOLESCENT:
746: \G superceeded by @code{accept}.
1.12 pazsan 747: [ has? file [IF] ]
748: blk off loadfile off
749: [ [THEN] ]
1.64 pazsan 750: refill drop ;
751: [THEN]
1.1 pazsan 752:
753: \ save-mem extend-mem
754:
755: has? os [IF]
756: : save-mem ( addr1 u -- addr2 u ) \ gforth
757: \g copy a memory block into a newly allocated region in the heap
758: swap >r
759: dup allocate throw
760: swap 2dup r> -rot move ;
761:
1.68 anton 762: : free-mem-var ( addr -- )
763: \ addr is the address of a 2variable containing address and size
764: \ of a memory range; frees memory and clears the 2variable.
765: dup 2@ drop dup
766: if ( addr mem-start )
767: free throw
768: 0 0 rot 2!
769: else
770: 2drop
771: then ;
772:
1.1 pazsan 773: : extend-mem ( addr1 u1 u -- addr addr2 u2 )
774: \ extend memory block allocated from the heap by u aus
1.105 anton 775: \ the (possibly reallocated) piece is addr2 u2, the extension is at addr
1.1 pazsan 776: over >r + dup >r resize throw
777: r> over r> + -rot ;
778: [THEN]
779:
780: \ EVALUATE 17may93jaw
781:
1.64 pazsan 782: has? file 0= has? new-input 0= and [IF]
1.1 pazsan 783: : push-file ( -- ) r>
1.12 pazsan 784: tibstack @ >r >tib @ >r #tib @ >r
1.1 pazsan 785: >tib @ tibstack @ = IF r@ tibstack +! THEN
786: tibstack @ >tib ! >in @ >r >r ;
787:
788: : pop-file ( throw-code -- throw-code )
789: r>
1.12 pazsan 790: r> >in ! r> #tib ! r> >tib ! r> tibstack ! >r ;
1.1 pazsan 791: [THEN]
792:
1.64 pazsan 793: has? new-input 0= [IF]
1.29 crook 794: : evaluate ( c-addr u -- ) \ core,block
1.40 crook 795: \G Save the current input source specification. Store @code{-1} in
796: \G @code{source-id} and @code{0} in @code{blk}. Set @code{>IN} to
797: \G @code{0} and make the string @i{c-addr u} the input source
798: \G and input buffer. Interpret. When the parse area is empty,
799: \G restore the input source specification.
1.64 pazsan 800: [ has? file [IF] ]
1.92 anton 801: s" *evaluated string*" loadfilename>r
1.64 pazsan 802: [ [THEN] ]
1.40 crook 803: push-file #tib ! >tib !
1.130 anton 804: input-start-line
1.29 crook 805: [ has? file [IF] ]
806: blk off loadfile off -1 loadline !
807: [ [THEN] ]
808: ['] interpret catch
1.56 anton 809: pop-file
1.64 pazsan 810: [ has? file [IF] ]
1.92 anton 811: r>loadfilename
1.64 pazsan 812: [ [THEN] ]
1.56 anton 813: throw ;
1.64 pazsan 814: [THEN]
1.1 pazsan 815:
816: \ \ Quit 13feb93py
817:
818: Defer 'quit
819:
820: Defer .status
821:
822: : prompt state @ IF ." compiled" EXIT THEN ." ok" ;
823:
1.39 anton 824: : (quit) ( -- )
825: \ exits only through THROW etc.
826: BEGIN
1.98 anton 827: .status
828: ['] cr catch if
1.99 anton 829: >stderr cr ." Can't print to stdout, leaving" cr
1.98 anton 830: \ if stderr does not work either, already DoError causes a hang
831: 2 (bye)
832: endif
1.138 pazsan 833: refill WHILE
1.122 anton 834: interpret prompt
835: REPEAT
836: bye ;
1.1 pazsan 837:
838: ' (quit) IS 'quit
839:
840: \ \ DOERROR (DOERROR) 13jun93jaw
841:
1.131 pazsan 842: has? ec 0= [IF]
1.1 pazsan 843: 8 Constant max-errors
1.130 anton 844: 5 has? file 2 and + Constant /error
1.1 pazsan 845: Variable error-stack 0 error-stack !
1.112 pazsan 846: max-errors /error * cells allot
1.1 pazsan 847: \ format of one cell:
1.133 anton 848: \ source ( c-addr u )
849: \ last parsed lexeme ( c-addr u )
1.1 pazsan 850: \ line-number
851: \ Loadfilename ( addr u )
852:
1.133 anton 853: : error> ( -- c-addr1 u1 c-addr2 u2 line# [addr u] )
1.64 pazsan 854: -1 error-stack +!
855: error-stack dup @
1.112 pazsan 856: /error * cells + cell+
857: /error cells bounds DO
1.130 anton 858: I @
859: cell +LOOP ;
860:
1.133 anton 861: : >error ( c-addr1 u1 c-addr2 u2 line# [addr u] -- )
1.64 pazsan 862: error-stack dup @ dup 1+
863: max-errors 1- min error-stack !
1.112 pazsan 864: /error * cells + cell+
865: /error 1- cells bounds swap DO
1.130 anton 866: I !
867: -1 cells +LOOP ;
868:
1.133 anton 869: : input-error-data ( -- c-addr1 u1 c-addr2 u2 line# [addr u] )
1.130 anton 870: \ error data for the current input, to be used by >error or .error-frame
1.133 anton 871: source input-lexeme 2@ sourceline#
1.130 anton 872: [ has? file [IF] ] sourcefilename [ [THEN] ] ;
1.64 pazsan 873:
1.1 pazsan 874: : dec. ( n -- ) \ gforth
1.40 crook 875: \G Display @i{n} as a signed decimal number, followed by a space.
876: \ !! not used...
1.1 pazsan 877: base @ decimal swap . base ! ;
878:
1.111 anton 879: : dec.r ( u n -- ) \ gforth
880: \G Display @i{u} as a unsigned decimal number in a field @i{n}
881: \G characters wide.
882: base @ >r decimal .r r> base ! ;
1.23 jwilke 883:
1.1 pazsan 884: : hex. ( u -- ) \ gforth
1.40 crook 885: \G Display @i{u} as an unsigned hex number, prefixed with a "$" and
1.17 crook 886: \G followed by a space.
1.40 crook 887: \ !! not used...
1.33 jwilke 888: [char] $ emit base @ swap hex u. base ! ;
1.1 pazsan 889:
1.94 anton 890: : -trailing ( c_addr u1 -- c_addr u2 ) \ string dash-trailing
891: \G Adjust the string specified by @i{c-addr, u1} to remove all
892: \G trailing spaces. @i{u2} is the length of the modified string.
893: BEGIN
1.102 pazsan 894: dup
1.94 anton 895: WHILE
1.102 pazsan 896: 1- 2dup + c@ bl <>
897: UNTIL 1+ THEN ;
1.94 anton 898:
1.1 pazsan 899: DEFER DOERROR
1.33 jwilke 900:
901: has? backtrace [IF]
1.15 anton 902: Defer dobacktrace ( -- )
903: ' noop IS dobacktrace
1.33 jwilke 904: [THEN]
1.1 pazsan 905:
1.23 jwilke 906: : .error-string ( throw-code -- )
907: dup -2 =
908: IF "error @ ?dup IF count type THEN drop
909: ELSE .error
910: THEN ;
911:
1.111 anton 912: : umin ( u1 u2 -- u )
913: 2dup u>
914: if
915: swap
916: then
917: drop ;
918:
1.112 pazsan 919: Defer mark-start
920: Defer mark-end
921:
922: :noname ." >>>" ; IS mark-start
923: :noname ." <<<" ; IS mark-end
924:
1.130 anton 925: : part-type ( addr1 u1 u -- addr2 u2 )
926: \ print first u characters of addr1 u1, addr2 u2 is the rest
1.133 anton 927: over umin 2 pick over type /string ;
1.130 anton 928:
1.133 anton 929: : .error-line ( c-addr1 u1 c-addr2 u2 -- )
930: \ print error in line c-addr1 u1, where the error-causing lexeme
931: \ is c-addr2 u2
932: >r 2 pick - part-type ( c-addr3 u3 R: u2 )
933: mark-start r> part-type mark-end ( c-addr4 u4 )
934: type ;
1.130 anton 935:
1.133 anton 936: : .error-frame ( throwcode addr1 u1 addr2 u2 n2 [addr3 u3] -- throwcode )
937: \ addr3 u3: filename of included file - optional
1.130 anton 938: \ n2: line number
1.133 anton 939: \ addr2 u2: parsed lexeme (should be marked as causing the error)
1.130 anton 940: \ addr1 u1: input line
941: error-stack @
942: IF ( throwcode addr1 u1 n0 n1 n2 [addr2 u2] )
943: [ has? file [IF] ] \ !! unbalanced stack effect
1.129 pazsan 944: over IF
945: cr ." in file included from "
946: type ." :"
1.130 anton 947: 0 dec.r 2drop 2drop
948: ELSE
949: 2drop 2drop 2drop drop
950: THEN
951: [ [THEN] ] ( throwcode addr1 u1 n0 n1 n2 )
952: ELSE ( throwcode addr1 u1 n0 n1 n2 [addr2 u2] )
953: [ has? file [IF] ]
954: cr type ." :"
955: [ [THEN] ] ( throwcode addr1 u1 n0 n1 n2 )
956: dup 0 dec.r ." : " 5 pick .error-string
957: IF \ if line# non-zero, there is a line
958: cr .error-line
959: ELSE
960: 2drop 2drop
961: THEN
962: THEN ;
1.1 pazsan 963:
964: : (DoError) ( throw-code -- )
965: [ has? os [IF] ]
1.8 pazsan 966: >stderr
1.1 pazsan 967: [ [THEN] ]
1.130 anton 968: input-error-data .error-frame
1.1 pazsan 969: error-stack @ 0 ?DO
1.64 pazsan 970: error>
1.1 pazsan 971: .error-frame
972: LOOP
1.33 jwilke 973: drop
974: [ has? backtrace [IF] ]
975: dobacktrace
976: [ [THEN] ]
1.8 pazsan 977: normal-dp dpp ! ;
1.1 pazsan 978:
979: ' (DoError) IS DoError
1.131 pazsan 980:
981: [ELSE]
982: : dec. base @ >r decimal . r> base ! ;
983: : DoError ( throw-code -- ) ." Error# " dec. cr ;
984: [THEN]
1.1 pazsan 985:
986: : quit ( ?? -- ?? ) \ core
1.27 crook 987: \G Empty the return stack, make the user input device
988: \G the input source, enter interpret state and start
989: \G the text interpreter.
1.64 pazsan 990: rp0 @ rp! handler off clear-tibstack
991: [ has? new-input 0= [IF] ] >tib @ >r [ [THEN] ]
1.1 pazsan 992: BEGIN
993: [ has? compiler [IF] ]
1.104 anton 994: [compile] [
1.1 pazsan 995: [ [THEN] ]
1.104 anton 996: \ stack depths may be arbitrary here
1.1 pazsan 997: ['] 'quit CATCH dup
998: WHILE
1.104 anton 999: <# \ reset hold area, or we may get another error
1000: DoError
1001: \ stack depths may be arbitrary still (or again), so clear them
1002: clearstacks
1003: [ has? new-input [IF] ] clear-tibstack
1004: [ [ELSE] ] r@ >tib ! r@ tibstack !
1005: [ [THEN] ]
1.1 pazsan 1006: REPEAT
1.64 pazsan 1007: drop [ has? new-input [IF] ] clear-tibstack
1008: [ [ELSE] ] r> >tib !
1009: [ [THEN] ] ;
1.1 pazsan 1010:
1011: \ \ Cold Boot 13feb93py
1012:
1013: : (bootmessage)
1.101 anton 1014: ." Gforth " version-string type
1.130 anton 1015: ." , Copyright (C) 1995-2006 Free Software Foundation, Inc." cr
1.101 anton 1016: ." Gforth comes with ABSOLUTELY NO WARRANTY; for details type `license'"
1.1 pazsan 1017: [ has? os [IF] ]
1018: cr ." Type `bye' to exit"
1019: [ [THEN] ] ;
1020:
1021: defer bootmessage
1.135 pazsan 1022: has? file [IF]
1.1 pazsan 1023: defer process-args
1.135 pazsan 1024: [THEN]
1.1 pazsan 1025:
1026: ' (bootmessage) IS bootmessage
1027:
1.136 pazsan 1028: has? ec 0= [IF]
1.10 anton 1029: Defer 'cold ( -- ) \ gforth tick-cold
1.1 pazsan 1030: \ hook (deferred word) for things to do right before interpreting the
1031: \ command-line arguments
1032: ' noop IS 'cold
1.136 pazsan 1033: [THEN]
1.1 pazsan 1034:
1.76 jwilke 1035: AVariable init8 NIL init8 !
1.1 pazsan 1036:
1037: : cold ( -- ) \ gforth
1.135 pazsan 1038: [ has? backtrace [IF] ]
1.44 anton 1039: rp@ backtrace-rp0 !
1040: [ [THEN] ]
1.1 pazsan 1041: [ has? file [IF] ]
1.78 pazsan 1042: os-cold
1.1 pazsan 1043: [ [THEN] ]
1.126 pazsan 1044: [ has? ec 0= [IF] ]
1.116 anton 1045: set-encoding-fixed-width
1.136 pazsan 1046: 'cold
1.126 pazsan 1047: [ [THEN] ]
1.1 pazsan 1048: init8 chainperform
1049: [ has? file [IF] ]
1.8 pazsan 1050: process-args
1.12 pazsan 1051: loadline off
1.1 pazsan 1052: [ [THEN] ]
1053: bootmessage
1.12 pazsan 1054: quit ;
1.1 pazsan 1055:
1.64 pazsan 1056: has? new-input 0= [IF]
1.5 anton 1057: : clear-tibstack ( -- )
1058: [ has? glocals [IF] ]
1059: lp@ forthstart 7 cells + @ -
1060: [ [ELSE] ]
1061: [ has? os [IF] ]
1.8 pazsan 1062: r0 @ forthstart 6 cells + @ -
1.5 anton 1063: [ [ELSE] ]
1.139 pazsan 1064: sp@ cell+
1.5 anton 1065: [ [THEN] ]
1066: [ [THEN] ]
1.138 pazsan 1067: dup >tib ! tibstack ! #tib off
1068: input-start-line ;
1.64 pazsan 1069: [THEN]
1.5 anton 1070:
1.64 pazsan 1071: : boot ( path n **argv argc -- )
1.134 pazsan 1072: [ has? no-userspace 0= [IF] ]
1.1 pazsan 1073: main-task up!
1.134 pazsan 1074: [ [THEN] ]
1.1 pazsan 1075: [ has? os [IF] ]
1.78 pazsan 1076: os-boot
1.134 pazsan 1077: [ [THEN] ]
1078: [ has? rom [IF] ]
1.137 pazsan 1079: ram-mirror ram-start ram-size cmove
1.1 pazsan 1080: [ [THEN] ]
1081: sp@ sp0 !
1.74 pazsan 1082: [ has? peephole [IF] ]
1.87 anton 1083: \ only needed for greedy static superinstruction selection
1084: \ primtable prepare-peephole-table TO peeptable
1.74 pazsan 1085: [ [THEN] ]
1.64 pazsan 1086: [ has? new-input [IF] ]
1087: current-input off
1088: [ [THEN] ]
1.5 anton 1089: clear-tibstack
1.127 anton 1090: 0 0 includefilename 2!
1.1 pazsan 1091: rp@ rp0 !
1092: [ has? floating [IF] ]
1093: fp@ fp0 !
1094: [ [THEN] ]
1.46 anton 1095: handler off
1.98 anton 1096: ['] cold catch dup -&2049 <> if \ broken pipe?
1097: DoError cr
1098: endif
1.1 pazsan 1099: [ has? os [IF] ]
1.35 anton 1100: 1 (bye) \ !! determin exit code from throw code?
1.1 pazsan 1101: [ [THEN] ]
1102: ;
1103:
1104: has? os [IF]
1105: : bye ( -- ) \ tools-ext
1106: [ has? file [IF] ]
1107: script? 0= IF cr THEN
1108: [ [ELSE] ]
1109: cr
1110: [ [THEN] ]
1111: 0 (bye) ;
1112: [THEN]
1113:
1114: \ **argv may be scanned by the C starter to get some important
1115: \ information, as -display and -geometry for an X client FORTH
1116: \ or space and stackspace overrides
1117:
1118: \ 0 arg contains, however, the name of the program.
1119:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>