File:
[gforth] /
gforth /
extend.fs
Revision
1.15:
download - view:
text,
annotated -
select for diffs
Fri Feb 9 17:34:09 1996 UTC (27 years, 1 month ago) by
anton
Branches:
MAIN
CVS tags:
HEAD
?DUP-IF and ?DUP-0=-IF are now supported by primitives
added primitives EMIT-FILE, STDOUT, STDERR
EMIT and TYPE now work through file words
added some code for the BUGGY_LONG_LONG case (not yet complete)
eliminated D! and D@
made DMIN, DMAX, DABS high-level
added compat/control.fs (?DUP-IF etc.)
1: \ EXTEND.FS CORE-EXT Word not fully tested! 12may93jaw
2:
3: \ 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: \ May be cross-compiled
23:
24: decimal
25:
26: \ .( 12may93jaw
27:
28: : .( ( compilation "...<paren>" -- ) \ core-ext dot-paren
29: [char] ) parse type ; immediate
30:
31: \ VALUE 2>R 2R> 2R@ 17may93jaw
32:
33: : value ( w -- ) \ core-ext
34: (constant) , ;
35: \ !! 2value
36:
37: : 2Literal ( compilation w1 w2 -- ; run-time -- w1 w2 ) \ double two-literal
38: swap postpone Literal postpone Literal ; immediate restrict
39:
40: : dabs ( d1 -- d2 ) \ double
41: dup 0< IF dnegate THEN ;
42:
43: : m*/ ( d1 n2 u3 -- dqout ) \ double m-star-slash
44: >r s>d >r abs -rot
45: s>d r> xor r> swap >r >r dabs rot tuck um* 2swap um*
46: swap >r 0 d+ r> -rot r@ um/mod -rot r> um/mod nip swap
47: r> IF dnegate THEN ;
48:
49: \ CASE OF ENDOF ENDCASE 17may93jaw
50:
51: \ just as described in dpANS5
52:
53: 0 CONSTANT case ( compilation -- case-sys ; run-time -- ) \ core-ext
54: immediate
55:
56: : of ( compilation -- of-sys ; run-time x1 x2 -- |x1 ) \ core-ext
57: \ !! the implementation does not match the stack effect
58: 1+ >r
59: postpone over postpone = postpone if postpone drop
60: r> ; immediate
61:
62: : endof ( compilation case-sys1 of-sys -- case-sys2 ; run-time -- ) \ core-ext end-of
63: >r postpone else r> ; immediate
64:
65: : endcase ( compilation case-sys -- ; run-time x -- ) \ core-ext end-case
66: postpone drop
67: 0 ?do postpone then loop ; immediate
68:
69: \ C" 17may93jaw
70:
71: : (c") "lit ;
72:
73: : CLiteral
74: postpone (c") here over char+ allot place align ; immediate restrict
75:
76: : C" ( compilation "...<quote>" -- ; run-time -- c-addr ) \ core-ext c-quote
77: [char] " parse postpone CLiteral ; immediate restrict
78:
79: \ UNUSED 17may93jaw
80:
81: : unused ( -- u ) \ core-ext
82: s0 @ 512 - \ for stack
83: here - ;
84:
85: \ [COMPILE] 17may93jaw
86:
87: : [compile] ( compilation "name" -- ; run-time ? -- ? ) \ core-ext bracket-compile
88: ' compile, ; immediate
89:
90: \ MARKER 17may93jaw
91:
92: \ : marker here last @ create , , DOES> dup @ last ! cell+ @ dp ! ;
93: \ doesn't work now. vocabularies?
94:
95: \ CONVERT 17may93jaw
96:
97: : convert ( ud1 c-addr1 -- ud2 c-addr2 ) \ core-ext
98: \ obsolescent; supersedet by @code{>number}.
99: true >number drop ;
100:
101: \ ERASE 17may93jaw
102:
103: : erase ( addr len -- ) \ core-ext
104: \ !! dependence on "1 chars 1 ="
105: ( 0 1 chars um/mod nip ) 0 fill ;
106: : blank ( addr len -- ) \ string
107: bl fill ;
108:
109: \ SEARCH 02sep94py
110:
111: : search ( buf buflen text textlen -- restbuf restlen flag ) \ string
112: 2over 2 pick - 1+ 3 pick c@ >r
113: BEGIN
114: r@ scan dup
115: WHILE
116: >r >r 2dup r@ -text
117: 0=
118: IF
119: >r drop 2drop r> r> r> rot + 1- rdrop true
120: EXIT
121: THEN
122: r> r> 1 /string
123: REPEAT
124: 2drop 2drop rdrop false ;
125:
126: \ ROLL 17may93jaw
127:
128: : roll ( x0 x1 .. xn n -- x1 .. xn x0 ) \ core-ext
129: dup 1+ pick >r
130: cells sp@ cell+ dup cell+ rot move drop r> ;
131:
132: \ SOURCE-ID SAVE-INPUT RESTORE-INPUT 11jun93jaw
133:
134: : source-id ( -- 0 | -1 | fileid ) \ core-ext source-i-d
135: loadfile @ dup 0= IF drop sourceline# 0 min THEN ;
136:
137: : save-input ( -- x1 .. xn n ) \ core-ext
138: >in @
139: loadfile @
140: if
141: loadfile @ file-position throw
142: else
143: blk @
144: linestart @
145: then
146: sourceline#
147: >tib @
148: source-id
149: 6 ;
150:
151: : restore-input ( x1 .. xn n -- flag ) \ core-ext
152: 6 <> -12 and throw
153: source-id <> -12 and throw
154: >tib !
155: >r ( line# )
156: loadfile @ 0<>
157: if
158: loadfile @ reposition-file throw
159: else
160: linestart !
161: blk !
162: sourceline# r@ <> blk @ 0= and loadfile @ 0= and
163: if
164: drop rdrop true EXIT
165: then
166: then
167: r> loadline !
168: >in !
169: false ;
170:
171: \ : save-input ( -- x1 .. xn n ) \ core-ext
172: \ >in @
173: \ loadfile @ ?dup
174: \ IF dup file-position throw sourceline# >tib @ 6
175: \ #tib @ >tib +!
176: \ ELSE sourceline# blk @ linestart @ >tib @ 5 THEN
177: \ ;
178:
179: \ : restore-input ( x1 .. xn n -- flag ) \ core-ext
180: \ swap >tib !
181: \ 6 = IF loadline ! rot dup loadfile !
182: \ reposition-file IF drop true EXIT THEN
183: \ ELSE linestart ! blk !
184: \ dup sourceline# <> IF 2drop true EXIT THEN
185: \ loadline !
186: \ THEN
187: \ >in ! false ;
188:
189:
190:
191: \ This things we don't need, but for being complete... jaw
192:
193: \ EXPECT SPAN 17may93jaw
194:
195: variable span ( -- a-addr ) \ core-ext
196: \ obsolescent
197:
198: : expect ( c-addr +len -- ) \ core-ext
199: \ obsolescent; use accept
200: 0 rot over
201: BEGIN ( maxlen span c-addr pos1 )
202: key decode ( maxlen span c-addr pos2 flag )
203: >r 2over = r> or
204: UNTIL
205: type-rest drop
206: 2drop nip span ! ;
207:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>