Annotation of gforth/primitives, revision 1.24

1.6       anton       1: \ Copyright 1992 by the ANSI figForth Development Group
                      2: \ 
                      3: \ WARNING: This file is processed by m4. Make sure your identifiers
                      4: \ don't collide with m4's (e.g. by undefining them).
                      5: \ 
1.23      pazsan      6: \ 
                      7: \ 
1.6       anton       8: \ This file contains instructions in the following format:
                      9: \ 
1.23      pazsan     10: \ forth name   stack effect    category        [pronunciation]
1.6       anton      11: \ [""glossary entry""]
                     12: \ C code
                     13: \ [:
                     14: \ Forth code]
                     15: \ 
1.23      pazsan     16: \ The pronunciation is also used for forming C names.
                     17: \ 
                     18: \ 
1.6       anton      19: \ 
1.23      pazsan     20: \ These informations are automatically translated into C-code for the
                     21: \ interpreter and into some other files. I hope that your C compiler has
1.6       anton      22: \ decent optimization, otherwise the automatically generated code will
                     23: \ be somewhat slow. The Forth version of the code is included for manual
                     24: \ compilers, so they will need to compile only the important words.
                     25: \ 
                     26: \ Note that stack pointer adjustment is performed according to stack
                     27: \ effect by automatically generated code and NEXT is automatically
                     28: \ appended to the C code. Also, you can use the names in the stack
                     29: \ effect in the C code. Stack access is automatic. One exception: if
                     30: \ your code does not fall through, the results are not stored into the
                     31: \ stack. Use different names on both sides of the '--', if you change a
                     32: \ value (some stores to the stack are optimized away).
                     33: \ 
1.23      pazsan     34: \ 
                     35: \ 
1.6       anton      36: \ The stack variables have the following types:
1.23      pazsan     37: \ 
1.6       anton      38: \ name matches type
                     39: \ f.*          Bool
                     40: \ c.*          Char
                     41: \ [nw].*               Cell
                     42: \ u.*          UCell
                     43: \ d.*          DCell
                     44: \ ud.*         UDCell
                     45: \ r.*          Float
                     46: \ a_.*         Cell *
                     47: \ c_.*         Char *
                     48: \ f_.*         Float *
                     49: \ df_.*                DFloat *
                     50: \ sf_.*                SFloat *
                     51: \ xt.*         XT
                     52: \ wid.*                WID
                     53: \ f83name.*    F83Name *
                     54: \ 
1.23      pazsan     55: \ 
                     56: \ 
1.6       anton      57: \ In addition the following names can be used:
                     58: \ ip   the instruction pointer
                     59: \ sp   the data stack pointer
                     60: \ rp   the parameter stack pointer
1.23      pazsan     61: \ lp   the locals stack pointer
1.6       anton      62: \ NEXT executes NEXT
                     63: \ cfa  
                     64: \ NEXT1        executes NEXT1
                     65: \ FLAG(x)      makes a Forth flag from a C flag
                     66: \ 
1.23      pazsan     67: \ 
                     68: \ 
1.6       anton      69: \ Percentages in comments are from Koopmans book: average/maximum use
1.23      pazsan     70: \ (taken from four, not very representative benchmarks)
                     71: \ 
1.6       anton      72: \ 
1.23      pazsan     73: \ 
1.6       anton      74: \ To do:
                     75: \ 
                     76: \ throw execute, cfa and NEXT1 out?
                     77: \ macroize *ip, ip++, *ip++ (pipelining)?
