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

  1. /* DOLOOPT.C
  2.  
  3.     Vrsn  Date   Comment
  4.     ----|-------|---------------------------------------------------------------
  5.     0.00 26nov94 Test (DO), (LOOP), (LOOP)I.
  6.     0.01 27nov94 Added code to test (+LOOP) and (+LOOP)I.
  7.     0.02 28nov94 Added code to test J, and used val_EP from debug.c (that's
  8.                  what it's for!).
  9.     0.03 30nov94 Modified so that testing is automatic, and can run with or
  10.                  without debugging information. Modified to give a return value
  11.                  from main.
  12.     0.04 13jan95 Added code to test UNLOOP.
  13.     0.05 17feb95 Modified to work with new version of storage.c, and use
  14.                  btests.h rather than bintern.h.
  15.     0.06 28feb95 Removed printf format errors.
  16.  
  17.     Reuben Thomas
  18.  
  19.  
  20.     Test the DO...LOOP support instructions. Also uses instructions with
  21.     lower opcodes.
  22.  
  23. */
  24.  
  25.  
  26. #include <stdio.h>
  27. #include <stdlib.h>
  28. #include <string.h>
  29. #include "beetle.h"     /* main header */
  30. #include "btests.h"    /* Beetle tests header */
  31. #include "opcodes.h"    /* opcode enumeration */
  32. #include "debug.h"      /* debugging functions */
  33.  
  34.  
  35. char *correct[] = { "0 1 2", "3 2 1 0", "1", "1 2 3 4", "1 1" };
  36.  
  37.  
  38. int main(void)
  39. {
  40.     int i;
  41.  
  42.     init_beetle((BYTE *)malloc(1024), 256, 16);
  43.     here = EP;
  44.     S0 = SP;    /* save base of stack */
  45.  
  46.     start_ass();
  47.     ass(O_LITERALI); ilit(3);
  48.     ass(O_ZERO); ass(O_DO); ilit(0);    /* pad instruction word with NEXT */
  49.     ass(O_RFETCH); ass(O_LOOP); lit(24); ilit(0);   /* pad instruction word with
  50.                                                        NEXT */
  51.     ass(O_ZERO); ass(O_LITERAL); lit(3); ass(O_DO); ass(O_NEXT00);
  52.     ass(O_RFETCH); ass(O_MONE); ass(O_PLOOPI); ilit(-1);
  53.     ass(O_CELL); ass(O_ONE); ass(O_DO); ass(O_NEXT00);
  54.     ass(O_RFETCH); ass(O_CELL); ass(O_PLOOP); lit(48); ass(O_NEXT00);
  55.     ass(O_ONE); ass(O_ONE); ass(O_DO); ass(O_NEXT00);
  56.     ass(O_RFETCH); ass(O_LOOPI); ilit(-1);
  57.     ass(O_ONE); ass(O_TOR); ass(O_CELL); ass(O_TOR);
  58.     ass(O_MONE); ass(O_TOR); ass(O_J); ass(O_NEXT00);
  59.     ass(O_DUP); ass(O_UNLOOP);
  60.     end_ass();
  61.  
  62.     NEXT;   /* load first instruction word */
  63.  
  64.     while (val_EP() < 36) single_step();
  65. #ifdef B_DEBUG
  66.     show_data_stack();  printf("Correct stack: %s\n\n", correct[0]);
  67. #endif
  68.     if (strcmp(correct[0], val_data_stack())) {
  69.         printf("Error in DoLoopT: EP = %ld\n", val_EP());
  70.         exit(1);
  71.     }
  72.     SP = S0;
  73.  
  74.     while (val_EP() < 48) single_step();
  75. #ifdef B_DEBUG
  76.     show_data_stack();  printf("Correct stack: %s\n\n", correct[1]);
  77. #endif
  78.     if (strcmp(correct[1], val_data_stack())) {
  79.         printf("Error in DoLoopT: EP = %ld\n", val_EP());
  80.         exit(1);
  81.     }
  82.     SP = S0;
  83.  
  84.     while (val_EP() < 56) single_step();
  85. #ifdef B_DEBUG
  86.     show_data_stack();  printf("Correct stack: %s\n\n", correct[2]);
  87. #endif
  88.     if (strcmp(correct[2], val_data_stack())) {
  89.         printf("Error in DoLoopT: EP = %ld\n", val_EP());
  90.         exit(1);
  91.     }
  92.     SP = S0;
  93.  
  94.     for (i = 0; i < 12; i++) single_step();
  95. #ifdef B_DEBUG
  96.     show_data_stack();  printf("Correct stack: %s\n\n", correct[3]);
  97. #endif
  98.     if (strcmp(correct[3], val_data_stack())) {
  99.         printf("Error in DoLoopT: EP = %ld\n", val_EP());
  100.         exit(1);
  101.     }
  102.     SP = S0;
  103.  
  104.     EP = (CELL *)(64 + M0);  NEXT;    /* start execution at 64 */
  105.     while (((BYTE *)EP - M0) < 76) single_step();
  106. #ifdef B_DEBUG
  107.     printf("3rd item on return stack is %d (should be %d).\n", *(RP + 2), *SP);
  108. #endif
  109.     if (*(RP + 2) != *SP) {
  110.         printf("Error in DoLoopT: EP = %ld\n", val_EP());
  111.         exit(1);
  112.     }
  113.  
  114.     single_step(); single_step();
  115. #ifdef B_DEBUG
  116.     show_data_stack();  printf("Correct stack: %s\n\n", correct[4]);
  117. #endif
  118.     if (strcmp(correct[4], val_data_stack())) {
  119.         printf("Error in DoLoopT: EP = %ld\n", val_EP());
  120.         exit(1);
  121.     }
  122.  
  123.     printf("DoLoopT ran OK\n");
  124.     return 0;
  125. }
  126.