1 \ @(#) misc2.fth 98/01/26 1.2
2 \ Utilities for PForth extracted from HMSL
5 \ Copyright 1994 3DO, Phil Burk, Larry Polansky, David Rosenboom
7 \ The pForth software code is dedicated to the public domain,
8 \ and any third party may reproduce, distribute and modify
9 \ the pForth software code or any derivative works thereof
10 \ without any compensation or license. The pForth software
11 \ code is provided on an "as is" basis without any warranty
12 \ of any kind, including, without limitation, the implied
13 \ warranties of merchantability and fitness for a particular
14 \ purpose and their equivalents under the laws of any jurisdiction.
16 \ 00001 9/14/92 Added call, 'c w->s
17 \ 00002 11/23/92 Moved redef of : to loadcom.fth
21 : 'N ( <name> -- , make 'n state smart )
25 IF namebase - ( make nfa relocatable )
26 [compile] literal ( store nfa of word to be compiled )
32 : ?LITERAL ( n -- , do literal if compiling )
38 : 'c ( <name> -- xt , state sensitive ' )
45 create msec-delay 10000 , ( default for SUN )
46 : (MSEC) ( #msecs -- )
56 : SHIFT ( val n -- val<<n )
64 variable rand-seed here rand-seed !
65 : random ( -- random_number )
68 65535 and dup rand-seed !
70 : choose ( range -- random_number , in range )
74 : wchoose ( hi lo -- random_number )
79 \ sort top two items on stack.
80 : 2sort ( a b -- a<b | b<a , largest on top of stack)
86 \ sort top two items on stack.
87 : -2sort ( a b -- a>b | b>a , smallest on top of stack)
93 : barray ( #bytes -- ) ( index -- addr )
98 : warray ( #words -- ) ( index -- addr )
103 : array ( #cells -- ) ( index -- addr )
108 : .bin ( n -- , print in binary )
109 base @ binary swap . base !
112 base @ decimal swap . base !
115 base @ hex swap . base !
118 : B->S ( c -- c' , sign extend byte )
126 : W->S ( 16bit-signed -- 32bit-signed )
135 : WITHIN { n1 n2 n3 -- flag }
146 : MOVE ( src dst num -- )
155 : ERASE ( caddr num -- )
164 : BLANK ( addr u -- , set memory to blank )
173 \ Obsolete but included for CORE EXT word set.
174 : QUERY REFILL DROP ;
176 : EXPECT accept span ! ;
180 : UNUSED ( -- unused , dictionary space )
184 : MAP ( -- , dump interesting dictionary info )
186 ." CODEBASE = " codebase .hex cr
187 ." HERE = " here .hex cr
188 ." CODELIMIT = " codelimit .hex cr
189 ." Compiled Code Size = " here codebase - . cr
190 ." CODE-SIZE = " code-size @ . cr
191 ." Code Room UNUSED = " UNUSED . cr
193 ." NAMEBASE = " namebase .hex cr
194 ." HEADERS-PTR @ = " headers-ptr @ .hex cr
195 ." NAMELIMIT = " namelimit .hex cr
196 ." CONTEXT @ = " context @ .hex cr
197 ." LATEST = " latest .hex ." = " latest id. cr
198 ." Compiled Name size = " headers-ptr @ namebase - . cr
199 ." HEADERS-SIZE = " headers-size @ . cr
200 ." Name Room Left = " namelimit headers-ptr @ - . cr
204 \ Search for substring S2 in S1
205 : SEARCH { addr1 cnt1 addr2 cnt2 | addr3 cnt3 flag -- addr3 cnt3 flag }
206 \ ." Search for " addr2 cnt2 type ." in " addr1 cnt1 type cr
207 \ if true, s1 contains s2 at addr3 with cnt3 chars remaining
219 addr1 i j + chars + c@ <> \ mismatch?
227 addr1 i chars + -> addr3
238 : env= ( c-addr u c-addr1 u1 x -- x true true | c-addr u false )
239 { x } 2over compare 0= if 2drop x true true else false then
242 : 2env= ( c-addr u c-addr1 u1 x y -- x y true true | c-addr u false )
243 { x y } 2over compare 0= if 2drop x y true true else false then
246 0 invert constant max-u
247 0 invert 1 rshift constant max-n
251 : ENVIRONMENT? ( c-addr u -- false | i*x true )
252 s" /COUNTED-STRING" 255 env= if exit then
253 s" /HOLD" 128 env= if exit then \ same as PAD
254 s" /PAD" 128 env= if exit then
255 s" ADDRESS-UNITS-BITS" 8 env= if exit then
256 s" FLOORED" false env= if exit then
257 s" MAX-CHAR" 255 env= if exit then
258 s" MAX-D" max-n max-u 2env= if exit then
259 s" MAX-N" max-n env= if exit then
260 s" MAX-U" max-u env= if exit then
261 s" MAX-UD" max-u max-u 2env= if exit then
262 s" RETURN-STACK-CELLS" 512 env= if exit then \ DEFAULT_RETURN_DEPTH
263 s" STACK-CELLS" 512 env= if exit then \ DEFAULT_USER_DEPTH
264 \ FIXME: maybe define those: