home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / Apps / DevTools / COWS / Fred / COWSTestBench.m < prev    next >
Encoding:
Text File  |  1995-06-12  |  2.6 KB  |  129 lines

  1. /*
  2.     Copyright (C) 1994 Sean Luke
  3.  
  4.     COWSTestBench.m
  5.     Version 1.0
  6.     
  7.     Speciall Modified for Fred!
  8.     
  9.     Sean Luke
  10.     
  11.     This object is just a front end to make the interpreter look pretty in this
  12.     example program...
  13.     
  14. */
  15.  
  16. #import "COWSTestBench.h"
  17. #import "COWSInterpreter.h"
  18. #import <appkit/appkit.h>
  19. #import "COWSLibrary.h"
  20. #import "COWSStringNode.h"
  21. #import <string.h>
  22.  
  23. @implementation COWSTestBench
  24.  
  25. - print:sender
  26. {
  27.     [interpreter printProgram];
  28.     [interpreter printDictionaries];
  29.     return self;
  30. }
  31.  
  32. - setTimedEntry:sender
  33. {
  34.     [interpreter setForeground: (BOOL)[[foreground cellAt:0:0] intValue]];
  35.     [interpreter setLocked: [locked intValue]];
  36.     [interpreter setTimedEntrySpeed:[timedEntry floatValue]];
  37.     [interpreter setRepeats:[repeats intValue]];
  38.     [self revertTimedEntry:sender];                    // makes fields pretty
  39.     return self;
  40. }
  41.  
  42. - revertTimedEntry:sender
  43. {
  44.     [foreground selectCellAt:
  45.         ([interpreter foreground] ? 0 : 1):0];
  46.     [timedEntry setFloatValue:[interpreter timedEntrySpeed]];
  47.     [repeats setIntValue:[interpreter repeats]];
  48.     [locked setIntValue:[interpreter locked]];
  49.     return self;
  50. }
  51.  
  52. - load:sender
  53. {
  54.     int x=[program textLength];
  55.     char prog[x+1];
  56.     
  57.     [program getSubstring:prog start:0 length:x];
  58.     prog[x]='\0';                            // some bug in Text object
  59.     [interpreter clearLibraryFunctions];
  60.     [interpreter addLibrary:library];
  61.     [interpreter addLibrary:fred];
  62.     [interpreter setDelegate:self];
  63.     if ([interpreter setProgram:prog]>=0)
  64.         {
  65.         printf ("LOADED PROGRAM\n");
  66.         }
  67.     else printf ("ERROR PARSING PROGRAM\n");
  68.     return self;
  69. }
  70.  
  71. - execute:sender
  72. {
  73.     id arg_list=[[COWSArgumentList alloc] init];
  74.     int m=1;
  75.     id args=[[COWSArgumentList alloc] init];
  76.         
  77.     while (m<=6&&strlen([[matrix cellAt:m:0] stringValue]))
  78.         {
  79.         id temp=[[COWSStringNode alloc] init];
  80.         [temp setString:[[matrix cellAt:m:0] stringValue]];
  81.         [arg_list push:temp]; 
  82.         m++;
  83.         }
  84.     
  85.     // this is in wrong order...so reverse it...
  86.     
  87.     while([arg_list top]!=NULL)
  88.         {
  89.         [args push:[arg_list pop]];
  90.         }
  91.     [arg_list free];
  92.         
  93.     [interpreter interpretFunction:[[matrix cellAt:0:0] stringValue]
  94.         arguments:args];
  95.     [args free];
  96.     return self;
  97. }
  98.  
  99. - loadAndExecute:sender
  100. {
  101.     [self load:self];
  102.     [self execute:self];
  103.     return self;
  104. }
  105.  
  106. - stop:sender
  107. {
  108.     printf("\nSTOPPED PROGRAM\n");
  109.     [interpreter stopInterpreting];
  110.     return self;
  111. }
  112.  
  113.  
  114. - finishedInterpreting:(const char*)returnValue:(int)thisMessage:sender
  115. {
  116.     printf("\n FINISHED PROGRAM message: %d  return:  %s\n",thisMessage,returnValue);
  117.     return self;
  118. }
  119.  
  120. - errorInterpreting:(int) thisError:(const char*)thisFunction:
  121.     (int)thisPosition:(const char*)thisString:sender
  122. {
  123.     // doesn't do anything right now...my errors are printed to stdout.
  124.     return self;
  125. }
  126.  
  127.  
  128. @end
  129.