File:  [gforth] / gforth / test / coretest.fs
Revision 1.1: download - view: text, annotated - select for diffs
Wed May 21 20:40:19 1997 UTC (22 years, 6 months ago) by anton
Branches: MAIN
CVS tags: v0-4-0, HEAD
jwilke's changes:
Moved many files to other directories
renamed many files
other changes unknown to me.

    1: \ From: John Hayes S1I
    2: \ Subject: core.fr
    3: \ Date: Mon, 27 Nov 95 13:10
    4: 
    5: \ (C) 1995 JOHNS HOPKINS UNIVERSITY / APPLIED PHYSICS LABORATORY
    6: \ MAY BE DISTRIBUTED FREELY AS LONG AS THIS COPYRIGHT NOTICE REMAINS.
    7: \ VERSION 1.2
    8: \ THIS PROGRAM TESTS THE CORE WORDS OF AN ANS FORTH SYSTEM.
    9: \ THE PROGRAM ASSUMES A TWO'S COMPLEMENT IMPLEMENTATION WHERE
   10: \ THE RANGE OF SIGNED NUMBERS IS -2^(N-1) ... 2^(N-1)-1 AND
   11: \ THE RANGE OF UNSIGNED NUMBERS IS 0 ... 2^(N)-1.
   12: \ I HAVEN'T FIGURED OUT HOW TO TEST KEY, QUIT, ABORT, OR ABORT"...
   13: \ I ALSO HAVEN'T THOUGHT OF A WAY TO TEST ENVIRONMENT?...
   14: 
   15: TESTING CORE WORDS
   16: HEX
   17: 
   18: \ ------------------------------------------------------------------------
   19: TESTING BASIC ASSUMPTIONS
   20: 
   21: { -> }					\ START WITH CLEAN SLATE
   22: ( TEST IF ANY BITS ARE SET; ANSWER IN BASE 1 )
   23: { : BITSSET? IF 0 0 ELSE 0 THEN ; -> }
   24: {  0 BITSSET? -> 0 }		( ZERO IS ALL BITS CLEAR )
   25: {  1 BITSSET? -> 0 0 }		( OTHER NUMBER HAVE AT LEAST ONE BIT )
   26: { -1 BITSSET? -> 0 0 }
   27: 
   28: \ ------------------------------------------------------------------------
   29: TESTING BOOLEANS: INVERT AND OR XOR
   30: 
   31: { 0 0 AND -> 0 }
   32: { 0 1 AND -> 0 }
   33: { 1 0 AND -> 0 }
   34: { 1 1 AND -> 1 }
   35: 
   36: { 0 INVERT 1 AND -> 1 }
   37: { 1 INVERT 1 AND -> 0 }
   38: 
   39: 0	 CONSTANT 0S
   40: 0 INVERT CONSTANT 1S
   41: 
   42: { 0S INVERT -> 1S }
   43: { 1S INVERT -> 0S }
   44: 
   45: { 0S 0S AND -> 0S }
   46: { 0S 1S AND -> 0S }
   47: { 1S 0S AND -> 0S }
   48: { 1S 1S AND -> 1S }
   49: 
   50: { 0S 0S OR -> 0S }
   51: { 0S 1S OR -> 1S }
   52: { 1S 0S OR -> 1S }
   53: { 1S 1S OR -> 1S }
   54: 
   55: { 0S 0S XOR -> 0S }
   56: { 0S 1S XOR -> 1S }
   57: { 1S 0S XOR -> 1S }
   58: { 1S 1S XOR -> 0S }
   59: 
   60: \ ------------------------------------------------------------------------
   61: TESTING 2* 2/ LSHIFT RSHIFT
   62: 
   63: ( WE TRUST 1S, INVERT, AND BITSSET?; WE WILL CONFIRM RSHIFT LATER )
   64: 1S 1 RSHIFT INVERT CONSTANT MSB
   65: { MSB BITSSET? -> 0 0 }
   66: 
   67: { 0S 2* -> 0S }
   68: { 1 2* -> 2 }
   69: { 4000 2* -> 8000 }
   70: { 1S 2* 1 XOR -> 1S }
   71: { MSB 2* -> 0S }
   72: 
   73: { 0S 2/ -> 0S }
   74: { 1 2/ -> 0 }
   75: { 4000 2/ -> 2000 }
   76: { 1S 2/ -> 1S }				\ MSB PROPOGATED
   77: { 1S 1 XOR 2/ -> 1S }
   78: { MSB 2/ MSB AND -> MSB }
   79: 
   80: { 1 0 LSHIFT -> 1 }
   81: { 1 1 LSHIFT -> 2 }
   82: { 1 2 LSHIFT -> 4 }
   83: { 1 F LSHIFT -> 8000 }			\ BIGGEST GUARANTEED SHIFT
   84: { 1S 1 LSHIFT 1 XOR -> 1S }
   85: { MSB 1 LSHIFT -> 0 }
   86: 
   87: { 1 0 RSHIFT -> 1 }
   88: { 1 1 RSHIFT -> 0 }
   89: { 2 1 RSHIFT -> 1 }
   90: { 4 2 RSHIFT -> 1 }
   91: { 8000 F RSHIFT -> 1 }			\ BIGGEST
   92: { MSB 1 RSHIFT MSB AND -> 0 }		\ RSHIFT ZERO FILLS MSBS
   93: { MSB 1 RSHIFT 2* -> MSB }
   94: 
   95: \ ------------------------------------------------------------------------
   96: TESTING COMPARISONS: 0= = 0< < > U< MIN MAX
   97: 0 INVERT			CONSTANT MAX-UINT
   98: 0 INVERT 1 RSHIFT		CONSTANT MAX-INT
   99: 0 INVERT 1 RSHIFT INVERT	CONSTANT MIN-INT
  100: 0 INVERT 1 RSHIFT		CONSTANT MID-UINT
  101: 0 INVERT 1 RSHIFT INVERT	CONSTANT MID-UINT+1
  102: 
  103: 0S CONSTANT <FALSE>
  104: 1S CONSTANT <TRUE>
  105: 
  106: { 0 0= -> <TRUE> }
  107: { 1 0= -> <FALSE> }
  108: { 2 0= -> <FALSE> }
  109: { -1 0= -> <FALSE> }
  110: { MAX-UINT 0= -> <FALSE> }
  111: { MIN-INT 0= -> <FALSE> }
  112: { MAX-INT 0= -> <FALSE> }
  113: 
  114: { 0 0 = -> <TRUE> }
  115: { 1 1 = -> <TRUE> }
  116: { -1 -1 = -> <TRUE> }
  117: { 1 0 = -> <FALSE> }
  118: { -1 0 = -> <FALSE> }
  119: { 0 1 = -> <FALSE> }
  120: { 0 -1 = -> <FALSE> }
  121: 
  122: { 0 0< -> <FALSE> }
  123: { -1 0< -> <TRUE> }
  124: { MIN-INT 0< -> <TRUE> }
  125: { 1 0< -> <FALSE> }
  126: { MAX-INT 0< -> <FALSE> }
  127: 
  128: { 0 1 < -> <TRUE> }
  129: { 1 2 < -> <TRUE> }
  130: { -1 0 < -> <TRUE> }
  131: { -1 1 < -> <TRUE> }
  132: { MIN-INT 0 < -> <TRUE> }
  133: { MIN-INT MAX-INT < -> <TRUE> }
  134: { 0 MAX-INT < -> <TRUE> }
  135: { 0 0 < -> <FALSE> }
  136: { 1 1 < -> <FALSE> }
  137: { 1 0 < -> <FALSE> }
  138: { 2 1 < -> <FALSE> }
  139: { 0 -1 < -> <FALSE> }
  140: { 1 -1 < -> <FALSE> }
  141: { 0 MIN-INT < -> <FALSE> }
  142: { MAX-INT MIN-INT < -> <FALSE> }
  143: { MAX-INT 0 < -> <FALSE> }
  144: 
  145: { 0 1 > -> <FALSE> }
  146: { 1 2 > -> <FALSE> }
  147: { -1 0 > -> <FALSE> }
  148: { -1 1 > -> <FALSE> }
  149: { MIN-INT 0 > -> <FALSE> }
  150: { MIN-INT MAX-INT > -> <FALSE> }
  151: { 0 MAX-INT > -> <FALSE> }
  152: { 0 0 > -> <FALSE> }
  153: { 1 1 > -> <FALSE> }
  154: { 1 0 > -> <TRUE> }
  155: { 2 1 > -> <TRUE> }
  156: { 0 -1 > -> <TRUE> }
  157: { 1 -1 > -> <TRUE> }
  158: { 0 MIN-INT > -> <TRUE> }
  159: { MAX-INT MIN-INT > -> <TRUE> }
  160: { MAX-INT 0 > -> <TRUE> }
  161: 
  162: { 0 1 U< -> <TRUE> }
  163: { 1 2 U< -> <TRUE> }
  164: { 0 MID-UINT U< -> <TRUE> }
  165: { 0 MAX-UINT U< -> <TRUE> }
  166: { MID-UINT MAX-UINT U< -> <TRUE> }
  167: { 0 0 U< -> <FALSE> }
  168: { 1 1 U< -> <FALSE> }
  169: { 1 0 U< -> <FALSE> }
  170: { 2 1 U< -> <FALSE> }
  171: { MID-UINT 0 U< -> <FALSE> }
  172: { MAX-UINT 0 U< -> <FALSE> }
  173: { MAX-UINT MID-UINT U< -> <FALSE> }
  174: 
  175: { 0 1 MIN -> 0 }
  176: { 1 2 MIN -> 1 }
  177: { -1 0 MIN -> -1 }
  178: { -1 1 MIN -> -1 }
  179: { MIN-INT 0 MIN -> MIN-INT }
  180: { MIN-INT MAX-INT MIN -> MIN-INT }
  181: { 0 MAX-INT MIN -> 0 }
  182: { 0 0 MIN -> 0 }
  183: { 1 1 MIN -> 1 }
  184: { 1 0 MIN -> 0 }
  185: { 2 1 MIN -> 1 }
  186: { 0 -1 MIN -> -1 }
  187: { 1 -1 MIN -> -1 }
  188: { 0 MIN-INT MIN -> MIN-INT }
  189: { MAX-INT MIN-INT MIN -> MIN-INT }
  190: { MAX-INT 0 MIN -> 0 }
  191: 
  192: { 0 1 MAX -> 1 }
  193: { 1 2 MAX -> 2 }
  194: { -1 0 MAX -> 0 }
  195: { -1 1 MAX -> 1 }
  196: { MIN-INT 0 MAX -> 0 }
  197: { MIN-INT MAX-INT MAX -> MAX-INT }
  198: { 0 MAX-INT MAX -> MAX-INT }
  199: { 0 0 MAX -> 0 }
  200: { 1 1 MAX -> 1 }
  201: { 1 0 MAX -> 1 }
  202: { 2 1 MAX -> 2 }
  203: { 0 -1 MAX -> 0 }
  204: { 1 -1 MAX -> 1 }
  205: { 0 MIN-INT MAX -> 0 }
  206: { MAX-INT MIN-INT MAX -> MAX-INT }
  207: { MAX-INT 0 MAX -> MAX-INT }
  208: 
  209: \ ------------------------------------------------------------------------
  210: TESTING STACK OPS: 2DROP 2DUP 2OVER 2SWAP ?DUP DEPTH DROP DUP OVER ROT SWAP
  211: 
  212: { 1 2 2DROP -> }
  213: { 1 2 2DUP -> 1 2 1 2 }
  214: { 1 2 3 4 2OVER -> 1 2 3 4 1 2 }
  215: { 1 2 3 4 2SWAP -> 3 4 1 2 }
  216: { 0 ?DUP -> 0 }
  217: { 1 ?DUP -> 1 1 }
  218: { -1 ?DUP -> -1 -1 }
  219: { DEPTH -> 0 }
  220: { 0 DEPTH -> 0 1 }
  221: { 0 1 DEPTH -> 0 1 2 }
  222: { 0 DROP -> }
  223: { 1 2 DROP -> 1 }
  224: { 1 DUP -> 1 1 }
  225: { 1 2 OVER -> 1 2 1 }
  226: { 1 2 3 ROT -> 2 3 1 }
  227: { 1 2 SWAP -> 2 1 }
  228: 
  229: \ ------------------------------------------------------------------------
  230: TESTING >R R> R@
  231: 
  232: { : GR1 >R R> ; -> }
  233: { : GR2 >R R@ R> DROP ; -> }
  234: { 123 GR1 -> 123 }
  235: { 123 GR2 -> 123 }
  236: { 1S GR1 -> 1S }   ( RETURN STACK HOLDS CELLS )
  237: 
  238: \ ------------------------------------------------------------------------
  239: TESTING ADD/SUBTRACT: + - 1+ 1- ABS NEGATE
  240: 
  241: { 0 5 + -> 5 }
  242: { 5 0 + -> 5 }
  243: { 0 -5 + -> -5 }
  244: { -5 0 + -> -5 }
  245: { 1 2 + -> 3 }
  246: { 1 -2 + -> -1 }
  247: { -1 2 + -> 1 }
  248: { -1 -2 + -> -3 }
  249: { -1 1 + -> 0 }
  250: { MID-UINT 1 + -> MID-UINT+1 }
  251: 
  252: { 0 5 - -> -5 }
  253: { 5 0 - -> 5 }
  254: { 0 -5 - -> 5 }
  255: { -5 0 - -> -5 }
  256: { 1 2 - -> -1 }
  257: { 1 -2 - -> 3 }
  258: { -1 2 - -> -3 }
  259: { -1 -2 - -> 1 }
  260: { 0 1 - -> -1 }
  261: { MID-UINT+1 1 - -> MID-UINT }
  262: 
  263: { 0 1+ -> 1 }
  264: { -1 1+ -> 0 }
  265: { 1 1+ -> 2 }
  266: { MID-UINT 1+ -> MID-UINT+1 }
  267: 
  268: { 2 1- -> 1 }
  269: { 1 1- -> 0 }
  270: { 0 1- -> -1 }
  271: { MID-UINT+1 1- -> MID-UINT }
  272: 
  273: { 0 NEGATE -> 0 }
  274: { 1 NEGATE -> -1 }
  275: { -1 NEGATE -> 1 }
  276: { 2 NEGATE -> -2 }
  277: { -2 NEGATE -> 2 }
  278: 
  279: { 0 ABS -> 0 }
  280: { 1 ABS -> 1 }
  281: { -1 ABS -> 1 }
  282: { MIN-INT ABS -> MID-UINT+1 }
  283: 
  284: \ ------------------------------------------------------------------------
  285: TESTING MULTIPLY: S>D * M* UM*
  286: 
  287: { 0 S>D -> 0 0 }
  288: { 1 S>D -> 1 0 }
  289: { 2 S>D -> 2 0 }
  290: { -1 S>D -> -1 -1 }
  291: { -2 S>D -> -2 -1 }
  292: { MIN-INT S>D -> MIN-INT -1 }
  293: { MAX-INT S>D -> MAX-INT 0 }
  294: 
  295: { 0 0 M* -> 0 S>D }
  296: { 0 1 M* -> 0 S>D }
  297: { 1 0 M* -> 0 S>D }
  298: { 1 2 M* -> 2 S>D }
  299: { 2 1 M* -> 2 S>D }
  300: { 3 3 M* -> 9 S>D }
  301: { -3 3 M* -> -9 S>D }
  302: { 3 -3 M* -> -9 S>D }
  303: { -3 -3 M* -> 9 S>D }
  304: { 0 MIN-INT M* -> 0 S>D }
  305: { 1 MIN-INT M* -> MIN-INT S>D }
  306: { 2 MIN-INT M* -> 0 1S }
  307: { 0 MAX-INT M* -> 0 S>D }
  308: { 1 MAX-INT M* -> MAX-INT S>D }
  309: { 2 MAX-INT M* -> MAX-INT 1 LSHIFT 0 }
  310: { MIN-INT MIN-INT M* -> 0 MSB 1 RSHIFT }
  311: { MAX-INT MIN-INT M* -> MSB MSB 2/ }
  312: { MAX-INT MAX-INT M* -> 1 MSB 2/ INVERT }
  313: 
  314: { 0 0 * -> 0 }				\ TEST IDENTITIES
  315: { 0 1 * -> 0 }
  316: { 1 0 * -> 0 }
  317: { 1 2 * -> 2 }
  318: { 2 1 * -> 2 }
  319: { 3 3 * -> 9 }
  320: { -3 3 * -> -9 }
  321: { 3 -3 * -> -9 }
  322: { -3 -3 * -> 9 }
  323: 
  324: { MID-UINT+1 1 RSHIFT 2 * -> MID-UINT+1 }
  325: { MID-UINT+1 2 RSHIFT 4 * -> MID-UINT+1 }
  326: { MID-UINT+1 1 RSHIFT MID-UINT+1 OR 2 * -> MID-UINT+1 }
  327: 
  328: { 0 0 UM* -> 0 0 }
  329: { 0 1 UM* -> 0 0 }
  330: { 1 0 UM* -> 0 0 }
  331: { 1 2 UM* -> 2 0 }
  332: { 2 1 UM* -> 2 0 }
  333: { 3 3 UM* -> 9 0 }
  334: 
  335: { MID-UINT+1 1 RSHIFT 2 UM* -> MID-UINT+1 0 }
  336: { MID-UINT+1 2 UM* -> 0 1 }
  337: { MID-UINT+1 4 UM* -> 0 2 }
  338: { 1S 2 UM* -> 1S 1 LSHIFT 1 }
  339: { MAX-UINT MAX-UINT UM* -> 1 1 INVERT }
  340: 
  341: \ ------------------------------------------------------------------------
  342: TESTING DIVIDE: FM/MOD SM/REM UM/MOD */ */MOD / /MOD MOD
  343: 
  344: { 0 S>D 1 FM/MOD -> 0 0 }
  345: { 1 S>D 1 FM/MOD -> 0 1 }
  346: { 2 S>D 1 FM/MOD -> 0 2 }
  347: { -1 S>D 1 FM/MOD -> 0 -1 }
  348: { -2 S>D 1 FM/MOD -> 0 -2 }
  349: { 0 S>D -1 FM/MOD -> 0 0 }
  350: { 1 S>D -1 FM/MOD -> 0 -1 }
  351: { 2 S>D -1 FM/MOD -> 0 -2 }
  352: { -1 S>D -1 FM/MOD -> 0 1 }
  353: { -2 S>D -1 FM/MOD -> 0 2 }
  354: { 2 S>D 2 FM/MOD -> 0 1 }
  355: { -1 S>D -1 FM/MOD -> 0 1 }
  356: { -2 S>D -2 FM/MOD -> 0 1 }
  357: {  7 S>D  3 FM/MOD -> 1 2 }
  358: {  7 S>D -3 FM/MOD -> -2 -3 }
  359: { -7 S>D  3 FM/MOD -> 2 -3 }
  360: { -7 S>D -3 FM/MOD -> -1 2 }
  361: { MAX-INT S>D 1 FM/MOD -> 0 MAX-INT }
  362: { MIN-INT S>D 1 FM/MOD -> 0 MIN-INT }
  363: { MAX-INT S>D MAX-INT FM/MOD -> 0 1 }
  364: { MIN-INT S>D MIN-INT FM/MOD -> 0 1 }
  365: { 1S 1 4 FM/MOD -> 3 MAX-INT }
  366: { 1 MIN-INT M* 1 FM/MOD -> 0 MIN-INT }
  367: { 1 MIN-INT M* MIN-INT FM/MOD -> 0 1 }
  368: { 2 MIN-INT M* 2 FM/MOD -> 0 MIN-INT }
  369: { 2 MIN-INT M* MIN-INT FM/MOD -> 0 2 }
  370: { 1 MAX-INT M* 1 FM/MOD -> 0 MAX-INT }
  371: { 1 MAX-INT M* MAX-INT FM/MOD -> 0 1 }
  372: { 2 MAX-INT M* 2 FM/MOD -> 0 MAX-INT }
  373: { 2 MAX-INT M* MAX-INT FM/MOD -> 0 2 }
  374: { MIN-INT MIN-INT M* MIN-INT FM/MOD -> 0 MIN-INT }
  375: { MIN-INT MAX-INT M* MIN-INT FM/MOD -> 0 MAX-INT }
  376: { MIN-INT MAX-INT M* MAX-INT FM/MOD -> 0 MIN-INT }
  377: { MAX-INT MAX-INT M* MAX-INT FM/MOD -> 0 MAX-INT }
  378: 
  379: { 0 S>D 1 SM/REM -> 0 0 }
  380: { 1 S>D 1 SM/REM -> 0 1 }
  381: { 2 S>D 1 SM/REM -> 0 2 }
  382: { -1 S>D 1 SM/REM -> 0 -1 }
  383: { -2 S>D 1 SM/REM -> 0 -2 }
  384: { 0 S>D -1 SM/REM -> 0 0 }
  385: { 1 S>D -1 SM/REM -> 0 -1 }
  386: { 2 S>D -1 SM/REM -> 0 -2 }
  387: { -1 S>D -1 SM/REM -> 0 1 }
  388: { -2 S>D -1 SM/REM -> 0 2 }
  389: { 2 S>D 2 SM/REM -> 0 1 }
  390: { -1 S>D -1 SM/REM -> 0 1 }
  391: { -2 S>D -2 SM/REM -> 0 1 }
  392: {  7 S>D  3 SM/REM -> 1 2 }
  393: {  7 S>D -3 SM/REM -> 1 -2 }
  394: { -7 S>D  3 SM/REM -> -1 -2 }
  395: { -7 S>D -3 SM/REM -> -1 2 }
  396: { MAX-INT S>D 1 SM/REM -> 0 MAX-INT }
  397: { MIN-INT S>D 1 SM/REM -> 0 MIN-INT }
  398: { MAX-INT S>D MAX-INT SM/REM -> 0 1 }
  399: { MIN-INT S>D MIN-INT SM/REM -> 0 1 }
  400: { 1S 1 4 SM/REM -> 3 MAX-INT }
  401: { 2 MIN-INT M* 2 SM/REM -> 0 MIN-INT }
  402: { 2 MIN-INT M* MIN-INT SM/REM -> 0 2 }
  403: { 2 MAX-INT M* 2 SM/REM -> 0 MAX-INT }
  404: { 2 MAX-INT M* MAX-INT SM/REM -> 0 2 }
  405: { MIN-INT MIN-INT M* MIN-INT SM/REM -> 0 MIN-INT }
  406: { MIN-INT MAX-INT M* MIN-INT SM/REM -> 0 MAX-INT }
  407: { MIN-INT MAX-INT M* MAX-INT SM/REM -> 0 MIN-INT }
  408: { MAX-INT MAX-INT M* MAX-INT SM/REM -> 0 MAX-INT }
  409: 
  410: { 0 0 1 UM/MOD -> 0 0 }
  411: { 1 0 1 UM/MOD -> 0 1 }
  412: { 1 0 2 UM/MOD -> 1 0 }
  413: { 3 0 2 UM/MOD -> 1 1 }
  414: { MAX-UINT 2 UM* 2 UM/MOD -> 0 MAX-UINT }
  415: { MAX-UINT 2 UM* MAX-UINT UM/MOD -> 0 2 }
  416: { MAX-UINT MAX-UINT UM* MAX-UINT UM/MOD -> 0 MAX-UINT }
  417: 
  418: : IFFLOORED
  419:    [ -3 2 / -2 = INVERT ] LITERAL IF POSTPONE \ THEN ;
  420: : IFSYM
  421:    [ -3 2 / -1 = INVERT ] LITERAL IF POSTPONE \ THEN ;
  422: 
  423: \ THE SYSTEM MIGHT DO EITHER FLOORED OR SYMMETRIC DIVISION.
  424: \ SINCE WE HAVE ALREADY TESTED M*, FM/MOD, AND SM/REM WE CAN USE THEM IN TEST.
  425: IFFLOORED : T/MOD  >R S>D R> FM/MOD ;
  426: IFFLOORED : T/     T/MOD SWAP DROP ;
  427: IFFLOORED : TMOD   T/MOD DROP ;
  428: IFFLOORED : T*/MOD >R M* R> FM/MOD ;
  429: IFFLOORED : T*/    T*/MOD SWAP DROP ;
  430: IFSYM     : T/MOD  >R S>D R> SM/REM ;
  431: IFSYM     : T/     T/MOD SWAP DROP ;
  432: IFSYM     : TMOD   T/MOD DROP ;
  433: IFSYM     : T*/MOD >R M* R> SM/REM ;
  434: IFSYM     : T*/    T*/MOD SWAP DROP ;
  435: 
  436: { 0 1 /MOD -> 0 1 T/MOD }
  437: { 1 1 /MOD -> 1 1 T/MOD }
  438: { 2 1 /MOD -> 2 1 T/MOD }
  439: { -1 1 /MOD -> -1 1 T/MOD }
  440: { -2 1 /MOD -> -2 1 T/MOD }
  441: { 0 -1 /MOD -> 0 -1 T/MOD }
  442: { 1 -1 /MOD -> 1 -1 T/MOD }
  443: { 2 -1 /MOD -> 2 -1 T/MOD }
  444: { -1 -1 /MOD -> -1 -1 T/MOD }
  445: { -2 -1 /MOD -> -2 -1 T/MOD }
  446: { 2 2 /MOD -> 2 2 T/MOD }
  447: { -1 -1 /MOD -> -1 -1 T/MOD }
  448: { -2 -2 /MOD -> -2 -2 T/MOD }
  449: { 7 3 /MOD -> 7 3 T/MOD }
  450: { 7 -3 /MOD -> 7 -3 T/MOD }
  451: { -7 3 /MOD -> -7 3 T/MOD }
  452: { -7 -3 /MOD -> -7 -3 T/MOD }
  453: { MAX-INT 1 /MOD -> MAX-INT 1 T/MOD }
  454: { MIN-INT 1 /MOD -> MIN-INT 1 T/MOD }
  455: { MAX-INT MAX-INT /MOD -> MAX-INT MAX-INT T/MOD }
  456: { MIN-INT MIN-INT /MOD -> MIN-INT MIN-INT T/MOD }
  457: 
  458: { 0 1 / -> 0 1 T/ }
  459: { 1 1 / -> 1 1 T/ }
  460: { 2 1 / -> 2 1 T/ }
  461: { -1 1 / -> -1 1 T/ }
  462: { -2 1 / -> -2 1 T/ }
  463: { 0 -1 / -> 0 -1 T/ }
  464: { 1 -1 / -> 1 -1 T/ }
  465: { 2 -1 / -> 2 -1 T/ }
  466: { -1 -1 / -> -1 -1 T/ }
  467: { -2 -1 / -> -2 -1 T/ }
  468: { 2 2 / -> 2 2 T/ }
  469: { -1 -1 / -> -1 -1 T/ }
  470: { -2 -2 / -> -2 -2 T/ }
  471: { 7 3 / -> 7 3 T/ }
  472: { 7 -3 / -> 7 -3 T/ }
  473: { -7 3 / -> -7 3 T/ }
  474: { -7 -3 / -> -7 -3 T/ }
  475: { MAX-INT 1 / -> MAX-INT 1 T/ }
  476: { MIN-INT 1 / -> MIN-INT 1 T/ }
  477: { MAX-INT MAX-INT / -> MAX-INT MAX-INT T/ }
  478: { MIN-INT MIN-INT / -> MIN-INT MIN-INT T/ }
  479: 
  480: { 0 1 MOD -> 0 1 TMOD }
  481: { 1 1 MOD -> 1 1 TMOD }
  482: { 2 1 MOD -> 2 1 TMOD }
  483: { -1 1 MOD -> -1 1 TMOD }
  484: { -2 1 MOD -> -2 1 TMOD }
  485: { 0 -1 MOD -> 0 -1 TMOD }
  486: { 1 -1 MOD -> 1 -1 TMOD }
  487: { 2 -1 MOD -> 2 -1 TMOD }
  488: { -1 -1 MOD -> -1 -1 TMOD }
  489: { -2 -1 MOD -> -2 -1 TMOD }
  490: { 2 2 MOD -> 2 2 TMOD }
  491: { -1 -1 MOD -> -1 -1 TMOD }
  492: { -2 -2 MOD -> -2 -2 TMOD }
  493: { 7 3 MOD -> 7 3 TMOD }
  494: { 7 -3 MOD -> 7 -3 TMOD }
  495: { -7 3 MOD -> -7 3 TMOD }
  496: { -7 -3 MOD -> -7 -3 TMOD }
  497: { MAX-INT 1 MOD -> MAX-INT 1 TMOD }
  498: { MIN-INT 1 MOD -> MIN-INT 1 TMOD }
  499: { MAX-INT MAX-INT MOD -> MAX-INT MAX-INT TMOD }
  500: { MIN-INT MIN-INT MOD -> MIN-INT MIN-INT TMOD }
  501: 
  502: { 0 2 1 */ -> 0 2 1 T*/ }
  503: { 1 2 1 */ -> 1 2 1 T*/ }
  504: { 2 2 1 */ -> 2 2 1 T*/ }
  505: { -1 2 1 */ -> -1 2 1 T*/ }
  506: { -2 2 1 */ -> -2 2 1 T*/ }
  507: { 0 2 -1 */ -> 0 2 -1 T*/ }
  508: { 1 2 -1 */ -> 1 2 -1 T*/ }
  509: { 2 2 -1 */ -> 2 2 -1 T*/ }
  510: { -1 2 -1 */ -> -1 2 -1 T*/ }
  511: { -2 2 -1 */ -> -2 2 -1 T*/ }
  512: { 2 2 2 */ -> 2 2 2 T*/ }
  513: { -1 2 -1 */ -> -1 2 -1 T*/ }
  514: { -2 2 -2 */ -> -2 2 -2 T*/ }
  515: { 7 2 3 */ -> 7 2 3 T*/ }
  516: { 7 2 -3 */ -> 7 2 -3 T*/ }
  517: { -7 2 3 */ -> -7 2 3 T*/ }
  518: { -7 2 -3 */ -> -7 2 -3 T*/ }
  519: { MAX-INT 2 MAX-INT */ -> MAX-INT 2 MAX-INT T*/ }
  520: { MIN-INT 2 MIN-INT */ -> MIN-INT 2 MIN-INT T*/ }
  521: 
  522: { 0 2 1 */MOD -> 0 2 1 T*/MOD }
  523: { 1 2 1 */MOD -> 1 2 1 T*/MOD }
  524: { 2 2 1 */MOD -> 2 2 1 T*/MOD }
  525: { -1 2 1 */MOD -> -1 2 1 T*/MOD }
  526: { -2 2 1 */MOD -> -2 2 1 T*/MOD }
  527: { 0 2 -1 */MOD -> 0 2 -1 T*/MOD }
  528: { 1 2 -1 */MOD -> 1 2 -1 T*/MOD }
  529: { 2 2 -1 */MOD -> 2 2 -1 T*/MOD }
  530: { -1 2 -1 */MOD -> -1 2 -1 T*/MOD }
  531: { -2 2 -1 */MOD -> -2 2 -1 T*/MOD }
  532: { 2 2 2 */MOD -> 2 2 2 T*/MOD }
  533: { -1 2 -1 */MOD -> -1 2 -1 T*/MOD }
  534: { -2 2 -2 */MOD -> -2 2 -2 T*/MOD }
  535: { 7 2 3 */MOD -> 7 2 3 T*/MOD }
  536: { 7 2 -3 */MOD -> 7 2 -3 T*/MOD }
  537: { -7 2 3 */MOD -> -7 2 3 T*/MOD }
  538: { -7 2 -3 */MOD -> -7 2 -3 T*/MOD }
  539: { MAX-INT 2 MAX-INT */MOD -> MAX-INT 2 MAX-INT T*/MOD }
  540: { MIN-INT 2 MIN-INT */MOD -> MIN-INT 2 MIN-INT T*/MOD }
  541: 
  542: \ ------------------------------------------------------------------------
  543: TESTING HERE , @ ! CELL+ CELLS C, C@ C! CHARS 2@ 2! ALIGN ALIGNED +! ALLOT
  544: 
  545: HERE 1 ALLOT
  546: HERE
  547: CONSTANT 2NDA
  548: CONSTANT 1STA
  549: { 1STA 2NDA U< -> <TRUE> }		\ HERE MUST GROW WITH ALLOT
  550: { 1STA 1+ -> 2NDA }			\ ... BY ONE ADDRESS UNIT
  551: ( MISSING TEST: NEGATIVE ALLOT )
  552: 
  553: HERE 1 ,
  554: HERE 2 ,
  555: CONSTANT 2ND
  556: CONSTANT 1ST
  557: { 1ST 2ND U< -> <TRUE> }			\ HERE MUST GROW WITH ALLOT
  558: { 1ST CELL+ -> 2ND }			\ ... BY ONE CELL
  559: { 1ST 1 CELLS + -> 2ND }
  560: { 1ST @ 2ND @ -> 1 2 }
  561: { 5 1ST ! -> }
  562: { 1ST @ 2ND @ -> 5 2 }
  563: { 6 2ND ! -> }
  564: { 1ST @ 2ND @ -> 5 6 }
  565: { 1ST 2@ -> 6 5 }
  566: { 2 1 1ST 2! -> }
  567: { 1ST 2@ -> 2 1 }
  568: { 1S 1ST !  1ST @ -> 1S }		\ CAN STORE CELL-WIDE VALUE
  569: 
  570: HERE 1 C,
  571: HERE 2 C,
  572: CONSTANT 2NDC
  573: CONSTANT 1STC
  574: { 1STC 2NDC U< -> <TRUE> }		\ HERE MUST GROW WITH ALLOT
  575: { 1STC CHAR+ -> 2NDC }			\ ... BY ONE CHAR
  576: { 1STC 1 CHARS + -> 2NDC }
  577: { 1STC C@ 2NDC C@ -> 1 2 }
  578: { 3 1STC C! -> }
  579: { 1STC C@ 2NDC C@ -> 3 2 }
  580: { 4 2NDC C! -> }
  581: { 1STC C@ 2NDC C@ -> 3 4 }
  582: 
  583: ALIGN 1 ALLOT HERE ALIGN HERE 3 CELLS ALLOT
  584: CONSTANT A-ADDR  CONSTANT UA-ADDR
  585: { UA-ADDR ALIGNED -> A-ADDR }
  586: {    1 A-ADDR C!  A-ADDR C@ ->    1 }
  587: { 1234 A-ADDR  !  A-ADDR  @ -> 1234 }
  588: { 123 456 A-ADDR 2!  A-ADDR 2@ -> 123 456 }
  589: { 2 A-ADDR CHAR+ C!  A-ADDR CHAR+ C@ -> 2 }
  590: { 3 A-ADDR CELL+ C!  A-ADDR CELL+ C@ -> 3 }
  591: { 1234 A-ADDR CELL+ !  A-ADDR CELL+ @ -> 1234 }
  592: { 123 456 A-ADDR CELL+ 2!  A-ADDR CELL+ 2@ -> 123 456 }
  593: 
  594: : BITS ( X -- U )
  595:    0 SWAP BEGIN DUP WHILE DUP MSB AND IF >R 1+ R> THEN 2* REPEAT DROP ;
  596: ( CHARACTERS >= 1 AU, <= SIZE OF CELL, >= 8 BITS )
  597: { 1 CHARS 1 < -> <FALSE> }
  598: { 1 CHARS 1 CELLS > -> <FALSE> }
  599: ( TBD: HOW TO FIND NUMBER OF BITS? )
  600: 
  601: ( CELLS >= 1 AU, INTEGRAL MULTIPLE OF CHAR SIZE, >= 16 BITS )
  602: { 1 CELLS 1 < -> <FALSE> }
  603: { 1 CELLS 1 CHARS MOD -> 0 }
  604: { 1S BITS 10 < -> <FALSE> }
  605: 
  606: { 0 1ST ! -> }
  607: { 1 1ST +! -> }
  608: { 1ST @ -> 1 }
  609: { -1 1ST +! 1ST @ -> 0 }
  610: 
  611: \ ------------------------------------------------------------------------
  612: TESTING CHAR [CHAR] [ ] BL S"
  613: 
  614: { BL -> 20 }
  615: { CHAR X -> 58 }
  616: { CHAR HELLO -> 48 }
  617: { : GC1 [CHAR] X ; -> }
  618: { : GC2 [CHAR] HELLO ; -> }
  619: { GC1 -> 58 }
  620: { GC2 -> 48 }
  621: { : GC3 [ GC1 ] LITERAL ; -> }
  622: { GC3 -> 58 }
  623: { : GC4 S" XY" ; -> }
  624: { GC4 SWAP DROP -> 2 }
  625: { GC4 DROP DUP C@ SWAP CHAR+ C@ -> 58 59 }
  626: 
  627: \ ------------------------------------------------------------------------
  628: TESTING ' ['] FIND EXECUTE IMMEDIATE COUNT LITERAL POSTPONE STATE
  629: 
  630: { : GT1 123 ; -> }
  631: { ' GT1 EXECUTE -> 123 }
  632: { : GT2 ['] GT1 ; IMMEDIATE -> }
  633: { GT2 EXECUTE -> 123 }
  634: HERE 3 C, CHAR G C, CHAR T C, CHAR 1 C, CONSTANT GT1STRING
  635: HERE 3 C, CHAR G C, CHAR T C, CHAR 2 C, CONSTANT GT2STRING
  636: { GT1STRING FIND -> ' GT1 -1 }
  637: { GT2STRING FIND -> ' GT2 1 }
  638: ( HOW TO SEARCH FOR NON-EXISTENT WORD? )
  639: { : GT3 GT2 LITERAL ; -> }
  640: { GT3 -> ' GT1 }
  641: { GT1STRING COUNT -> GT1STRING CHAR+ 3 }
  642: 
  643: { : GT4 POSTPONE GT1 ; IMMEDIATE -> }
  644: { : GT5 GT4 ; -> }
  645: { GT5 -> 123 }
  646: { : GT6 345 ; IMMEDIATE -> }
  647: { : GT7 POSTPONE GT6 ; -> }
  648: { GT7 -> 345 }
  649: 
  650: { : GT8 STATE @ ; IMMEDIATE -> }
  651: { GT8 -> 0 }
  652: { : GT9 GT8 LITERAL ; -> }
  653: { GT9 0= -> <FALSE> }
  654: 
  655: \ ------------------------------------------------------------------------
  656: TESTING IF ELSE THEN BEGIN WHILE REPEAT UNTIL RECURSE
  657: 
  658: { : GI1 IF 123 THEN ; -> }
  659: { : GI2 IF 123 ELSE 234 THEN ; -> }
  660: { 0 GI1 -> }
  661: { 1 GI1 -> 123 }
  662: { -1 GI1 -> 123 }
  663: { 0 GI2 -> 234 }
  664: { 1 GI2 -> 123 }
  665: { -1 GI1 -> 123 }
  666: 
  667: { : GI3 BEGIN DUP 5 < WHILE DUP 1+ REPEAT ; -> }
  668: { 0 GI3 -> 0 1 2 3 4 5 }
  669: { 4 GI3 -> 4 5 }
  670: { 5 GI3 -> 5 }
  671: { 6 GI3 -> 6 }
  672: 
  673: { : GI4 BEGIN DUP 1+ DUP 5 > UNTIL ; -> }
  674: { 3 GI4 -> 3 4 5 6 }
  675: { 5 GI4 -> 5 6 }
  676: { 6 GI4 -> 6 7 }
  677: 
  678: { : GI5 BEGIN DUP 2 > WHILE DUP 5 < WHILE DUP 1+ REPEAT 123 ELSE 345 THEN ; -> }
  679: { 1 GI5 -> 1 345 }
  680: { 2 GI5 -> 2 345 }
  681: { 3 GI5 -> 3 4 5 123 }
  682: { 4 GI5 -> 4 5 123 }
  683: { 5 GI5 -> 5 123 }
  684: 
  685: { : GI6 ( N -- 0,1,..N ) DUP IF DUP >R 1- RECURSE R> THEN ; -> }
  686: { 0 GI6 -> 0 }
  687: { 1 GI6 -> 0 1 }
  688: { 2 GI6 -> 0 1 2 }
  689: { 3 GI6 -> 0 1 2 3 }
  690: { 4 GI6 -> 0 1 2 3 4 }
  691: 
  692: \ ------------------------------------------------------------------------
  693: TESTING DO LOOP +LOOP I J UNLOOP LEAVE EXIT
  694: 
  695: { : GD1 DO I LOOP ; -> }
  696: { 4 1 GD1 -> 1 2 3 }
  697: { 2 -1 GD1 -> -1 0 1 }
  698: { MID-UINT+1 MID-UINT GD1 -> MID-UINT }
  699: 
  700: { : GD2 DO I -1 +LOOP ; -> }
  701: { 1 4 GD2 -> 4 3 2 1 }
  702: { -1 2 GD2 -> 2 1 0 -1 }
  703: { MID-UINT MID-UINT+1 GD2 -> MID-UINT+1 MID-UINT }
  704: 
  705: { : GD3 DO 1 0 DO J LOOP LOOP ; -> }
  706: { 4 1 GD3 -> 1 2 3 }
  707: { 2 -1 GD3 -> -1 0 1 }
  708: { MID-UINT+1 MID-UINT GD3 -> MID-UINT }
  709: 
  710: { : GD4 DO 1 0 DO J LOOP -1 +LOOP ; -> }
  711: { 1 4 GD4 -> 4 3 2 1 }
  712: { -1 2 GD4 -> 2 1 0 -1 }
  713: { MID-UINT MID-UINT+1 GD4 -> MID-UINT+1 MID-UINT }
  714: 
  715: { : GD5 123 SWAP 0 DO I 4 > IF DROP 234 LEAVE THEN LOOP ; -> }
  716: { 1 GD5 -> 123 }
  717: { 5 GD5 -> 123 }
  718: { 6 GD5 -> 234 }
  719: 
  720: { : GD6  ( PAT: {0 0},{0 0}{1 0}{1 1},{0 0}{1 0}{1 1}{2 0}{2 1}{2 2} )
  721:    0 SWAP 0 DO
  722:       I 1+ 0 DO I J + 3 = IF I UNLOOP I UNLOOP EXIT THEN 1+ LOOP
  723:     LOOP ; -> }
  724: { 1 GD6 -> 1 }
  725: { 2 GD6 -> 3 }
  726: { 3 GD6 -> 4 1 2 }
  727: 
  728: \ ------------------------------------------------------------------------
  729: TESTING DEFINING WORDS: : ; CONSTANT VARIABLE CREATE DOES> >BODY
  730: 
  731: { 123 CONSTANT X123 -> }
  732: { X123 -> 123 }
  733: { : EQU CONSTANT ; -> }
  734: { X123 EQU Y123 -> }
  735: { Y123 -> 123 }
  736: 
  737: { VARIABLE V1 -> }
  738: { 123 V1 ! -> }
  739: { V1 @ -> 123 }
  740: 
  741: { : NOP : POSTPONE ; ; -> }
  742: { NOP NOP1 NOP NOP2 -> }
  743: { NOP1 -> }
  744: { NOP2 -> }
  745: 
  746: { : DOES1 DOES> @ 1 + ; -> }
  747: { : DOES2 DOES> @ 2 + ; -> }
  748: { CREATE CR1 -> }
  749: { CR1 -> HERE }
  750: { ' CR1 >BODY -> HERE }
  751: { 1 , -> }
  752: { CR1 @ -> 1 }
  753: { DOES1 -> }
  754: { CR1 -> 2 }
  755: { DOES2 -> }
  756: { CR1 -> 3 }
  757: 
  758: { : WEIRD: CREATE DOES> 1 + DOES> 2 + ; -> }
  759: { WEIRD: W1 -> }
  760: { ' W1 >BODY -> HERE }
  761: { W1 -> HERE 1 + }
  762: { W1 -> HERE 2 + }
  763: 
  764: \ ------------------------------------------------------------------------
  765: TESTING EVALUATE
  766: 
  767: : GE1 S" 123" ; IMMEDIATE
  768: : GE2 S" 123 1+" ; IMMEDIATE
  769: : GE3 S" : GE4 345 ;" ;
  770: : GE5 EVALUATE ; IMMEDIATE
  771: 
  772: { GE1 EVALUATE -> 123 }			( TEST EVALUATE IN INTERP. STATE )
  773: { GE2 EVALUATE -> 124 }
  774: { GE3 EVALUATE -> }
  775: { GE4 -> 345 }
  776: 
  777: { : GE6 GE1 GE5 ; -> }			( TEST EVALUATE IN COMPILE STATE )
  778: { GE6 -> 123 }
  779: { : GE7 GE2 GE5 ; -> }
  780: { GE7 -> 124 }
  781: 
  782: \ ------------------------------------------------------------------------
  783: TESTING SOURCE >IN WORD
  784: 
  785: : GS1 S" SOURCE" 2DUP EVALUATE
  786:        >R SWAP >R = R> R> = ;
  787: { GS1 -> <TRUE> <TRUE> }
  788: 
  789: VARIABLE SCANS
  790: : RESCAN?  -1 SCANS +! SCANS @ IF 0 >IN ! THEN ;
  791: 
  792: { 2 SCANS !
  793: 345 RESCAN?
  794: -> 345 345 }
  795: 
  796: : GS2  5 SCANS ! S" 123 RESCAN?" EVALUATE ;
  797: { GS2 -> 123 123 123 123 123 }
  798: 
  799: : GS3 WORD COUNT SWAP C@ ;
  800: { BL GS3 HELLO -> 5 CHAR H }
  801: { CHAR " GS3 GOODBYE" -> 7 CHAR G }
  802: { BL GS3
  803: DROP -> 0 }				\ BLANK LINE RETURN ZERO-LENGTH STRING
  804: 
  805: : GS4 SOURCE >IN ! DROP ;
  806: { GS4 123 456
  807: -> }
  808: 
  809: \ ------------------------------------------------------------------------
  810: TESTING <# # #S #> HOLD SIGN BASE >NUMBER HEX DECIMAL
  811: 
  812: : S=  \ ( ADDR1 C1 ADDR2 C2 -- T/F ) COMPARE TWO STRINGS.
  813:    >R SWAP R@ = IF			\ MAKE SURE STRINGS HAVE SAME LENGTH
  814:       R> ?DUP IF			\ IF NON-EMPTY STRINGS
  815: 	 0 DO
  816: 	    OVER C@ OVER C@ - IF 2DROP <FALSE> UNLOOP EXIT THEN
  817: 	    SWAP CHAR+ SWAP CHAR+
  818:          LOOP
  819:       THEN
  820:       2DROP <TRUE>			\ IF WE GET HERE, STRINGS MATCH
  821:    ELSE
  822:       R> DROP 2DROP <FALSE>		\ LENGTHS MISMATCH
  823:    THEN ;
  824: 
  825: : GP1  <# 41 HOLD 42 HOLD 0 0 #> S" BA" S= ;
  826: { GP1 -> <TRUE> }
  827: 
  828: : GP2  <# -1 SIGN 0 SIGN -1 SIGN 0 0 #> S" --" S= ;
  829: { GP2 -> <TRUE> }
  830: 
  831: : GP3  <# 1 0 # # #> S" 01" S= ;
  832: { GP3 -> <TRUE> }
  833: 
  834: : GP4  <# 1 0 #S #> S" 1" S= ;
  835: { GP4 -> <TRUE> }
  836: 
  837: 24 CONSTANT MAX-BASE			\ BASE 2 .. 36
  838: : COUNT-BITS
  839:    0 0 INVERT BEGIN DUP WHILE >R 1+ R> 2* REPEAT DROP ;
  840: COUNT-BITS 2* CONSTANT #BITS-UD		\ NUMBER OF BITS IN UD
  841: 
  842: : GP5
  843:    BASE @ <TRUE>
  844:    MAX-BASE 1+ 2 DO			\ FOR EACH POSSIBLE BASE
  845:       I BASE !				\ TBD: ASSUMES BASE WORKS
  846:       I 0 <# #S #> S" 10" S= AND
  847:    LOOP
  848:    SWAP BASE ! ;
  849: { GP5 -> <TRUE> }
  850: 
  851: : GP6
  852:    BASE @ >R  2 BASE !
  853:    MAX-UINT MAX-UINT <# #S #>		\ MAXIMUM UD TO BINARY
  854:    R> BASE !				\ S: C-ADDR U
  855:    DUP #BITS-UD = SWAP
  856:    0 DO					\ S: C-ADDR FLAG
  857:       OVER C@ [CHAR] 1 = AND		\ ALL ONES
  858:       >R CHAR+ R>
  859:    LOOP SWAP DROP ;
  860: { GP6 -> <TRUE> }
  861: 
  862: : GP7
  863:    BASE @ >R    MAX-BASE BASE !
  864:    <TRUE>
  865:    A 0 DO
  866:       I 0 <# #S #>
  867:       1 = SWAP C@ I 30 + = AND AND
  868:    LOOP
  869:    MAX-BASE A DO
  870:       I 0 <# #S #>
  871:       1 = SWAP C@ 41 I A - + = AND AND
  872:    LOOP
  873:    R> BASE ! ;
  874: 
  875: { GP7 -> <TRUE> }
  876: 
  877: \ >NUMBER TESTS
  878: CREATE GN-BUF 0 C,
  879: : GN-STRING	GN-BUF 1 ;
  880: : GN-CONSUMED	GN-BUF CHAR+ 0 ;
  881: : GN'		[CHAR] ' WORD CHAR+ C@ GN-BUF C!  GN-STRING ;
  882: 
  883: { 0 0 GN' 0' >NUMBER -> 0 0 GN-CONSUMED }
  884: { 0 0 GN' 1' >NUMBER -> 1 0 GN-CONSUMED }
  885: { 1 0 GN' 1' >NUMBER -> BASE @ 1+ 0 GN-CONSUMED }
  886: { 0 0 GN' -' >NUMBER -> 0 0 GN-STRING }	\ SHOULD FAIL TO CONVERT THESE
  887: { 0 0 GN' +' >NUMBER -> 0 0 GN-STRING }
  888: { 0 0 GN' .' >NUMBER -> 0 0 GN-STRING }
  889: 
  890: : >NUMBER-BASED
  891:    BASE @ >R BASE ! >NUMBER R> BASE ! ;
  892: 
  893: { 0 0 GN' 2' 10 >NUMBER-BASED -> 2 0 GN-CONSUMED }
  894: { 0 0 GN' 2'  2 >NUMBER-BASED -> 0 0 GN-STRING }
  895: { 0 0 GN' F' 10 >NUMBER-BASED -> F 0 GN-CONSUMED }
  896: { 0 0 GN' G' 10 >NUMBER-BASED -> 0 0 GN-STRING }
  897: { 0 0 GN' G' MAX-BASE >NUMBER-BASED -> 10 0 GN-CONSUMED }
  898: { 0 0 GN' Z' MAX-BASE >NUMBER-BASED -> 23 0 GN-CONSUMED }
  899: 
  900: : GN1	\ ( UD BASE -- UD' LEN ) UD SHOULD EQUAL UD' AND LEN SHOULD BE ZERO.
  901:    BASE @ >R BASE !
  902:    <# #S #>
  903:    0 0 2SWAP >NUMBER SWAP DROP		\ RETURN LENGTH ONLY
  904:    R> BASE ! ;
  905: { 0 0 2 GN1 -> 0 0 0 }
  906: { MAX-UINT 0 2 GN1 -> MAX-UINT 0 0 }
  907: { MAX-UINT DUP 2 GN1 -> MAX-UINT DUP 0 }
  908: { 0 0 MAX-BASE GN1 -> 0 0 0 }
  909: { MAX-UINT 0 MAX-BASE GN1 -> MAX-UINT 0 0 }
  910: { MAX-UINT DUP MAX-BASE GN1 -> MAX-UINT DUP 0 }
  911: 
  912: : GN2	\ ( -- 16 10 )
  913:    BASE @ >R  HEX BASE @  DECIMAL BASE @  R> BASE ! ;
  914: { GN2 -> 10 A }
  915: 
  916: \ ------------------------------------------------------------------------
  917: TESTING FILL MOVE
  918: 
  919: CREATE FBUF 00 C, 00 C, 00 C,
  920: CREATE SBUF 12 C, 34 C, 56 C,
  921: : SEEBUF FBUF C@  FBUF CHAR+ C@  FBUF CHAR+ CHAR+ C@ ;
  922: 
  923: { FBUF 0 20 FILL -> }
  924: { SEEBUF -> 00 00 00 }
  925: 
  926: { FBUF 1 20 FILL -> }
  927: { SEEBUF -> 20 00 00 }
  928: 
  929: { FBUF 3 20 FILL -> }
  930: { SEEBUF -> 20 20 20 }
  931: 
  932: { FBUF FBUF 3 CHARS MOVE -> }		\ BIZARRE SPECIAL CASE
  933: { SEEBUF -> 20 20 20 }
  934: 
  935: { SBUF FBUF 0 CHARS MOVE -> }
  936: { SEEBUF -> 20 20 20 }
  937: 
  938: { SBUF FBUF 1 CHARS MOVE -> }
  939: { SEEBUF -> 12 20 20 }
  940: 
  941: { SBUF FBUF 3 CHARS MOVE -> }
  942: { SEEBUF -> 12 34 56 }
  943: 
  944: { FBUF FBUF CHAR+ 2 CHARS MOVE -> }
  945: { SEEBUF -> 12 12 34 }
  946: 
  947: { FBUF CHAR+ FBUF 2 CHARS MOVE -> }
  948: { SEEBUF -> 12 34 34 }
  949: 
  950: \ ------------------------------------------------------------------------
  951: TESTING OUTPUT: . ." CR EMIT SPACE SPACES TYPE U.
  952: 
  953: : OUTPUT-TEST
  954:    ." YOU SHOULD SEE THE STANDARD GRAPHIC CHARACTERS:" CR
  955:    41 BL DO I EMIT LOOP CR
  956:    61 41 DO I EMIT LOOP CR
  957:    7F 61 DO I EMIT LOOP CR
  958:    ." YOU SHOULD SEE 0-9 SEPARATED BY A SPACE:" CR
  959:    9 1+ 0 DO I . LOOP CR
  960:    ." YOU SHOULD SEE 0-9 (WITH NO SPACES):" CR
  961:    [CHAR] 9 1+ [CHAR] 0 DO I 0 SPACES EMIT LOOP CR
  962:    ." YOU SHOULD SEE A-G SEPARATED BY A SPACE:" CR
  963:    [CHAR] G 1+ [CHAR] A DO I EMIT SPACE LOOP CR
  964:    ." YOU SHOULD SEE 0-5 SEPARATED BY TWO SPACES:" CR
  965:    5 1+ 0 DO I [CHAR] 0 + EMIT 2 SPACES LOOP CR
  966:    ." YOU SHOULD SEE TWO SEPARATE LINES:" CR
  967:    S" LINE 1" TYPE CR S" LINE 2" TYPE CR
  968:    ." YOU SHOULD SEE THE NUMBER RANGES OF SIGNED AND UNSIGNED NUMBERS:" CR
  969:    ."   SIGNED: " MIN-INT . MAX-INT . CR
  970:    ." UNSIGNED: " 0 U. MAX-UINT U. CR
  971: ;
  972: 
  973: { OUTPUT-TEST -> }
  974: 
  975: \ ------------------------------------------------------------------------
  976: \ commented out to allow batch testing -anton
  977: \ TESTING INPUT: ACCEPT
  978: 
  979: CREATE ABUF 80 CHARS ALLOT
  980: 
  981: : ACCEPT-TEST
  982:    CR ." PLEASE TYPE UP TO 80 CHARACTERS:" CR
  983:    ABUF 80 ACCEPT
  984:    CR ." RECEIVED: " [CHAR] " EMIT
  985:    ABUF SWAP TYPE [CHAR] " EMIT CR
  986: ;
  987: 
  988: \ { ACCEPT-TEST -> }
  989: 
  990: \ ------------------------------------------------------------------------
  991: TESTING DICTIONARY SEARCH RULES
  992: 
  993: { : GDX   123 ; : GDX   GDX 234 ; -> }
  994: 
  995: { GDX -> 123 234 }
  996: 
  997: 

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