[gforth] / gforth / extend.fs  

gforth: gforth/extend.fs


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.11 : value ( w -- ) \ core-ext
34 : anton 1.3 (constant) , ;
35 :     \ !! 2value
36 : anton 1.1
37 : anton 1.11 : 2Literal ( compilation w1 w2 -- ; run-time -- w1 w2 ) \ double two-literal
38 :     swap postpone Literal postpone Literal ; immediate restrict
39 : pazsan 1.2
40 : anton 1.16 ' drop alias d>s ( d -- n ) \ double d_to_s
41 :    
42 : anton 1.11 : m*/ ( d1 n2 u3 -- dqout ) \ double m-star-slash
43 :     >r s>d >r abs -rot
44 :     s>d r> xor r> swap >r >r dabs rot tuck um* 2swap um*
45 :     swap >r 0 d+ r> -rot r@ um/mod -rot r> um/mod nip swap
46 :     r> IF dnegate THEN ;
47 : pazsan 1.4
48 : anton 1.1 \ CASE OF ENDOF ENDCASE 17may93jaw
49 :    
50 :     \ just as described in dpANS5
51 :    
52 : anton 1.11 0 CONSTANT case ( compilation -- case-sys ; run-time -- ) \ core-ext
53 :     immediate
54 : anton 1.1
55 : anton 1.11 : of ( compilation -- of-sys ; run-time x1 x2 -- |x1 ) \ core-ext
56 :     \ !! the implementation does not match the stack effect
57 :     1+ >r
58 :     postpone over postpone = postpone if postpone drop
59 :     r> ; immediate
60 :    
61 :     : endof ( compilation case-sys1 of-sys -- case-sys2 ; run-time -- ) \ core-ext end-of
62 :     >r postpone else r> ; immediate
63 :    
64 :     : endcase ( compilation case-sys -- ; run-time x -- ) \ core-ext end-case
65 :     postpone drop
66 :     0 ?do postpone then loop ; immediate
67 : anton 1.1
68 :     \ C" 17may93jaw
69 :    
70 :     : (c") "lit ;
71 :    
72 : anton 1.11 : CLiteral
73 :     postpone (c") here over char+ allot place align ; immediate restrict
74 :    
75 :     : C" ( compilation "...<quote>" -- ; run-time -- c-addr ) \ core-ext c-quote
76 :     [char] " parse postpone CLiteral ; immediate restrict
77 : anton 1.1
78 :     \ UNUSED 17may93jaw
79 :    
80 : anton 1.11 : unused ( -- u ) \ core-ext
81 :     s0 @ 512 - \ for stack
82 :     here - ;
83 : anton 1.1
84 :     \ [COMPILE] 17may93jaw
85 :    
86 : anton 1.11 : [compile] ( compilation "name" -- ; run-time ? -- ? ) \ core-ext bracket-compile
87 :     ' compile, ; immediate
88 : anton 1.1
89 :     \ MARKER 17may93jaw
90 :    
91 :     \ : marker here last @ create , , DOES> dup @ last ! cell+ @ dp ! ;
92 :     \ doesn't work now. vocabularies?
93 :    
94 :     \ CONVERT 17may93jaw
95 :    
96 : anton 1.11 : convert ( ud1 c-addr1 -- ud2 c-addr2 ) \ core-ext
97 :     \ obsolescent; supersedet by @code{>number}.
98 :     true >number drop ;
99 : anton 1.1
100 :     \ ERASE 17may93jaw
101 :    
102 : anton 1.11 : erase ( addr len -- ) \ core-ext
103 :     \ !! dependence on "1 chars 1 ="
104 :     ( 0 1 chars um/mod nip ) 0 fill ;
105 :     : blank ( addr len -- ) \ string
106 :     bl fill ;
107 : anton 1.1
108 : pazsan 1.7 \ SEARCH 02sep94py
109 :    
110 : anton 1.11 : search ( buf buflen text textlen -- restbuf restlen flag ) \ string
111 :     2over 2 pick - 1+ 3 pick c@ >r
112 :     BEGIN
113 :     r@ scan dup
114 :     WHILE
115 :     >r >r 2dup r@ -text
116 :     0=
117 :     IF
118 :     >r drop 2drop r> r> r> rot + 1- rdrop true
119 :     EXIT
120 :     THEN
121 :     r> r> 1 /string
122 :     REPEAT
123 :     2drop 2drop rdrop false ;
124 : pazsan 1.7
125 : anton 1.1 \ SOURCE-ID SAVE-INPUT RESTORE-INPUT 11jun93jaw
126 :    
127 : anton 1.11 : source-id ( -- 0 | -1 | fileid ) \ core-ext source-i-d
128 : anton 1.13 loadfile @ dup 0= IF drop sourceline# 0 min THEN ;
129 : anton 1.1
130 : anton 1.11 : save-input ( -- x1 .. xn n ) \ core-ext
131 : anton 1.14 >in @
132 :     loadfile @
133 :     if
134 :     loadfile @ file-position throw
135 :     else
136 :     blk @
137 :     linestart @
138 :     then
139 :     sourceline#
140 :     >tib @
141 :     source-id
142 :     6 ;
143 : anton 1.1
144 : anton 1.11 : restore-input ( x1 .. xn n -- flag ) \ core-ext
145 : anton 1.14 6 <> -12 and throw
146 :     source-id <> -12 and throw
147 :     >tib !
148 :     >r ( line# )
149 :     loadfile @ 0<>
150 :     if
151 :     loadfile @ reposition-file throw
152 :     else
153 :     linestart !
154 :     blk !
155 :     sourceline# r@ <> blk @ 0= and loadfile @ 0= and
156 :     if
157 :     drop rdrop true EXIT
158 :     then
159 :     then
160 :     r> loadline !
161 :     >in !
162 :     false ;
163 :    
164 :     \ : save-input ( -- x1 .. xn n ) \ core-ext
165 :     \ >in @
166 :     \ loadfile @ ?dup
167 :     \ IF dup file-position throw sourceline# >tib @ 6
168 :     \ #tib @ >tib +!
169 :     \ ELSE sourceline# blk @ linestart @ >tib @ 5 THEN
170 :     \ ;
171 :    
172 :     \ : restore-input ( x1 .. xn n -- flag ) \ core-ext
173 :     \ swap >tib !
174 :     \ 6 = IF loadline ! rot dup loadfile !
175 :     \ reposition-file IF drop true EXIT THEN
176 :     \ ELSE linestart ! blk !
177 :     \ dup sourceline# <> IF 2drop true EXIT THEN
178 :     \ loadline !
179 :     \ THEN
180 :     \ >in ! false ;
181 : anton 1.1
182 :    
183 :    
184 :     \ This things we don't need, but for being complete... jaw
185 :    
186 :     \ EXPECT SPAN 17may93jaw
187 :    
188 : anton 1.11 variable span ( -- a-addr ) \ core-ext
189 :     \ obsolescent
190 : anton 1.1
191 : anton 1.11 : expect ( c-addr +len -- ) \ core-ext
192 :     \ obsolescent; use accept
193 : anton 1.9 0 rot over
194 :     BEGIN ( maxlen span c-addr pos1 )
195 :     key decode ( maxlen span c-addr pos2 flag )
196 :     >r 2over = r> or
197 :     UNTIL
198 : pazsan 1.17 2 pick swap /string type
199 :     nip span ! ;
200 : anton 1.1

CVS Admin

Powered by ViewCVS 1.0-dev
(Powered by ViewCVS)

ViewCVS and CVS Help