Annotation of gforth/prim, revision 1.7
1.1 anton 1: \ Gforth primitives
2:
3: \ Copyright (C) 1995,1996 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: \ WARNING: This file is processed by m4. Make sure your identifiers
23: \ don't collide with m4's (e.g. by undefining them).
24: \
25: \
26: \
27: \ This file contains primitive specifications in the following format:
28: \
29: \ forth name stack effect category [pronunciation]
30: \ [""glossary entry""]
31: \ C code
32: \ [:
33: \ Forth code]
34: \
35: \ prims2x is pedantic about tabs vs. blanks. The fields of the first
36: \ line of a primitive are separated by tabs, the stack items in a
37: \ stack effect by blanks.
38: \
39: \ Both pronounciation and stack items (in the stack effect) must
40: \ conform to the C name syntax or the C compiler will complain.
41: \
42: \
43: \ These specifications are automatically translated into C-code for the
44: \ interpreter and into some other files. I hope that your C compiler has
45: \ decent optimization, otherwise the automatically generated code will
46: \ be somewhat slow. The Forth version of the code is included for manual
47: \ compilers, so they will need to compile only the important words.
48: \
49: \ Note that stack pointer adjustment is performed according to stack
50: \ effect by automatically generated code and NEXT is automatically
51: \ appended to the C code. Also, you can use the names in the stack
52: \ effect in the C code. Stack access is automatic. One exception: if
53: \ your code does not fall through, the results are not stored into the
54: \ stack. Use different names on both sides of the '--', if you change a
55: \ value (some stores to the stack are optimized away).
56: \
57: \
58: \
59: \ The stack variables have the following types:
60: \
61: \ name matches type
62: \ f.* Bool
63: \ c.* Char
64: \ [nw].* Cell
65: \ u.* UCell
66: \ d.* DCell
67: \ ud.* UDCell
68: \ r.* Float
69: \ a_.* Cell *
70: \ c_.* Char *
71: \ f_.* Float *
72: \ df_.* DFloat *
73: \ sf_.* SFloat *
74: \ xt.* XT
75: \ wid.* WID
76: \ f83name.* F83Name *
77: \
78: \
79: \
80: \ In addition the following names can be used:
81: \ ip the instruction pointer
82: \ sp the data stack pointer
83: \ rp the parameter stack pointer
84: \ lp the locals stack pointer
85: \ NEXT executes NEXT
86: \ cfa
87: \ NEXT1 executes NEXT1
88: \ FLAG(x) makes a Forth flag from a C flag
89: \
90: \
91: \
92: \ Percentages in comments are from Koopmans book: average/maximum use
93: \ (taken from four, not very representative benchmarks)
94: \
95: \
96: \
97: \ To do:
98: \
99: \ throw execute, cfa and NEXT1 out?
100: \ macroize *ip, ip++, *ip++ (pipelining)?
101:
102: \ these m4 macros would collide with identifiers
103: undefine(`index')
104: undefine(`shift')
105:
106: noop -- gforth
107: ;
108: :
109: ;
110:
111: lit -- w gforth
112: w = (Cell)NEXT_INST;
113: INC_IP(1);
114: :
115: r> dup @ swap cell+ >r ;
116:
117: execute xt -- core
118: ip=IP;
119: IF_TOS(TOS = sp[0]);
120: EXEC(xt);
121:
122: perform a_addr -- gforth
123: ""equivalent to @code{@ execute}""
124: /* and pfe */
125: ip=IP;
126: IF_TOS(TOS = sp[0]);
127: EXEC(*(Xt *)a_addr);
128: :
129: @ execute ;
130:
1.6 jwilke 131: \+has? glocals [IF]
1.1 anton 132:
133: branch-lp+!# -- gforth branch_lp_plus_store_number
134: /* this will probably not be used */
135: branch_adjust_lp:
136: lp += (Cell)(IP[1]);
137: goto branch;
138:
139: \+[THEN]
140:
141: branch -- gforth
142: branch:
143: ip = (Xt *)(((Cell)IP)+(Cell)NEXT_INST);
144: NEXT_P0;
145: :
146: r> dup @ + >r ;
147:
148: \ condbranch(forthname,restline,code,forthcode)
149: \ this is non-syntactical: code must open a brace that is closed by the macro
150: define(condbranch,
151: $1 $2
152: $3 ip = (Xt *)(((Cell)IP)+(Cell)NEXT_INST);
153: NEXT_P0;
154: NEXT;
155: }
156: else
157: INC_IP(1);
158: $4
159:
1.6 jwilke 160: \+has? glocals [IF]
1.1 anton 161:
162: $1-lp+!# $2_lp_plus_store_number
163: $3 goto branch_adjust_lp;
164: }
165: else
166: INC_IP(2);
167:
168: \+[THEN]
169: )
170:
171: condbranch(?branch,f -- f83 question_branch,
172: if (f==0) {
173: IF_TOS(TOS = sp[0]);
1.5 jwilke 174: ,:
175: 0= dup \ !f !f
176: r> dup @ \ !f !f IP branchoffset
177: rot and + \ !f IP|IP+branchoffset
178: swap 0= cell and + \ IP''
179: >r ;)
1.1 anton 180:
181: \ we don't need an lp_plus_store version of the ?dup-stuff, because it
182: \ is only used in if's (yet)
183:
1.6 jwilke 184: \+has? xconds [IF]
1.1 anton 185:
186: ?dup-?branch f -- f new question_dupe_question_branch
187: ""The run-time procedure compiled by @code{?DUP-IF}.""
188: if (f==0) {
189: sp++;
190: IF_TOS(TOS = sp[0]);
191: ip = (Xt *)(((Cell)IP)+(Cell)NEXT_INST);
192: NEXT_P0;
193: NEXT;
194: }
195: else
196: INC_IP(1);
197:
198: ?dup-0=-?branch f -- new question_dupe_zero_equals_question_branch
199: ""The run-time procedure compiled by @code{?DUP-0=-IF}.""
200: /* the approach taken here of declaring the word as having the stack
201: effect ( f -- ) and correcting for it in the branch-taken case costs a
202: few cycles in that case, but is easy to convert to a CONDBRANCH
203: invocation */
204: if (f!=0) {
205: sp--;
206: ip = (Xt *)(((Cell)IP)+(Cell)NEXT_INST);
207: NEXT_P0;
208: NEXT;
209: }
210: else
211: INC_IP(1);
212:
213: \+[THEN]
214:
215: condbranch((next),-- cmFORTH paren_next,
216: if ((*rp)--) {
217: ,:
218: r> r> dup 1- >r
219: IF dup @ + >r ELSE cell+ >r THEN ;)
220:
221: condbranch((loop),-- gforth paren_loop,
222: Cell index = *rp+1;
223: Cell limit = rp[1];
224: if (index != limit) {
225: *rp = index;
226: ,:
227: r> r> 1+ r> 2dup =
228: IF >r 1- >r cell+ >r
229: ELSE >r >r dup @ + >r THEN ;)
230:
231: condbranch((+loop),n -- gforth paren_plus_loop,
232: /* !! check this thoroughly */
233: Cell index = *rp;
234: /* sign bit manipulation and test: (x^y)<0 is equivalent to (x<0) != (y<0) */
235: /* dependent upon two's complement arithmetic */
236: Cell olddiff = index-rp[1];
237: if ((olddiff^(olddiff+n))>=0 /* the limit is not crossed */
238: || (olddiff^n)>=0 /* it is a wrap-around effect */) {
239: #ifdef i386
240: *rp += n;
241: #else
242: *rp = index + n;
243: #endif
244: IF_TOS(TOS = sp[0]);
245: ,:
246: r> swap
247: r> r> 2dup - >r
248: 2 pick r@ + r@ xor 0< 0=
249: 3 pick r> xor 0< 0= or
250: IF >r + >r dup @ + >r
251: ELSE >r >r drop cell+ >r THEN ;)
252:
1.6 jwilke 253: \+has? xconds [IF]
1.1 anton 254:
255: condbranch((-loop),u -- gforth paren_minus_loop,
256: /* !! check this thoroughly */
257: Cell index = *rp;
258: UCell olddiff = index-rp[1];
259: if (olddiff>u) {
260: #ifdef i386
261: *rp -= u;
262: #else
263: *rp = index - u;
264: #endif
265: IF_TOS(TOS = sp[0]);
266: ,)
267:
268: condbranch((s+loop),n -- gforth paren_symmetric_plus_loop,
269: ""The run-time procedure compiled by S+LOOP. It loops until the index
270: crosses the boundary between limit and limit-sign(n). I.e. a symmetric
271: version of (+LOOP).""
272: /* !! check this thoroughly */
273: Cell index = *rp;
274: Cell diff = index-rp[1];
275: Cell newdiff = diff+n;
276: if (n<0) {
277: diff = -diff;
278: newdiff = -newdiff;
279: }
280: if (diff>=0 || newdiff<0) {
281: #ifdef i386
282: *rp += n;
283: #else
284: *rp = index + n;
285: #endif
286: IF_TOS(TOS = sp[0]);
287: ,)
288:
289: \+[THEN]
290:
291: unloop -- core
292: rp += 2;
293: :
294: r> rdrop rdrop >r ;
295:
296: (for) ncount -- cmFORTH paren_for
297: /* or (for) = >r -- collides with unloop! */
298: *--rp = 0;
299: *--rp = ncount;
300: :
301: r> swap 0 >r >r >r ;
302:
303: (do) nlimit nstart -- gforth paren_do
304: /* or do it in high-level? 0.09/0.23% */
305: *--rp = nlimit;
306: *--rp = nstart;
307: :
308: r> swap rot >r >r >r ;
309:
310: (?do) nlimit nstart -- gforth paren_question_do
311: *--rp = nlimit;
312: *--rp = nstart;
313: if (nstart == nlimit) {
314: IF_TOS(TOS = sp[0]);
315: goto branch;
316: }
317: else {
318: INC_IP(1);
319: }
320: :
321: 2dup =
322: IF r> swap rot >r >r
323: dup @ + >r
324: ELSE r> swap rot >r >r
325: cell+ >r
326: THEN ; \ --> CORE-EXT
327:
1.6 jwilke 328: \+has? xconds [IF]
1.1 anton 329:
330: (+do) nlimit nstart -- gforth paren_plus_do
331: *--rp = nlimit;
332: *--rp = nstart;
333: if (nstart >= nlimit) {
334: IF_TOS(TOS = sp[0]);
335: goto branch;
336: }
337: else {
338: INC_IP(1);
339: }
340: :
341: swap 2dup
342: r> swap >r swap >r
343: >=
344: IF
345: dup @ +
346: ELSE
347: cell+
348: THEN >r ;
349:
350: (u+do) ulimit ustart -- gforth paren_u_plus_do
351: *--rp = ulimit;
352: *--rp = ustart;
353: if (ustart >= ulimit) {
354: IF_TOS(TOS = sp[0]);
355: goto branch;
356: }
357: else {
358: INC_IP(1);
359: }
360: :
361: swap 2dup
362: r> swap >r swap >r
363: u>=
364: IF
365: dup @ +
366: ELSE
367: cell+
368: THEN >r ;
369:
370: (-do) nlimit nstart -- gforth paren_minus_do
371: *--rp = nlimit;
372: *--rp = nstart;
373: if (nstart <= nlimit) {
374: IF_TOS(TOS = sp[0]);
375: goto branch;
376: }
377: else {
378: INC_IP(1);
379: }
380: :
381: swap 2dup
382: r> swap >r swap >r
383: <=
384: IF
385: dup @ +
386: ELSE
387: cell+
388: THEN >r ;
389:
390: (u-do) ulimit ustart -- gforth paren_u_minus_do
391: *--rp = ulimit;
392: *--rp = ustart;
393: if (ustart <= ulimit) {
394: IF_TOS(TOS = sp[0]);
395: goto branch;
396: }
397: else {
398: INC_IP(1);
399: }
400: :
401: swap 2dup
402: r> swap >r swap >r
403: u<=
404: IF
405: dup @ +
406: ELSE
407: cell+
408: THEN >r ;
409:
410: \+[THEN]
411:
1.5 jwilke 412: \ don't make any assumptions where the return stack is!!
413: \ implement this in machine code if it should run quickly!
414:
1.1 anton 415: i -- n core
416: n = *rp;
417: :
1.5 jwilke 418: \ rp@ cell+ @ ;
419: r> r> tuck >r >r ;
1.1 anton 420:
421: i' -- w gforth i_tick
422: ""loop end value""
423: w = rp[1];
424: :
1.5 jwilke 425: \ rp@ cell+ cell+ @ ;
426: r> r> r> dup itmp ! >r >r >r itmp @ ;
427: variable itmp
1.1 anton 428:
429: j -- n core
430: n = rp[2];
431: :
1.5 jwilke 432: \ rp@ cell+ cell+ cell+ @ ;
433: r> r> r> r> dup itmp ! >r >r >r >r itmp @ ;
434: [IFUNDEF] itmp variable itmp [THEN]
1.1 anton 435:
436: k -- n gforth
437: n = rp[4];
438: :
1.5 jwilke 439: \ rp@ [ 5 cells ] Literal + @ ;
440: r> r> r> r> r> r> dup itmp ! >r >r >r >r >r >r itmp @ ;
441: [IFUNDEF] itmp variable itmp [THEN]
1.1 anton 442:
443: \ digit is high-level: 0/0%
444:
445: move c_from c_to ucount -- core
446: memmove(c_to,c_from,ucount);
447: /* make an Ifdef for bsd and others? */
448: :
449: >r 2dup u< IF r> cmove> ELSE r> cmove THEN ;
450:
451: cmove c_from c_to u -- string
452: while (u-- > 0)
453: *c_to++ = *c_from++;
454: :
455: bounds ?DO dup c@ I c! 1+ LOOP drop ;
456:
457: cmove> c_from c_to u -- string c_move_up
458: while (u-- > 0)
459: c_to[u] = c_from[u];
460: :
461: dup 0= IF drop 2drop exit THEN
462: rot over + -rot bounds swap 1-
463: DO 1- dup c@ I c! -1 +LOOP drop ;
464:
465: fill c_addr u c -- core
466: memset(c_addr,c,u);
467: :
468: -rot bounds
469: ?DO dup I c! LOOP drop ;
470:
471: compare c_addr1 u1 c_addr2 u2 -- n string
472: ""Compare the strings lexicographically. If they are equal, n is 0; if
473: the first string is smaller, n is -1; if the first string is larger, n
474: is 1. Currently this is based on the machine's character
475: comparison. In the future, this may change to considering the current
476: locale and its collation order.""
477: n = memcmp(c_addr1, c_addr2, u1<u2 ? u1 : u2);
478: if (n==0)
479: n = u1-u2;
480: if (n<0)
481: n = -1;
482: else if (n>0)
483: n = 1;
484: :
485: rot 2dup - >r min swap -text dup
486: IF rdrop
487: ELSE drop r@ 0>
488: IF rdrop -1
489: ELSE r> 1 and
490: THEN
491: THEN ;
492:
493: -text c_addr1 u c_addr2 -- n new dash_text
494: n = memcmp(c_addr1, c_addr2, u);
495: if (n<0)
496: n = -1;
497: else if (n>0)
498: n = 1;
499: :
500: swap bounds
501: ?DO dup c@ I c@ = WHILE 1+ LOOP drop 0
502: ELSE c@ I c@ - unloop THEN -text-flag ;
503: : -text-flag ( n -- -1/0/1 )
504: dup 0< IF drop -1 ELSE 0> 1 and THEN ;
505:
506: toupper c1 -- c2 gforth
507: c2 = toupper(c1);
508: :
509: dup [char] a - [ char z char a - 1 + ] Literal u< bl and - ;
510:
511: capscomp c_addr1 u c_addr2 -- n new
512: n = memcasecmp(c_addr1, c_addr2, u); /* !! use something that works in all locales */
513: if (n<0)
514: n = -1;
515: else if (n>0)
516: n = 1;
517: :
518: swap bounds
519: ?DO dup c@ I c@ <>
520: IF dup c@ toupper I c@ toupper =
521: ELSE true THEN WHILE 1+ LOOP drop 0
522: ELSE c@ toupper I c@ toupper - unloop THEN -text-flag ;
523:
524: -trailing c_addr u1 -- c_addr u2 string dash_trailing
525: u2 = u1;
1.4 anton 526: while (u2>0 && c_addr[u2-1] == ' ')
1.1 anton 527: u2--;
528: :
529: BEGIN 1- 2dup + c@ bl = WHILE
530: dup 0= UNTIL ELSE 1+ THEN ;
531:
532: /string c_addr1 u1 n -- c_addr2 u2 string slash_string
533: c_addr2 = c_addr1+n;
534: u2 = u1-n;
535: :
536: tuck - >r + r> dup 0< IF - 0 THEN ;
537:
538: + n1 n2 -- n core plus
539: n = n1+n2;
540:
541: \ PFE-0.9.14 has it differently, but the next release will have it as follows
542: under+ n1 n2 n3 -- n n2 gforth under_plus
543: ""add @var{n3} to @var{n1} (giving @var{n})""
544: n = n1+n3;
545: :
546: rot + swap ;
547:
548: - n1 n2 -- n core minus
549: n = n1-n2;
550: :
551: negate + ;
552:
553: negate n1 -- n2 core
554: /* use minus as alias */
555: n2 = -n1;
556: :
557: invert 1+ ;
558:
559: 1+ n1 -- n2 core one_plus
560: n2 = n1+1;
561: :
562: 1 + ;
563:
564: 1- n1 -- n2 core one_minus
565: n2 = n1-1;
566: :
567: 1 - ;
568:
569: max n1 n2 -- n core
570: if (n1<n2)
571: n = n2;
572: else
573: n = n1;
574: :
575: 2dup < IF swap THEN drop ;
576:
577: min n1 n2 -- n core
578: if (n1<n2)
579: n = n1;
580: else
581: n = n2;
582: :
583: 2dup > IF swap THEN drop ;
584:
585: abs n1 -- n2 core
586: if (n1<0)
587: n2 = -n1;
588: else
589: n2 = n1;
590: :
591: dup 0< IF negate THEN ;
592:
593: * n1 n2 -- n core star
594: n = n1*n2;
595: :
596: um* drop ;
597:
598: / n1 n2 -- n core slash
599: n = n1/n2;
600: :
601: /mod nip ;
602:
603: mod n1 n2 -- n core
604: n = n1%n2;
605: :
606: /mod drop ;
607:
608: /mod n1 n2 -- n3 n4 core slash_mod
609: n4 = n1/n2;
610: n3 = n1%n2; /* !! is this correct? look into C standard! */
611: :
612: >r s>d r> fm/mod ;
613:
614: 2* n1 -- n2 core two_star
615: n2 = 2*n1;
616: :
617: dup + ;
618:
619: 2/ n1 -- n2 core two_slash
620: /* !! is this still correct? */
621: n2 = n1>>1;
622: :
623: dup MINI and IF 1 ELSE 0 THEN
624: [ bits/byte cell * 1- ] literal
1.5 jwilke 625: 0 DO 2* swap dup 2* >r MINI and
1.1 anton 626: IF 1 ELSE 0 THEN or r> swap
627: LOOP nip ;
628:
629: fm/mod d1 n1 -- n2 n3 core f_m_slash_mod
630: ""floored division: d1 = n3*n1+n2, n1>n2>=0 or 0>=n2>n1""
631: #ifdef BUGGY_LONG_LONG
632: DCell r = fmdiv(d1,n1);
633: n2=r.hi;
634: n3=r.lo;
635: #else
636: /* assumes that the processor uses either floored or symmetric division */
637: n3 = d1/n1;
638: n2 = d1%n1;
639: /* note that this 1%-3>0 is optimized by the compiler */
640: if (1%-3>0 && (d1<0) != (n1<0) && n2!=0) {
641: n3--;
642: n2+=n1;
643: }
644: #endif
645: :
646: dup >r dup 0< IF negate >r dnegate r> THEN
647: over 0< IF tuck + swap THEN
648: um/mod
649: r> 0< IF swap negate swap THEN ;
650:
651: sm/rem d1 n1 -- n2 n3 core s_m_slash_rem
652: ""symmetric division: d1 = n3*n1+n2, sign(n2)=sign(d1) or 0""
653: #ifdef BUGGY_LONG_LONG
654: DCell r = smdiv(d1,n1);
655: n2=r.hi;
656: n3=r.lo;
657: #else
658: /* assumes that the processor uses either floored or symmetric division */
659: n3 = d1/n1;
660: n2 = d1%n1;
661: /* note that this 1%-3<0 is optimized by the compiler */
662: if (1%-3<0 && (d1<0) != (n1<0) && n2!=0) {
663: n3++;
664: n2-=n1;
665: }
666: #endif
667: :
668: over >r dup >r abs -rot
669: dabs rot um/mod
670: r> r@ xor 0< IF negate THEN
671: r> 0< IF swap negate swap THEN ;
672:
673: m* n1 n2 -- d core m_star
674: #ifdef BUGGY_LONG_LONG
675: d = mmul(n1,n2);
676: #else
677: d = (DCell)n1 * (DCell)n2;
678: #endif
679: :
680: 2dup 0< and >r
681: 2dup swap 0< and >r
682: um* r> - r> - ;
683:
684: um* u1 u2 -- ud core u_m_star
685: /* use u* as alias */
686: #ifdef BUGGY_LONG_LONG
687: ud = ummul(u1,u2);
688: #else
689: ud = (UDCell)u1 * (UDCell)u2;
690: #endif
691: :
692: >r >r 0 0 r> r> [ 8 cells ] literal 0
693: DO
694: over >r dup >r 0< and d2*+ drop
695: r> 2* r> swap
696: LOOP 2drop ;
697: : d2*+ ( ud n -- ud+n c )
698: over MINI
699: and >r >r 2dup d+ swap r> + swap r> ;
700:
701: um/mod ud u1 -- u2 u3 core u_m_slash_mod
702: #ifdef BUGGY_LONG_LONG
703: UDCell r = umdiv(ud,u1);
704: u2=r.hi;
705: u3=r.lo;
706: #else
707: u3 = ud/u1;
708: u2 = ud%u1;
709: #endif
710: :
711: 0 swap [ 8 cells 1 + ] literal 0
1.5 jwilke 712: ?DO /modstep
1.1 anton 713: LOOP drop swap 1 rshift or swap ;
714: : /modstep ( ud c R: u -- ud-?u c R: u )
1.5 jwilke 715: >r over r@ u< 0= or IF r@ - 1 ELSE 0 THEN d2*+ r> ;
1.1 anton 716: : d2*+ ( ud n -- ud+n c )
717: over MINI
718: and >r >r 2dup d+ swap r> + swap r> ;
719:
720: m+ d1 n -- d2 double m_plus
721: #ifdef BUGGY_LONG_LONG
722: d2.lo = d1.lo+n;
723: d2.hi = d1.hi - (n<0) + (d2.lo<d1.lo);
724: #else
725: d2 = d1+n;
726: #endif
727: :
728: s>d d+ ;
729:
730: d+ d1 d2 -- d double d_plus
731: #ifdef BUGGY_LONG_LONG
732: d.lo = d1.lo+d2.lo;
733: d.hi = d1.hi + d2.hi + (d.lo<d1.lo);
734: #else
735: d = d1+d2;
736: #endif
737: :
738: rot + >r tuck + swap over u> r> swap - ;
739:
740: d- d1 d2 -- d double d_minus
741: #ifdef BUGGY_LONG_LONG
742: d.lo = d1.lo - d2.lo;
743: d.hi = d1.hi-d2.hi-(d1.lo<d2.lo);
744: #else
745: d = d1-d2;
746: #endif
747: :
748: dnegate d+ ;
749:
750: dnegate d1 -- d2 double
751: /* use dminus as alias */
752: #ifdef BUGGY_LONG_LONG
753: d2 = dnegate(d1);
754: #else
755: d2 = -d1;
756: #endif
757: :
758: invert swap negate tuck 0= - ;
759:
760: d2* d1 -- d2 double d_two_star
761: #ifdef BUGGY_LONG_LONG
762: d2.lo = d1.lo<<1;
763: d2.hi = (d1.hi<<1) | (d1.lo>>(CELL_BITS-1));
764: #else
765: d2 = 2*d1;
766: #endif
767: :
768: 2dup d+ ;
769:
770: d2/ d1 -- d2 double d_two_slash
771: #ifdef BUGGY_LONG_LONG
772: d2.hi = d1.hi>>1;
773: d2.lo= (d1.lo>>1) | (d1.hi<<(CELL_BITS-1));
774: #else
775: d2 = d1>>1;
776: #endif
777: :
778: dup 1 and >r 2/ swap 2/ [ 1 8 cells 1- lshift 1- ] Literal and
779: r> IF [ 1 8 cells 1- lshift ] Literal + THEN swap ;
780:
781: and w1 w2 -- w core
782: w = w1&w2;
783:
784: or w1 w2 -- w core
785: w = w1|w2;
786: :
787: invert swap invert and invert ;
788:
789: xor w1 w2 -- w core
790: w = w1^w2;
791:
792: invert w1 -- w2 core
793: w2 = ~w1;
794: :
795: MAXU xor ;
796:
797: rshift u1 n -- u2 core
798: u2 = u1>>n;
799: :
800: 0 ?DO 2/ MAXI and LOOP ;
801:
802: lshift u1 n -- u2 core
803: u2 = u1<<n;
804: :
805: 0 ?DO 2* LOOP ;
806:
807: \ comparisons(prefix, args, prefix, arg1, arg2, wordsets...)
808: define(comparisons,
809: $1= $2 -- f $6 $3equals
810: f = FLAG($4==$5);
811: :
812: [ char $1x char 0 = [IF]
813: ] IF false ELSE true THEN [
814: [ELSE]
815: ] xor 0= [
816: [THEN] ] ;
817:
818: $1<> $2 -- f $7 $3different
819: f = FLAG($4!=$5);
820: :
821: [ char $1x char 0 = [IF]
822: ] IF true ELSE false THEN [
823: [ELSE]
824: ] xor 0<> [
825: [THEN] ] ;
826:
827: $1< $2 -- f $8 $3less
828: f = FLAG($4<$5);
829: :
830: [ char $1x char 0 = [IF]
831: ] MINI and 0<> [
832: [ELSE] char $1x char u = [IF]
833: ] 2dup xor 0< IF nip ELSE - THEN 0< [
834: [ELSE]
835: ] MINI xor >r MINI xor r> u< [
836: [THEN]
837: [THEN] ] ;
838:
839: $1> $2 -- f $9 $3greater
840: f = FLAG($4>$5);
841: :
842: [ char $1x char 0 = [IF] ] negate [ [ELSE] ] swap [ [THEN] ]
843: $1< ;
844:
845: $1<= $2 -- f gforth $3less_or_equal
846: f = FLAG($4<=$5);
847: :
848: $1> 0= ;
849:
850: $1>= $2 -- f gforth $3greater_or_equal
851: f = FLAG($4>=$5);
852: :
853: [ char $1x char 0 = [IF] ] negate [ [ELSE] ] swap [ [THEN] ]
854: $1<= ;
855:
856: )
857:
858: comparisons(0, n, zero_, n, 0, core, core-ext, core, core-ext)
859: comparisons(, n1 n2, , n1, n2, core, core-ext, core, core)
860: comparisons(u, u1 u2, u_, u1, u2, gforth, gforth, core, core-ext)
861:
862: \ dcomparisons(prefix, args, prefix, arg1, arg2, wordsets...)
863: define(dcomparisons,
864: $1= $2 -- f $6 $3equals
865: #ifdef BUGGY_LONG_LONG
866: f = FLAG($4.lo==$5.lo && $4.hi==$5.hi);
867: #else
868: f = FLAG($4==$5);
869: #endif
870:
871: $1<> $2 -- f $7 $3different
872: #ifdef BUGGY_LONG_LONG
873: f = FLAG($4.lo!=$5.lo || $4.hi!=$5.hi);
874: #else
875: f = FLAG($4!=$5);
876: #endif
877:
878: $1< $2 -- f $8 $3less
879: #ifdef BUGGY_LONG_LONG
880: f = FLAG($4.hi==$5.hi ? $4.lo<$5.lo : $4.hi<$5.hi);
881: #else
882: f = FLAG($4<$5);
883: #endif
884:
885: $1> $2 -- f $9 $3greater
886: #ifdef BUGGY_LONG_LONG
887: f = FLAG($4.hi==$5.hi ? $4.lo>$5.lo : $4.hi>$5.hi);
888: #else
889: f = FLAG($4>$5);
890: #endif
891:
892: $1<= $2 -- f gforth $3less_or_equal
893: #ifdef BUGGY_LONG_LONG
894: f = FLAG($4.hi==$5.hi ? $4.lo<=$5.lo : $4.hi<=$5.hi);
895: #else
896: f = FLAG($4<=$5);
897: #endif
898:
899: $1>= $2 -- f gforth $3greater_or_equal
900: #ifdef BUGGY_LONG_LONG
901: f = FLAG($4.hi==$5.hi ? $4.lo>=$5.lo : $4.hi>=$5.hi);
902: #else
903: f = FLAG($4>=$5);
904: #endif
905:
906: )
907:
1.6 jwilke 908: \+has? dcomps [IF]
1.1 anton 909:
910: dcomparisons(d, d1 d2, d_, d1, d2, double, gforth, double, gforth)
911: dcomparisons(d0, d, d_zero_, d, DZERO, double, gforth, double, gforth)
912: dcomparisons(du, ud1 ud2, d_u_, ud1, ud2, gforth, gforth, double-ext, gforth)
913:
914: \+[THEN]
915:
916: within u1 u2 u3 -- f core-ext
917: f = FLAG(u1-u2 < u3-u2);
918: :
919: over - >r - r> u< ;
920:
921: sp@ -- a_addr gforth spat
922: a_addr = sp+1;
923:
924: sp! a_addr -- gforth spstore
925: sp = a_addr;
926: /* works with and without TOS caching */
927:
928: rp@ -- a_addr gforth rpat
929: a_addr = rp;
930:
931: rp! a_addr -- gforth rpstore
932: rp = a_addr;
933:
1.6 jwilke 934: \+has? floating [IF]
1.1 anton 935:
936: fp@ -- f_addr gforth fp_fetch
937: f_addr = fp;
938:
939: fp! f_addr -- gforth fp_store
940: fp = f_addr;
941:
942: \+[THEN]
943:
944: ;s -- gforth semis
945: ip = (Xt *)(*rp++);
946: NEXT_P0;
947:
948: >r w -- core to_r
949: *--rp = w;
950: :
951: (>r) ;
952: : (>r) rp@ cell+ @ rp@ ! rp@ cell+ ! ;
953:
954: r> -- w core r_from
955: w = *rp++;
956: :
957: rp@ cell+ @ rp@ @ rp@ cell+ ! (rdrop) rp@ ! ;
958: Create (rdrop) ' ;s A,
959:
960: rdrop -- gforth
961: rp++;
962: :
963: r> r> drop >r ;
964:
965: 2>r w1 w2 -- core-ext two_to_r
966: *--rp = w1;
967: *--rp = w2;
968: :
969: swap r> swap >r swap >r >r ;
970:
971: 2r> -- w1 w2 core-ext two_r_from
972: w2 = *rp++;
973: w1 = *rp++;
974: :
975: r> r> swap r> swap >r swap ;
976:
977: 2r@ -- w1 w2 core-ext two_r_fetch
978: w2 = rp[0];
979: w1 = rp[1];
980: :
981: i' j ;
982:
983: 2rdrop -- gforth two_r_drop
984: rp+=2;
985: :
986: r> r> drop r> drop >r ;
987:
988: over w1 w2 -- w1 w2 w1 core
989: :
990: sp@ cell+ @ ;
991:
992: drop w -- core
993: :
994: IF THEN ;
995:
996: swap w1 w2 -- w2 w1 core
997: :
998: >r (swap) ! r> (swap) @ ;
999: Variable (swap)
1000:
1001: dup w -- w w core
1002: :
1003: sp@ @ ;
1004:
1005: rot w1 w2 w3 -- w2 w3 w1 core rote
1006: :
1007: [ defined? (swap) [IF] ]
1008: (swap) ! (rot) ! >r (rot) @ (swap) @ r> ;
1009: Variable (rot)
1010: [ELSE] ]
1011: >r swap r> swap ;
1012: [THEN]
1013:
1014: -rot w1 w2 w3 -- w3 w1 w2 gforth not_rote
1015: :
1016: rot rot ;
1017:
1018: nip w1 w2 -- w2 core-ext
1019: :
1.6 jwilke 1020: swap drop ;
1.1 anton 1021:
1022: tuck w1 w2 -- w2 w1 w2 core-ext
1023: :
1024: swap over ;
1025:
1026: ?dup w -- w core question_dupe
1027: if (w!=0) {
1028: IF_TOS(*sp-- = w;)
1029: #ifndef USE_TOS
1030: *--sp = w;
1031: #endif
1032: }
1033: :
1034: dup IF dup THEN ;
1035:
1036: pick u -- w core-ext
1037: w = sp[u+1];
1038: :
1039: 1+ cells sp@ + @ ;
1040:
1041: 2drop w1 w2 -- core two_drop
1042: :
1043: drop drop ;
1044:
1045: 2dup w1 w2 -- w1 w2 w1 w2 core two_dupe
1046: :
1047: over over ;
1048:
1049: 2over w1 w2 w3 w4 -- w1 w2 w3 w4 w1 w2 core two_over
1050: :
1051: 3 pick 3 pick ;
1052:
1053: 2swap w1 w2 w3 w4 -- w3 w4 w1 w2 core two_swap
1054: :
1055: rot >r rot r> ;
1056:
1057: 2rot w1 w2 w3 w4 w5 w6 -- w3 w4 w5 w6 w1 w2 double-ext two_rote
1058: :
1059: >r >r 2swap r> r> 2swap ;
1060:
1061: 2nip w1 w2 w3 w4 -- w3 w4 gforth two_nip
1062: :
1063: 2swap 2drop ;
1064:
1065: 2tuck w1 w2 w3 w4 -- w3 w4 w1 w2 w3 w4 gforth two_tuck
1066: :
1067: 2swap 2over ;
1068:
1069: \ toggle is high-level: 0.11/0.42%
1070:
1071: @ a_addr -- w core fetch
1072: w = *a_addr;
1073:
1074: ! w a_addr -- core store
1075: *a_addr = w;
1076:
1077: +! n a_addr -- core plus_store
1078: *a_addr += n;
1079: :
1080: tuck @ + swap ! ;
1081:
1082: c@ c_addr -- c core cfetch
1083: c = *c_addr;
1084: :
1085: [ bigendian [IF] ]
1086: [ cell>bit 4 = [IF] ]
1087: dup [ 0 cell - ] Literal and @ swap 1 and
1088: IF $FF and ELSE 8>> THEN ;
1089: [ [ELSE] ]
1090: dup [ cell 1- ] literal and
1091: tuck - @ swap [ cell 1- ] literal xor
1092: 0 ?DO 8>> LOOP $FF and
1093: [ [THEN] ]
1094: [ [ELSE] ]
1095: [ cell>bit 4 = [IF] ]
1096: dup [ 0 cell - ] Literal and @ swap 1 and
1097: IF 8>> ELSE $FF and THEN
1098: [ [ELSE] ]
1099: dup [ cell 1- ] literal and
1100: tuck - @ swap
1101: 0 ?DO 8>> LOOP 255 and
1102: [ [THEN] ]
1103: [ [THEN] ]
1104: ;
1105: : 8>> 2/ 2/ 2/ 2/ 2/ 2/ 2/ 2/ ;
1106:
1107: c! c c_addr -- core cstore
1108: *c_addr = c;
1109: :
1110: [ bigendian [IF] ]
1111: [ cell>bit 4 = [IF] ]
1112: tuck 1 and IF $FF and ELSE 8<< THEN >r
1113: dup -2 and @ over 1 and cells masks + @ and
1114: r> or swap -2 and ! ;
1115: Create masks $00FF , $FF00 ,
1116: [ELSE] ]
1117: dup [ cell 1- ] literal and dup
1118: [ cell 1- ] literal xor >r
1119: - dup @ $FF r@ 0 ?DO 8<< LOOP invert and
1120: rot $FF and r> 0 ?DO 8<< LOOP or swap ! ;
1121: [THEN]
1122: [ELSE] ]
1123: [ cell>bit 4 = [IF] ]
1124: tuck 1 and IF 8<< ELSE $FF and THEN >r
1125: dup -2 and @ over 1 and cells masks + @ and
1126: r> or swap -2 and ! ;
1127: Create masks $FF00 , $00FF ,
1128: [ELSE] ]
1129: dup [ cell 1- ] literal and dup >r
1130: - dup @ $FF r@ 0 ?DO 8<< LOOP invert and
1131: rot $FF and r> 0 ?DO 8<< LOOP or swap ! ;
1132: [THEN]
1133: [THEN]
1134: : 8<< 2* 2* 2* 2* 2* 2* 2* 2* ;
1135:
1136: 2! w1 w2 a_addr -- core two_store
1137: a_addr[0] = w2;
1138: a_addr[1] = w1;
1139: :
1140: tuck ! cell+ ! ;
1141:
1142: 2@ a_addr -- w1 w2 core two_fetch
1143: w2 = a_addr[0];
1144: w1 = a_addr[1];
1145: :
1146: dup cell+ @ swap @ ;
1147:
1148: cell+ a_addr1 -- a_addr2 core cell_plus
1149: a_addr2 = a_addr1+1;
1150: :
1151: cell + ;
1152:
1153: cells n1 -- n2 core
1154: n2 = n1 * sizeof(Cell);
1155: :
1156: [ cell
1157: 2/ dup [IF] ] 2* [ [THEN]
1158: 2/ dup [IF] ] 2* [ [THEN]
1159: 2/ dup [IF] ] 2* [ [THEN]
1160: 2/ dup [IF] ] 2* [ [THEN]
1161: drop ] ;
1162:
1163: char+ c_addr1 -- c_addr2 core care_plus
1164: c_addr2 = c_addr1 + 1;
1165: :
1166: 1+ ;
1167:
1168: (chars) n1 -- n2 gforth paren_cares
1169: n2 = n1 * sizeof(Char);
1170: :
1171: ;
1172:
1173: count c_addr1 -- c_addr2 u core
1174: u = *c_addr1;
1175: c_addr2 = c_addr1+1;
1176: :
1177: dup 1+ swap c@ ;
1178:
1179: (f83find) c_addr u f83name1 -- f83name2 new paren_f83find
1180: for (; f83name1 != NULL; f83name1 = f83name1->next)
1181: if ((UCell)F83NAME_COUNT(f83name1)==u &&
1182: memcasecmp(c_addr, f83name1->name, u)== 0 /* or inline? */)
1183: break;
1184: f83name2=f83name1;
1185: :
1186: BEGIN dup WHILE (find-samelen) dup WHILE
1187: >r 2dup r@ cell+ char+ capscomp 0=
1188: IF 2drop r> EXIT THEN
1189: r> @
1190: REPEAT THEN nip nip ;
1191: : (find-samelen) ( u f83name1 -- u f83name2/0 )
1192: BEGIN 2dup cell+ c@ $1F and <> WHILE @ dup 0= UNTIL THEN ;
1193:
1.6 jwilke 1194: \+has? hash [IF]
1.1 anton 1195:
1196: (hashfind) c_addr u a_addr -- f83name2 new paren_hashfind
1197: F83Name *f83name1;
1198: f83name2=NULL;
1199: while(a_addr != NULL)
1200: {
1201: f83name1=(F83Name *)(a_addr[1]);
1202: a_addr=(Cell *)(a_addr[0]);
1203: if ((UCell)F83NAME_COUNT(f83name1)==u &&
1204: memcasecmp(c_addr, f83name1->name, u)== 0 /* or inline? */)
1205: {
1206: f83name2=f83name1;
1207: break;
1208: }
1209: }
1210: :
1211: BEGIN dup WHILE
1212: 2@ >r >r dup r@ cell+ c@ $1F and =
1213: IF 2dup r@ cell+ char+ capscomp 0=
1214: IF 2drop r> rdrop EXIT THEN THEN
1215: rdrop r>
1216: REPEAT nip nip ;
1217:
1218: (tablefind) c_addr u a_addr -- f83name2 new paren_tablefind
1219: ""A case-sensitive variant of @code{(hashfind)}""
1220: F83Name *f83name1;
1221: f83name2=NULL;
1222: while(a_addr != NULL)
1223: {
1224: f83name1=(F83Name *)(a_addr[1]);
1225: a_addr=(Cell *)(a_addr[0]);
1226: if ((UCell)F83NAME_COUNT(f83name1)==u &&
1227: memcmp(c_addr, f83name1->name, u)== 0 /* or inline? */)
1228: {
1229: f83name2=f83name1;
1230: break;
1231: }
1232: }
1233: :
1234: BEGIN dup WHILE
1235: 2@ >r >r dup r@ cell+ c@ $1F and =
1236: IF 2dup r@ cell+ char+ -text 0=
1237: IF 2drop r> rdrop EXIT THEN THEN
1238: rdrop r>
1239: REPEAT nip nip ;
1240:
1241: (hashkey) c_addr u1 -- u2 gforth paren_hashkey
1242: u2=0;
1243: while(u1--)
1244: u2+=(Cell)toupper(*c_addr++);
1245: :
1246: 0 -rot bounds ?DO I c@ toupper + LOOP ;
1247:
1248: (hashkey1) c_addr u ubits -- ukey gforth paren_hashkey1
1249: ""ukey is the hash key for the string c_addr u fitting in ubits bits""
1250: /* this hash function rotates the key at every step by rot bits within
1251: ubits bits and xors it with the character. This function does ok in
1252: the chi-sqare-test. Rot should be <=7 (preferably <=5) for
1253: ASCII strings (larger if ubits is large), and should share no
1254: divisors with ubits.
1255: */
1256: unsigned rot = ((char []){5,0,1,2,3,4,5,5,5,5,3,5,5,5,5,7,5,5,5,5,7,5,5,5,5,6,5,5,5,5,7,5,5})[ubits];
1257: Char *cp = c_addr;
1258: for (ukey=0; cp<c_addr+u; cp++)
1259: ukey = ((((ukey<<rot) | (ukey>>(ubits-rot)))
1260: ^ toupper(*cp))
1261: & ((1<<ubits)-1));
1262: :
1263: dup rot-values + c@ over 1 swap lshift 1- >r
1264: tuck - 2swap r> 0 2swap bounds
1265: ?DO dup 4 pick lshift swap 3 pick rshift or
1266: I c@ toupper xor
1267: over and LOOP
1268: nip nip nip ;
1269: Create rot-values
1270: 5 c, 0 c, 1 c, 2 c, 3 c, 4 c, 5 c, 5 c, 5 c, 5 c,
1271: 3 c, 5 c, 5 c, 5 c, 5 c, 7 c, 5 c, 5 c, 5 c, 5 c,
1272: 7 c, 5 c, 5 c, 5 c, 5 c, 6 c, 5 c, 5 c, 5 c, 5 c,
1273: 7 c, 5 c, 5 c,
1274:
1275: \+[THEN]
1276:
1277: (parse-white) c_addr1 u1 -- c_addr2 u2 gforth paren_parse_white
1278: /* use !isgraph instead of isspace? */
1279: Char *endp = c_addr1+u1;
1280: while (c_addr1<endp && isspace(*c_addr1))
1281: c_addr1++;
1282: if (c_addr1<endp) {
1283: for (c_addr2 = c_addr1; c_addr1<endp && !isspace(*c_addr1); c_addr1++)
1284: ;
1285: u2 = c_addr1-c_addr2;
1286: }
1287: else {
1288: c_addr2 = c_addr1;
1289: u2 = 0;
1290: }
1291: :
1292: BEGIN dup WHILE over c@ bl <= WHILE 1 /string
1293: REPEAT THEN 2dup
1294: BEGIN dup WHILE over c@ bl > WHILE 1 /string
1295: REPEAT THEN nip - ;
1296:
1297: aligned c_addr -- a_addr core
1298: a_addr = (Cell *)((((Cell)c_addr)+(sizeof(Cell)-1))&(-sizeof(Cell)));
1299: :
1300: [ cell 1- ] Literal + [ -1 cells ] Literal and ;
1301:
1302: faligned c_addr -- f_addr float f_aligned
1303: f_addr = (Float *)((((Cell)c_addr)+(sizeof(Float)-1))&(-sizeof(Float)));
1304: :
1305: [ 1 floats 1- ] Literal + [ -1 floats ] Literal and ;
1306:
1307: >body xt -- a_addr core to_body
1308: a_addr = PFA(xt);
1309: :
1310: 2 cells + ;
1311:
1312: >code-address xt -- c_addr gforth to_code_address
1313: ""c_addr is the code address of the word xt""
1314: /* !! This behaves installation-dependently for DOES-words */
1315: c_addr = (Address)CODE_ADDRESS(xt);
1316: :
1317: @ ;
1318:
1319: >does-code xt -- a_addr gforth to_does_code
1320: ""If xt ist the execution token of a defining-word-defined word,
1321: a_addr is the start of the Forth code after the DOES>;
1322: Otherwise a_addr is 0.""
1323: a_addr = (Cell *)DOES_CODE(xt);
1324: :
1325: cell+ @ ;
1326:
1327: code-address! c_addr xt -- gforth code_address_store
1328: ""Creates a code field with code address c_addr at xt""
1329: MAKE_CF(xt, c_addr);
1330: CACHE_FLUSH(xt,PFA(0));
1331: :
1332: ! ;
1333:
1334: does-code! a_addr xt -- gforth does_code_store
1335: ""creates a code field at xt for a defining-word-defined word; a_addr
1336: is the start of the Forth code after DOES>""
1337: MAKE_DOES_CF(xt, a_addr);
1338: CACHE_FLUSH(xt,PFA(0));
1339: :
1340: dodoes: over ! cell+ ! ;
1341:
1342: does-handler! a_addr -- gforth does_handler_store
1343: ""creates a DOES>-handler at address a_addr. a_addr usually points
1344: just behind a DOES>.""
1345: MAKE_DOES_HANDLER(a_addr);
1346: CACHE_FLUSH(a_addr,DOES_HANDLER_SIZE);
1347: :
1348: drop ;
1349:
1350: /does-handler -- n gforth slash_does_handler
1351: ""the size of a does-handler (includes possible padding)""
1352: /* !! a constant or environmental query might be better */
1353: n = DOES_HANDLER_SIZE;
1354: :
1355: 2 cells ;
1356:
1357: threading-method -- n gforth threading_method
1358: ""0 if the engine is direct threaded. Note that this may change during
1359: the lifetime of an image.""
1360: #if defined(DOUBLY_INDIRECT)
1361: n=2;
1362: #else
1363: # if defined(DIRECT_THREADED)
1364: n=0;
1365: # else
1366: n=1;
1367: # endif
1368: #endif
1369: :
1370: 1 ;
1371:
1.6 jwilke 1372: \+has? os [IF]
1.1 anton 1373:
1374: (key) -- n gforth paren_key
1375: fflush(stdout);
1376: /* !! noecho */
1377: n = key();
1378:
1379: key? -- n facility key_q
1380: fflush(stdout);
1381: n = key_query;
1382:
1383: stdout -- wfileid gforth
1384: wfileid = (Cell)stdout;
1385:
1386: stderr -- wfileid gforth
1387: wfileid = (Cell)stderr;
1388:
1389: form -- urows ucols gforth
1390: ""The number of lines and columns in the terminal. These numbers may change
1391: with the window size.""
1392: /* we could block SIGWINCH here to get a consistent size, but I don't
1393: think this is necessary or always beneficial */
1394: urows=rows;
1395: ucols=cols;
1396:
1397: flush-icache c_addr u -- gforth flush_icache
1398: ""Make sure that the instruction cache of the processor (if there is
1399: one) does not contain stale data at @var{c_addr} and @var{u} bytes
1400: afterwards. @code{END-CODE} performs a @code{flush-icache}
1401: automatically. Caveat: @code{flush-icache} might not work on your
1402: installation; this is usually the case if direct threading is not
1403: supported on your machine (take a look at your @file{machine.h}) and
1404: your machine has a separate instruction cache. In such cases,
1405: @code{flush-icache} does nothing instead of flushing the instruction
1406: cache.""
1407: FLUSH_ICACHE(c_addr,u);
1408:
1409: (bye) n -- gforth paren_bye
1410: return (Label *)n;
1411:
1412: (system) c_addr u -- wretval wior gforth peren_system
1413: int old_tp=terminal_prepped;
1414: deprep_terminal();
1415: wretval=system(cstr(c_addr,u,1)); /* ~ expansion on first part of string? */
1416: wior = IOR(wretval==-1 || (wretval==127 && errno != 0));
1417: if (old_tp)
1418: prep_terminal();
1419:
1420: getenv c_addr1 u1 -- c_addr2 u2 gforth
1421: c_addr2 = getenv(cstr(c_addr1,u1,1));
1422: u2 = (c_addr2 == NULL ? 0 : strlen(c_addr2));
1423:
1424: open-pipe c_addr u ntype -- wfileid wior gforth open_pipe
1425: wfileid=(Cell)popen(cstr(c_addr,u,1),fileattr[ntype]); /* ~ expansion of 1st arg? */
1426: wior = IOR(wfileid==0); /* !! the man page says that errno is not set reliably */
1427:
1428: close-pipe wfileid -- wretval wior gforth close_pipe
1429: wretval = pclose((FILE *)wfileid);
1430: wior = IOR(wretval==-1);
1431:
1432: time&date -- nsec nmin nhour nday nmonth nyear facility-ext time_and_date
1433: struct timeval time1;
1434: struct timezone zone1;
1435: struct tm *ltime;
1436: gettimeofday(&time1,&zone1);
1437: ltime=localtime((time_t *)&time1.tv_sec);
1438: nyear =ltime->tm_year+1900;
1439: nmonth=ltime->tm_mon+1;
1440: nday =ltime->tm_mday;
1441: nhour =ltime->tm_hour;
1442: nmin =ltime->tm_min;
1443: nsec =ltime->tm_sec;
1444:
1445: ms n -- facility-ext
1446: struct timeval timeout;
1447: timeout.tv_sec=n/1000;
1448: timeout.tv_usec=1000*(n%1000);
1449: (void)select(0,0,0,0,&timeout);
1450:
1451: allocate u -- a_addr wior memory
1452: a_addr = (Cell *)malloc(u?u:1);
1453: wior = IOR(a_addr==NULL);
1454:
1455: free a_addr -- wior memory
1456: free(a_addr);
1457: wior = 0;
1458:
1459: resize a_addr1 u -- a_addr2 wior memory
1460: ""Change the size of the allocated area at @i{a_addr1} to @i{u}
1461: address units, possibly moving the contents to a different
1462: area. @i{a_addr2} is the address of the resulting area. If
1463: @code{a_addr1} is 0, Gforth's (but not the standard) @code{resize}
1464: @code{allocate}s @i{u} address units.""
1465: /* the following check is not necessary on most OSs, but it is needed
1466: on SunOS 4.1.2. */
1467: if (a_addr1==NULL)
1468: a_addr2 = (Cell *)malloc(u);
1469: else
1470: a_addr2 = (Cell *)realloc(a_addr1, u);
1471: wior = IOR(a_addr2==NULL); /* !! Define a return code */
1472:
1473: strerror n -- c_addr u gforth
1474: c_addr = strerror(n);
1475: u = strlen(c_addr);
1476:
1477: strsignal n -- c_addr u gforth
1478: c_addr = strsignal(n);
1479: u = strlen(c_addr);
1480:
1481: call-c w -- gforth call_c
1482: ""Call the C function pointed to by @i{w}. The C function has to
1483: access the stack itself. The stack pointers are exported in the global
1484: variables @code{SP} and @code{FP}.""
1485: /* This is a first attempt at support for calls to C. This may change in
1486: the future */
1487: IF_FTOS(fp[0]=FTOS);
1488: FP=fp;
1489: SP=sp;
1490: ((void (*)())w)();
1491: sp=SP;
1492: fp=FP;
1493: IF_TOS(TOS=sp[0]);
1494: IF_FTOS(FTOS=fp[0]);
1495:
1.6 jwilke 1496: \+[THEN] ( has? os ) has? file [IF]
1.1 anton 1497:
1498: close-file wfileid -- wior file close_file
1499: wior = IOR(fclose((FILE *)wfileid)==EOF);
1500:
1501: open-file c_addr u ntype -- w2 wior file open_file
1502: w2 = (Cell)fopen(tilde_cstr(c_addr, u, 1), fileattr[ntype]);
1503: wior = IOR(w2 == 0);
1504:
1505: create-file c_addr u ntype -- w2 wior file create_file
1506: Cell fd;
1507: fd = open(tilde_cstr(c_addr, u, 1), O_CREAT|O_TRUNC|ufileattr[ntype], 0666);
1508: if (fd != -1) {
1509: w2 = (Cell)fdopen(fd, fileattr[ntype]);
1510: wior = IOR(w2 == 0);
1511: } else {
1512: w2 = 0;
1513: wior = IOR(1);
1514: }
1515:
1516: delete-file c_addr u -- wior file delete_file
1517: wior = IOR(unlink(tilde_cstr(c_addr, u, 1))==-1);
1518:
1519: rename-file c_addr1 u1 c_addr2 u2 -- wior file-ext rename_file
1520: char *s1=tilde_cstr(c_addr2, u2, 1);
1521: wior = IOR(rename(tilde_cstr(c_addr1, u1, 0), s1)==-1);
1522:
1523: file-position wfileid -- ud wior file file_position
1524: /* !! use tell and lseek? */
1525: ud = LONG2UD(ftell((FILE *)wfileid));
1526: wior = IOR(UD2LONG(ud)==-1);
1527:
1528: reposition-file ud wfileid -- wior file reposition_file
1529: wior = IOR(fseek((FILE *)wfileid, UD2LONG(ud), SEEK_SET)==-1);
1530:
1531: file-size wfileid -- ud wior file file_size
1532: #include <sys/stat.h>
1533: struct stat buf;
1534: wior = IOR(fstat(fileno((FILE *)wfileid), &buf)==-1);
1535: ud = LONG2UD(buf.st_size);
1536:
1537: resize-file ud wfileid -- wior file resize_file
1538: wior = IOR(ftruncate(fileno((FILE *)wfileid), UD2LONG(ud))==-1);
1539:
1540: read-file c_addr u1 wfileid -- u2 wior file read_file
1541: /* !! fread does not guarantee enough */
1542: u2 = fread(c_addr, sizeof(Char), u1, (FILE *)wfileid);
1543: wior = FILEIO(u2<u1 && ferror((FILE *)wfileid));
1544: /* !! is the value of ferror errno-compatible? */
1545: if (wior)
1546: clearerr((FILE *)wfileid);
1547:
1548: read-line c_addr u1 wfileid -- u2 flag wior file read_line
1549: /*
1550: Cell c;
1551: flag=-1;
1552: for(u2=0; u2<u1; u2++)
1553: {
1554: *c_addr++ = (Char)(c = getc((FILE *)wfileid));
1555: if(c=='\n') break;
1556: if(c==EOF)
1557: {
1558: flag=FLAG(u2!=0);
1559: break;
1560: }
1561: }
1562: wior=FILEIO(ferror((FILE *)wfileid));
1563: */
1564: if ((flag=FLAG(!feof((FILE *)wfileid) &&
1565: fgets(c_addr,u1+1,(FILE *)wfileid) != NULL))) {
1566: wior=FILEIO(ferror((FILE *)wfileid)); /* !! ior? */
1567: if (wior)
1568: clearerr((FILE *)wfileid);
1569: u2 = strlen(c_addr);
1570: u2-=((u2>0) && (c_addr[u2-1]==NEWLINE));
1571: }
1572: else {
1573: wior=0;
1574: u2=0;
1575: }
1576:
1.6 jwilke 1577: \+[THEN] has? file [IF] -1 [ELSE] has? os [THEN] [IF]
1.1 anton 1578:
1579: write-file c_addr u1 wfileid -- wior file write_file
1580: /* !! fwrite does not guarantee enough */
1581: {
1582: UCell u2 = fwrite(c_addr, sizeof(Char), u1, (FILE *)wfileid);
1583: wior = FILEIO(u2<u1 && ferror((FILE *)wfileid));
1584: if (wior)
1585: clearerr((FILE *)wfileid);
1586: }
1587:
1588: emit-file c wfileid -- wior gforth emit_file
1589: wior = FILEIO(putc(c, (FILE *)wfileid)==EOF);
1590: if (wior)
1591: clearerr((FILE *)wfileid);
1592:
1.6 jwilke 1593: \+[THEN] has? file [IF]
1.1 anton 1594:
1595: flush-file wfileid -- wior file-ext flush_file
1596: wior = IOR(fflush((FILE *) wfileid)==EOF);
1597:
1598: file-status c_addr u -- ntype wior file-ext file_status
1599: char *filename=tilde_cstr(c_addr, u, 1);
1600: if (access (filename, F_OK) != 0) {
1601: ntype=0;
1602: wior=IOR(1);
1603: }
1604: else if (access (filename, R_OK | W_OK) == 0) {
1605: ntype=2; /* r/w */
1606: wior=0;
1607: }
1608: else if (access (filename, R_OK) == 0) {
1609: ntype=0; /* r/o */
1610: wior=0;
1611: }
1612: else if (access (filename, W_OK) == 0) {
1613: ntype=4; /* w/o */
1614: wior=0;
1615: }
1616: else {
1617: ntype=1; /* well, we cannot access the file, but better deliver a legal
1618: access mode (r/o bin), so we get a decent error later upon open. */
1619: wior=0;
1620: }
1621:
1.6 jwilke 1622: \+[THEN] ( has? file ) has? floating [IF]
1.1 anton 1623:
1624: comparisons(f, r1 r2, f_, r1, r2, gforth, gforth, float, gforth)
1625: comparisons(f0, r, f_zero_, r, 0., float, gforth, float, gforth)
1626:
1627: d>f d -- r float d_to_f
1628: #ifdef BUGGY_LONG_LONG
1629: extern double ldexp(double x, int exp);
1630: r = ldexp((Float)d.hi,CELL_BITS) + (Float)d.lo;
1631: #else
1632: r = d;
1633: #endif
1634:
1635: f>d r -- d float f_to_d
1636: #ifdef BUGGY_LONG_LONG
1637: d.hi = ldexp(r,-CELL_BITS) - (r<0);
1638: d.lo = r-ldexp((Float)d.hi,CELL_BITS);
1639: #else
1640: d = r;
1641: #endif
1642:
1643: f! r f_addr -- float f_store
1644: *f_addr = r;
1645:
1646: f@ f_addr -- r float f_fetch
1647: r = *f_addr;
1648:
1649: df@ df_addr -- r float-ext d_f_fetch
1650: #ifdef IEEE_FP
1651: r = *df_addr;
1652: #else
1653: !! df@
1654: #endif
1655:
1656: df! r df_addr -- float-ext d_f_store
1657: #ifdef IEEE_FP
1658: *df_addr = r;
1659: #else
1660: !! df!
1661: #endif
1662:
1663: sf@ sf_addr -- r float-ext s_f_fetch
1664: #ifdef IEEE_FP
1665: r = *sf_addr;
1666: #else
1667: !! sf@
1668: #endif
1669:
1670: sf! r sf_addr -- float-ext s_f_store
1671: #ifdef IEEE_FP
1672: *sf_addr = r;
1673: #else
1674: !! sf!
1675: #endif
1676:
1677: f+ r1 r2 -- r3 float f_plus
1678: r3 = r1+r2;
1679:
1680: f- r1 r2 -- r3 float f_minus
1681: r3 = r1-r2;
1682:
1683: f* r1 r2 -- r3 float f_star
1684: r3 = r1*r2;
1685:
1686: f/ r1 r2 -- r3 float f_slash
1687: r3 = r1/r2;
1688:
1689: f** r1 r2 -- r3 float-ext f_star_star
1690: ""@i{r3} is @i{r1} raised to the @i{r2}th power""
1691: r3 = pow(r1,r2);
1692:
1693: fnegate r1 -- r2 float
1694: r2 = - r1;
1695:
1696: fdrop r -- float
1697:
1698: fdup r -- r r float
1699:
1700: fswap r1 r2 -- r2 r1 float
1701:
1702: fover r1 r2 -- r1 r2 r1 float
1703:
1704: frot r1 r2 r3 -- r2 r3 r1 float
1705:
1706: fnip r1 r2 -- r2 gforth
1707:
1708: ftuck r1 r2 -- r2 r1 r2 gforth
1709:
1710: float+ f_addr1 -- f_addr2 float float_plus
1711: f_addr2 = f_addr1+1;
1712:
1713: floats n1 -- n2 float
1714: n2 = n1*sizeof(Float);
1715:
1716: floor r1 -- r2 float
1717: ""round towards the next smaller integral value, i.e., round toward negative infinity""
1718: /* !! unclear wording */
1719: r2 = floor(r1);
1720:
1721: fround r1 -- r2 float
1722: ""round to the nearest integral value""
1723: /* !! unclear wording */
1724: #ifdef HAVE_RINT
1725: r2 = rint(r1);
1726: #else
1727: r2 = floor(r1+0.5);
1728: /* !! This is not quite true to the rounding rules given in the standard */
1729: #endif
1730:
1731: fmax r1 r2 -- r3 float
1732: if (r1<r2)
1733: r3 = r2;
1734: else
1735: r3 = r1;
1736:
1737: fmin r1 r2 -- r3 float
1738: if (r1<r2)
1739: r3 = r1;
1740: else
1741: r3 = r2;
1742:
1743: represent r c_addr u -- n f1 f2 float
1744: char *sig;
1745: int flag;
1746: int decpt;
1747: sig=ecvt(r, u, &decpt, &flag);
1748: n=(r==0 ? 1 : decpt);
1749: f1=FLAG(flag!=0);
1750: f2=FLAG(isdigit(sig[0])!=0);
1751: memmove(c_addr,sig,u);
1752:
1753: >float c_addr u -- flag float to_float
1754: /* real signature: c_addr u -- r t / f */
1755: Float r;
1756: char *number=cstr(c_addr, u, 1);
1757: char *endconv;
1758: while(isspace(number[--u]) && u>0);
1759: switch(number[u])
1760: {
1761: case 'd':
1762: case 'D':
1763: case 'e':
1764: case 'E': break;
1765: default : u++; break;
1766: }
1767: number[u]='\0';
1768: r=strtod(number,&endconv);
1769: if((flag=FLAG(!(Cell)*endconv)))
1770: {
1771: IF_FTOS(fp[0] = FTOS);
1772: fp += -1;
1773: FTOS = r;
1774: }
1775: else if(*endconv=='d' || *endconv=='D')
1776: {
1777: *endconv='E';
1778: r=strtod(number,&endconv);
1779: if((flag=FLAG(!(Cell)*endconv)))
1780: {
1781: IF_FTOS(fp[0] = FTOS);
1782: fp += -1;
1783: FTOS = r;
1784: }
1785: }
1786:
1787: fabs r1 -- r2 float-ext
1788: r2 = fabs(r1);
1789:
1790: facos r1 -- r2 float-ext
1791: r2 = acos(r1);
1792:
1793: fasin r1 -- r2 float-ext
1794: r2 = asin(r1);
1795:
1796: fatan r1 -- r2 float-ext
1797: r2 = atan(r1);
1798:
1799: fatan2 r1 r2 -- r3 float-ext
1800: ""@i{r1/r2}=tan@i{r3}. The standard does not require, but probably
1801: intends this to be the inverse of @code{fsincos}. In gforth it is.""
1802: r3 = atan2(r1,r2);
1803:
1804: fcos r1 -- r2 float-ext
1805: r2 = cos(r1);
1806:
1807: fexp r1 -- r2 float-ext
1808: r2 = exp(r1);
1809:
1810: fexpm1 r1 -- r2 float-ext
1811: ""@i{r2}=@i{e}**@i{r1}@minus{}1""
1812: #ifdef HAVE_EXPM1
1.3 pazsan 1813: extern double
1814: #ifdef NeXT
1815: const
1816: #endif
1817: expm1(double);
1.1 anton 1818: r2 = expm1(r1);
1819: #else
1820: r2 = exp(r1)-1.;
1821: #endif
1822:
1823: fln r1 -- r2 float-ext
1824: r2 = log(r1);
1825:
1826: flnp1 r1 -- r2 float-ext
1827: ""@i{r2}=ln(@i{r1}+1)""
1828: #ifdef HAVE_LOG1P
1.3 pazsan 1829: extern double
1830: #ifdef NeXT
1831: const
1832: #endif
1833: log1p(double);
1.1 anton 1834: r2 = log1p(r1);
1835: #else
1836: r2 = log(r1+1.);
1837: #endif
1838:
1839: flog r1 -- r2 float-ext
1840: ""the decimal logarithm""
1841: r2 = log10(r1);
1842:
1843: falog r1 -- r2 float-ext
1844: ""@i{r2}=10**@i{r1}""
1845: extern double pow10(double);
1846: r2 = pow10(r1);
1847:
1848: fsin r1 -- r2 float-ext
1849: r2 = sin(r1);
1850:
1851: fsincos r1 -- r2 r3 float-ext
1852: ""@i{r2}=sin(@i{r1}), @i{r3}=cos(@i{r1})""
1853: r2 = sin(r1);
1854: r3 = cos(r1);
1855:
1856: fsqrt r1 -- r2 float-ext
1857: r2 = sqrt(r1);
1858:
1859: ftan r1 -- r2 float-ext
1860: r2 = tan(r1);
1861: :
1862: fsincos f/ ;
1863:
1864: fsinh r1 -- r2 float-ext
1865: r2 = sinh(r1);
1866: :
1867: fexpm1 fdup fdup 1. d>f f+ f/ f+ f2/ ;
1868:
1869: fcosh r1 -- r2 float-ext
1870: r2 = cosh(r1);
1871: :
1872: fexp fdup 1/f f+ f2/ ;
1873:
1874: ftanh r1 -- r2 float-ext
1875: r2 = tanh(r1);
1876: :
1877: f2* fexpm1 fdup 2. d>f f+ f/ ;
1878:
1879: fasinh r1 -- r2 float-ext
1880: r2 = asinh(r1);
1881: :
1882: fdup fdup f* 1. d>f f+ fsqrt f/ fatanh ;
1883:
1884: facosh r1 -- r2 float-ext
1885: r2 = acosh(r1);
1886: :
1887: fdup fdup f* 1. d>f f- fsqrt f+ fln ;
1888:
1889: fatanh r1 -- r2 float-ext
1890: r2 = atanh(r1);
1891: :
1892: fdup f0< >r fabs 1. d>f fover f- f/ f2* flnp1 f2/
1893: r> IF fnegate THEN ;
1894:
1895: sfloats n1 -- n2 float-ext s_floats
1896: n2 = n1*sizeof(SFloat);
1897:
1898: dfloats n1 -- n2 float-ext d_floats
1899: n2 = n1*sizeof(DFloat);
1900:
1901: sfaligned c_addr -- sf_addr float-ext s_f_aligned
1902: sf_addr = (SFloat *)((((Cell)c_addr)+(sizeof(SFloat)-1))&(-sizeof(SFloat)));
1903: :
1904: [ 1 sfloats 1- ] Literal + [ -1 sfloats ] Literal and ;
1905:
1906: dfaligned c_addr -- df_addr float-ext d_f_aligned
1907: df_addr = (DFloat *)((((Cell)c_addr)+(sizeof(DFloat)-1))&(-sizeof(DFloat)));
1908: :
1909: [ 1 dfloats 1- ] Literal + [ -1 dfloats ] Literal and ;
1910:
1911: \ The following words access machine/OS/installation-dependent
1912: \ Gforth internals
1913: \ !! how about environmental queries DIRECT-THREADED,
1914: \ INDIRECT-THREADED, TOS-CACHED, FTOS-CACHED, CODEFIELD-DOES */
1915:
1916: \ local variable implementation primitives
1.6 jwilke 1917: \+[THEN] ( has? floats ) has? glocals [IF]
1.1 anton 1918:
1919: @local# -- w gforth fetch_local_number
1920: w = *(Cell *)(lp+(Cell)NEXT_INST);
1921: INC_IP(1);
1922:
1923: @local0 -- w new fetch_local_zero
1924: w = *(Cell *)(lp+0*sizeof(Cell));
1925:
1926: @local1 -- w new fetch_local_four
1927: w = *(Cell *)(lp+1*sizeof(Cell));
1928:
1929: @local2 -- w new fetch_local_eight
1930: w = *(Cell *)(lp+2*sizeof(Cell));
1931:
1932: @local3 -- w new fetch_local_twelve
1933: w = *(Cell *)(lp+3*sizeof(Cell));
1934:
1.6 jwilke 1935: \+has? floating [IF]
1.1 anton 1936:
1937: f@local# -- r gforth f_fetch_local_number
1938: r = *(Float *)(lp+(Cell)NEXT_INST);
1939: INC_IP(1);
1940:
1941: f@local0 -- r new f_fetch_local_zero
1942: r = *(Float *)(lp+0*sizeof(Float));
1943:
1944: f@local1 -- r new f_fetch_local_eight
1945: r = *(Float *)(lp+1*sizeof(Float));
1946:
1947: \+[THEN]
1948:
1949: laddr# -- c_addr gforth laddr_number
1950: /* this can also be used to implement lp@ */
1951: c_addr = (Char *)(lp+(Cell)NEXT_INST);
1952: INC_IP(1);
1953:
1954: lp+!# -- gforth lp_plus_store_number
1955: ""used with negative immediate values it allocates memory on the
1956: local stack, a positive immediate argument drops memory from the local
1957: stack""
1958: lp += (Cell)NEXT_INST;
1959: INC_IP(1);
1960:
1961: lp- -- new minus_four_lp_plus_store
1962: lp += -sizeof(Cell);
1963:
1964: lp+ -- new eight_lp_plus_store
1965: lp += sizeof(Float);
1966:
1967: lp+2 -- new sixteen_lp_plus_store
1968: lp += 2*sizeof(Float);
1969:
1970: lp! c_addr -- gforth lp_store
1971: lp = (Address)c_addr;
1972:
1973: >l w -- gforth to_l
1974: lp -= sizeof(Cell);
1975: *(Cell *)lp = w;
1976:
1.6 jwilke 1977: \+has? floating [IF]
1.1 anton 1978:
1979: f>l r -- gforth f_to_l
1980: lp -= sizeof(Float);
1981: *(Float *)lp = r;
1982:
1.6 jwilke 1983: \+[THEN] [THEN] \ has? glocals
1.1 anton 1984:
1.6 jwilke 1985: \+has? OS [IF]
1.1 anton 1986:
1987: define(`uploop',
1988: `pushdef(`$1', `$2')_uploop(`$1', `$2', `$3', `$4', `$5')`'popdef(`$1')')
1989: define(`_uploop',
1990: `ifelse($1, `$3', `$5',
1991: `$4`'define(`$1', incr($1))_uploop(`$1', `$2', `$3', `$4', `$5')')')
1992: \ argflist(argnum): Forth argument list
1993: define(argflist,
1994: `ifelse($1, 0, `',
1995: `uploop(`_i', 1, $1, `format(`u%d ', _i)', `format(`u%d ', _i)')')')
1996: \ argdlist(argnum): declare C's arguments
1997: define(argdlist,
1998: `ifelse($1, 0, `',
1999: `uploop(`_i', 1, $1, `Cell, ', `Cell')')')
2000: \ argclist(argnum): pass C's arguments
2001: define(argclist,
2002: `ifelse($1, 0, `',
2003: `uploop(`_i', 1, $1, `format(`u%d, ', _i)', `format(`u%d', _i)')')')
2004: \ icall(argnum)
2005: define(icall,
2006: `icall$1 argflist($1)u -- uret gforth
2007: uret = ((Cell(*)(argdlist($1)))u)(argclist($1));
2008:
2009: ')
2010: define(fcall,
2011: `fcall$1 argflist($1)u -- rret gforth
2012: rret = ((Float(*)(argdlist($1)))u)(argclist($1));
2013:
2014: ')
2015:
2016:
2017: open-lib c_addr1 u1 -- u2 gforth open_lib
2018: #if defined(HAVE_LIBDL) || defined(HAVE_DLOPEN)
1.7 ! pazsan 2019: u2=(UCell) dlopen(cstr(c_addr1, u1, 1), RTLD_GLOBAL | RTLD_LAZY);
1.1 anton 2020: #else
2021: # ifdef HAVE_LIBKERNEL32
2022: u2 = (Cell) GetModuleHandle(cstr(c_addr1, u1, 1));
2023: # else
2024: #warning Define open-lib!
2025: u2 = 0;
2026: # endif
2027: #endif
2028:
2029: lib-sym c_addr1 u1 u2 -- u3 gforth lib_sym
2030: #if defined(HAVE_LIBDL) || defined(HAVE_DLOPEN)
2031: u3 = (UCell) dlsym((void*)u2,cstr(c_addr1, u1, 1));
2032: #else
2033: # ifdef HAVE_LIBKERNEL32
2034: u3 = (Cell) GetProcAddress((HMODULE)u2, cstr(c_addr1, u1, 1));
2035: # else
2036: #warning Define lib-sym!
2037: u3 = 0;
2038: # endif
2039: #endif
2040:
2041: uploop(i, 0, 7, `icall(i)')
2042: icall(20)
2043: uploop(i, 0, 7, `fcall(i)')
2044: fcall(20)
2045:
1.6 jwilke 2046: \+[THEN] \ has? OS
1.1 anton 2047:
2048: up! a_addr -- gforth up_store
2049: UP=up=(char *)a_addr;
2050: :
2051: up ! ;
2052: Variable UP
2053:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>