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

  1. /* COMPARET.C
  2.  
  3.     Vrsn  Date   Comment
  4.     ----|-------|---------------------------------------------------------------
  5.     0.00 22nov94 Test <, >, =, <>, 0<, 0>, 0=, U< and U>.
  6.     0.01 23nov94 Unused variable removed from main.
  7.     0.02 28nov94 Changed reference to b_mem to one to M0.
  8.     0.03 29nov94 Unused variable removed from main; type specifiers added to
  9.                  parameters of step. Modified so that testing is automatic, and
  10.                  can run with or without debugging information.
  11.     0.04 17feb95 Modified to work with new version of storage.c, and use
  12.                  btests.h rather than bintern.h.
  13.     0.05 28feb95 Removed printf format error.
  14.  
  15.     Reuben Thomas
  16.  
  17.  
  18.     Test the comparison operators. Also uses the NEXT instruction. We
  19.     only test simple cases here, assuming that the C compiler's comparison
  20.     routines will work for other cases.
  21.  
  22. */
  23.  
  24.  
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <string.h>
  28. #include "beetle.h"     /* main header */
  29. #include "btests.h"    /* Beetle tests header */
  30. #include "opcodes.h"    /* opcode enumeration */
  31. #include "debug.h"      /* debugging functions */
  32.  
  33.  
  34. CELL correct[] = { 0, -1, 0, -1, -1, 0, 0, 0, -1, 0, 0, -1, 0, 0, -1, -1, 0, 0,
  35.     -1, 0, 0, -1, 0, 0, -1, 0, 0, -1};
  36.  
  37.  
  38. void stack1(void)
  39. {
  40.     SP = S0;    /* empty the stack */
  41.  
  42.     *--SP = -4; *--SP = 3; *--SP = 2; *--SP = 2; *--SP = 1; *--SP = 3;
  43.     *--SP = 3; *--SP = 1;
  44. }
  45.  
  46. void stack2(void)
  47. {
  48.     SP = S0;    /* empty the stack */
  49.     *--SP = 1; *--SP = -1; *--SP = 237; *--SP = 237;
  50. }
  51.  
  52. void stack3(void)
  53. {
  54.     SP = S0;    /* empty the stack */
  55.  
  56.     *--SP = -1; *--SP = 0; *--SP = 237;
  57. }
  58.  
  59. void step(int start, int end)
  60. {
  61.     int i;
  62.  
  63.     for (i = start; i <= end; i++) {
  64.         single_step();
  65. #ifdef B_DEBUG
  66.         printf("I = %s\n", disass(I));
  67. #endif
  68.         if (I != O_NEXT00) {
  69. #ifdef B_DEBUG
  70.             printf("Result: %d; correct result: %d\n\n", *SP,
  71.                 correct[i - i / 5]);
  72. #endif
  73.             if (correct[i - i / 5] != *SP) {
  74.                 printf("Error in CompareT: EP = %ld\n", val_EP());
  75.                 exit(1);
  76.             }
  77.             SP++;    /* drop result of comparison */
  78.         }
  79. #ifdef B_DEBUG
  80.         else putchar('\n');
  81. #endif
  82.     }
  83. }
  84.  
  85. int main(void)
  86. {
  87.     init_beetle((BYTE *)malloc(1024), 256, 16);
  88.     here = EP;
  89.     S0 = SP;    /* save base of stack */
  90.  
  91.     start_ass();
  92.     ass(O_LESS); ass(O_LESS); ass(O_LESS); ass(O_LESS);
  93.     ass(O_GREATER); ass(O_GREATER); ass(O_GREATER); ass(O_GREATER);
  94.     ass(O_EQUAL); ass(O_EQUAL); ass(O_NEQUAL); ass(O_NEQUAL);
  95.     ass(O_LESS0); ass(O_LESS0); ass(O_LESS0); ass(O_GREATER0);
  96.     ass(O_GREATER0); ass(O_GREATER0); ass(O_EQUAL0); ass(O_EQUAL0);
  97.     ass(O_ULESS); ass(O_ULESS); ass(O_ULESS); ass(O_ULESS);
  98.     ass(O_UGREATER); ass(O_UGREATER); ass(O_UGREATER); ass(O_UGREATER);
  99.     end_ass();
  100.  
  101.     NEXT;   /* load first instruction word */
  102.  
  103.     stack1();        /* set up the stack with four standard pairs to compare */
  104.     step(0, 4);        /* do the < tests */
  105.     stack1();
  106.     step(5, 9);        /* do the > tests */
  107.     stack2();        /* set up the stack with two standard pairs to compare */
  108.     step(10, 11);   /* do the = tests */
  109.     stack2();
  110.     step(12, 14);   /* do the <> tests */
  111.     stack3();        /* set up the stack with three standard values */
  112.     step(15, 17);   /* do the 0< tests */
  113.     stack3();
  114.     step(18, 21);   /* do the 0> tests */
  115.     SP = S0;  *--SP = 237; *--SP = 0;    /* set up the stack with two values */
  116.     step(22, 24);   /* do the 0= tests */
  117.     stack1();        /* set up the stack with four standard pairs to compare */
  118.     step(25, 29);   /* do the U< tests */
  119.     stack1();
  120.     step(30, 34);   /* do the U> tests */
  121.  
  122.     printf("CompareT ran OK\n");
  123.     return 0;
  124. }
  125.