| \ definitions needed for interpreter only |
\ definitions needed for interpreter only |
| |
|
| \ Copyright (C) 1995-2000,2004,2005 Free Software Foundation, Inc. |
\ Copyright (C) 1995-2000,2004,2005,2007 Free Software Foundation, Inc. |
| |
|
| \ This file is part of Gforth. |
\ This file is part of Gforth. |
| |
|
| THEN |
THEN |
| r> ; |
r> ; |
| |
|
| |
: ?dnegate ( d1 f -- d2 ) |
| |
if |
| |
dnegate |
| |
then ; |
| |
|
| |
has? os 0= [IF] |
| |
: x@+/string ( addr u -- addr' u' c ) |
| |
over c@ >r 1 /string r> ; |
| |
[THEN] |
| |
|
| : s'>unumber? ( addr u -- ud flag ) |
: s'>unumber? ( addr u -- ud flag ) |
| \ convert string "C" or "C'" to character code |
\ convert string "C" or "C'" to character code |
| dup 0= if |
dup 0= if |
| endif |
endif |
| x@+/string 0 s" '" 2rot string-prefix? ; |
x@+/string 0 s" '" 2rot string-prefix? ; |
| |
|
| : s>unumber? ( addr u -- ud flag ) \ gforth |
: s>unumber? ( c-addr u -- ud flag ) \ gforth |
| \G converts string addr u into ud, flag indicates success |
\G converts string c-addr u into ud, flag indicates success |
| dpl on |
dpl on |
| over c@ '' = if |
over c@ '' = if |
| 1 /string s'>unumber? exit |
1 /string s'>unumber? exit |
| endif |
endif |
| base @ >r getbase |
base @ >r getbase sign? >r |
| 0. 2swap |
0. 2swap |
| BEGIN ( d addr len ) |
BEGIN ( d addr len ) |
| dup >r >number dup |
dup >r >number dup |
| WHILE \ the current char is '.' |
WHILE \ the current char is '.' |
| 1 /string |
1 /string |
| REPEAT THEN \ there are unparseable characters left |
REPEAT THEN \ there are unparseable characters left |
| 2drop false |
2drop rdrop false |
| ELSE |
ELSE |
| rdrop 2drop true |
rdrop 2drop r> ?dnegate true |
| THEN |
THEN |
| r> base ! ; |
r> base ! ; |
| |
|
| 0= IF |
0= IF |
| rdrop false |
rdrop false |
| ELSE \ no characters left, all ok |
ELSE \ no characters left, all ok |
| r> |
r> ?dnegate |
| IF |
|
| dnegate |
|
| THEN |
|
| true |
true |
| THEN ; |
THEN ; |
| |
|
| then ; |
then ; |
| |
|
| has? f83headerstring [IF] |
has? f83headerstring [IF] |
| : name>string ( nt -- addr count ) \ gforth head-to-string |
: name>string ( nt -- addr count ) \ gforth name-to-string |
| \g @i{addr count} is the name of the word represented by @i{nt}. |
\g @i{addr count} is the name of the word represented by @i{nt}. |
| cell+ count lcount-mask and ; |
cell+ count lcount-mask and ; |
| |
|
| swap @ swap |
swap @ swap |
| THEN ; |
THEN ; |
| [ELSE] |
[ELSE] |
| : name>string ( nt -- addr count ) \ gforth head-to-string |
: name>string ( nt -- addr count ) \ gforth name-to-string |
| \g @i{addr count} is the name of the word represented by @i{nt}. |
\g @i{addr count} is the name of the word represented by @i{nt}. |
| cell+ dup cell+ swap @ lcount-mask and ; |
cell+ dup cell+ swap @ lcount-mask and ; |
| |
|
| THEN ; |
THEN ; |
| [THEN] |
[THEN] |
| |
|
| : name>int ( nt -- xt ) \ gforth |
: name>int ( nt -- xt ) \ gforth name-to-int |
| \G @i{xt} represents the interpretation semantics of the word |
\G @i{xt} represents the interpretation semantics of the word |
| \G @i{nt}. If @i{nt} has no interpretation semantics (i.e. is |
\G @i{nt}. If @i{nt} has no interpretation semantics (i.e. is |
| \G @code{compile-only}), @i{xt} is the execution token for |
\G @code{compile-only}), @i{xt} is the execution token for |
| \G @code{ticking-compile-only-error}, which performs @code{-2048 throw}. |
\G @code{ticking-compile-only-error}, which performs @code{-2048 throw}. |
| (name>x) (x>int) ; |
(name>x) (x>int) ; |
| |
|
| : name?int ( nt -- xt ) \ gforth |
: name?int ( nt -- xt ) \ gforth name-question-int |
| \G Like @code{name>int}, but perform @code{-2048 throw} if @i{nt} |
\G Like @code{name>int}, but perform @code{-2048 throw} if @i{nt} |
| \G has no interpretation semantics. |
\G has no interpretation semantics. |
| (name>x) restrict-mask and [ has? rom [IF] ] 0= [ [THEN] ] |
(name>x) restrict-mask and [ has? rom [IF] ] 0= [ [THEN] ] |
| |
|
| : >head-noprim ( cfa -- nt ) \ gforth to-head-noprim |
: >head-noprim ( cfa -- nt ) \ gforth to-head-noprim |
| \ also heuristic |
\ also heuristic |
| dup forthstart - max-name-length @ float+ cell+ min cell max cell ?do ( cfa ) |
dup forthstart - max-name-length @ |
| |
[ has? float [IF] ] float+ [ [ELSE] ] cell+ [ [THEN] ] cell+ min |
| |
cell max cell ?do ( cfa ) |
| dup i - dup @ [ alias-mask lcount-mask or ] literal |
dup i - dup @ [ alias-mask lcount-mask or ] literal |
| [ 1 bits/char 3 - lshift 1 - 1 bits/char 1 - lshift or |
[ 1 bits/char 3 - lshift 1 - 1 bits/char 1 - lshift or |
| -1 cells allot bigendian [IF] c, -1 1 cells 1- times |
-1 cells allot bigendian [IF] c, -1 1 cells 1- times |
| |
|
| [THEN] |
[THEN] |
| |
|
| cell% 2* 0 0 field >body ( xt -- a_addr ) \ core |
cell% 2* 0 0 field >body ( xt -- a_addr ) \ core to-body |
| \G Get the address of the body of the word represented by @i{xt} (the |
\G Get the address of the body of the word represented by @i{xt} (the |
| \G address of the word's data field). |
\G address of the word's data field). |
| drop drop |
drop drop |
| drop 0 |
drop 0 |
| endif ; |
endif ; |
| |
|
| |
has? prims [IF] |
| |
: flash! ! ; |
| |
: flashc! c! ; |
| |
[THEN] |
| |
|
| has? flash [IF] ' flash! [ELSE] ' ! [THEN] |
has? flash [IF] ' flash! [ELSE] ' ! [THEN] |
| alias code-address! ( c_addr xt -- ) \ gforth |
alias code-address! ( c_addr xt -- ) \ gforth |
| \G Create a code field with code address @i{c-addr} at @i{xt}. |
\G Create a code field with code address @i{c-addr} at @i{xt}. |
| backtrace-rp0 @ >r |
backtrace-rp0 @ >r |
| ['] interpret1 catch |
['] interpret1 catch |
| r> backtrace-rp0 ! |
r> backtrace-rp0 ! |
| throw>error ; |
throw ; |
| [ELSE] |
[ELSE] |
| : interpret ( ... -- ... ) |
: interpret ( ... -- ... ) |
| BEGIN |
BEGIN |
| |
|
| Defer 'quit |
Defer 'quit |
| |
|
| has? ec 0= [IF] |
has? os [IF] |
| Defer .status |
Defer .status |
| |
[ELSE] |
| |
: (bye) ( 0 -- ) \ back to DOS |
| |
drop 5 emit ; |
| |
|
| |
: bye ( -- ) 0 (bye) ; |
| [THEN] |
[THEN] |
| |
|
| : prompt state @ IF ." compiled" EXIT THEN ." ok" ; |
: prompt state @ IF ." compiled" EXIT THEN ." ok" ; |
| |
|
| \ \ DOERROR (DOERROR) 13jun93jaw |
\ \ DOERROR (DOERROR) 13jun93jaw |
| |
|
| has? ec 0= [IF] |
has? os [IF] |
| 8 Constant max-errors |
8 Constant max-errors |
| 5 has? file 2 and + Constant /error |
5 has? file 2 and + Constant /error |
| Variable error-stack 0 error-stack ! |
Variable error-stack 0 error-stack ! |
| |
|
| \ \ Cold Boot 13feb93py |
\ \ Cold Boot 13feb93py |
| |
|
| : (bootmessage) |
: (bootmessage) ( -- ) |
| ." Gforth " version-string type |
." Gforth " version-string type |
| ." , Copyright (C) 1995-2006 Free Software Foundation, Inc." cr |
." , Copyright (C) 1995-2006,2007 Free Software Foundation, Inc." cr |
| ." Gforth comes with ABSOLUTELY NO WARRANTY; for details type `license'" |
." Gforth comes with ABSOLUTELY NO WARRANTY; for details type `license'" |
| [ has? os [IF] ] |
[ has? os [IF] ] |
| cr ." Type `bye' to exit" |
cr ." Type `bye' to exit" |
| [ [THEN] ] ; |
[ [THEN] ] ; |
| |
|
| defer bootmessage \ gforth |
defer bootmessage ( -- ) \ gforth |
| \G Hook (deferred word) executed right after interpreting the OS |
\G Hook (deferred word) executed right after interpreting the OS |
| \G command-line arguments. Normally prints the Gforth startup |
\G command-line arguments. Normally prints the Gforth startup |
| \G message. |
\G message. |
| |
|
| ' (bootmessage) IS bootmessage |
' (bootmessage) IS bootmessage |
| |
|
| has? ec 0= [IF] |
has? os [IF] |
| Defer 'cold ( -- ) \ gforth tick-cold |
Defer 'cold ( -- ) \ gforth tick-cold |
| \G Hook (deferred word) for things to do right before interpreting the |
\G Hook (deferred word) for things to do right before interpreting the |
| \G OS command-line arguments. Normally does some initializations that |
\G OS command-line arguments. Normally does some initializations that |
| [ has? file [IF] ] |
[ has? file [IF] ] |
| os-cold |
os-cold |
| [ [THEN] ] |
[ [THEN] ] |
| [ has? ec 0= [IF] ] |
[ has? os [IF] ] |
| set-encoding-fixed-width |
set-encoding-fixed-width |
| 'cold |
'cold |
| [ [THEN] ] |
[ [THEN] ] |
| [ has? floating [IF] ] |
[ has? floating [IF] ] |
| fp@ fp0 ! |
fp@ fp0 ! |
| [ [THEN] ] |
[ [THEN] ] |
| [ has? ec 0= [IF] ] |
[ has? os [IF] ] |
| handler off |
handler off |
| ['] cold catch dup -&2049 <> if \ broken pipe? |
['] cold catch dup -&2049 <> if \ broken pipe? |
| DoError cr |
DoError cr |