home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / RiscOS / APP / DEVS / FORTH / BEETLE / BEETLE.ZIP / Beetle / aritmtit.c next >
C/C++ Source or Header  |  1997-04-22  |  3KB  |  95 lines

  1. /* ARITMTIT.C
  2.  
  3.     Vrsn  Date   Comment
  4.     ----|-------|---------------------------------------------------------------
  5.     0.00 18nov94 Test 0, 1, -1, CELL and -CELL.
  6.     0.01 19nov94 Added code to test +, -, >-<, 1+, 1-, CELL+, CELL-, *, /,
  7.                  MOD and /MOD.
  8.     0.02 20nov94 Added code to test 2/ and CELLS.
  9.     0.03 22nov94 Changed to work with new version of debug.h; added code to
  10.                  test ABS, NEGATE, MAX and MIN.
  11.     0.04 23nov94 Removed spurious variable from main.
  12.     0.05 28nov94 Changed reference to b_mem to one to M0.
  13.     0.06 29nov94 Modified so that testing is automatic, and can run with or
  14.                  without debugging information.
  15.     0.07 30nov94 Modified to give return value from main.
  16.     0.08 13jan95 Added code to test U/MOD and S/REM.
  17.     0.09 17feb95 Modified to work with new storage.c, and use btests.h rather
  18.                  than bintern.h.
  19.     0.10 28feb95 Corrected printf format error.
  20.  
  21.     Reuben Thomas
  22.  
  23.  
  24.     Test the arithmetic operators. Also uses the NEXT, SWAP, ROT, DROP, and
  25.     (LITERAL)I instructions. Since overtest.c supposedly tests the compiler's
  26.     arithmetic in overflow conditions, we only test the stack handling and basic
  27.     correctness of the operators here, assuming that if the arithmetic works in
  28.     one case, it will work in all. Note that the correct stack values are not
  29.     quite independent of the cell size (in CELL_W and QCELL_W); some stack
  30.     pictures implicitly refer to it.
  31.  
  32. */
  33.  
  34.  
  35. #include <stdio.h>
  36. #include <stdlib.h>
  37. #include <string.h>
  38. #include "beetle.h"     /* main header */
  39. #include "btests.h"    /* Beetle tests header */
  40. #include "opcodes.h"    /* opcode enumeration */
  41. #include "debug.h"      /* debugging functions */
  42.  
  43.  
  44. char *correct[] = { "", "0", "0 1", "0 1 -1", "0 1 -1 " QCELL_W,
  45.     "0 1 -1 " QCELL_W " -" QCELL_W, "0 1 " QCELL_W " -" QCELL_W " -1",
  46.     "0 1 " QCELL_W " -5", "0 1 -1", "0 2", "0 3", "0 2", "2 0", "2 " QCELL_W,
  47.     "2 0", "2 0 -1", "2 0 -1 " QCELL_W, "2 0 -" QCELL_W, "2 -" QCELL_W, "-2 -1",
  48.     "2", "2 -1", "0", "1", QCELL_W, "2", "", QCELL_W, "-" QCELL_W, QCELL_W,
  49.     QCELL_W, QCELL_W " 1", QCELL_W, QCELL_W " -" QCELL_W, "-" QCELL_W,
  50.     "-" QCELL_W " 3", "-1 -1", "-1", "-1 -2", "1 1" };
  51.  
  52.  
  53. int main(void)
  54. {
  55.     int i;
  56.  
  57.     init_beetle((BYTE *)malloc(1024), 256, 16);
  58.     here = EP;
  59.     S0 = SP;    /* save base of stack */
  60.  
  61.     start_ass();
  62.     ass(O_ZERO); ass(O_ONE); ass(O_MONE); ass(O_CELL);
  63.     ass(O_MCELL); ass(O_ROT); ass(O_PLUS); ass(O_PLUS);
  64.     ass(O_MINUS); ass(O_PLUS1); ass(O_MINUS1); ass(O_SWAP);
  65.     ass(O_PLUSCELL); ass(O_MINUSCELL); ass(O_MONE); ass(O_CELL);
  66.     ass(O_STAR); ass(O_SWAPMINUS); ass(O_SLASHMOD); ass(O_SLASH);
  67.     ass(O_MONE); ass(O_MOD); ass(O_PLUS1); ass(O_CELLS);
  68.     ass(O_SLASH2); ass(O_DROP); ass(O_CELL); ass(O_NEGATE);
  69.     ass(O_ABS); ass(O_ABS); ass(O_ONE); ass(O_MAX);
  70.     ass(O_MCELL); ass(O_MIN); ass(O_LITERALI); ilit(3);
  71.     ass(O_SSLASHREM); ass(O_DROP); ass(O_LITERALI); ilit(-2);
  72.     ass(O_USLASHMOD); ass(O_NEXTFF);
  73.     end_ass();
  74.  
  75.     NEXT;   /* load first instruction word */
  76.  
  77.     for (i = 0; i <= instrs - instrs / 5; i++) {
  78. #ifdef B_DEBUG
  79.         show_data_stack();  printf("Correct stack: %s\n\n", correct[i]);
  80. #endif
  81.         if (strcmp(correct[i], val_data_stack())) {
  82.             printf("Error in AritmtiT: EP = %ld\n", val_EP());
  83.             exit(1);
  84.         }
  85.         single_step();
  86.         if (I == O_NEXT00) i--;
  87. #ifdef B_DEBUG
  88.         printf("I = %s\n", disass(I));
  89. #endif
  90.     }
  91.  
  92.     printf("AritmtiT ran OK\n");
  93.     return 0;
  94. }
  95.