1.1       anton      78: 
1.6       anton      79: \ these m4 macros would collide with identifiers
1.1       anton      80: undefine(`index')
                     81: undefine(`shift')
                     82: 
                     83: noop   --              fig
                     84: ;
1.18      pazsan     85: :
                     86:  ;
1.1       anton      87: 
                     88: lit    -- w            fig
                     89: w = (Cell)*ip++;
                     90: 
                     91: execute                xt --           core,fig
                     92: cfa = xt;
                     93: IF_TOS(TOS = sp[0]);
                     94: NEXT1;
                     95: 
1.9       anton      96: branch-lp+!#   --      new     branch_lp_plus_store_number
                     97: /* this will probably not be used */
                     98: branch_adjust_lp:
                     99: lp += (int)(ip[1]);
                    100: goto branch;
                    101: 
1.1       anton     102: branch --              fig
                    103: branch:
                    104: ip = (Xt *)(((int)ip)+(int)*ip);
1.18      pazsan    105: :
                    106:  r> dup @ + >r ;
1.1       anton     107: 
1.9       anton     108: \ condbranch(forthname,restline,code)
                    109: \ this is non-syntactical: code must open a brace that is close by the macro
                    110: define(condbranch,
                    111: $1     $2
                    112: $3    goto branch;
                    113: }
                    114: else
                    115:     ip++;
                    116: 
                    117: $1-lp+!#       $2_lp_plus_store_number
                    118: $3    goto branch_adjust_lp;
                    119: }
                    120: else
                    121:     ip+=2;
                    122: 
                    123: )
                    124: 
                    125: condbranch(?branch,f --                f83     question_branch,
1.1       anton     126: if (f==0) {
                    127:     IF_TOS(TOS = sp[0]);
1.9       anton     128: )
1.1       anton     129: 
1.9       anton     130: condbranch((next),--           cmFORTH paren_next,
1.1       anton     131: if ((*rp)--) {
1.9       anton     132: )
1.1       anton     133: 
1.9       anton     134: condbranch((loop),--           fig     paren_loop,
1.1       anton     135: int index = *rp+1;
                    136: int limit = rp[1];
                    137: if (index != limit) {
                    138:     *rp = index;
1.9       anton     139: )
1.1       anton     140: 
1.9       anton     141: condbranch((+loop),n --                fig     paren_plus_loop,
1.1       anton     142: /* !! check this thoroughly */
                    143: int index = *rp;
                    144: /* sign bit manipulation and test: (x^y)<0 is equivalent to (x<0) != (y<0) */
                    145: /* dependent upon two's complement arithmetic */
1.15      pazsan    146: int olddiff = index-rp[1];
1.18      pazsan    147: #ifdef undefined
1.9       anton     148: if ((olddiff^(olddiff+n))>=0   /* the limit is not crossed */
                    149:     || (olddiff^n)>=0          /* it is a wrap-around effect */) {
1.15      pazsan    150: #else
                    151: #ifndef MAXINT
                    152: #define MAXINT ((1<<(8*sizeof(Cell)-1))-1)
                    153: #endif
1.18      pazsan    154: if(((olddiff^MAXINT) >= n) ^ ((olddiff+n) < 0)) {
1.15      pazsan    155: #endif
                    156: #ifdef i386
                    157:     *rp += n;
                    158: #else
                    159:     *rp = index + n;
                    160: #endif
1.1       anton     161:     IF_TOS(TOS = sp[0]);
1.9       anton     162: )
1.1       anton     163: 
1.9       anton     164: condbranch((s+loop),n --               new     paren_symmetric_plus_loop,
1.1       anton     165: ""The run-time procedure compiled by S+LOOP. It loops until the index
                    166: crosses the boundary between limit and limit-sign(n). I.e. a symmetric
                    167: version of (+LOOP).""
                    168: /* !! check this thoroughly */
1.15      pazsan    169: int index = *rp;
                    170: int diff = index-rp[1];
1.1       anton     171: int newdiff = diff+n;
                    172: if (n<0) {
                    173:     diff = -diff;
1.15      pazsan    174:     newdiff = -newdiff;
1.1       anton     175: }
                    176: if (diff>=0 || newdiff<0) {
1.15      pazsan    177: #ifdef i386
                    178:     *rp += n;
                    179: #else
                    180:     *rp = index + n;
                    181: #endif
1.1       anton     182:     IF_TOS(TOS = sp[0]);
1.9       anton     183: )
1.1       anton     184: 
                    185: unloop         --      core
                    186: rp += 2;
1.18      pazsan    187: :
                    188:  r> rdrop rdrop >r ;
1.1       anton     189: 
                    190: (for)  ncount --               cmFORTH         paren_for
                    191: /* or (for) = >r -- collides with unloop! */
                    192: *--rp = 0;
                    193: *--rp = ncount;
1.18      pazsan    194: :
                    195:  r> swap 0 >r >r >r ;
1.1       anton     196: 
                    197: (do)   nlimit nstart --                fig             paren_do
                    198: /* or do it in high-level? 0.09/0.23% */
                    199: *--rp = nlimit;
                    200: *--rp = nstart;
                    201: :
1.13      pazsan    202:  r> -rot swap >r >r >r ;
1.1       anton     203: 
                    204: (?do)  nlimit nstart --        core-ext        paren_question_do
                    205: *--rp = nlimit;
                    206: *--rp = nstart;
                    207: if (nstart == nlimit) {
                    208:     IF_TOS(TOS = sp[0]);
                    209:     goto branch;
                    210:     }
                    211: else {
                    212:     ip++;
                    213: }
                    214: 
                    215: i      -- n            core,fig
                    216: n = *rp;
                    217: 
                    218: j      -- n            core
                    219: n = rp[2];
                    220: 
1.6       anton     221: \ digit is high-level: 0/0%
1.1       anton     222: 
1.10      pazsan    223: (emit) c --            fig     paren_emit
1.1       anton     224: putchar(c);
                    225: emitcounter++;
1.10      pazsan    226: 
                    227: (type) c_addr n --     fig     paren_type
                    228: fwrite(c_addr,sizeof(Char),n,stdout);
                    229: emitcounter += n;
1.1       anton     230: 
1.15      pazsan    231: (key)  -- n            fig     paren_key
1.1       anton     232: fflush(stdout);
                    233: /* !! noecho */
                    234: n = key();
                    235: 
1.2       pazsan    236: key?   -- n            fig     key_q
                    237: fflush(stdout);
                    238: n = key_query;
                    239: 
1.1       anton     240: cr     --              fig
                    241: puts("");
1.18      pazsan    242: :
                    243:  $0A emit ;
1.1       anton     244: 
                    245: move   c_from c_to ucount --           core
                    246: memmove(c_to,c_from,ucount);
1.6       anton     247: /* make an Ifdef for bsd and others? */
1.18      pazsan    248: :
                    249:  >r 2dup u< IF r> cmove> ELSE r> cmove THEN ;
1.1       anton     250: 
                    251: cmove  c_from c_to u --        string
                    252: while (u-- > 0)
                    253:   *c_to++ = *c_from++;
1.18      pazsan    254: :
                    255:  bounds ?DO  dup c@ I c! 1+  LOOP  drop ;
1.1       anton     256: 
                    257: cmove> c_from c_to u --        string  c_move_up
                    258: while (u-- > 0)
                    259:   c_to[u] = c_from[u];
1.18      pazsan    260: :
                    261:  dup 0= IF  drop 2drop exit  THEN
                    262:  rot over + -rot bounds swap 1-
                    263:  DO  1- dup c@ I c!  -1 +LOOP  drop ;
1.1       anton     264: 
                    265: fill   c_addr u c --   core
                    266: memset(c_addr,c,u);
1.18      pazsan    267: :
                    268:  -rot bounds
                    269:  ?DO  dup I c!  LOOP  drop ;
1.1       anton     270: 
                    271: compare                c_addr1 u1 c_addr2 u2 -- n      string
                    272: n = memcmp(c_addr1, c_addr2, u1<u2 ? u1 : u2);
                    273: if (n==0)
                    274:   n = u1-u2;
                    275: if (n<0)
                    276:   n = -1;
                    277: else if (n>0)
                    278:   n = 1;
1.18      pazsan    279: :
                    280:  rot 2dup - >r min swap -text dup
                    281:  IF    rdrop
                    282:  ELSE  drop r@ 0>
                    283:        IF    rdrop -1
                    284:        ELSE  r> 1 and
                    285:        THEN
                    286:  THEN ;
1.1       anton     287: 
                    288: -text          c_addr1 u c_addr2 -- n  new     dash_text
                    289: n = memcmp(c_addr1, c_addr2, u);
                    290: if (n<0)
                    291:   n = -1;
                    292: else if (n>0)
                    293:   n = 1;
1.18      pazsan    294: :
                    295:  swap bounds
                    296:  ?DO  dup c@ I c@ = WHILE  1+  LOOP  drop 0
                    297:  ELSE  c@ I c@ - unloop  THEN  -text-flag ;
                    298: : -text-flag ( n -- -1/0/1 )
                    299:  dup 0< IF  drop -1  ELSE  0>  IF  1  ELSE  0  THEN  THEN  ;
1.1       anton     300: 
                    301: capscomp       c_addr1 u c_addr2 -- n  new
                    302: Char c1, c2;
                    303: for (;; u--, c_addr1++, c_addr2++) {
                    304:   if (u == 0) {
                    305:     n = 0;
                    306:     break;
                    307:   }
                    308:   c1 = toupper(*c_addr1);
                    309:   c2 = toupper(*c_addr2);
                    310:   if (c1 != c2) {
                    311:     if (c1 < c2)
                    312:       n = -1;
                    313:     else
                    314:       n = 1;
                    315:     break;
                    316:   }
                    317: }
1.18      pazsan    318: :
                    319:  swap bounds
                    320:  ?DO  dup c@ toupper I c@ toupper = WHILE  1+  LOOP  drop 0
                    321:  ELSE  c@ toupper I c@ toupper - unloop  THEN  -text-flag ;
1.1       anton     322: 
                    323: -trailing      c_addr u1 -- c_addr u2          string  dash_trailing
                    324: u2 = u1;
                    325: while (c_addr[u2-1] == ' ')
                    326:   u2--;
1.18      pazsan    327: :
                    328:  BEGIN  1- 2dup + c@ bl =  WHILE
                    329:         dup  0= UNTIL  ELSE  1+  THEN ;
1.1       anton     330: 
                    331: /string                c_addr1 u1 n -- c_addr2 u2      string  slash_string
                    332: c_addr2 = c_addr1+n;
                    333: u2 = u1-n;
1.18      pazsan    334: :
                    335:  tuck - >r + r> dup 0< IF  - 0  THEN ;
1.1       anton     336: 
                    337: +      n1 n2 -- n              core,fig        plus
                    338: n = n1+n2;
                    339: 
                    340: -      n1 n2 -- n              core,fig        minus
                    341: n = n1-n2;
1.18      pazsan    342: :
                    343:  negate + ;
1.1       anton     344: 
                    345: negate n1 -- n2                core,fig
                    346: /* use minus as alias */
                    347: n2 = -n1;
1.18      pazsan    348: :
                    349:  invert 1+ ;
1.1       anton     350: 
                    351: 1+     n1 -- n2                core            one_plus
                    352: n2 = n1+1;
1.18      pazsan    353: :
                    354:  1 + ;
1.1       anton     355: 
                    356: 1-     n1 -- n2                core            one_minus
                    357: n2 = n1-1;
1.18      pazsan    358: :
                    359:  1 - ;
1.1       anton     360: 
                    361: max    n1 n2 -- n      core
                    362: if (n1<n2)
                    363:   n = n2;
                    364: else
                    365:   n = n1;
                    366: :
1.18      pazsan    367:  2dup < IF swap THEN drop ;
1.1       anton     368: 
                    369: min    n1 n2 -- n      core
                    370: if (n1<n2)
                    371:   n = n1;
                    372: else
                    373:   n = n2;
1.18      pazsan    374: :
                    375:  2dup > IF swap THEN drop ;
1.1       anton     376: 
                    377: abs    n1 -- n2        core
                    378: if (n1<0)
                    379:   n2 = -n1;
                    380: else
                    381:   n2 = n1;
1.18      pazsan    382: :
                    383:  dup 0< IF negate THEN ;
1.1       anton     384: 
                    385: *      n1 n2 -- n              core,fig        star
                    386: n = n1*n2;
1.18      pazsan    387: :
                    388:  um* drop ;
1.1       anton     389: 
                    390: /      n1 n2 -- n              core,fig        slash
                    391: n = n1/n2;
1.18      pazsan    392: :
                    393:  /mod nip ;
1.1       anton     394: 
                    395: mod    n1 n2 -- n              core
                    396: n = n1%n2;
1.18      pazsan    397: :
                    398:  /mod drop ;
1.1       anton     399: 
                    400: /mod   n1 n2 -- n3 n4          core            slash_mod
                    401: n4 = n1/n2;
                    402: n3 = n1%n2; /* !! is this correct? look into C standard! */
1.18      pazsan    403: :
                    404:  >r s>d r> fm/mod ;
1.1       anton     405: 
                    406: 2*     n1 -- n2                core            two_star
                    407: n2 = 2*n1;
1.18      pazsan    408: :
                    409:  dup + ;
1.1       anton     410: 
                    411: 2/     n1 -- n2                core            two_slash
                    412: /* !! is this still correct? */
                    413: n2 = n1>>1;
                    414: 
                    415: fm/mod d1 n1 -- n2 n3          core            f_m_slash_mod
                    416: ""floored division: d1 = n3*n1+n2, n1>n2>=0 or 0>=n2>n1""
                    417: /* assumes that the processor uses either floored or symmetric division */
                    418: n3 = d1/n1;
                    419: n2 = d1%n1;
                    420: /* note that this 1%-3>0 is optimized by the compiler */
                    421: if (1%-3>0 && (d1<0) != (n1<0) && n2!=0) {
                    422:   n3--;
                    423:   n2+=n1;
                    424: }
                    425: 
                    426: sm/rem d1 n1 -- n2 n3          core            s_m_slash_rem
                    427: ""symmetric division: d1 = n3*n1+n2, sign(n2)=sign(d1) or 0""
                    428: /* assumes that the processor uses either floored or symmetric division */
                    429: n3 = d1/n1;
                    430: n2 = d1%n1;
                    431: /* note that this 1%-3<0 is optimized by the compiler */
                    432: if (1%-3<0 && (d1<0) != (n1<0) && n2!=0) {
                    433:   n3++;
                    434:   n2-=n1;
                    435: }
1.18      pazsan    436: :
                    437:  over >r dup >r abs -rot
                    438:  dabs rot um/mod
                    439:  r> 0< IF       negate       THEN
                    440:  r> 0< IF  swap negate swap  THEN ;
1.1       anton     441: 
                    442: m*     n1 n2 -- d              core    m_star
                    443: d = (DCell)n1 * (DCell)n2;
1.18      pazsan    444: :
                    445:  2dup      0< and >r
                    446:  2dup swap 0< and >r
                    447:  um* r> - r> - ;
1.1       anton     448: 
                    449: um*    u1 u2 -- ud             core    u_m_star
                    450: /* use u* as alias */
                    451: ud = (UDCell)u1 * (UDCell)u2;
                    452: 
                    453: um/mod ud u1 -- u2 u3          core    u_m_slash_mod
                    454: u3 = ud/u1;
                    455: u2 = ud%u1;
1.19      pazsan    456: :
                    457:   dup IF  0 (um/mod)  THEN  nip ; 
                    458: : (um/mod)  ( ud ud--ud u)
                    459:   2dup >r >r  dup 0< 
                    460:   IF    2drop 0 
                    461:   ELSE  2dup d+  (um/mod)  2*  THEN 
                    462:   -rot  r> r> 2over 2over  du<
                    463:   IF    2drop rot 
                    464:   ELSE  dnegate  d+  rot 1+  THEN ; 
1.1       anton     465: 
                    466: m+     d1 n -- d2              double          m_plus
                    467: d2 = d1+n;
1.18      pazsan    468: :
                    469:  s>d d+ ;
1.1       anton     470: 
                    471: d+     d1 d2 -- d              double,fig      d_plus
                    472: d = d1+d2;
1.18      pazsan    473: :
                    474:  >r swap >r over 2/ over 2/ + >r over 1 and over 1 and + 2/
                    475:  r> + >r + r> 0< r> r> + swap - ;
1.1       anton     476: 
                    477: d-     d1 d2 -- d              double          d_minus
                    478: d = d1-d2;
1.18      pazsan    479: :
                    480:  dnegate d+ ;
1.1       anton     481: 
                    482: dnegate        d1 -- d2                double
                    483: /* use dminus as alias */
                    484: d2 = -d1;
1.18      pazsan    485: :
                    486:  invert swap negate tuck 0= - ;
1.1       anton     487: 
                    488: dmax   d1 d2 -- d      double
                    489: if (d1<d2)
                    490:   d = d2;
                    491: else
                    492:   d = d1;
1.18      pazsan    493: :
                    494:  2over 2over d> IF  2swap  THEN 2drop ;
1.1       anton     495: 
                    496: dmin   d1 d2 -- d      double
                    497: if (d1<d2)
                    498:   d = d1;
                    499: else
                    500:   d = d2;
1.18      pazsan    501: :
                    502:  2over 2over d< IF  2swap  THEN 2drop ;
1.1       anton     503: 
                    504: dabs   d1 -- d2        double
                    505: if (d1<0)
                    506:   d2 = -d1;
                    507: else
                    508:   d2 = d1;
1.18      pazsan    509: :
                    510:  dup 0< IF dnegate THEN ;
1.1       anton     511: 
                    512: d2*    d1 -- d2                double          d_two_star
                    513: d2 = 2*d1;
1.18      pazsan    514: :
                    515:  2dup d+ ;
1.1       anton     516: 
                    517: d2/    d1 -- d2                double          d_two_slash
                    518: /* !! is this still correct? */
1.13      pazsan    519: d2 = d1>>1;
1.18      pazsan    520: :
                    521:  dup 1 and >r 2/ swap 2/ [ 1 8 cells 1- lshift 1- ] Literal and
                    522:  r> IF  [ 1 8 cells 1- lshift ] Literal + THEN  swap ;
1.1       anton     523: 
                    524: d>s    d -- n                  double          d_to_s
                    525: /* make this an alias for drop? */
                    526: n = d;
1.18      pazsan    527: :
                    528:  drop ;
1.1       anton     529: 
                    530: and    w1 w2 -- w              core,fig
                    531: w = w1&w2;
                    532: 
                    533: or     w1 w2 -- w              core,fig
                    534: w = w1|w2;
                    535: 
                    536: xor    w1 w2 -- w              core,fig
                    537: w = w1^w2;
                    538: 
                    539: invert w1 -- w2                core
                    540: w2 = ~w1;
1.18      pazsan    541: :
                    542:  -1 xor ;
1.1       anton     543: 
                    544: rshift u1 n -- u2              core
                    545:   u2 = u1>>n;
                    546: 
                    547: lshift u1 n -- u2              core
                    548:   u2 = u1<<n;
                    549: 
1.6       anton     550: \ comparisons(prefix, args, prefix, arg1, arg2, wordsets...)
1.1       anton     551: define(comparisons,
                    552: $1=    $2 -- f         $6      $3equals
                    553: f = FLAG($4==$5);
                    554: 
                    555: $1<>   $2 -- f         $7      $3different
                    556: /* use != as alias ? */
                    557: f = FLAG($4!=$5);
                    558: 
                    559: $1<    $2 -- f         $8      $3less
                    560: f = FLAG($4<$5);
                    561: 
                    562: $1>    $2 -- f         $9      $3greater
                    563: f = FLAG($4>$5);
                    564: 
                    565: $1<=   $2 -- f         new     $3less_or_equal
                    566: f = FLAG($4<=$5);
                    567: 
                    568: $1>=   $2 -- f         new     $3greater_or_equal
                    569: f = FLAG($4>=$5);
                    570: 
                    571: )
                    572: 
                    573: comparisons(0, n, zero_, n, 0, core, core-ext, core, core-ext)
                    574: comparisons(, n1 n2, , n1, n2, core, core-ext, core, core)
                    575: comparisons(u, u1 u2, u_, u1, u2, new, new, core, core-ext)
                    576: comparisons(d, d1 d2, d_, d1, d2, double, new, double, new)
                    577: comparisons(d0, d, d_zero_, d, 0, double, new, double, new)
                    578: comparisons(du, ud1 ud2, d_u_, ud1, ud2, new, new, double-ext, new)
                    579: 
                    580: within u1 u2 u3 -- f           core-ext
                    581: f = FLAG(u1-u2 < u3-u2);
1.18      pazsan    582: :
                    583:  over - >r - r> u< ;
1.1       anton     584: 
                    585: sp@    -- a_addr               fig             spat
1.15      pazsan    586: a_addr = sp+1;
1.1       anton     587: 
                    588: sp!    a_addr --               fig             spstore
1.15      pazsan    589: sp = a_addr;
1.1       anton     590: /* works with and without TOS caching */
                    591: 
                    592: rp@    -- a_addr               fig             rpat
                    593: a_addr = rp;
                    594: 
                    595: rp!    a_addr --               fig             rpstore
                    596: rp = a_addr;
                    597: 
                    598: fp@    -- f_addr       new     fp_fetch
                    599: f_addr = fp;
                    600: 
                    601: fp!    f_addr --       new     fp_store
                    602: fp = f_addr;
                    603: 
1.3       pazsan    604: ;s     --              core    exit
1.1       anton     605: ip = (Xt *)(*rp++);
                    606: 
                    607: >r     w --            core,fig        to_r
                    608: *--rp = w;
                    609: 
                    610: r>     -- w            core,fig        r_from
                    611: w = *rp++;
                    612: 
                    613: r@     -- w            core,fig        r_fetch
                    614: /* use r as alias */
                    615: /* make r@ an alias for i */
                    616: w = *rp;
                    617: 
                    618: rdrop  --              fig
                    619: rp++;
                    620: 
                    621: i'     -- w            fig             i_tick
                    622: w=rp[1];
                    623: 
1.14      anton     624: 2>r    w1 w2 --        core-ext        two_to_r
                    625: *--rp = w1;
                    626: *--rp = w2;
                    627: 
                    628: 2r>    -- w1 w2        core-ext        two_r_from
                    629: w2 = *rp++;
                    630: w1 = *rp++;
                    631: 
                    632: 2r@    -- w1 w2        core-ext        two_r_fetch
                    633: w2 = rp[0];
                    634: w1 = rp[1];
                    635: 
                    636: 2rdrop --              new     two_r_drop
                    637: rp+=2;
                    638: 
1.1       anton     639: over   w1 w2 -- w1 w2 w1               core,fig
                    640: 
                    641: drop   w --            core,fig
                    642: 
                    643: swap   w1 w2 -- w2 w1          core,fig
                    644: 
                    645: dup    w -- w w                core,fig
                    646: 
                    647: rot    w1 w2 w3 -- w2 w3 w1    core    rote
                    648: 
                    649: -rot   w1 w2 w3 -- w3 w1 w2    fig     not_rote
1.18      pazsan    650: :
                    651:  rot rot ;
1.1       anton     652: 
                    653: nip    w1 w2 -- w2             core-ext
1.18      pazsan    654: :
                    655:  swap drop ;
1.1       anton     656: 
                    657: tuck   w1 w2 -- w2 w1 w2       core-ext
1.18      pazsan    658: :
                    659:  swap over ;
1.1       anton     660: 
                    661: ?dup   w -- w                  core    question_dupe
                    662: if (w!=0) {
1.7       pazsan    663:   IF_TOS(*sp-- = w;)
1.1       anton     664: #ifndef USE_TOS
1.7       pazsan    665:   *--sp = w;
1.1       anton     666: #endif
                    667: }
1.18      pazsan    668: :
                    669:  dup IF dup THEN ;
1.1       anton     670: 
                    671: pick   u -- w                  core-ext
                    672: w = sp[u+1];
1.18      pazsan    673: :
                    674:  1+ cells sp@ + @ ;
1.1       anton     675: 
                    676: 2drop  w1 w2 --                core    two_drop
1.18      pazsan    677: :
                    678:  drop drop ;
1.1       anton     679: 
                    680: 2dup   w1 w2 -- w1 w2 w1 w2    core    two_dupe
1.18      pazsan    681: :
                    682:  over over ;
1.1       anton     683: 
                    684: 2over  w1 w2 w3 w4 -- w1 w2 w3 w4 w1 w2        core    two_over
1.18      pazsan    685: :
                    686:  3 pick 3 pick ;
1.1       anton     687: 
                    688: 2swap  w1 w2 w3 w4 -- w3 w4 w1 w2      core    two_swap
1.18      pazsan    689: :
                    690:  >r -rot r> -rot ;
1.1       anton     691: 
                    692: 2rot   w1 w2 w3 w4 w5 w6 -- w3 w4 w5 w6 w1 w2  double  two_rote
1.18      pazsan    693: :
                    694:  >r >r 2swap r> r> 2swap ;
1.1       anton     695: 
1.6       anton     696: \ toggle is high-level: 0.11/0.42%
1.1       anton     697: 
                    698: @      a_addr -- w             fig     fetch
                    699: w = *a_addr;
                    700: 
                    701: !      w a_addr --             core,fig        store
                    702: *a_addr = w;
                    703: 
                    704: +!     n a_addr --             core,fig        plus_store
                    705: *a_addr += n;
                    706: 
                    707: c@     c_addr -- c             fig     cfetch
                    708: c = *c_addr;
                    709: 
                    710: c!     c c_addr --             fig     cstore
                    711: *c_addr = c;
                    712: 
                    713: 2!     w1 w2 a_addr --         core    two_store
                    714: a_addr[0] = w2;
                    715: a_addr[1] = w1;
1.18      pazsan    716: :
                    717:  tuck ! cell+ ! ;
1.1       anton     718: 
                    719: 2@     a_addr -- w1 w2         core    two_fetch
                    720: w2 = a_addr[0];
                    721: w1 = a_addr[1];
1.18      pazsan    722: :
                    723:  dup cell+ @ swap @ ;
1.1       anton     724: 
                    725: d!     d a_addr --             double  d_store
                    726: /* !! alignment problems on some machines */
                    727: *(DCell *)a_addr = d;
                    728: 
                    729: d@     a_addr -- d             double  d_fetch
                    730: d = *(DCell *)a_addr;
                    731: 
                    732: cell+  a_addr1 -- a_addr2      core    cell_plus
                    733: a_addr2 = a_addr1+1;
1.18      pazsan    734: :
                    735:  [ cell ] Literal + ;
1.1       anton     736: 
                    737: cells  n1 -- n2                core
                    738: n2 = n1 * sizeof(Cell);
1.18      pazsan    739: :
                    740:  [ cell ]
                    741:  [ 2/ dup ] [IF] 2* [THEN]
                    742:  [ 2/ dup ] [IF] 2* [THEN]
                    743:  [ 2/ dup ] [IF] 2* [THEN]
                    744:  [ 2/ dup ] [IF] 2* [THEN]
                    745:  [ drop ] ;
1.1       anton     746: 
                    747: char+  c_addr1 -- c_addr2      core    care_plus
1.18      pazsan    748: c_addr2 = c_addr1 + 1;
                    749: :
                    750:  1+ ;
1.1       anton     751: 
1.24    ! anton     752: (chars)                n1 -- n2        gforth  paren_cares
1.1       anton     753: n2 = n1 * sizeof(Char);
1.18      pazsan    754: :
                    755:  ;
1.1       anton     756: 
                    757: count  c_addr1 -- c_addr2 u    core
                    758: u = *c_addr1;
                    759: c_addr2 = c_addr1+1;
1.18      pazsan    760: :
                    761:  dup 1+ swap c@ ;
1.1       anton     762: 
                    763: (bye)  n --    toolkit-ext     paren_bye
1.15      pazsan    764: return (Label *)n;
1.1       anton     765: 
                    766: system c_addr u -- n   own
1.17      anton     767: n=system(cstr(c_addr,u,1));
1.1       anton     768: 
1.16      anton     769: getenv c_addr1 u1 -- c_addr2 u2        new
1.17      anton     770: c_addr2 = getenv(cstr(c_addr1,u1,1));
1.16      anton     771: u2=strlen(c_addr2);
                    772: 
1.1       anton     773: popen  c_addr u n -- wfileid   own
                    774: static char* mode[2]={"r","w"};
1.17      anton     775: wfileid=(Cell)popen(cstr(c_addr,u,1),mode[n]);
1.1       anton     776: 
1.18      pazsan    777: pclose wfileid -- wior own
1.1       anton     778: wior=pclose((FILE *)wfileid);
1.2       pazsan    779: 
1.21      pazsan    780: time&date      -- nsec nmin nhour nday nmonth nyear    facility-ext    time_and_date
1.2       pazsan    781: struct timeval time1;
                    782: struct timezone zone1;
                    783: struct tm *ltime;
                    784: gettimeofday(&time1,&zone1);
                    785: ltime=localtime(&time1.tv_sec);
                    786: nyear =ltime->tm_year+1900;
1.21      pazsan    787: nmonth=ltime->tm_mon+1;
1.2       pazsan    788: nday  =ltime->tm_mday;
                    789: nhour =ltime->tm_hour;
                    790: nmin  =ltime->tm_min;
                    791: nsec  =ltime->tm_sec;
                    792: 
1.16      anton     793: ms     n --    facility-ext
1.2       pazsan    794: struct timeval timeout;
                    795: timeout.tv_sec=n/1000;
                    796: timeout.tv_usec=1000*(n%1000);
                    797: (void)select(0,0,0,0,&timeout);
1.1       anton     798: 
                    799: allocate       u -- a_addr wior        memory
                    800: a_addr = (Cell *)malloc(u);
1.6       anton     801: wior = a_addr==NULL;   /* !! Define a return code */
1.1       anton     802: 
                    803: free           a_addr -- wior          memory
                    804: free(a_addr);
                    805: wior = 0;
                    806: 
                    807: resize         a_addr1 u -- a_addr2 wior       memory
                    808: a_addr2 = realloc(a_addr1, u);
1.6       anton     809: wior = a_addr2==NULL;  /* !! Define a return code */
1.1       anton     810: 
                    811: (f83find)      c_addr u f83name1 -- f83name2   new     paren_f83find
                    812: for (; f83name1 != NULL; f83name1 = f83name1->next)
1.8       pazsan    813:   if (F83NAME_COUNT(f83name1)==u &&
1.13      pazsan    814:       strncasecmp(c_addr, f83name1->name, u)== 0 /* or inline? */)
1.8       pazsan    815:     break;
                    816: f83name2=f83name1;
1.18      pazsan    817: :
                    818:  BEGIN  dup  WHILE
                    819:         >r dup r@ cell+ c@ $1F and =
                    820:        IF  2dup r@ cell+ char+ capscomp  0=
                    821:            IF  2drop r>  EXIT  THEN  THEN
                    822:        r> @
                    823:  REPEAT  nip nip ;
1.8       pazsan    824: 
1.13      pazsan    825: (hashfind)     c_addr u a_addr -- f83name2     new     paren_hashfind
                    826: F83Name *f83name1;
                    827: f83name2=NULL;
                    828: while(a_addr != NULL)
                    829: {
                    830:    f83name1=(F83Name *)(a_addr[1]);
                    831:    a_addr=(Cell *)(a_addr[0]);
                    832:    if (F83NAME_COUNT(f83name1)==u &&
                    833:        strncasecmp(c_addr, f83name1->name, u)== 0 /* or inline? */)
                    834:      {
                    835:        f83name2=f83name1;
                    836:        break;
                    837:      }
                    838: }
1.18      pazsan    839: :
                    840:  BEGIN  dup  WHILE
                    841:         2@ >r >r dup r@ cell+ c@ $1F and =
                    842:         IF  2dup r@ cell+ char+ capscomp 0=
                    843:            IF  2drop r> rdrop  EXIT  THEN  THEN
                    844:        rdrop r>
                    845:  REPEAT nip nip ;
1.13      pazsan    846: 
1.14      anton     847: (hashkey)      c_addr u1 -- u2         new     paren_hashkey
1.13      pazsan    848: u2=0;
                    849: while(u1--)
                    850:    u2+=(int)toupper(*c_addr++);
1.18      pazsan    851: :
                    852:  0 -rot bounds ?DO  I c@ toupper +  LOOP ;
1.14      anton     853: 
                    854: (hashkey1)     c_addr u ubits -- ukey          new     paren_hashkey1
                    855: ""ukey is the hash key for the string c_addr u fitting in ubits bits""
                    856: /* this hash function rotates the key at every step by rot bits within
                    857:    ubits bits and xors it with the character. This function does ok in
                    858:    the chi-sqare-test.  Rot should be <=7 (preferably <=5) for
                    859:    ASCII strings (larger if ubits is large), and should share no
                    860:    divisors with ubits.
                    861: */
                    862: 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];
                    863: Char *cp = c_addr;
                    864: for (ukey=0; cp<c_addr+u; cp++)
                    865:     ukey = ((((ukey<<rot) | (ukey>>(ubits-rot))) 
                    866:             ^ toupper(*cp))
                    867:            & ((1<<ubits)-1));
1.18      pazsan    868: :
                    869:  dup rot-values + c@ over 1 swap lshift 1- >r
                    870:  tuck - 2swap r> 0 2swap bounds
                    871:  ?DO  dup 4 pick lshift swap 3 pick rshift or
                    872:       I c@ toupper xor
                    873:       over and  LOOP
                    874:  nip nip nip ;
                    875: Create rot-values
                    876:   5 c, 0 c, 1 c, 2 c, 3 c,  4 c, 5 c, 5 c, 5 c, 5 c,
                    877:   3 c, 5 c, 5 c, 5 c, 5 c,  7 c, 5 c, 5 c, 5 c, 5 c,
                    878:   7 c, 5 c, 5 c, 5 c, 5 c,  6 c, 5 c, 5 c, 5 c, 5 c,
                    879:   7 c, 5 c, 5 c,
1.1       anton     880: 
                    881: (parse-white)  c_addr1 u1 -- c_addr2 u2        new     paren_parse_white
                    882: /* use !isgraph instead of isspace? */
                    883: Char *endp = c_addr1+u1;
                    884: while (c_addr1<endp && isspace(*c_addr1))
                    885:   c_addr1++;
                    886: if (c_addr1<endp) {
                    887:   for (c_addr2 = c_addr1; c_addr1<endp && !isspace(*c_addr1); c_addr1++)
                    888:     ;
                    889:   u2 = c_addr1-c_addr2;
                    890: }
                    891: else {
                    892:   c_addr2 = c_addr1;
                    893:   u2 = 0;
                    894: }
1.18      pazsan    895: :
                    896:  BEGIN  dup  WHILE  over c@ bl <=  WHILE  1 /string
                    897:  REPEAT  THEN  2dup
                    898:  BEGIN  dup  WHILE  over c@ bl >   WHILE  1 /string
                    899:  REPEAT  THEN  nip - ;
1.1       anton     900: 
                    901: close-file     wfileid -- wior file    close_file
1.7       pazsan    902: wior = FILEIO(fclose((FILE *)wfileid)==EOF);
1.1       anton     903: 
                    904: open-file      c_addr u ntype -- w2 wior       file    open_file
1.18      pazsan    905: w2 = (Cell)fopen(cstr(c_addr, u, 1), fileattr[ntype]);
1.7       pazsan    906: wior =  FILEEXIST(w2 == NULL);
1.1       anton     907: 
                    908: create-file    c_addr u ntype -- w2 wior       file    create_file
                    909: int    fd;
1.18      pazsan    910: fd = creat(cstr(c_addr, u, 1), 0644);
1.1       anton     911: if (fd > -1) {
                    912:   w2 = (Cell)fdopen(fd, fileattr[ntype]);
                    913:   assert(w2 != NULL);
                    914:   wior = 0;
                    915: } else {
                    916:   assert(fd == -1);
1.7       pazsan    917:   wior = FILEIO(fd);
1.1       anton     918:   w2 = 0;
                    919: }
                    920: 
                    921: delete-file    c_addr u -- wior                file    delete_file
1.18      pazsan    922: wior = FILEEXIST(unlink(cstr(c_addr, u, 1)));
1.1       anton     923: 
                    924: rename-file    c_addr1 u1 c_addr2 u2 -- wior   file-ext        rename_file
1.18      pazsan    925: char *s1=cstr(c_addr2, u2, 1);
1.17      anton     926: wior = FILEEXIST(rename(cstr(c_addr1, u1, 0), s1));
1.1       anton     927: 
                    928: file-position  wfileid -- ud wior      file    file_position
                    929: /* !! use tell and lseek? */
                    930: ud = ftell((FILE *)wfileid);
                    931: wior = 0; /* !! or wior = FLAG(ud<0) */
                    932: 
                    933: reposition-file        ud wfileid -- wior      file    reposition_file
1.7       pazsan    934: wior = FILEIO(fseek((FILE *)wfileid, (long)ud, SEEK_SET));
1.1       anton     935: 
                    936: file-size      wfileid -- ud wior      file    file_size
                    937: struct stat buf;
1.7       pazsan    938: wior = FILEEXIST(fstat(fileno((FILE *)wfileid), &buf));
1.1       anton     939: ud = buf.st_size;
                    940: 
                    941: resize-file    ud wfileid -- wior      file    resize_file
1.7       pazsan    942: wior = FILEIO(ftruncate(fileno((FILE *)wfileid), (int)ud));
1.1       anton     943: 
                    944: read-file      c_addr u1 wfileid -- u2 wior    file    read_file
                    945: /* !! fread does not guarantee enough */
                    946: u2 = fread(c_addr, sizeof(Char), u1, (FILE *)wfileid);
1.7       pazsan    947: wior = FILEIO(u2<u1 && ferror((FILE *)wfileid));
1.1       anton     948: /* !! who performs clearerr((FILE *)wfileid); ? */
                    949: 
                    950: read-line      c_addr u1 wfileid -- u2 flag wior       file    read_line
1.13      pazsan    951: /*
                    952: Cell c;
                    953: flag=-1;
                    954: for(u2=0; u2<u1; u2++)
                    955: {
                    956:    *c_addr++ = (Char)(c = getc((FILE *)wfileid));
                    957:    if(c=='\n') break;
                    958:    if(c==EOF)
                    959:      {
                    960:        flag=FLAG(u2!=0);
                    961:        break;
                    962:      }
                    963: }
                    964: wior=FILEIO(ferror((FILE *)wfileid));
                    965: */
                    966: if ((flag=FLAG(!feof((FILE *)wfileid) &&
                    967:               fgets(c_addr,u1+1,(FILE *)wfileid) != NULL))) {
1.11      anton     968:   wior=FILEIO(ferror((FILE *)wfileid));
1.13      pazsan    969:   u2 = strlen(c_addr);
1.11      anton     970:   u2-=((u2>0) && (c_addr[u2-1]==NEWLINE));
                    971: }
                    972: else {
                    973:   wior=0;
                    974:   u2=0;
                    975: }
1.1       anton     976: 
                    977: write-file     c_addr u1 wfileid -- wior       file    write_file
                    978: /* !! fwrite does not guarantee enough */
                    979: {
                    980:   int u2 = fwrite(c_addr, sizeof(Char), u1, (FILE *)wfileid);
1.7       pazsan    981:   wior = FILEIO(u2<u1 && ferror((FILE *)wfileid));
1.1       anton     982: }
                    983: 
                    984: flush-file     wfileid -- wior         file-ext        flush_file
1.7       pazsan    985: wior = FILEIO(fflush((FILE *) wfileid));
1.1       anton     986: 
                    987: comparisons(f, r1 r2, f_, r1, r2, new, new, float, new)
                    988: comparisons(f0, r, f_zero_, r, 0., float, new, float, new)
                    989: 
                    990: d>f            d -- r          float   d_to_f
                    991: r = d;
                    992: 
                    993: f>d            r -- d          float   f_to_d
                    994: /* !! basis 15 is not very specific */
                    995: d = r;
                    996: 
                    997: f!             r f_addr --     float   f_store
                    998: *f_addr = r;
                    999: 
                   1000: f@             f_addr -- r     float   f_fetch
                   1001: r = *f_addr;
                   1002: 
                   1003: df@            df_addr -- r    float-ext       d_f_fetch
                   1004: #ifdef IEEE_FP
                   1005: r = *df_addr;
                   1006: #else
                   1007: !! df@
                   1008: #endif
                   1009: 
                   1010: df!            r df_addr --    float-ext       d_f_store
                   1011: #ifdef IEEE_FP
                   1012: *df_addr = r;
                   1013: #else
                   1014: !! df!
                   1015: #endif
                   1016: 
                   1017: sf@            sf_addr -- r    float-ext       s_f_fetch
                   1018: #ifdef IEEE_FP
                   1019: r = *sf_addr;
                   1020: #else
                   1021: !! sf@
                   1022: #endif
                   1023: 
                   1024: sf!            r sf_addr --    float-ext       s_f_store
                   1025: #ifdef IEEE_FP
                   1026: *sf_addr = r;
                   1027: #else
                   1028: !! sf!
                   1029: #endif
                   1030: 
                   1031: f+             r1 r2 -- r3     float   f_plus
                   1032: r3 = r1+r2;
                   1033: 
                   1034: f-             r1 r2 -- r3     float   f_minus
                   1035: r3 = r1-r2;
                   1036: 
                   1037: f*             r1 r2 -- r3     float   f_star
                   1038: r3 = r1*r2;
                   1039: 
                   1040: f/             r1 r2 -- r3     float   f_slash
                   1041: r3 = r1/r2;
                   1042: 
                   1043: f**            r1 r2 -- r3     float-ext       f_star_star
                   1044: r3 = pow(r1,r2);
                   1045: 
                   1046: fnegate                r1 -- r2        float
                   1047: r2 = - r1;
                   1048: 
                   1049: fdrop          r --            float
                   1050: 
                   1051: fdup           r -- r r        float
                   1052: 
                   1053: fswap          r1 r2 -- r2 r1  float
                   1054: 
                   1055: fover          r1 r2 -- r1 r2 r1       float
                   1056: 
                   1057: frot           r1 r2 r3 -- r2 r3 r1    float
                   1058: 
                   1059: float+         f_addr1 -- f_addr2      float   float_plus
                   1060: f_addr2 = f_addr1+1;
                   1061: 
                   1062: floats         n1 -- n2        float
                   1063: n2 = n1*sizeof(Float);
                   1064: 
                   1065: floor          r1 -- r2        float
                   1066: /* !! unclear wording */
                   1067: r2 = floor(r1);
                   1068: 
                   1069: fround         r1 -- r2        float
                   1070: /* !! unclear wording */
                   1071: r2 = rint(r1);
                   1072: 
                   1073: fmax           r1 r2 -- r3     float
                   1074: if (r1<r2)
                   1075:   r3 = r2;
                   1076: else
                   1077:   r3 = r1;
                   1078: 
                   1079: fmin           r1 r2 -- r3     float
                   1080: if (r1<r2)
                   1081:   r3 = r1;
                   1082: else
                   1083:   r3 = r2;
                   1084: 
                   1085: represent              r c_addr u -- n f1 f2   float
                   1086: char *sig;
                   1087: int flag;
1.9       anton    1088: int decpt;
                   1089: sig=ecvt(r, u, &decpt, &flag);
                   1090: n=decpt;
1.1       anton    1091: f1=FLAG(flag!=0);
                   1092: f2=FLAG(isdigit(sig[0])!=0);
                   1093: memmove(c_addr,sig,u);
                   1094: 
                   1095: >float c_addr u -- flag        float   to_float
                   1096: /* real signature: c_addr u -- r t / f */
                   1097: Float r;
1.17      anton    1098: char *number=cstr(c_addr, u, 1);
1.1       anton    1099: char *endconv;
1.23      pazsan   1100: while(isspace(number[u-1])) u--;
                   1101: switch(number[u-1])
                   1102: {
                   1103:        case 'd':
                   1104:        case 'D':
                   1105:        case 'e':
                   1106:        case 'E': u--; break;
                   1107:        default: break;
                   1108: }
                   1109: number[u]='\0';
1.1       anton    1110: r=strtod(number,&endconv);
1.8       pazsan   1111: if((flag=FLAG(!(int)*endconv)))
1.1       anton    1112: {
                   1113:        IF_FTOS(fp[0] = FTOS);
                   1114:        fp += -1;
                   1115:        FTOS = r;
                   1116: }
                   1117: else if(*endconv=='d' || *endconv=='D')
                   1118: {
                   1119:        *endconv='E';
                   1120:        r=strtod(number,&endconv);
1.8       pazsan   1121:        if((flag=FLAG(!(int)*endconv)))
1.1       anton    1122:        {
                   1123:                IF_FTOS(fp[0] = FTOS);
                   1124:                fp += -1;
                   1125:                FTOS = r;
                   1126:        }
                   1127: }
                   1128: 
                   1129: fabs           r1 -- r2        float-ext
                   1130: r2 = fabs(r1);
                   1131: 
                   1132: facos          r1 -- r2        float-ext
                   1133: r2 = acos(r1);
                   1134: 
                   1135: fasin          r1 -- r2        float-ext
                   1136: r2 = asin(r1);
                   1137: 
                   1138: fatan          r1 -- r2        float-ext
                   1139: r2 = atan(r1);
                   1140: 
                   1141: fatan2         r1 r2 -- r3     float-ext
                   1142: r3 = atan2(r1,r2);
                   1143: 
                   1144: fcos           r1 -- r2        float-ext
                   1145: r2 = cos(r1);
                   1146: 
                   1147: fexp           r1 -- r2        float-ext
                   1148: r2 = exp(r1);
                   1149: 
1.3       pazsan   1150: fexpm1         r1 -- r2        float-ext
                   1151: r2 =
1.18      pazsan   1152: #ifdef HAS_EXPM1
1.3       pazsan   1153:        expm1(r1);
                   1154: #else
                   1155:        exp(r1)-1;
                   1156: #endif
                   1157: 
1.1       anton    1158: fln            r1 -- r2        float-ext
                   1159: r2 = log(r1);
                   1160: 
1.3       pazsan   1161: flnp1          r1 -- r2        float-ext
                   1162: r2 =
1.18      pazsan   1163: #ifdef HAS_LOG1P
1.3       pazsan   1164:        log1p(r1);
                   1165: #else
1.18      pazsan   1166: log(r1+1);
1.3       pazsan   1167: #endif
                   1168: 
1.1       anton    1169: flog           r1 -- r2        float-ext
                   1170: r2 = log10(r1);
                   1171: 
1.3       pazsan   1172: fsin           r1 -- r2        float-ext
                   1173: r2 = sin(r1);
                   1174: 
                   1175: fsincos                r1 -- r2 r3     float-ext
1.1       anton    1176: r2 = sin(r1);
                   1177: r3 = cos(r1);
                   1178: 
                   1179: fsqrt          r1 -- r2        float-ext
                   1180: r2 = sqrt(r1);
                   1181: 
                   1182: ftan           r1 -- r2        float-ext
                   1183: r2 = tan(r1);
                   1184: 
1.6       anton    1185: \ The following words access machine/OS/installation-dependent ANSI
                   1186: \   figForth internals
                   1187: \ !! how about environmental queries DIRECT-THREADED,
                   1188: \   INDIRECT-THREADED, TOS-CACHED, FTOS-CACHED, CODEFIELD-DOES */
1.1       anton    1189: 
                   1190: >body          xt -- a_addr    core    to_body
                   1191: a_addr = PFA(xt);
                   1192: 
                   1193: >code-address          xt -- c_addr            new     to_code_address
                   1194: ""c_addr is the code address of the word xt""
                   1195: /* !! This behaves installation-dependently for DOES-words */
                   1196: c_addr = CODE_ADDRESS(xt);
                   1197: 
                   1198: >does-code     xt -- a_addr            new     to_does_code
                   1199: ""If xt ist the execution token of a defining-word-defined word,
                   1200: a_addr is the start of the Forth code after the DOES>; Otherwise the
                   1201: behaviour is uundefined""
                   1202: /* !! there is currently no way to determine whether a word is
                   1203: defining-word-defined */
1.20      anton    1204: a_addr = (Cell *)DOES_CODE(xt);
1.1       anton    1205: 
1.4       pazsan   1206: code-address!          n xt -- new     code_address_store
1.1       anton    1207: ""Creates a code field with code address c_addr at xt""
1.4       pazsan   1208: MAKE_CF(xt, symbols[CF(n)]);
1.5       pazsan   1209: CACHE_FLUSH(xt,PFA(0));
1.1       anton    1210: 
                   1211: does-code!     a_addr xt --            new     does_code_store
                   1212: ""creates a code field at xt for a defining-word-defined word; a_addr
                   1213: is the start of the Forth code after DOES>""
                   1214: MAKE_DOES_CF(xt, a_addr);
1.5       pazsan   1215: CACHE_FLUSH(xt,PFA(0));
1.1       anton    1216: 
                   1217: does-handler!  a_addr --       new     does_jump_store
                   1218: ""creates a DOES>-handler at address a_addr. a_addr usually points
                   1219: just behind a DOES>.""
                   1220: MAKE_DOES_HANDLER(a_addr);
1.5       pazsan   1221: CACHE_FLUSH(a_addr,DOES_HANDLER_SIZE);
1.1       anton    1222: 
                   1223: /does-handler  -- n    new     slash_does_handler
                   1224: ""the size of a does-handler (includes possible padding)""
                   1225: /* !! a constant or environmental query might be better */
                   1226: n = DOES_HANDLER_SIZE;
                   1227: 
                   1228: toupper        c1 -- c2        new
                   1229: c2 = toupper(c1);
                   1230: 
1.6       anton    1231: \ local variable implementation primitives
1.1       anton    1232: @local#                -- w    new     fetch_local_number
                   1233: w = *(Cell *)(lp+(int)(*ip++));
                   1234: 
1.9       anton    1235: @local0        -- w    new     fetch_local_zero
1.18      pazsan   1236: w = *(Cell *)(lp+0*sizeof(Cell));
1.9       anton    1237: 
1.18      pazsan   1238: @local1        -- w    new     fetch_local_four
                   1239: w = *(Cell *)(lp+1*sizeof(Cell));
1.9       anton    1240: 
1.18      pazsan   1241: @local2        -- w    new     fetch_local_eight
                   1242: w = *(Cell *)(lp+2*sizeof(Cell));
1.9       anton    1243: 
1.18      pazsan   1244: @local3        -- w    new     fetch_local_twelve
                   1245: w = *(Cell *)(lp+3*sizeof(Cell));
1.9       anton    1246: 
1.1       anton    1247: f@local#       -- r    new     f_fetch_local_number
                   1248: r = *(Float *)(lp+(int)(*ip++));
                   1249: 
1.9       anton    1250: f@local0       -- r    new     f_fetch_local_zero
1.18      pazsan   1251: r = *(Float *)(lp+0*sizeof(Float));
1.9       anton    1252: 
1.18      pazsan   1253: f@local1       -- r    new     f_fetch_local_eight
                   1254: r = *(Float *)(lp+1*sizeof(Float));
1.9       anton    1255: 
1.1       anton    1256: laddr#         -- c_addr       new     laddr_number
                   1257: /* this can also be used to implement lp@ */
                   1258: c_addr = (Char *)(lp+(int)(*ip++));
                   1259: 
                   1260: lp+!#  --      new     lp_plus_store_number
                   1261: ""used with negative immediate values it allocates memory on the
                   1262: local stack, a positive immediate argument drops memory from the local
                   1263: stack""
                   1264: lp += (int)(*ip++);
1.9       anton    1265: 
1.18      pazsan   1266: lp-    --      new     minus_four_lp_plus_store
                   1267: lp += -sizeof(Cell);
1.9       anton    1268: 
1.18      pazsan   1269: lp+    --      new     eight_lp_plus_store
                   1270: lp += sizeof(Float);
1.9       anton    1271: 
1.18      pazsan   1272: lp+2   --      new     sixteen_lp_plus_store
                   1273: lp += 2*sizeof(Float);
1.1       anton    1274: 
                   1275: lp!    c_addr --       new     lp_store
                   1276: lp = (Address)c_addr;
                   1277: 
                   1278: >l     w --    new     to_l
                   1279: lp -= sizeof(Cell);
                   1280: *(Cell *)lp = w;
                   1281: 
                   1282: f>l    r --    new     f_to_l
                   1283: lp -= sizeof(Float);
                   1284: *(Float *)lp = r;
1.4       pazsan   1285: 
                   1286: up!    a_addr --       new     up_store
1.18      pazsan   1287: up0=up=(char *)a_addr;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>