| 1 : |
anton
|
1.1
|
\ EXTEND.FS CORE-EXT Word not fully tested! 12may93jaw |
| 2 : |
|
|
|
| 3 : |
anton
|
1.12
|
\ Copyright (C) 1995 Free Software Foundation, Inc. |
| 4 : |
|
|
|
| 5 : |
|
|
\ This file is part of Gforth. |
| 6 : |
|
|
|
| 7 : |
|
|
\ Gforth is free software; you can redistribute it and/or |
| 8 : |
|
|
\ modify it under the terms of the GNU General Public License |
| 9 : |
|
|
\ as published by the Free Software Foundation; either version 2 |
| 10 : |
|
|
\ of the License, or (at your option) any later version. |
| 11 : |
|
|
|
| 12 : |
|
|
\ This program is distributed in the hope that it will be useful, |
| 13 : |
|
|
\ but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 : |
|
|
\ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 : |
|
|
\ GNU General Public License for more details. |
| 16 : |
|
|
|
| 17 : |
|
|
\ You should have received a copy of the GNU General Public License |
| 18 : |
|
|
\ along with this program; if not, write to the Free Software |
| 19 : |
|
|
\ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 20 : |
|
|
|
| 21 : |
|
|
|
| 22 : |
anton
|
1.1
|
\ May be cross-compiled |
| 23 : |
|
|
|
| 24 : |
|
|
decimal |
| 25 : |
|
|
|
| 26 : |
|
|
\ .( 12may93jaw |
| 27 : |
|
|
|
| 28 : |
anton
|
1.11
|
: .( ( compilation "...<paren>" -- ) \ core-ext dot-paren |
| 29 : |
anton
|
1.8
|
[char] ) parse type ; immediate |
| 30 : |
anton
|
1.1
|
|
| 31 : |
|
|
\ VALUE 2>R 2R> 2R@ 17may93jaw |
| 32 : |
|
|
|
| 33 : |
anton
|
1.3
|
\ !! 2value |
| 34 : |
anton
|
1.1
|
|
| 35 : |
anton
|
1.11
|
: 2Literal ( compilation w1 w2 -- ; run-time -- w1 w2 ) \ double two-literal |
| 36 : |
|
|
swap postpone Literal postpone Literal ; immediate restrict |
| 37 : |
pazsan
|
1.2
|
|
| 38 : |
anton
|
1.16
|
' drop alias d>s ( d -- n ) \ double d_to_s |
| 39 : |
|
|
|
| 40 : |
anton
|
1.11
|
: m*/ ( d1 n2 u3 -- dqout ) \ double m-star-slash |
| 41 : |
|
|
>r s>d >r abs -rot |
| 42 : |
|
|
s>d r> xor r> swap >r >r dabs rot tuck um* 2swap um* |
| 43 : |
|
|
swap >r 0 d+ r> -rot r@ um/mod -rot r> um/mod nip swap |
| 44 : |
|
|
r> IF dnegate THEN ; |
| 45 : |
pazsan
|
1.4
|
|
| 46 : |
anton
|
1.1
|
\ CASE OF ENDOF ENDCASE 17may93jaw |
| 47 : |
|
|
|
| 48 : |
|
|
\ just as described in dpANS5 |
| 49 : |
|
|
|
| 50 : |
anton
|
1.11
|
0 CONSTANT case ( compilation -- case-sys ; run-time -- ) \ core-ext |
| 51 : |
|
|
immediate |
| 52 : |
anton
|
1.1
|
|
| 53 : |
anton
|
1.11
|
: of ( compilation -- of-sys ; run-time x1 x2 -- |x1 ) \ core-ext |
| 54 : |
|
|
\ !! the implementation does not match the stack effect |
| 55 : |
|
|
1+ >r |
| 56 : |
|
|
postpone over postpone = postpone if postpone drop |
| 57 : |
|
|
r> ; immediate |
| 58 : |
|
|
|
| 59 : |
|
|
: endof ( compilation case-sys1 of-sys -- case-sys2 ; run-time -- ) \ core-ext end-of |
| 60 : |
|
|
>r postpone else r> ; immediate |
| 61 : |
|
|
|
| 62 : |
|
|
: endcase ( compilation case-sys -- ; run-time x -- ) \ core-ext end-case |
| 63 : |
|
|
postpone drop |
| 64 : |
|
|
0 ?do postpone then loop ; immediate |
| 65 : |
anton
|
1.1
|
|
| 66 : |
|
|
\ C" 17may93jaw |
| 67 : |
|
|
|
| 68 : |
|
|
: (c") "lit ; |
| 69 : |
|
|
|
| 70 : |
anton
|
1.11
|
: CLiteral |
| 71 : |
|
|
postpone (c") here over char+ allot place align ; immediate restrict |
| 72 : |
|
|
|
| 73 : |
|
|
: C" ( compilation "...<quote>" -- ; run-time -- c-addr ) \ core-ext c-quote |
| 74 : |
|
|
[char] " parse postpone CLiteral ; immediate restrict |
| 75 : |
anton
|
1.1
|
|
| 76 : |
|
|
\ [COMPILE] 17may93jaw |
| 77 : |
|
|
|
| 78 : |
anton
|
1.11
|
: [compile] ( compilation "name" -- ; run-time ? -- ? ) \ core-ext bracket-compile |
| 79 : |
pazsan
|
1.24
|
comp' drop compile, ; immediate |
| 80 : |
anton
|
1.1
|
|
| 81 : |
|
|
\ CONVERT 17may93jaw |
| 82 : |
|
|
|
| 83 : |
anton
|
1.11
|
: convert ( ud1 c-addr1 -- ud2 c-addr2 ) \ core-ext |
| 84 : |
anton
|
1.26
|
\G obsolescent; superseded by @code{>number}. |
| 85 : |
|
|
char+ true >number drop ; |
| 86 : |
anton
|
1.1
|
|
| 87 : |
|
|
\ ERASE 17may93jaw |
| 88 : |
|
|
|
| 89 : |
anton
|
1.11
|
: erase ( addr len -- ) \ core-ext |
| 90 : |
|
|
\ !! dependence on "1 chars 1 =" |
| 91 : |
|
|
( 0 1 chars um/mod nip ) 0 fill ; |
| 92 : |
|
|
: blank ( addr len -- ) \ string |
| 93 : |
|
|
bl fill ; |
| 94 : |
anton
|
1.1
|
|
| 95 : |
pazsan
|
1.7
|
\ SEARCH 02sep94py |
| 96 : |
|
|
|
| 97 : |
anton
|
1.28
|
: search ( c-addr1 u1 c-addr2 u2 -- c-addr3 u3 flag ) \ string |
| 98 : |
|
|
\ not very efficient; but if we want efficiency, we'll do it as primitive |
| 99 : |
|
|
2>r 2dup |
| 100 : |
|
|
begin |
| 101 : |
|
|
dup r@ >= |
| 102 : |
|
|
while |
| 103 : |
|
|
over 2r@ swap -text 0= if |
| 104 : |
|
|
2swap 2drop 2r> 2drop true exit |
| 105 : |
|
|
endif |
| 106 : |
|
|
1 /string |
| 107 : |
|
|
repeat |
| 108 : |
|
|
2drop 2r> 2drop false ; |
| 109 : |
pazsan
|
1.7
|
|
| 110 : |
anton
|
1.1
|
\ SOURCE-ID SAVE-INPUT RESTORE-INPUT 11jun93jaw |
| 111 : |
|
|
|
| 112 : |
anton
|
1.22
|
: source-id ( -- 0 | -1 | fileid ) \ core-ext,file source-i-d |
| 113 : |
anton
|
1.13
|
loadfile @ dup 0= IF drop sourceline# 0 min THEN ; |
| 114 : |
anton
|
1.1
|
|
| 115 : |
anton
|
1.11
|
: save-input ( -- x1 .. xn n ) \ core-ext |
| 116 : |
anton
|
1.14
|
>in @ |
| 117 : |
|
|
loadfile @ |
| 118 : |
|
|
if |
| 119 : |
|
|
loadfile @ file-position throw |
| 120 : |
|
|
else |
| 121 : |
|
|
blk @ |
| 122 : |
|
|
linestart @ |
| 123 : |
|
|
then |
| 124 : |
|
|
sourceline# |
| 125 : |
|
|
>tib @ |
| 126 : |
|
|
source-id |
| 127 : |
|
|
6 ; |
| 128 : |
anton
|
1.1
|
|
| 129 : |
anton
|
1.11
|
: restore-input ( x1 .. xn n -- flag ) \ core-ext |
| 130 : |
anton
|
1.14
|
6 <> -12 and throw |
| 131 : |
|
|
source-id <> -12 and throw |
| 132 : |
|
|
>tib ! |
| 133 : |
|
|
>r ( line# ) |
| 134 : |
|
|
loadfile @ 0<> |
| 135 : |
|
|
if |
| 136 : |
|
|
loadfile @ reposition-file throw |
| 137 : |
|
|
else |
| 138 : |
|
|
linestart ! |
| 139 : |
|
|
blk ! |
| 140 : |
|
|
sourceline# r@ <> blk @ 0= and loadfile @ 0= and |
| 141 : |
|
|
if |
| 142 : |
|
|
drop rdrop true EXIT |
| 143 : |
|
|
then |
| 144 : |
|
|
then |
| 145 : |
|
|
r> loadline ! |
| 146 : |
|
|
>in ! |
| 147 : |
|
|
false ; |
| 148 : |
|
|
|
| 149 : |
anton
|
1.1
|
\ This things we don't need, but for being complete... jaw |
| 150 : |
|
|
|
| 151 : |
|
|
\ EXPECT SPAN 17may93jaw |
| 152 : |
|
|
|
| 153 : |
anton
|
1.11
|
variable span ( -- a-addr ) \ core-ext |
| 154 : |
|
|
\ obsolescent |
| 155 : |
anton
|
1.1
|
|
| 156 : |
anton
|
1.11
|
: expect ( c-addr +len -- ) \ core-ext |
| 157 : |
|
|
\ obsolescent; use accept |
| 158 : |
anton
|
1.9
|
0 rot over |
| 159 : |
|
|
BEGIN ( maxlen span c-addr pos1 ) |
| 160 : |
|
|
key decode ( maxlen span c-addr pos2 flag ) |
| 161 : |
|
|
>r 2over = r> or |
| 162 : |
|
|
UNTIL |
| 163 : |
pazsan
|
1.17
|
2 pick swap /string type |
| 164 : |
|
|
nip span ! ; |
| 165 : |
jwilke
|
1.27
|
|
| 166 : |
|
|
\ marker 18dec94py |
| 167 : |
|
|
|
| 168 : |
|
|
\ Marker creates a mark that is removed (including everything |
| 169 : |
|
|
\ defined afterwards) when executing the mark. |
| 170 : |
|
|
|
| 171 : |
|
|
: marker, ( -- mark ) here dup A, |
| 172 : |
|
|
voclink @ A, voclink |
| 173 : |
|
|
BEGIN @ dup WHILE dup 0 wordlist-link - @ A, REPEAT drop |
| 174 : |
|
|
udp @ , ; |
| 175 : |
|
|
|
| 176 : |
|
|
: marker! ( mark -- ) |
| 177 : |
|
|
dup @ swap cell+ |
| 178 : |
|
|
dup @ voclink ! cell+ |
| 179 : |
|
|
voclink |
| 180 : |
|
|
BEGIN |
| 181 : |
|
|
@ dup |
| 182 : |
|
|
WHILE |
| 183 : |
|
|
over @ over 0 wordlist-link - ! |
| 184 : |
|
|
swap cell+ swap |
| 185 : |
|
|
REPEAT |
| 186 : |
|
|
drop voclink |
| 187 : |
|
|
BEGIN |
| 188 : |
|
|
@ dup |
| 189 : |
|
|
WHILE |
| 190 : |
|
|
dup 0 wordlist-link - rehash |
| 191 : |
|
|
REPEAT |
| 192 : |
|
|
drop |
| 193 : |
|
|
@ udp ! dp ! ; |
| 194 : |
|
|
|
| 195 : |
|
|
: marker ( "mark" -- ) |
| 196 : |
|
|
marker, Create A, |
| 197 : |
|
|
DOES> ( -- ) |
| 198 : |
|
|
@ marker! ; |
| 199 : |
anton
|
1.1
|
|