From b87ebad78830f8c2c0d515934b7d11a98d338313 Mon Sep 17 00:00:00 2001 From: Lassi Kortela Date: Fri, 5 Aug 2022 12:28:41 +0300 Subject: [PATCH] GScheme-20050303.tar --- #EnvWindow.m# | 171 ++ Document.h | 14 +- Document.m | 160 +- EnvWindow.h | 12 +- EnvWindow.m | 127 +- GNUmakefile | 2 +- GScheme.app/GScheme | 218 --- GScheme.app/Resources/GScheme.desktop | 8 - GScheme.app/Resources/Info-gnustep.plist | 29 - GScheme.app/Resources/library.scm | 109 -- GScheme.app/Resources/library.scm~ | 103 - GSchemeInfo.plist | 7 +- Icons/GScheme.tiff | Bin 0 -> 9592 bytes Icons/lambda1.tiff | Bin 0 -> 9592 bytes NOTES | 6 + Primitive.h | 130 ++ Primitive.m | 1023 +++++++++- SCMTextView.h | 9 +- SCMTextView.m | 52 +- Scheme/library.scm | 43 + Scheme/library.scm~ | 44 + SchemeDelegate.h | 10 +- SchemeDelegate.m | 461 +++-- SchemeTypes.h | 45 +- SchemeTypes.m | 255 +-- TestScheme.app/Resources/Info-gnustep.plist | 6 - TestScheme.app/Resources/TestScheme.desktop | 5 - TestScheme.app/TestScheme | 218 --- VScheme.h | 38 +- VScheme.m | 722 +++++-- examples/allocate1.scm | 6 + examples/args1.scm | 6 + examples/args2.scm | 6 + examples/browse.scm | 1 - examples/eval.scm | 33 + examples/eval1.scm | 56 + examples/library.scm | 3 + examples/mandel.scm | 37 + examples/parse-error.scm | 8 + examples/parse-error1.scm | 55 + examples/parse-error2.scm | 28 + examples/parse-error3.scm | 6 + examples/parse-error4.scm | 6 + examples/plotfancy.scm | 49 + examples/qsort.scm | 143 ++ examples/qsort1.scm | 181 ++ examples/queenspic.scm | 98 + examples/randcircles.scm | 17 + examples/random.scm | 28 + examples/randrects.scm | 18 + examples/strings.scm | 119 ++ examples/text.scm | 31 + lex.yy.c | 1939 ------------------- scheme.flex | 2 +- scheme.lex.m | 2 +- scheme.tab.m | 1112 +++++++---- scheme.y | 164 +- 57 files changed, 4430 insertions(+), 3751 deletions(-) create mode 100644 #EnvWindow.m# delete mode 100755 GScheme.app/GScheme delete mode 100644 GScheme.app/Resources/GScheme.desktop delete mode 100644 GScheme.app/Resources/Info-gnustep.plist delete mode 100644 GScheme.app/Resources/library.scm delete mode 100644 GScheme.app/Resources/library.scm~ create mode 100644 Icons/GScheme.tiff create mode 100644 Icons/lambda1.tiff create mode 100644 NOTES delete mode 100644 TestScheme.app/Resources/Info-gnustep.plist delete mode 100644 TestScheme.app/Resources/TestScheme.desktop delete mode 100755 TestScheme.app/TestScheme create mode 100644 examples/allocate1.scm create mode 100644 examples/args1.scm create mode 100644 examples/args2.scm create mode 100644 examples/eval.scm create mode 100644 examples/eval1.scm create mode 100644 examples/mandel.scm create mode 100644 examples/parse-error.scm create mode 100644 examples/parse-error1.scm create mode 100644 examples/parse-error2.scm create mode 100644 examples/parse-error3.scm create mode 100644 examples/parse-error4.scm create mode 100644 examples/plotfancy.scm create mode 100644 examples/qsort.scm create mode 100644 examples/qsort1.scm create mode 100644 examples/queenspic.scm create mode 100644 examples/randcircles.scm create mode 100644 examples/random.scm create mode 100644 examples/randrects.scm create mode 100644 examples/strings.scm create mode 100644 examples/text.scm delete mode 100644 lex.yy.c diff --git a/#EnvWindow.m# b/#EnvWindow.m# new file mode 100644 index 0000000..b955a15 --- /dev/null +++ b/#EnvWindow.m# @@ -0,0 +1,171 @@ + +#import "EnvWindow.h" +#import "VScheme.h" + +@implementation EnvWindow + +#define WIDTH 300 +#define HEIGHT 200 + +static int count = 0; +- initWithEnv:(Environment *)env +{ + NSWindow *window; + Environment *layer; int lind; + NSRect contentRect = {{0, 0}, {WIDTH, HEIGHT}}; + NSRect winRect = + {{250+(count%12)*24, 100+(count%12)*24}, {WIDTH, HEIGHT}}; + NSRect textRect; + unsigned int style = NSTitledWindowMask | NSClosableWindowMask | + NSMiniaturizableWindowMask | NSResizableWindowMask; + NSString *title = + [NSString stringWithFormat:@"Scheme Env. # %d", ++count]; + + length = [env chainLength]; + names = NSZoneMalloc([self zone], length*sizeof(id)); + values = NSZoneMalloc([self zone], length*sizeof(id)); + + NSAutoreleasePool *pool = [NSAutoreleasePool new]; + + for(lind=length-1, layer = env; lind>=0; lind--){ + NSMapTable *data = [layer data]; + + names[lind] = [NSMutableArray arrayWithArray:[data allKeys]]; + [names[lind] sortUsingSelector:@selector(compare:)]; + [names[lind] retain]; + + values[lind] = [NSMutableArray arrayWithCapacity:[names[lind] count]]; + [values[lind] retain]; + + NSMapEnumerator en = [names[lind] objectEnumerator]; + id key, val; + while(NSNextMapEnumeratorPair(&enumerator, (void**)&key, (void**)&val)){ + id obj = NSMapGet(data, key); + [values[lind] addObject:[VScheme valToString:obj]]; + } + + layer = [layer parent]; + } + + [pool release]; + + [self initWithContentRect:winRect + styleMask:style + backing:NSBackingStoreRetained + defer:NO]; + [self setMinSize:NSMakeSize(WIDTH, HEIGHT)]; + [self setReleasedWhenClosed:YES]; + + + NSTableColumn *nameColumn, *valueColumn; + + nameColumn = + [(NSTableColumn *)[NSTableColumn alloc] + initWithIdentifier: @"Name"]; + [nameColumn setEditable: NO]; + [[nameColumn headerCell] setStringValue: @"Name"]; + [nameColumn setMinWidth:WIDTH/2]; + + valueColumn = + [(NSTableColumn *)[NSTableColumn alloc] + initWithIdentifier: @"Value"]; + [valueColumn setEditable: NO]; + [[valueColumn headerCell] setStringValue: @"Value"]; + [valueColumn setMinWidth:WIDTH/2]; + + table = + [[NSTableView alloc] initWithFrame:contentRect]; + [table addTableColumn:nameColumn]; RELEASE(nameColumn); + [table addTableColumn:valueColumn]; RELEASE(valueColumn); + + current=length-1; + [table setDataSource:self]; + + scrollView = [[NSScrollView alloc] initWithFrame:contentRect]; + [scrollView setHasHorizontalScroller:YES]; + [scrollView setHasVerticalScroller:YES]; + [scrollView setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable]; + [[scrollView contentView] + setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable]; + [[scrollView contentView] setAutoresizesSubviews:YES]; + + [table setFrameSize:[scrollView contentSize]]; + [scrollView setDocumentView:table]; + + [self setContentView:scrollView]; + // RELEASE(scrollView); + + [self setTitle:title]; + [self display]; + [self makeKeyAndOrderFront:nil]; + + return self; +} + +- up:(id)sender +{ + if(!current){ + NSBeep(); + } + else{ + current--; + [table reloadData]; + } + + return self; +} + +- down:(id)sender +{ + if(current==length-1){ + NSBeep(); + } + else{ + current++; + [table reloadData]; + } + + return self; +} + +- (int)numberOfRowsInTableView:(NSTableView *)aTableView +{ + return [names[current] count]; +} + +- (id)tableView:(NSTableView *)aTableView + objectValueForTableColumn:(NSTableColumn *)aTableColumn + row:(int)rowIndex +{ + if(rowIndex>=[names[current] count]){ + return nil; + } + + if([[aTableColumn identifier] isEqualToString:@"Name"]){ + return [names[current] objectAtIndex:rowIndex]; + } + else{ + return [values[current] objectAtIndex:rowIndex]; + } +} + +- (void)dealloc +{ + int ind; + + [table release]; + [scrollView release]; + + for(ind=0; ind #import #import -#import + +#import "SCMTextView.h" @interface Document : NSDocument { - NSTextView *tview; + NSScrollView *sview; + SCMTextView *tview; + NSString *progstr; BOOL readOnly; } - init; -- (void)dealloc; - +- (void)textDidChange:(NSNotification *)textObject; - (void)makeWindowControllers; - evaluate:(id)sender; @@ -48,6 +50,8 @@ - (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)aType; - (BOOL)readFromFile:(NSString *)fileName ofType:(NSString *)docType; -- (BOOL)writeToFile:(NSString *)fileName ofType:(NSString *)docType; +- (BOOL)writeToFile:(NSString *)fullDocumentPath ofType:(NSString *)docType + originalFile:(NSString *)fullOriginalDocumentPath + saveOperation:(NSSaveOperationType)saveOperationType; @end diff --git a/Document.m b/Document.m index 100f780..2d75024 100644 --- a/Document.m +++ b/Document.m @@ -26,6 +26,7 @@ */ #include #include + #include "Document.h" #include "SCMTextView.h" @@ -43,10 +44,9 @@ return [super init]; } -- (void)dealloc +- (void)textDidChange:(NSNotification *)textObject { - // RELEASE (tview); - [super dealloc]; + [self updateChangeCount: NSChangeDone]; } - (NSData *)dataRepresentationOfType:(NSString *)aType @@ -58,7 +58,6 @@ NSString *msg = [NSString stringWithFormat: @"Unknown type: %@", [aType uppercaseString]]; NSRunAlertPanel(@"Alert", msg, @"Ok", nil, nil); - // [msg autorelease]; return nil; } } @@ -73,8 +72,7 @@ NSString *msg = [NSString stringWithFormat: @"Unknown type: %@", [aType uppercaseString]]; NSRunAlertPanel(@"Alert", msg, @"Ok", nil, nil); - // [msg autorelease]; - return NO; + return NO; } return YES; @@ -90,29 +88,31 @@ readOnly = YES; NSRunAlertPanel(@"Alert", msg, @"Ok", nil, nil); - // [msg autorelease]; - } + } return [super readFromFile:fileName ofType:docType]; } -- (BOOL)writeToFile:(NSString *)fileName ofType:(NSString *)docType +- (BOOL)writeToFile:(NSString *)fullDocumentPath ofType:(NSString *)docType + originalFile:(NSString *)fullOriginalDocumentPath + saveOperation:(NSSaveOperationType)saveOperationType; { - BOOL result = [super writeToFile:fileName ofType:docType]; - if(result==YES && readOnly==YES){ + BOOL result = + [super writeToFile:fullDocumentPath ofType:docType + originalFile:fullOriginalDocumentPath + saveOperation:saveOperationType]; + if(result==YES && readOnly==YES && saveOperationType==NSSaveAsOperation){ NSString *msg = [NSString stringWithFormat: @"File now writable: %@", - fileName]; + fullDocumentPath]; NSRunAlertPanel(@"Alert", msg, @"Ok", nil, nil); - // [msg autorelease]; - + readOnly = NO; [tview setEditable:YES]; } else if(result==NO){ NSString *msg = [NSString stringWithFormat: @"Write failed: %@", - fileName]; + fullDocumentPath]; NSRunAlertPanel(@"Alert", msg, @"Ok", nil, nil); - // [msg autorelease]; } return result; @@ -136,12 +136,19 @@ extern NSWindow *interpreterWindow; res = [vm processString:progstr mode:MODE_EVALUATE]; if(res==NO){ + int errpos = [vm errpos]; + if(errpos!=-1){ + [tview selectLineAtPos:errpos]; + } + NSRunAlertPanel(@"Error", [vm errmsg], @"Ok", nil, nil); } else{ [interpreterWindow makeKeyAndOrderFront:self]; } + + return self; } - (void) makeWindowControllers @@ -150,88 +157,89 @@ extern NSWindow *interpreterWindow; NSWindow *win = [self makeWindow]; controller = [[NSWindowController alloc] initWithWindow: win]; - // RELEASE (win); + RELEASE (win); [self addWindowController:controller]; - // RELEASE(controller); + RELEASE(controller); // We have to do this ourself, as there is currently no nib file [self windowControllerDidLoadNib:controller]; } - @end +int shiftPos = 0; +#define WREP 7 + @implementation Document (Private) -static int shiftPos = 0; -#define WREP 7 - - (NSWindow*)makeWindow { - NSWindow *window; - NSScrollView *scrollView; - NSTextView *textView; - NSRect scrollViewRect = {{0, 0}, {470, 400}}; - NSRect winRect = {{100+25*(shiftPos%WREP), 100+25*(shiftPos%WREP)}, - {470, 400}}; - NSRect textRect; - unsigned int style = NSTitledWindowMask | NSClosableWindowMask | - NSMiniaturizableWindowMask | NSResizableWindowMask; - shiftPos++; + NSWindow *window; + NSScrollView *scrollView; + SCMTextView *textView; + NSRect scrollViewRect = {{0, 0}, {470, 400}}; + NSRect winRect = {{100+25*(shiftPos%WREP), 100+25*(shiftPos%WREP)}, + {470, 400}}; + NSRect textRect; + unsigned int style = NSTitledWindowMask | NSClosableWindowMask | + NSMiniaturizableWindowMask | NSResizableWindowMask; + shiftPos++; - // This is expected to be retained, as it would normaly come from a - // nib file, where the owner would retain it. - window = [[NSWindow alloc] initWithContentRect: winRect - styleMask: style - backing: NSBackingStoreRetained - defer: NO]; - [window setMinSize:NSMakeSize(300, 300)]; + // This is expected to be retained, as it would normaly come from a + // nib file, where the owner would retain it. + window = [[NSWindow alloc] initWithContentRect: winRect + styleMask: style + backing: NSBackingStoreRetained + defer: NO]; + [window setMinSize:NSMakeSize(300, 300)]; + [window setReleasedWhenClosed:YES]; - scrollView = [[NSScrollView alloc] initWithFrame: scrollViewRect]; - [scrollView setHasHorizontalScroller: NO]; - [scrollView setHasVerticalScroller: YES]; - [scrollView setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable]; - [[scrollView contentView] setAutoresizingMask: NSViewHeightSizable - | NSViewWidthSizable]; - [[scrollView contentView] setAutoresizesSubviews:YES]; + scrollView = [[NSScrollView alloc] initWithFrame: scrollViewRect]; + [scrollView setHasHorizontalScroller: NO]; + [scrollView setHasVerticalScroller: YES]; + [scrollView setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable]; + [[scrollView contentView] setAutoresizingMask: NSViewHeightSizable + | NSViewWidthSizable]; + [[scrollView contentView] setAutoresizesSubviews:YES]; + sview = scrollView; - // Build up the text network - textRect = [[scrollView contentView] frame]; - textView = [[SCMTextView alloc] initWithFrame: textRect]; + // Build up the text network + textRect = [[scrollView contentView] frame]; + textView = [[SCMTextView alloc] initWithFrame: textRect]; - [textView setBackgroundColor: [NSColor whiteColor]]; + [textView setBackgroundColor: [NSColor whiteColor]]; - [textView setString:progstr]; - [textView setFont:[NSFont userFixedPitchFontOfSize:12]]; - [textView setEditable:(readOnly==NO ? YES : NO)]; + [textView setString:progstr]; + [textView setFont:[NSFont userFixedPitchFontOfSize:12]]; + [textView setEditable:(readOnly==NO ? YES : NO)]; - [textView setDelegate: self]; - [textView setHorizontallyResizable: NO]; - [textView setVerticallyResizable: YES]; - [textView setMinSize: NSMakeSize (0, 0)]; - [textView setMaxSize: NSMakeSize (1E7, 1E7)]; - [textView setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable]; - [[textView textContainer] setContainerSize: NSMakeSize (textRect.size.width, - 1e7)]; - [[textView textContainer] setWidthTracksTextView: YES]; - // Store the text view in an ivar - tview = textView; + [textView setDelegate: self]; + [textView setHorizontallyResizable: NO]; + [textView setVerticallyResizable: YES]; + [textView setMinSize: NSMakeSize (0, 0)]; + [textView setMaxSize: NSMakeSize (1E7, 1E7)]; + [textView setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable]; + [[textView textContainer] setContainerSize: NSMakeSize (textRect.size.width, + 1e7)]; + [[textView textContainer] setWidthTracksTextView: YES]; + // Store the text view in an ivar + tview = textView; - [scrollView setDocumentView: textView]; - // RELEASE(textView); - [window setContentView: scrollView]; - // RELEASE(scrollView); + [scrollView setDocumentView: textView]; + RELEASE(textView); + [window setContentView: scrollView]; + RELEASE(scrollView); - // Make the Document the delegate of the window - [window setDelegate: self]; + // Make the Document the delegate of the window + [window setDelegate: self]; + [window setTitle:[self displayName]]; - // Make the text view the first responder - [window makeFirstResponder:textView]; - [window display]; - [window orderFront: nil]; + // Make the text view the first responder + [window makeFirstResponder:textView]; + [window display]; + [window orderFront: nil]; - return window; + return window; } - @end diff --git a/EnvWindow.h b/EnvWindow.h index 1d619e1..220e440 100644 --- a/EnvWindow.h +++ b/EnvWindow.h @@ -8,9 +8,11 @@ int current; int length; - id *forms; + id *names; + id *values; NSScrollView *scrollView; + NSTableView *table; } - initWithEnv:(Environment *)env; @@ -18,7 +20,13 @@ - up:(id)sender; - down:(id)sender; -- releaseForms; +- (int)numberOfRowsInTableView:(NSTableView *)aTableView; +- (id)tableView:(NSTableView *)aTableView + objectValueForTableColumn:(NSTableColumn *)aTableColumn + row:(int)rowIndex; + + +- (void)dealloc; @end diff --git a/EnvWindow.m b/EnvWindow.m index f54af3c..8e7447f 100644 --- a/EnvWindow.m +++ b/EnvWindow.m @@ -12,7 +12,7 @@ static int count = 0; { NSWindow *window; Environment *layer; int lind; - NSRect scrollViewRect = {{0, 0}, {WIDTH, HEIGHT}}; + NSRect contentRect = {{0, 0}, {WIDTH, HEIGHT}}; NSRect winRect = {{250+(count%12)*24, 100+(count%12)*24}, {WIDTH, HEIGHT}}; NSRect textRect; @@ -21,59 +21,76 @@ static int count = 0; NSString *title = [NSString stringWithFormat:@"Scheme Env. # %d", ++count]; - length = [env chainLength]; current=length-1; - forms = NSZoneMalloc([self zone], length*sizeof(id)); + length = [env chainLength]; + names = NSZoneMalloc([self zone], length*sizeof(id)); + values = NSZoneMalloc([self zone], length*sizeof(id)); + NSAutoreleasePool *pool = [NSAutoreleasePool new]; + for(lind=length-1, layer = env; lind>=0; lind--){ - NSMutableDictionary *data = [layer data]; - NSMutableArray *keys; - NSEnumerator *en; - id key, form; + NSMapTable *data = [layer data]; - keys = [NSMutableArray arrayWithCapacity:1]; - [keys setArray:[data allKeys]]; - [keys sortUsingSelector:@selector(compare:)]; + names[lind] = [NSMutableArray arrayWithArray:NSAllMapTableKeys(data)]; + [names[lind] sortUsingSelector:@selector(compare:)]; + [names[lind] retain]; + + values[lind] = [NSMutableArray arrayWithCapacity:[names[lind] count]]; + [values[lind] retain]; - en = [keys objectEnumerator]; - - - forms[lind] = form = - [[NSForm alloc] initWithFrame:scrollViewRect]; + NSEnumerator *en = [names[lind] objectEnumerator]; + id key; while((key = [en nextObject])!=nil){ - id obj = [data objectForKey:key]; - id ctitle = [NSString stringWithFormat:@" %@ ", key]; - id cell = [form addEntry:ctitle]; - - [cell setEditable:NO]; - [cell setEnabled:NO]; - [cell setStringValue:[VScheme valToString:obj]]; + id obj = NSMapGet(data, key); + [values[lind] addObject:[VScheme valToString:obj]]; } - - [form setEntryWidth:WIDTH]; - [form setAutosizesCells:YES]; - [form setAutoresizingMask:NSViewWidthSizable]; - - // [form retain]; - + layer = [layer parent]; } + [pool release]; + [self initWithContentRect:winRect styleMask:style backing:NSBackingStoreRetained defer:NO]; [self setMinSize:NSMakeSize(WIDTH, HEIGHT)]; [self setReleasedWhenClosed:YES]; + + + NSTableColumn *nameColumn, *valueColumn; + + nameColumn = + [(NSTableColumn *)[NSTableColumn alloc] + initWithIdentifier: @"Name"]; + [nameColumn setEditable: NO]; + [[nameColumn headerCell] setStringValue: @"Name"]; + [nameColumn setMinWidth:WIDTH/2]; + + valueColumn = + [(NSTableColumn *)[NSTableColumn alloc] + initWithIdentifier: @"Value"]; + [valueColumn setEditable: NO]; + [[valueColumn headerCell] setStringValue: @"Value"]; + [valueColumn setMinWidth:WIDTH/2]; + + table = + [[NSTableView alloc] initWithFrame:contentRect]; + [table addTableColumn:nameColumn]; RELEASE(nameColumn); + [table addTableColumn:valueColumn]; RELEASE(valueColumn); + + current=length-1; + [table setDataSource:self]; - scrollView = [[NSScrollView alloc] initWithFrame: scrollViewRect]; + scrollView = [[NSScrollView alloc] initWithFrame:contentRect]; [scrollView setHasHorizontalScroller:YES]; [scrollView setHasVerticalScroller:YES]; [scrollView setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable]; - [[scrollView contentView] setAutoresizingMask: NSViewHeightSizable - | NSViewWidthSizable]; + [[scrollView contentView] + setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable]; [[scrollView contentView] setAutoresizesSubviews:YES]; - [scrollView setDocumentView:forms[current]]; + [table setFrameSize:[scrollView contentSize]]; + [scrollView setDocumentView:table]; [self setContentView:scrollView]; // RELEASE(scrollView); @@ -91,10 +108,8 @@ static int count = 0; NSBeep(); } else{ - NSRect bounds = [forms[current] bounds]; current--; - [forms[current] setEntryWidth:bounds.size.width]; - [scrollView setDocumentView:forms[current]]; + [table reloadData]; } return self; @@ -106,29 +121,51 @@ static int count = 0; NSBeep(); } else{ - NSRect bounds = [forms[current] bounds]; current++; - [forms[current] setEntryWidth:bounds.size.width]; - [scrollView setDocumentView:forms[current]]; + [table reloadData]; } return self; } -- releaseForms +- (int)numberOfRowsInTableView:(NSTableView *)aTableView +{ + return [names[current] count]; +} + +- (id)tableView:(NSTableView *)aTableView + objectValueForTableColumn:(NSTableColumn *)aTableColumn + row:(int)rowIndex +{ + if(rowIndex>=[names[current] count]){ + return nil; + } + + if([[aTableColumn identifier] isEqualToString:@"Name"]){ + return [names[current] objectAtIndex:rowIndex]; + } + else{ + return [values[current] objectAtIndex:rowIndex]; + } +} + +- (void)dealloc { int ind; - [scrollView setDocumentView:nil]; + [table release]; [scrollView release]; for(ind=0; ind -# Date: May 1999 -# -# This file is part of the GNUstep Makefile Package. -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# You should have received a copy of the GNU General Public -# License along with this library; see the file COPYING.LIB. -# If not, write to the Free Software Foundation, -# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -# This is a shell script which attempts to find the GNUstep executable -# of the same name based on the current host and library_combo. - -#-------------------------------------------------------------------------- -# Main body -#-------------------------------------------------------------------------- -if [ -z "$EXEEXT" ]; then - EXEEXT= -fi -if [ -z "$LIBRARY_COMBO" ]; then - LIBRARY_COMBO=gnu-gnu-gnu -fi - -# Process arguments -app=$0 -show_available_platforms=0 -show_relative_path=0 -show_full_path=0 -while true -do - case $1 in - - --script-help) - echo usage: `basename $0` [--library-combo=...] - echo " [--available-platforms][--full-executable-path]" - echo " [--relative-executable-path] [arguments...]" - echo - echo " --library-combo=... specifies a GNUstep backend to use." - echo " It overrides the default LIBRARY_COMBO environment variable." - echo - echo " --available-platforms displays a list of valid exec hosts" - echo " --full-executable-path displays full path to executable" - echo " --relative-executable-path displays subdirectory path" - echo " arguments... are the arguments to the application." - exit 0 - ;; - --library-combo=*) - LIBRARY_COMBO=`echo $1 | sed 's/--library-combo=//'` - shift - ;; - --available-platforms) - show_available_platforms=1 - exit 0 - ;; - --full-executable-path) - show_full_path=1 - break - ;; - --relative-executable-path) - show_relative_path=1 - break - ;; - *) - break;; - esac -done - -if [ "$LIBRARY_COMBO" = nx ]; then - LIBRARY_COMBO=nx-nx-nx -elif [ "$LIBRARY_COMBO" = gnu ]; then - LIBRARY_COMBO=gnu-gnu-gnu -elif [ "$LIBRARY_COMBO" = fd ]; then - LIBRARY_COMBO=gnu-fd-gnu -fi -export LIBRARY_COMBO - -# Find path to ourself -app=`echo $app | sed 's%/*$%%'` -dir=`dirname $app` - -case $app in - /*) # An absolute path. - full_appname=$dir;; - */*) # A relative path - full_appname=`(cd $dir; pwd)`;; - *) # A path that needs to be searched - if [ -n $GNUSTEP_PATHPREFIX_LIST ]; then - SPATH=$GNUSTEP_PATHPREFIX_LIST - else - SPATH=$PATH - fi - SPATH=.:$SPATH - IFS=: - for path_dir in $SPATH; do - if [ -d $path_dir/$dir ]; then - full_appname=`(cd $path_dir/$dir; pwd)` - break; - fi - if [ -d $path_dir/Applications/$dir ]; then - full_appname=`(cd $path_dir/Applications/$dir; pwd)` - break; - fi - done;; -esac - -if [ -z "$full_appname" ]; then - echo "Can't find absolute path for $app! Please specify full path when" - echo "invoking executable" - exit 1 -fi - -# -# get base app name -# -app=`echo $app | sed 's/\.[a-z]*$//'` -app=`basename $app` -appname= -if [ -f "$full_appname/Resources/Info-gnustep.plist" ]; then -# -n disable auto-print (for portability reasons) -# /^ *NSExecutable *=/ matches every line beginning with -# zero or more spaces, followed by 'NSExecutable', followed by zero or -# more spaces, followed by '=' -# to this line we apply the following commands: -# s/"//g; which deletes all " in the line. -# s/^ *NSExecutable *= *\([^ ;]*\) *;.*/\1/p; -# which replaces 'NSExecutable = Gorm; ' with 'Gorm', then, because -# of the 'p' at the end, prints out the result -# q; which quits sed since we know there must be only a single line -# to replace. - appname=`sed -n -e '/^ *NSExecutable *=/ \ - {s/"//g; s/^ *NSExecutable *= *\([^ ;]*\) *;.*/\1/p; q;}' \ - "$full_appname/Resources/Info-gnustep.plist"` -fi -if [ -z "$appname" ]; then - appname=$app -fi - -appname="$appname$EXEEXT" - -if [ $show_available_platforms = 1 ]; then - cd $full_appname - #available_platforms - exit 0 -fi - -# -# Determine the host information -# -if [ -z "$GNUSTEP_HOST" ]; then - GNUSTEP_HOST=`(cd /tmp; $GNUSTEP_SYSTEM_ROOT/Makefiles/config.guess)` - GNUSTEP_HOST=`(cd /tmp; $GNUSTEP_SYSTEM_ROOT/Makefiles/config.sub $GNUSTEP_HOST)` - export GNUSTEP_HOST -fi -if [ -z "$GNUSTEP_HOST_CPU" ]; then - GNUSTEP_HOST_CPU=`$GNUSTEP_SYSTEM_ROOT/Makefiles/cpu.sh $GNUSTEP_HOST` - GNUSTEP_HOST_CPU=`$GNUSTEP_SYSTEM_ROOT/Makefiles/clean_cpu.sh $GNUSTEP_HOST_CPU` - export GNUSTEP_HOST_CPU -fi -if [ -z "$GNUSTEP_HOST_VENDOR" ]; then - GNUSTEP_HOST_VENDOR=`$GNUSTEP_SYSTEM_ROOT/Makefiles/vendor.sh $GNUSTEP_HOST` - GNUSTEP_HOST_VENDOR=`$GNUSTEP_SYSTEM_ROOT/Makefiles/clean_vendor.sh $GNUSTEP_HOST_VENDOR` - export GNUSTEP_HOST_VENDOR -fi -if [ -z "$GNUSTEP_HOST_OS" ]; then - GNUSTEP_HOST_OS=`$GNUSTEP_SYSTEM_ROOT/Makefiles/os.sh $GNUSTEP_HOST` - GNUSTEP_HOST_OS=`$GNUSTEP_SYSTEM_ROOT/Makefiles/clean_os.sh $GNUSTEP_HOST_OS` - export GNUSTEP_HOST_OS -fi - -# -# Make sure the executable is there -# -if [ -x $full_appname/$GNUSTEP_HOST_CPU/$GNUSTEP_HOST_OS/$LIBRARY_COMBO/$appname ]; then - relative_path=$GNUSTEP_HOST_CPU/$GNUSTEP_HOST_OS/$LIBRARY_COMBO/$appname -elif [ -x $full_appname/$GNUSTEP_HOST_CPU/$GNUSTEP_HOST_OS/$appname ]; then - relative_path=$GNUSTEP_HOST_CPU/$GNUSTEP_HOST_OS/$appname -elif [ -x $full_appname/$GNUSTEP_HOST_CPU/$appname ]; then - relative_path=$GNUSTEP_HOST_CPU/$appname -elif [ $appname != $app -a -x $full_appname/$appname ]; then - relative_path=$appname -else - echo "$full_appname application does not have a binary for this kind of machine/operating system ($GNUSTEP_HOST_CPU/$GNUSTEP_HOST_OS)." - exit 1 -fi - -if [ $show_relative_path = 1 ]; then - echo $relative_path - exit 0 -fi -if [ $show_full_path = 1 ]; then - echo $full_appname/$relative_path - exit 0 -fi - -if [ "$LIBRARY_COMBO" = nx-nx-nx -a $GNUSTEP_HOST_OS = nextstep4 ]; then - if [ -f "$full_appname/library_paths.openapp" ]; then - additional_library_paths="`cat $full_appname/library_paths.openapp`" - fi -else - if [ -f "$full_appname/$GNUSTEP_HOST_CPU/$GNUSTEP_HOST_OS/$LIBRARY_COMBO/library_paths.openapp" ]; then - additional_library_paths="`cat $full_appname/$GNUSTEP_HOST_CPU/$GNUSTEP_HOST_OS/$LIBRARY_COMBO/library_paths.openapp`" - fi -fi - -# Load up LD_LIBRARY_PATH -. $GNUSTEP_SYSTEM_ROOT/Makefiles/ld_lib_path.sh - -exec $full_appname/$relative_path "$@" - diff --git a/GScheme.app/Resources/GScheme.desktop b/GScheme.app/Resources/GScheme.desktop deleted file mode 100644 index 8425164..0000000 --- a/GScheme.app/Resources/GScheme.desktop +++ /dev/null @@ -1,8 +0,0 @@ -[Desktop Entry] -Encoding=UTF-8 -Type=Application -Version=GScheme 0.1 -Name=GScheme -Exec=openapp GScheme.app -#TryExec=GScheme.app -MimeType= diff --git a/GScheme.app/Resources/Info-gnustep.plist b/GScheme.app/Resources/Info-gnustep.plist deleted file mode 100644 index da54d8f..0000000 --- a/GScheme.app/Resources/Info-gnustep.plist +++ /dev/null @@ -1,29 +0,0 @@ -{ - ApplicationDescription = "A scheme interpreter"; - ApplicationName = GScheme; - ApplicationRelease = "GScheme 0.1"; - Authors = ( - "Marko Riedel " - ); - Copyright = "Copyright (C) 2002 Free Software Foundation, Inc."; - CopyrightDescription = "This program is released under the GNU General Public License"; - FullVersionID = "0.1, June 2002"; - NOTE = "Automatically generated, do not edit!"; - NSExecutable = GScheme; - NSMainNibFile = ""; - NSPrincipalClass = NSApplication; - NSTypes = ( - { - NSDOSExtensions = ( - scm - ); - NSDocumentClass = Document; - NSHumanReadableName = "Scheme program"; - NSName = scm; - NSRole = Editor; - NSUnixExtensions = ( - scm - ); - } - ); -} \ No newline at end of file diff --git a/GScheme.app/Resources/library.scm b/GScheme.app/Resources/library.scm deleted file mode 100644 index b08daa4..0000000 --- a/GScheme.app/Resources/library.scm +++ /dev/null @@ -1,109 +0,0 @@ - -(define vector - (lambda args - (list->vector args))) - - -(define list-n - (lambda (n) - (if (zero? n) '() - (cons n (list-n (- n 1)))))) - -(define list-ref - (lambda (l n) - (if (zero? n) - (car l) - (list-ref (cdr l) (- n 1))))) - -(define length - (lambda (l) - (if (or (null? l) (not (pair? l))) 0 - (+ 1 (length (cdr l)))))) - -(define filter - (lambda (l f) - (if (null? l) '() - (if (f (car l)) - (cons (car l) (filter (cdr l) f)) - (filter (cdr l) f))))) - -(define reverse - (letrec - ((rev - (lambda (l acc) - (if (null? l) acc - (rev (cdr l) (cons (car l) acc)))))) - (lambda (l) - (rev l '())))) - -(define append - (lambda (l . ls) - (if (null? l) - (if (pair? ls) - (if (pair? (cdr ls)) - (apply append ls) - (car ls)) ls) - (cons (car l) - (apply append (cons (cdr l) ls)))))) - -(define eqv? eq?) -(define equal? - (lambda (obj1 obj2) - (if (and (pair? obj1) (pair? obj2)) - (and (equal? (car obj1) (car obj2)) - (equal? (cdr obj1) (cdr obj2))) - (if (or (pair? obj1) (pair? obj2)) #f - (eqv? obj1 obj2))))) - -(define memgeneric - (lambda (obj l pred) - (if (null? l) '() - (if (pred obj (car l)) l - (memgeneric obj (cdr l) pred))))) - -(define memq - (lambda (obj l) (memgeneric obj l eq?))) -(define memv - (lambda (obj l) (memgeneric obj l eqv?))) -(define member - (lambda (obj l) (memgeneric obj l equal?))) - -(define association - (lambda (obj l pred) - (if (null? l) #f - (if (and (pair? (car l)) - (pred obj (car (car l)))) - (car l) - (association obj (cdr l) pred))))) - -(define assq - (lambda (obj l) (association obj l eq?))) -(define assv - (lambda (obj l) (association obj l eqv?))) -(define assoc - (lambda (obj l) (association obj l equal?))) - - -(define map-over-single-list - (lambda (p l) - (if (null? l) '() - (cons (p (car l)) - (map-over-single-list p (cdr l)))))) - -(define map - (lambda (proc . lists) - (if (memq '() lists) '() - (cons - (apply proc - (map-over-single-list car lists)) - (apply map - (cons proc (map-over-single-list cdr lists))))))) - -(define for-each - (lambda (proc . lists) - (if (memq '() lists) '() - (begin - (apply proc - (map-over-single-list car lists)) - (apply for-each - (cons proc (map-over-single-list cdr lists))))))) diff --git a/GScheme.app/Resources/library.scm~ b/GScheme.app/Resources/library.scm~ deleted file mode 100644 index c1ae59e..0000000 --- a/GScheme.app/Resources/library.scm~ +++ /dev/null @@ -1,103 +0,0 @@ -(define list-n - (lambda (n) - (if (zero? n) '() - (cons n (list-n (- n 1)))))) - -(define list-ref - (lambda (l n) - (if (zero? n) - (car l) - (list-ref (cdr l) (- n 1))))) - -(define length - (lambda (l) - (if (or (null? l) (not (pair? l))) 0 - (+ 1 (length (cdr l)))))) - -(define filter - (lambda (l f) - (if (null? l) '() - (if (f (car l)) - (cons (car l) (filter (cdr l) f)) - (filter (cdr l) f))))) - -(define reverse - (letrec - ((rev - (lambda (l acc) - (if (null? l) acc - (rev (cdr l) (cons (car l) acc)))))) - (lambda (l) - (rev l '())))) - -(define append - (lambda (l . ls) - (if (null? l) - (if (pair? ls) - (if (pair? (cdr ls)) - (apply append ls) - (car ls)) ls) - (cons (car l) - (apply append (cons (cdr l) ls)))))) - -(define eqv? eq?) -(define equal? - (lambda (obj1 obj2) - (if (and (pair? obj1) (pair? obj2)) - (and (equal? (car obj1) (car obj2)) - (equal? (cdr obj1) (cdr obj2))) - (if (or (pair? obj1) (pair? obj2)) #f - (eqv? obj1 obj2))))) - -(define memgeneric - (lambda (obj l pred) - (if (null? l) '() - (if (pred obj (car l)) l - (memgeneric obj (cdr l) pred))))) - -(define memq - (lambda (obj l) (memgeneric obj l eq?))) -(define memv - (lambda (obj l) (memgeneric obj l eqv?))) -(define member - (lambda (obj l) (memgeneric obj l equal?))) - -(define association - (lambda (obj l pred) - (if (null? l) #f - (if (and (pair? (car l)) - (pred obj (car (car l)))) - (car l) - (association obj (cdr l) pred))))) - -(define assq - (lambda (obj l) (association obj l eq?))) -(define assv - (lambda (obj l) (association obj l eqv?))) -(define assoc - (lambda (obj l) (association obj l equal?))) - - -(define map-over-single-list - (lambda (p l) - (if (null? l) '() - (cons (p (car l)) - (map-over-single-list p (cdr l)))))) - -(define map - (lambda (proc . lists) - (if (memq '() lists) '() - (cons - (apply proc - (map-over-single-list car lists)) - (apply map - (cons proc (map-over-single-list cdr lists))))))) - -(define for-each - (lambda (proc . lists) - (if (memq '() lists) '() - (begin - (apply proc - (map-over-single-list car lists)) - (apply for-each - (cons proc (map-over-single-list cdr lists))))))) diff --git a/GSchemeInfo.plist b/GSchemeInfo.plist index 8f9e1b1..038757f 100644 --- a/GSchemeInfo.plist +++ b/GSchemeInfo.plist @@ -1,11 +1,12 @@ { ApplicationName = "GScheme"; ApplicationDescription = "A scheme interpreter"; - ApplicationRelease = "GScheme 0.1"; - FullVersionID = "0.1, June 2002"; + ApplicationRelease = "GScheme 0.5"; + FullVersionID = "0.5, January 2005"; Authors = ("Marko Riedel "); - Copyright = "Copyright (C) 2002 Free Software Foundation, Inc."; + Copyright = "Copyright (C) 2005 Free Software Foundation, Inc."; CopyrightDescription = "This program is released under the GNU General Public License"; + NSIcon = "GScheme.tiff"; NSTypes = ( { NSName = "scm"; diff --git a/Icons/GScheme.tiff b/Icons/GScheme.tiff new file mode 100644 index 0000000000000000000000000000000000000000..bc11f2afc927ce1a11b6bf287bb5c40a357e2e11 GIT binary patch literal 9592 zcmeI2!AiqG5QZmhl_FG7v4V=`pdvjaZM8l0;KhUHP*Cv&qD|YNMJa(?J^CWPphqut zw(P(XHX(|EtPEw@zq5aKza9RT9_o25s2>3=K6r2sI0Kvk&H!hCGr$?(4E!A)`=Q9sj@o+@`=8`D=?*$}Q~5zSmtsQ1K{#iH|2tthTM`w~MIyVytd zsXEUYMS6b1qIyXe$(Cnt;t+EY{yclKCtvTmPuwTY0B3+Rz!~5SUNTa_uqx2N+86rQQ8!W7j{!EU8VK(J>P^MJEwwnKDRm3= zj`W|Pf7e=BvN@>tr0%2MSN1uTTAb0ra|bwIpyy7hV+rc=_3Y0cMt;|c!tog3avu0m zFtXz?n%ei%z`pW^H|PX-KLmIaLjVF?;}F+h&fd(Q1VeukK0et!r{|p8?XKJIxa~9h Zw$rz#QS>@+-8hb&P&jd*(|MUs;2UO4Viy1a literal 0 HcmV?d00001 diff --git a/Icons/lambda1.tiff b/Icons/lambda1.tiff new file mode 100644 index 0000000000000000000000000000000000000000..e850edc9f59c2e9057ecc06030bff78567ea8568 GIT binary patch literal 9592 zcmeI2&q~8U5XL8Ml_FG7v4V=`pdvlwkJ=u3@Zv#pD5&@X(WY(CqDUZDkG_a6=+R4^ zEg4wCrbKZeD??fK>+F}^-wt0(4-JA2G!Fn~A3V4RoB_@NXMi)n8Q=_X27Z}=89qnD zwBJ?4Ezc(1LFSgV33nh~nN?Mj*Q=z9Sc~daVizoeQ^jNozlxn|MR%k1s?Yy{-_$!$ z{+VC>{h;%+Blq6K{^$8kx`T?{RDO|Bx{uDh{?*>ZN;BPgQ5)G?BlE zUG$pPs@iv%G2eT6O~tSBt9&|Z)ZaxcnWVx4@2Kc;?W4;;x!7B zXlSQ#GO_O_k$o8quF(nbz7Oywh5!V(!Xd6dpMz;Qjt1d4et5LIPS-iJy%X2-UGLPs Z@q6|pNnZM{o2ID~3nvbAI?u0T_y%RvVio`Z literal 0 HcmV?d00001 diff --git a/NOTES b/NOTES new file mode 100644 index 0000000..4163b18 --- /dev/null +++ b/NOTES @@ -0,0 +1,6 @@ +wrp +retaincount loop +external +paste +stop button +env browser diff --git a/Primitive.h b/Primitive.h index a86d8ce..8a4abbc 100644 --- a/Primitive.h +++ b/Primitive.h @@ -18,6 +18,7 @@ BOOL isPair(id item); BOOL isVector(id item); BOOL isTriple(id item); BOOL isPrimitive(id item); +BOOL isEval(id item); BOOL isClosure(id item); BOOL isThunk(id item); BOOL isFalse(id item); @@ -118,6 +119,11 @@ typedef enum { - (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs; @end +@interface PRMRandom : Primitive +- (NSString *)primName; +- (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs; +@end + @interface PRMQuotient : Primitive - (NSString *)primName; - (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs; @@ -183,6 +189,41 @@ typedef enum { - (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs; @end +@interface PRMDrawCircle : Primitive +- (NSString *)primName; +- (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs; +@end + +@interface PRMFillCircle : Primitive +- (NSString *)primName; +- (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs; +@end + +@interface PRMDrawRect : Primitive +- (NSString *)primName; +- (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs; +@end + +@interface PRMFillRect : Primitive +- (NSString *)primName; +- (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs; +@end + +@interface PRMDrawFont : Primitive +- (NSString *)primName; +- (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs; +@end + +@interface PRMDrawString : Primitive +- (NSString *)primName; +- (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs; +@end + +@interface PRMDrawShow : Primitive +- (NSString *)primName; +- (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs; +@end + @interface PRMSin : Primitive - (NSString *)primName; - (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs; @@ -193,6 +234,26 @@ typedef enum { - (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs; @end +@interface PRMTan : Primitive +- (NSString *)primName; +- (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs; +@end + +@interface PRMExp : Primitive +- (NSString *)primName; +- (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs; +@end + +@interface PRMLog : Primitive +- (NSString *)primName; +- (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs; +@end + +@interface PRMATan : Primitive +- (NSString *)primName; +- (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs; +@end + @interface PRMASin : Primitive - (NSString *)primName; - (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs; @@ -243,7 +304,76 @@ typedef enum { - (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs; @end +@interface PRMSymToStr : Primitive +- (NSString *)primName; +- (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs; +@end + +@interface PRMStrToSym : Primitive +- (NSString *)primName; +- (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs; +@end + +@interface PRMStringSize : Primitive +- (NSString *)primName; +- (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs; +@end + +@interface PRMStringLength : Primitive +- (NSString *)primName; +- (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs; +@end + +@interface PRMCharToInt : Primitive +- (NSString *)primName; +- (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs; +@end + +@interface PRMIntToChar : Primitive +- (NSString *)primName; +- (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs; +@end + +@interface PRMStringRef : Primitive +- (NSString *)primName; +- (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs; +@end + +@interface PRMListToStr : Primitive +- (NSString *)primName; +- (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs; +@end + +@interface PRMStrToList : Primitive +- (NSString *)primName; +- (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs; +@end + +@interface PRMStringAppend : Primitive +- (NSString *)primName; +- (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs; +@end + +@interface PRMMakeString : Primitive +- (NSString *)primName; +- (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs; +@end + +@interface PRMNumberToStr : Primitive +- (NSString *)primName; +- (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs; +@end + +@interface PRMFormat : Primitive +- (NSString *)primName; +- (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs; +@end + @interface PRMBrowseEnvironment : Primitive - (NSString *)primName; - (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs; @end + +@interface PRMEval : Primitive +- (NSString *)primName; +@end diff --git a/Primitive.m b/Primitive.m index 227221d..7a670d0 100644 --- a/Primitive.m +++ b/Primitive.m @@ -3,62 +3,67 @@ #import "VScheme.h" #import "SchemeDelegate.h" -BOOL isBoolean(id item) +inline BOOL isBoolean(id item) { return [item isKindOfClass:[Boolean class]]; } -BOOL isChar(id item) +inline BOOL isChar(id item) { return [item isKindOfClass:[Char class]]; } -BOOL isInt(id item) +inline BOOL isInt(id item) { return [item isKindOfClass:[Int class]]; } -BOOL isDouble(id item) +inline BOOL isDouble(id item) { return [item isKindOfClass:[Double class]]; } -BOOL isSymbol(id item) +inline BOOL isSymbol(id item) { return [item isKindOfClass:[Symbol class]]; } -BOOL isString(id item) +inline BOOL isString(id item) { return [item isKindOfClass:[String class]]; } -BOOL isPair(id item) +inline BOOL isPair(id item) { return [item isKindOfClass:[Pair class]]; } -BOOL isVector(id item) +inline BOOL isVector(id item) { return [item isKindOfClass:[Vector class]]; } -BOOL isTriple(id item) +inline BOOL isTriple(id item) { return [item isKindOfClass:[Triple class]]; } -BOOL isPrimitive(id item) +inline BOOL isPrimitive(id item) { return [item isKindOfClass:[Primitive class]]; } -BOOL isClosure(id item) +inline BOOL isEval(id item) +{ + return [item isKindOfClass:[PRMEval class]]; +} + +inline BOOL isClosure(id item) { return [item isKindOfClass:[Closure class]]; } -BOOL isThunk(id item) +inline BOOL isThunk(id item) { return [item isKindOfClass:[Thunk class]]; } @@ -155,6 +160,9 @@ BOOL isEqual(id itema, id itemb) - errmsg { + if([errmsg isKindOfClass:[NSConstantString class]]==NO){ + [errmsg autorelease]; + } return errmsg; } @@ -680,6 +688,41 @@ BOOL isEqual(id itema, id itemb) @end +@implementation PRMRandom + +- (NSString *)primName +{ + return @"random"; +} + +- (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs +{ + NUMTYPE nt = [self checkArgsNumeric:args offset:offs]; + + if(offs+1!=[args count]){ + errmsg = @"random takes exactly one argument"; + return NO; + } + + if(nt==NT_OTHER){ + errmsg = @"argument to random must be numeric"; + return NO; + } + + if(nt==NT_INTEGERS){ + int v = [[args objectAtIndex:offs] intVal]; + value = [[Int alloc] initSCMInt:(lrand48() % v)]; + } + else{ + double v = [[args objectAtIndex:offs] doubleVal]; + value = [[Double alloc] initSCMDouble:(drand48() * v)]; + } + + return YES; +} + +@end + @implementation PRMQuotient - (NSString *)primName @@ -932,14 +975,12 @@ BOOL isEqual(id itema, id itemb) item = [args objectAtIndex:offs]; if(isString(item)){ - res = [[NSString alloc] - initWithFormat:@"%@" locale: nil, - [item strVal]]; + res = [NSString + stringWithFormat:@"%@", [item strVal]]; } else if(isChar(item)){ - res = [[NSString alloc] - initWithFormat:@"%c" locale: nil, - [item charVal]]; + res = [NSString + stringWithFormat:@"%c", [item charVal]]; } else{ res = [VScheme valToString:item]; @@ -1096,6 +1137,247 @@ BOOL isEqual(id itema, id itemb) @end +@implementation PRMDrawCircle +- (NSString *)primName +{ + return @"draw-circle"; +} + +- (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs +{ + NUMTYPE nt = [self checkArgsNumeric:args offset:offs]; + DrawInst inst; + + if(offs+1!=[args count]){ + errmsg = @"draw-circle takes one argument"; + return NO; + } + + if(nt==NT_OTHER){ + errmsg = @"Argument to draw-circle must be numeric"; + return NO; + } + + inst.what = DRAW_CIRCLE; + inst.data.radius = [[args objectAtIndex:offs] doubleVal]; + + [vm recordImgInst:inst]; + + value = [NSNull null]; + return YES; +} + +@end + +@implementation PRMFillCircle +- (NSString *)primName +{ + return @"fill-circle"; +} + +- (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs +{ + NUMTYPE nt = [self checkArgsNumeric:args offset:offs]; + DrawInst inst; + + if(offs+1!=[args count]){ + errmsg = @"fill-circle takes one argument"; + return NO; + } + + if(nt==NT_OTHER){ + errmsg = @"Argument to fill-circle must be numeric"; + return NO; + } + + inst.what = FILL_CIRCLE; + inst.data.radius = [[args objectAtIndex:offs] doubleVal]; + + [vm recordImgInst:inst]; + + value = [NSNull null]; + return YES; +} + +@end + +@implementation PRMDrawRect +- (NSString *)primName +{ + return @"draw-rect"; +} + +- (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs +{ + NUMTYPE nt = [self checkArgsNumeric:args offset:offs]; + DrawInst inst; + + if(offs+2!=[args count]){ + errmsg = @"draw-rect takes two arguments"; + return NO; + } + + if(nt==NT_OTHER){ + errmsg = @"Arguments to draw-rect must be numeric"; + return NO; + } + + inst.what = DRAW_RECT; + inst.data.size = + NSMakeSize([[args objectAtIndex:offs] doubleVal], + [[args objectAtIndex:offs+1] doubleVal]); + + [vm recordImgInst:inst]; + + value = [NSNull null]; + return YES; +} + +@end + +@implementation PRMFillRect +- (NSString *)primName +{ + return @"fill-rect"; +} + +- (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs +{ + NUMTYPE nt = [self checkArgsNumeric:args offset:offs]; + DrawInst inst; + + if(offs+2!=[args count]){ + errmsg = @"fill-rect takes two arguments"; + return NO; + } + + if(nt==NT_OTHER){ + errmsg = @"Argument to fill-rect must be numeric"; + return NO; + } + + inst.what = FILL_RECT; + inst.data.size = + NSMakeSize([[args objectAtIndex:offs] doubleVal], + [[args objectAtIndex:offs+1] doubleVal]); + + [vm recordImgInst:inst]; + + value = [NSNull null]; + return YES; +} + +@end + +@implementation PRMDrawFont +- (NSString *)primName +{ + return @"draw-font"; +} + +- (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs +{ + DrawInst inst; + + if(offs+2!=[args count]){ + errmsg = @"draw-font takes two arguments"; + return NO; + } + + String *fontName = [args objectAtIndex:offs]; + if(isString(fontName)==NO){ + errmsg = @"draw-font: font name must be a string"; + return NO; + } + + NSString *fontNameStr = [fontName strVal]; + if([[[NSFontManager sharedFontManager] + availableFonts] containsObject:fontNameStr]==NO){ + errmsg = + [[NSString alloc] + initWithFormat:@"draw-font: no such font (%@)", fontNameStr]; + return NO; + } + + id size = [args objectAtIndex:offs+1]; + if(isInt(size)==NO && isDouble(size)==NO){ + errmsg = @"draw-font: size must be a number"; + return NO; + } + + float sizeVal = (float)[size doubleVal]; + NSFont *font = [NSFont fontWithName:fontNameStr size:sizeVal]; + [font retain]; + + inst.what = DRAW_FONT; + inst.data.font = font; + + [vm recordImgInst:inst]; + + value = [NSNull null]; + return YES; +} + +@end + +@implementation PRMDrawString +- (NSString *)primName +{ + return @"draw-string"; +} + +- (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs +{ + DrawInst inst; + + if(offs+1!=[args count]){ + errmsg = @"draw-string takes one argument"; + return NO; + } + + String *str = [args objectAtIndex:offs]; + if(isString(str)==NO){ + errmsg = @"draw-string: string required"; + return NO; + } + + NSString *string = [NSString stringWithString:[str strVal]]; + [string retain]; + + inst.what = DRAW_STRING; + inst.data.string = string; + + [vm recordImgInst:inst]; + + value = [NSNull null]; + return YES; +} + +@end + + +@implementation PRMDrawShow +- (NSString *)primName +{ + return @"draw-show"; +} + +- (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs +{ + if(offs!=[args count]){ + errmsg = @"draw-show takes no argument"; + return NO; + } + + [vm produceImage]; + [vm clearImage]; + + value = [NSNull null]; + return YES; +} + +@end + @implementation PRMSin - (NSString *)primName { @@ -1124,6 +1406,153 @@ BOOL isEqual(id itema, id itemb) @end +@implementation PRMCos +- (NSString *)primName +{ + return @"cos"; +} + +- (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs +{ + NUMTYPE nt = [self checkArgsNumeric:args offset:offs]; + double res; + + if(offs+1!=[args count]){ + errmsg = @"cos takes one argument"; + return NO; + } + + if(nt==NT_OTHER){ + errmsg = @"Argument to cos must be numeric"; + return NO; + } + + res = cos([[args objectAtIndex:offs] doubleVal]); + value = [[Double alloc] initSCMDouble:res]; + return YES; +} + +@end + +@implementation PRMTan +- (NSString *)primName +{ + return @"tan"; +} + +- (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs +{ + NUMTYPE nt = [self checkArgsNumeric:args offset:offs]; + double res; + + if(offs+1!=[args count]){ + errmsg = @"tan takes one argument"; + return NO; + } + + if(nt==NT_OTHER){ + errmsg = @"Argument to tan must be numeric"; + return NO; + } + + res = tan([[args objectAtIndex:offs] doubleVal]); + value = [[Double alloc] initSCMDouble:res]; + return YES; +} + +@end + +@implementation PRMExp +- (NSString *)primName +{ + return @"exp"; +} + +- (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs +{ + NUMTYPE nt = [self checkArgsNumeric:args offset:offs]; + double res; + + if(offs+1!=[args count]){ + errmsg = @"exp takes one argument"; + return NO; + } + + if(nt==NT_OTHER){ + errmsg = @"Argument to exp must be numeric"; + return NO; + } + + res = exp([[args objectAtIndex:offs] doubleVal]); + value = [[Double alloc] initSCMDouble:res]; + return YES; +} + +@end + +@implementation PRMLog +- (NSString *)primName +{ + return @"log"; +} + +- (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs +{ + NUMTYPE nt = [self checkArgsNumeric:args offset:offs]; + double v, res; + + if(offs+1!=[args count]){ + errmsg = @"log takes one argument"; + return NO; + } + + if(nt==NT_OTHER){ + errmsg = @"Argument to log must be numeric"; + return NO; + } + + v = [[args objectAtIndex:offs] doubleVal]; + if(v<=0.0){ + errmsg = @"Argument to log must be positive"; + return NO; + } + + res = log(v); + value = [[Double alloc] initSCMDouble:res]; + return YES; +} + +@end + +@implementation PRMATan +- (NSString *)primName +{ + return @"atan"; +} + +- (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs +{ + NUMTYPE nt = [self checkArgsNumeric:args offset:offs]; + double res, v; + + if(offs+1!=[args count]){ + errmsg = @"atan takes one argument"; + return NO; + } + + if(nt==NT_OTHER){ + errmsg = @"Argument to atan must be numeric"; + return NO; + } + + v = [[args objectAtIndex:offs] doubleVal]; + res = atan(v); + value = [[Double alloc] initSCMDouble:res]; + return YES; +} + +@end + @implementation PRMASin - (NSString *)primName { @@ -1158,34 +1587,6 @@ BOOL isEqual(id itema, id itemb) @end -@implementation PRMCos -- (NSString *)primName -{ - return @"cos"; -} - -- (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs -{ - NUMTYPE nt = [self checkArgsNumeric:args offset:offs]; - double res; - - if(offs+1!=[args count]){ - errmsg = @"cos takes one argument"; - return NO; - } - - if(nt==NT_OTHER){ - errmsg = @"Argument to cos must be numeric"; - return NO; - } - - res = cos([[args objectAtIndex:offs] doubleVal]); - value = [[Double alloc] initSCMDouble:res]; - return YES; -} - -@end - @implementation PRMACos - (NSString *)primName { @@ -1541,6 +1942,528 @@ BOOL isEqual(id itema, id itemb) @end +@implementation PRMSymToStr +- (NSString *)primName +{ + return @"symbol->string"; +} + +- (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs +{ + if(offs+1!=[args count]){ + errmsg = @"symbol->string takes one argument"; + return NO; + } + + Symbol *sym = [args objectAtIndex:offs]; + if(isSymbol(sym)==NO){ + errmsg = @"symbol->string: symbol required"; + return NO; + } + + value = [[String alloc] + initSCMString:(char *)[[sym symVal] cString]]; + return YES; +} + +@end + + +@implementation PRMStrToSym +- (NSString *)primName +{ + return @"string->symbol"; +} + +- (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs +{ + if(offs+1!=[args count]){ + errmsg = @"string->symbol takes one argument"; + return NO; + } + + String *str = [args objectAtIndex:offs]; + if(isString(str)==NO){ + errmsg = @"string->symbol: string required"; + return NO; + } + + value = [[Symbol alloc] + initSCMSymbol:(char *)[[str strVal] cString]]; + return YES; +} + +@end + +@implementation PRMStringSize +- (NSString *)primName +{ + return @"string-size"; +} + +- (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs +{ + if(offs+3!=[args count]){ + errmsg = @"string-size takes three arguments"; + return NO; + } + + String *str = [args objectAtIndex:offs]; + if(isString(str)==NO){ + errmsg = @"string-size: string required"; + return NO; + } + + String *fontName = [args objectAtIndex:offs+1]; + if(isString(fontName)==NO){ + errmsg = @"string-size: font name must be a string"; + return NO; + } + + NSString *fontNameStr = [fontName strVal]; + if([[[NSFontManager sharedFontManager] + availableFonts] containsObject:fontNameStr]==NO){ + errmsg = + [[NSString alloc] + initWithFormat:@"string-size: no such font (%@)", fontNameStr]; + return NO; + } + + id size = [args objectAtIndex:offs+2]; + if(isInt(size)==NO && isDouble(size)==NO){ + errmsg = @"string-size: size must be a number"; + return NO; + } + + float sizeVal = (float)[size doubleVal]; + NSFont *font = [NSFont fontWithName:fontNameStr size:sizeVal]; + + NSDictionary *attr = + [NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName, nil]; + NSSize result = [[str strVal] sizeWithAttributes:attr]; + + value = + [Pair + newCar:[[Double alloc] initSCMDouble:result.width] + Cdr:[[Double alloc] initSCMDouble:result.height]]; + return YES; +} + +@end + +@implementation PRMStringLength +- (NSString *)primName +{ + return @"string-length"; +} + +- (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs +{ + if(offs+1!=[args count]){ + errmsg = @"string-length takes three arguments"; + return NO; + } + + String *str = [args objectAtIndex:offs]; + if(isString(str)==NO){ + errmsg = @"string-length: string required"; + return NO; + } + + value = [[Int alloc] initSCMInt:[[str strVal] length]]; + return YES; +} + +@end + +@implementation PRMCharToInt +- (NSString *)primName +{ + return @"char->integer"; +} + +- (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs +{ + if(offs+1!=[args count]){ + errmsg = @"char->integer takes one argument"; + return NO; + } + + Char *ch = [args objectAtIndex:offs]; + if(isChar(ch)==NO){ + errmsg = @"char->integer: character required"; + return NO; + } + + value = [[Int alloc] + initSCMInt:(long int)[ch charVal]]; + return YES; +} + +@end + +@implementation PRMIntToChar +- (NSString *)primName +{ + return @"integer->char"; +} + +- (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs +{ + if(offs+1!=[args count]){ + errmsg = @"integer->char takes one argument"; + return NO; + } + + Int *i = [args objectAtIndex:offs]; + if(isInt(i)==NO){ + errmsg = @"integer->char: character required"; + return NO; + } + + value = [[Char alloc] + initSCMChar:(char)[i intVal]]; + return YES; +} + +@end + + +@implementation PRMStringRef +- (NSString *)primName +{ + return @"string-ref"; +} + +- (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs +{ + if(offs+2!=[args count]){ + errmsg = @"string-ref takes two argument"; + return NO; + } + + String *str = [args objectAtIndex:offs]; + if(isString(str)==NO){ + errmsg = @"string-ref: string required"; + return NO; + } + + Int *i = [args objectAtIndex:offs+1]; + if(isInt(i)==NO){ + errmsg = @"string-ref: integer position required"; + return NO; + } + int pos = [i intVal]; + + NSString *theStr = [str strVal]; + if(pos>=[theStr length]){ + errmsg = @"string-ref: index out of range"; + return NO; + } + + value = [[Char alloc] initSCMChar:[theStr characterAtIndex:pos]]; + return YES; +} + +@end + +@implementation PRMListToStr +- (NSString *)primName +{ + return @"list->string"; +} + +- (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs +{ + if(offs+1!=[args count]){ + errmsg = @"list->string takes one argument"; + return NO; + } + + Pair *p = [args objectAtIndex:offs]; + if(isPair(p)==NO && [NSNull null]!=(id)p){ + errmsg = @"list->string: pair required"; + return NO; + } + + int cpos = 0, cmax = 0; + while(isPair(p)){ + if(isChar([p car])==NO){ + errmsg = @"list->string: character required"; + return NO; + } + p = [p cdr]; + cmax++; + } + + char buf[cmax+1]; + p = [args objectAtIndex:offs]; + + while(isPair(p)){ + Char *ch = [p car]; + buf[cpos++] = [ch charVal]; + + p = [p cdr]; + } + buf[cpos] = 0; + + value = [[String alloc] initSCMString:buf]; + return YES; +} + +@end + +@implementation PRMStrToList +- (NSString *)primName +{ + return @"string->list"; +} + +- (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs +{ + if(offs+1!=[args count]){ + errmsg = @"string->list takes one argument"; + return NO; + } + + String *str = [args objectAtIndex:offs]; + if(isString(str)==NO){ + errmsg = @"string->list: string required"; + return NO; + } + + NSString *theStr = [str strVal]; + + id result = [NSNull null]; + int cmax = [theStr length], cpos; + + cpos = cmax-1; + while(cpos>=0){ + char c = [theStr characterAtIndex:cpos]; + result = + [Pair + newCar:[[Char alloc] initSCMChar:c] + Cdr:result]; + cpos--; + } + + value = result; + return YES; +} + +@end + +@implementation PRMStringAppend +- (NSString *)primName +{ + return @"string-append"; +} + +- (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs +{ + NSString *result = @""; + + int cpos = offs, cmax = [args count]; + while(cposstring"; +} + +- (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs +{ + if(offs+1!=[args count] && offs+2!=[args count]){ + errmsg = @"number->string takes one or two arguments"; + return NO; + } + + id n = [args objectAtIndex:offs]; + if(isInt(n)==NO && isDouble(n)==NO){ + errmsg = @"number->string: int or double required"; + return NO; + } + + if(isDouble(n)){ + NSNumber *num = [NSNumber numberWithDouble:[n doubleVal]]; + value = [[String alloc] initSCMString:(char *)[[num description] cString]]; + return YES; + } + + int radix = 10; + if(offs+2==[args count]){ + Int *r = [args objectAtIndex:offs+1]; + if(isInt(r)==NO){ + errmsg = @"number->string: radix must be an integer"; + return NO; + } + radix = [r intVal]; + if(radix<2 || radix>36){ + errmsg = @"number->string: radix must be >= 2 and <= 36"; + return NO; + } + } + + int number = [n intVal]; + if(radix==10 || !number){ + NSNumber *num = [NSNumber numberWithInt:number]; + value = [[String alloc] initSCMString:(char *)[[num description] cString]]; + return YES; + } + + int sign = 1; + if(number<0){ + sign = -1; + number = -number; + } + + NSString *result = @""; + while(number>0){ + int digit = number % radix; + result = + [[NSString stringWithFormat:@"%c", + (digit<10 ? '0' + digit : 'A' + digit-10)] + stringByAppendingString:result]; + number /= radix; + } + + if(sign==-1){ + result = [NSString stringWithFormat:@"-%@", result]; + } + + value = [[String alloc] initSCMString:(char *)[result cString]]; + return YES; +} + +@end + +@implementation PRMFormat +- (NSString *)primName +{ + return @"format"; +} + +- (BOOL)evalVM:(id)vm Args:(NSMutableArray *)args offset:(int)offs +{ + if(offs==[args count]){ + errmsg = @"format needs at least one argument"; + return NO; + } + + String *fmt = [args objectAtIndex:offs++]; + if(isString(fmt)==NO){ + errmsg = @"format: string required"; + return NO; + } + const char *fmtStr = [[fmt strVal] cString]; + + NSString *result = @""; + while(*fmtStr){ + NSString *item; + + if(fmtStr[0]=='~'){ + if(fmtStr[1]){ + switch(fmtStr[1]){ + case 'a': + case 's': + if(offs==[args count]){ + errmsg = @"format: ran out of arguments"; + return NO; + } + + id cur = [args objectAtIndex:offs++]; + if(isString(cur)){ + item = [NSString stringWithFormat:@"%@", [cur strVal]]; + } + else if(isChar(cur)){ + item = [NSString stringWithFormat:@"%c", [cur charVal]]; + } + else{ + item = [VScheme valToString:cur]; + } + break; + case '%': + item = @"\n"; + break; + case '~': + item = @"~"; + } + fmtStr++; + } + } + else{ + item = [NSString stringWithCString:fmtStr length:1]; + } + + result = [result stringByAppendingString:item]; + + fmtStr++; + } + + value = [[String alloc] initSCMString:(char *)[result cString]]; + return YES; +} + +@end + @implementation PRMBrowseEnvironment - (NSString *)primName { @@ -1564,3 +2487,11 @@ BOOL isEqual(id itema, id itemb) } @end + +@implementation PRMEval +- (NSString *)primName +{ + return @"eval"; +} + +@end diff --git a/SCMTextView.h b/SCMTextView.h index 9df68bc..eaba347 100644 --- a/SCMTextView.h +++ b/SCMTextView.h @@ -4,6 +4,13 @@ #import "VScheme.h" +@interface NSTextView (Misc) + +- placeCursorAtEnd; +- selectLineAtPos:(int)pos; + +@end + @interface SCMTextView : NSTextView - (void)insertText:(id)aString; @@ -18,8 +25,8 @@ - (id)initWithFrame:(NSRect)frameRect; - (void)insertText:(id)aString; +- (void)paste:(id)sender; -- placeCursorAtEnd; - (NSString *)getSuffix; - (void)setString:(NSString *)aString; diff --git a/SCMTextView.m b/SCMTextView.m index 17808d3..b267cb3 100644 --- a/SCMTextView.m +++ b/SCMTextView.m @@ -2,6 +2,28 @@ #import "SCMTextView.h" #import "SchemeDelegate.h" +@implementation NSTextView (Misc) + +- placeCursorAtEnd +{ + NSRange range = { [[self string] length], 0 }; + [self setSelectedRange:range]; + return self; +} + +- selectLineAtPos:(int)pos +{ + NSString *data = [self string]; + + unsigned startInd, endInd; + [data getLineStart:&startInd end:&endInd + contentsEnd:NULL forRange:NSMakeRange(pos, 0)]; + [self setSelectedRange:NSMakeRange(startInd, endInd-startInd)]; + + return self; +} + +@end @implementation SCMTextView @@ -10,7 +32,7 @@ int inslen = [aString length]; unichar ch = [aString characterAtIndex:0]; NSString *modified = @"", *single; - + if(inslen == 1 && ch==NSNewlineCharacter){ NSString *data = [self string]; NSRange range = [self selectedRange]; @@ -68,17 +90,21 @@ - (void)insertText:(id)aString { if([self selectedRange].location args))) + + +(define make-range + (lambda (a b) + (if (= a b) (list a) + (cons + a (make-range (+ 1 a) b))))) + + \ No newline at end of file diff --git a/Scheme/library.scm~ b/Scheme/library.scm~ index c1ae59e..c8c4594 100644 --- a/Scheme/library.scm~ +++ b/Scheme/library.scm~ @@ -1,3 +1,9 @@ + +(define vector + (lambda args + (list->vector args))) + + (define list-n (lambda (n) (if (zero? n) '() @@ -101,3 +107,41 @@ (map-over-single-list car lists)) (apply for-each (cons proc (map-over-single-list cdr lists))))))) + +(define pow (lambda (x y) (exp (* y (log x))))) + +(define caar (lambda (p) (car (car p)))) +(define cadr (lambda (p) (car (cdr p)))) +(define cdar (lambda (p) (cdr (car p)))) +(define cddr (lambda (p) (cdr (cdr p)))) + +(define caaar (lambda (p) (car (car (car p))))) +(define caadr (lambda (p) (car (car (cdr p))))) +(define cadar (lambda (p) (car (cdr (car p))))) +(define caddr (lambda (p) (car (cdr (cdr p))))) +(define cdaar (lambda (p) (cdr (car (car p))))) +(define cdadr (lambda (p) (cdr (car (cdr p))))) +(define cddar (lambda (p) (cdr (cdr (car p))))) +(define cdddr (lambda (p) (cdr (cdr (cdr p))))) + +(define min-max + (lambda (pred args) + (letrec + ((iter + (lambda (l m) + (if (null? l) m + (iter (cdr l) + (if (pred (car l) m) (car l) m)))))) + (iter (cdr args) (car args))))) + +(define min + (lambda args + (min-max < args))) + +(define max + (lambda args + (min-max > args))) + + + + diff --git a/SchemeDelegate.h b/SchemeDelegate.h index a0b2dba..3a6d8de 100644 --- a/SchemeDelegate.h +++ b/SchemeDelegate.h @@ -14,13 +14,19 @@ NSMutableArray *imageWindows; NSMutableArray *envWindows; + + NSPanel *interruptPanel; } - (void)applicationWillFinishLaunching:(NSNotification *)not; - (void)applicationDidFinishLaunching:(NSNotification *)not; + - makeInterpreterWindow; -- makeStatisticsWindow; +- makeStatisticsPanel; + +- makeInterruptPanel; +- (NSPanel *)interruptPanel; - input:(NSString *)data; - output:(NSString *)data; @@ -35,5 +41,7 @@ - reset:(id)sender; +- addExternal:(id)sender; +- evaluateExternal:(id)sender; @end diff --git a/SchemeDelegate.m b/SchemeDelegate.m index 9cd92d0..a08c293 100644 --- a/SchemeDelegate.m +++ b/SchemeDelegate.m @@ -9,219 +9,224 @@ VScheme *vm = nil; - (void)applicationWillFinishLaunching:(NSNotification *)not { // CREATE_AUTORELEASE_POOL(pool); - NSMenu *menu; - NSMenu *info; - NSMenu *file; - NSMenu *scheme; - NSMenu *env; - NSMenu *edit; - NSMenu *print; - NSMenu *services; - NSMenu *windows; + NSMenu *menu, *info, *file, *scheme, *external, *env, + *edit, *print, *services, *windows; - // Create the app menu - menu = [NSMenu new]; + // Create the app menu + menu = [NSMenu new]; - [menu addItemWithTitle: @"Info" - action: NULL - keyEquivalent: @""]; + [menu addItemWithTitle: @"Info" + action: NULL + keyEquivalent: @""]; - [menu addItemWithTitle: @"File" - action: NULL - keyEquivalent: @""]; + [menu addItemWithTitle: @"File" + action: NULL + keyEquivalent: @""]; - [menu addItemWithTitle: @"Edit" - action: NULL - keyEquivalent: @""]; + [menu addItemWithTitle: @"Edit" + action: NULL + keyEquivalent: @""]; - [menu addItemWithTitle: @"Windows" - action: NULL - keyEquivalent: @""]; + [menu addItemWithTitle: @"Windows" + action: NULL + keyEquivalent: @""]; - [menu addItemWithTitle: @"Scheme" - action: NULL - keyEquivalent: @""]; + [menu addItemWithTitle: @"Scheme" + action: NULL + keyEquivalent: @""]; - [menu addItemWithTitle: @"Environment" - action: NULL - keyEquivalent: @""]; + [menu addItemWithTitle: @"Environment" + action: NULL + keyEquivalent: @""]; - [menu addItemWithTitle: @"Services" - action: NULL - keyEquivalent: @""]; + [menu addItemWithTitle: @"Services" + action: NULL + keyEquivalent: @""]; - [menu addItemWithTitle: @"Hide" - action: @selector(hide:) - keyEquivalent: @"h"]; + [menu addItemWithTitle: @"Hide" + action: @selector(hide:) + keyEquivalent: @"h"]; - [menu addItemWithTitle: @"Quit" - action: @selector(terminate:) - keyEquivalent: @"q"]; + [menu addItemWithTitle: @"Quit" + action: @selector(terminate:) + keyEquivalent: @"q"]; - // Create the scheme submenu - scheme = [NSMenu new]; - [menu setSubmenu: scheme - forItem: [menu itemWithTitle: @"Scheme"]]; + // Create the scheme submenu + scheme = [NSMenu new]; + [menu setSubmenu: scheme + forItem: [menu itemWithTitle: @"Scheme"]]; - [scheme addItemWithTitle: @"Reset" - action: @selector(reset:) - keyEquivalent: @"+"]; + [scheme addItemWithTitle: @"Reset" + action: @selector(reset:) + keyEquivalent: @"+"]; - [scheme addItemWithTitle: @"Evaluate" - action: @selector(evaluate:) - keyEquivalent: @"#"]; + [scheme addItemWithTitle: @"Evaluate" + action: @selector(evaluate:) + keyEquivalent: @"#"]; - // Create the environment submenu - env = [NSMenu new]; - [menu setSubmenu: env - forItem: [menu itemWithTitle: @"Environment"]]; + [scheme addItemWithTitle: @"Evaluate external" + action:NULL + keyEquivalent: @""]; - [env addItemWithTitle: @"Up" - action: @selector(up:) - keyEquivalent: @""]; + external = [NSMenu new]; + [scheme setSubmenu: external + forItem: [scheme itemWithTitle: @"Evaluate external"]]; + [external addItemWithTitle: @"Add external" + action: @selector(addExternal:) + keyEquivalent: @""]; - [env addItemWithTitle: @"Down" - action: @selector(down:) - keyEquivalent: @""]; - // Create the info submenu - info = [NSMenu new]; - [menu setSubmenu: info - forItem: [menu itemWithTitle: @"Info"]]; + // Create the environment submenu + env = [NSMenu new]; + [menu setSubmenu: env + forItem: [menu itemWithTitle: @"Environment"]]; - [info addItemWithTitle: @"Info Panel..." - action: @selector(orderFrontStandardInfoPanel:) - keyEquivalent: @""]; + [env addItemWithTitle: @"Up" + action: @selector(up:) + keyEquivalent: @""]; + + [env addItemWithTitle: @"Down" + action: @selector(down:) + keyEquivalent: @""]; + + // Create the info submenu + info = [NSMenu new]; + [menu setSubmenu: info + forItem: [menu itemWithTitle: @"Info"]]; + + [info addItemWithTitle: @"Info Panel..." + action: @selector(orderFrontStandardInfoPanel:) + keyEquivalent: @""]; /* - [info addItemWithTitle: @"Preferences..." - action: NULL - keyEquivalent: @""]; + [info addItemWithTitle: @"Preferences..." + action: NULL + keyEquivalent: @""]; */ - [info addItemWithTitle: @"Help" - action: @selector (orderFrontHelpPanel:) - keyEquivalent: @"?"]; - // RELEASE(info); + [info addItemWithTitle: @"Help" + action: @selector (orderFrontHelpPanel:) + keyEquivalent: @"?"]; + // RELEASE(info); - // Create the file submenu - file = [NSMenu new]; - [menu setSubmenu: file - forItem: [menu itemWithTitle: @"File"]]; + // Create the file submenu + file = [NSMenu new]; + [menu setSubmenu: file + forItem: [menu itemWithTitle: @"File"]]; - [file addItemWithTitle: @"Open Document" - action: @selector(openDocument:) - keyEquivalent: @"o"]; + [file addItemWithTitle: @"Open Document" + action: @selector(openDocument:) + keyEquivalent: @"o"]; - [file addItemWithTitle: @"New Document" - action: @selector(newDocument:) - keyEquivalent: @"n"]; + [file addItemWithTitle: @"New Document" + action: @selector(newDocument:) + keyEquivalent: @"n"]; - [file addItemWithTitle: @"Save" - action: @selector(saveDocument:) - keyEquivalent: @"s"]; + [file addItemWithTitle: @"Save" + action: @selector(saveDocument:) + keyEquivalent: @"s"]; - [file addItemWithTitle: @"Save To..." - action: @selector(saveDocumentTo:) - keyEquivalent: @"t"]; + [file addItemWithTitle: @"Save To..." + action: @selector(saveDocumentTo:) + keyEquivalent: @"t"]; - [file addItemWithTitle: @"Save As..." - action: @selector(saveDocumentAs:) - keyEquivalent: @"S"]; + [file addItemWithTitle: @"Save As..." + action: @selector(saveDocumentAs:) + keyEquivalent: @"S"]; - [file addItemWithTitle: @"Save All" - action: @selector(saveDocumentAll:) - keyEquivalent: @""]; + [file addItemWithTitle: @"Save All" + action: @selector(saveDocumentAll:) + keyEquivalent: @""]; - [file addItemWithTitle: @"Revert to Saved" - action: @selector(revertDocumentToSaved:) - keyEquivalent: @"u"]; + [file addItemWithTitle: @"Revert to Saved" + action: @selector(revertDocumentToSaved:) + keyEquivalent: @"u"]; - [file addItemWithTitle: @"Close" - action: @selector(close) - keyEquivalent: @""]; + [file addItemWithTitle: @"Close" + action: @selector(close) + keyEquivalent: @""]; - [file addItemWithTitle: @"Insert File..." - action: @selector(insertFile:) - keyEquivalent: @""]; + [file addItemWithTitle: @"Insert File..." + action: @selector(insertFile:) + keyEquivalent: @""]; - // RELEASE(file); + // RELEASE(file); - // Create the edit submenu - edit = [NSMenu new]; - [menu setSubmenu: edit - forItem: [menu itemWithTitle: @"Edit"]]; + // Create the edit submenu + edit = [NSMenu new]; + [menu setSubmenu: edit + forItem: [menu itemWithTitle: @"Edit"]]; - [edit addItemWithTitle: @"Cut" - action: @selector(cut:) - keyEquivalent: @"x"]; + [edit addItemWithTitle: @"Cut" + action: @selector(cut:) + keyEquivalent: @"x"]; - [edit addItemWithTitle: @"Copy" - action: @selector(copy:) - keyEquivalent: @"c"]; + [edit addItemWithTitle: @"Copy" + action: @selector(copy:) + keyEquivalent: @"c"]; - [edit addItemWithTitle: @"Paste" - action: @selector(paste:) - keyEquivalent: @"v"]; + [edit addItemWithTitle: @"Paste" + action: @selector(paste:) + keyEquivalent: @"v"]; - [edit addItemWithTitle: @"Delete" - action: @selector(delete:) - keyEquivalent: @""]; + [edit addItemWithTitle: @"Delete" + action: @selector(delete:) + keyEquivalent: @""]; /* [edit addItemWithTitle: @"Undelete" - action: NULL - keyEquivalent: @""]; + action: NULL + keyEquivalent: @""]; */ - [edit addItemWithTitle: @"Select All" - action: @selector(selectAll:) - keyEquivalent: @"a"]; - // RELEASE(edit); + [edit addItemWithTitle: @"Select All" + action: @selector(selectAll:) + keyEquivalent: @"a"]; + // RELEASE(edit); - // Create the windows submenu - windows = [NSMenu new]; - [menu setSubmenu: windows - forItem: [menu itemWithTitle: @"Windows"]]; + // Create the windows submenu + windows = [NSMenu new]; + [menu setSubmenu: windows + forItem: [menu itemWithTitle: @"Windows"]]; - [windows addItemWithTitle: @"Arrange" - action: @selector(arrangeInFront:) - keyEquivalent: @""]; + [windows addItemWithTitle: @"Arrange" + action: @selector(arrangeInFront:) + keyEquivalent: @""]; - [windows addItemWithTitle: @"Miniaturize" - action: @selector(performMiniaturize:) - keyEquivalent: @"m"]; + [windows addItemWithTitle: @"Miniaturize" + action: @selector(performMiniaturize:) + keyEquivalent: @"m"]; - [windows addItemWithTitle: @"Close" - action: @selector(performClose:) - keyEquivalent: @"w"]; + [windows addItemWithTitle: @"Close" + action: @selector(performClose:) + keyEquivalent: @"w"]; - [windows addItemWithTitle: @"Close image windows" - action: @selector(closeImageWindows:) - keyEquivalent: @"W"]; + [windows addItemWithTitle: @"Close image windows" + action: @selector(closeImageWindows:) + keyEquivalent: @"W"]; - [windows addItemWithTitle: @"Close environment windows" - action: @selector(closeEnvWindows:) - keyEquivalent: @""]; + [windows addItemWithTitle: @"Close environment windows" + action: @selector(closeEnvWindows:) + keyEquivalent: @""]; - [NSApp setWindowsMenu: windows]; - // RELEASE(windows); + [NSApp setWindowsMenu: windows]; + // RELEASE(windows); - // Create the service submenu - services = [NSMenu new]; - [menu setSubmenu: services - forItem: [menu itemWithTitle: @"Services"]]; + // Create the service submenu + services = [NSMenu new]; + [menu setSubmenu: services + forItem: [menu itemWithTitle: @"Services"]]; - [NSApp setServicesMenu: services]; - // RELEASE(services); + [NSApp setServicesMenu: services]; + // RELEASE(services); - [NSApp setMainMenu: menu]; - // RELEASE(menu); + [NSApp setMainMenu: menu]; + // RELEASE(menu); - imageWindows = [NSMutableArray arrayWithCapacity:1]; - [imageWindows retain]; + imageWindows = [NSMutableArray arrayWithCapacity:1]; + [imageWindows retain]; - envWindows = [NSMutableArray arrayWithCapacity:1]; - [envWindows retain]; + envWindows = [NSMutableArray arrayWithCapacity:1]; + [envWindows retain]; - // RELEASE(pool); + // RELEASE(pool); } - (void)applicationDidFinishLaunching: (NSNotification *)not; @@ -229,7 +234,8 @@ VScheme *vm = nil; vm = [[VScheme alloc] init]; [vm setDelegate:self]; - [self makeStatisticsWindow]; + [self makeStatisticsPanel]; + [self makeInterruptPanel]; [self makeInterpreterWindow]; // Make the DocumentController the delegate of the application, @@ -239,6 +245,7 @@ VScheme *vm = nil; NSWindow *interpreterWindow = nil; + - makeInterpreterWindow { NSWindow *window; @@ -310,9 +317,9 @@ NSWindow *interpreterWindow = nil; return self; } -- makeStatisticsWindow +- makeStatisticsPanel { - NSWindow *window; + NSPanel *panel; NSScrollView *scrollView; SCMInteractive *textView; NSRect scrollViewRect = {{0, 0}, {470, 400}}; @@ -323,11 +330,11 @@ NSWindow *interpreterWindow = nil; // This is expected to be retained, as it would normaly come from a // nib file, where the owner would retain it. - window = [[NSWindow alloc] initWithContentRect: winRect + panel = [[NSPanel alloc] initWithContentRect: winRect styleMask: style backing: NSBackingStoreRetained defer: NO]; - [window setMinSize:NSMakeSize(300, 300)]; + [panel setMinSize:NSMakeSize(300, 300)]; scrollView = [[NSScrollView alloc] initWithFrame: scrollViewRect]; [scrollView setHasHorizontalScroller: NO]; @@ -363,21 +370,53 @@ NSWindow *interpreterWindow = nil; [scrollView setDocumentView: textView]; // RELEASE(textView); - [window setContentView: scrollView]; + [panel setContentView: scrollView]; // RELEASE(scrollView); - // Make the Document the delegate of the window - [window setDelegate: self]; + // Make the Document the delegate of the panel + [panel setDelegate: self]; + [panel setWorksWhenModal:NO]; // Make the text view the first responder - // [window makeFirstResponder:textView]; - [window setTitle:@"GScheme Statistics"]; - [window display]; - [window orderFront:nil]; + // [panel makeFirstResponder:textView]; + [panel setTitle:@"GScheme Statistics"]; + [panel display]; + [panel orderFront:nil]; return self; } +#define IPCWIDTH 100 +#define IPCHEIGHT 30 + + +- makeInterruptPanel +{ + interruptPanel = + [[NSPanel alloc] + initWithContentRect:NSMakeRect(0, 0, IPCWIDTH, IPCHEIGHT) + styleMask:NSBorderlessWindowMask + backing:NSBackingStoreBuffered + defer:NO]; + [interruptPanel setReleasedWhenClosed:NO]; + + NSButton *stopper; + stopper = [NSButton new]; + [stopper setTitle:@"Stop"]; + [stopper setTarget:vm]; + [stopper setAction:@selector(interrupt:)]; + + [interruptPanel setContentView:stopper]; + + return self; +} + +- (NSPanel *)interruptPanel +{ + return interruptPanel; +} + + - input:(NSString *)data { [intTextView appendString:data]; @@ -387,6 +426,7 @@ NSWindow *interpreterWindow = nil; - output:(NSString *)data { [intTextView appendString:data]; + [intTextView placeCursorAtEnd]; return self; } @@ -402,7 +442,12 @@ NSWindow *interpreterWindow = nil; - statistics:(NSString *)stats { NSString *sofar = [statTextView string]; - [statTextView setString:[sofar stringByAppendingString:stats]]; + [statTextView + replaceCharactersInRange:NSMakeRange([sofar length], 0) + withString:stats]; + + [statTextView placeCursorAtEnd]; + return self; } @@ -418,6 +463,67 @@ NSWindow *interpreterWindow = nil; [statTextView setString:GSCHEME]; } +- addExternal:(id)sender +{ + NSOpenPanel *openPanel = [NSOpenPanel openPanel]; + + [openPanel setTitle:@"Add external"]; + [openPanel setAllowsMultipleSelection:NO]; + [openPanel setPrompt:@"File:"]; + [openPanel setCanChooseDirectories:NO]; + + if([openPanel + runModalForTypes: + [NSArray arrayWithObject:@"scm"]]==NSOKButton){ + [[sender menu] addItemWithTitle:[openPanel filename] + action:@selector(evaluateExternal:) + keyEquivalent: @""]; + } + + return self; +} + +extern VScheme *vm; +extern NSWindow *interpreterWindow; + +extern int errno; + +- evaluateExternal:(id)sender +{ + SCMInteractive *intView = + [[interpreterWindow contentView] documentView]; + NSString *suffix = [intView getSuffix]; + + if([suffix length]>0){ + [intView appendString:@"\n> "]; + } + + NSString *progstr; + if((progstr = + [NSString stringWithContentsOfFile:[sender title]])==nil){ + NSString *msg = @"Load failed"; + if(errno){ + char *estr = strerror(errno); + msg = [msg stringByAppendingFormat:@": %s", estr]; + } + + NSRunAlertPanel(@"Error", msg, @"Ok", nil, nil); + return self; + } + + BOOL res = [vm processString:progstr mode:MODE_EVALUATE]; + if(res==NO){ + NSRunAlertPanel(@"Error", [vm errmsg], + @"Ok", nil, nil); + } + else{ + [interpreterWindow makeKeyAndOrderFront:self]; + } + + return self; +} + + - imageWindow:(NSWindow *)window { [imageWindows addObject:window]; @@ -441,21 +547,20 @@ NSWindow *interpreterWindow = nil; } else if([envWindows containsObject:win]==YES){ [envWindows removeObject:win]; - [win releaseForms]; } } - closeImageWindows:(id)sender { - [imageWindows - makeObjectsPerformSelector:@selector(close)]; + NSArray *cwins = [NSArray arrayWithArray:imageWindows]; + [cwins makeObjectsPerformSelector:@selector(close)]; return self; } - closeEnvWindows:(id)sender { - [envWindows - makeObjectsPerformSelector:@selector(close)]; + NSArray *cwins = [NSArray arrayWithArray:envWindows]; + [cwins makeObjectsPerformSelector:@selector(close)]; return self; } diff --git a/SchemeTypes.h b/SchemeTypes.h index af63d24..213577a 100644 --- a/SchemeTypes.h +++ b/SchemeTypes.h @@ -2,27 +2,13 @@ #import -@interface NSMutableArray (Wrap) - -- (void)prependObjWRP:(id)anObject; -- (void)addObjWRP:(id)anObject; - -- (void)replaceObjWRPAtIndex:(unsigned)index withObject:(id)anObject; - -@end - -@interface NSMutableDictionary (Wrap) - -- (void)setObjWRP:(id)anObject forKey:(id)aKey; - -@end - #define MARKABLE(_item) \ ((_item)!=nil && ((id)(_item))!=(id)[NSNull null] && \ [(_item) isKindOfClass:[SCMType class]]) @interface SCMType : NSObject { +@protected int mark; } @@ -107,6 +93,7 @@ NSString *value; } +- initSCMStringLEX:(char *)val; - initSCMString:(char *)val; - (NSString *)strVal; @@ -199,18 +186,18 @@ @interface Environment : SCMType { Environment *parent; - NSMutableDictionary *data; + NSMapTable *data; } -+ newParent:(Environment *)par Data:(NSMutableDictionary *)entries; -- initParent:(Environment *)par Data:(NSMutableDictionary *)entries; ++ newParent:(Environment *)par Data:(NSMapTable *)entries; +- initParent:(Environment *)par Data:(NSMapTable *)entries; - (int)chainLength; -- (NSMutableDictionary *)lookup:(NSString *)sym; +- (NSMapTable *)lookup:(NSString *)sym; - (Environment *)parent; -- (NSMutableDictionary *)data; +- (NSMapTable *)data; - setMarkToCurrent; @@ -294,11 +281,16 @@ typedef enum { @interface ByteCodes : SCMType { - NSMutableArray *data; + unsigned int capacity; + unsigned int length; + id *data; + + BOOL root; + id source; } + new; -- initWithMutableArray:(NSMutableArray *)theData; +- init; - prependTriple:(Triple *)theTriple; @@ -306,10 +298,17 @@ typedef enum { - appendByteCodes:(ByteCodes *)codes; -- (NSMutableArray *)codes; +- (id *)codes; +- (unsigned int)length; - setMarkToCurrent; +- (BOOL)root; +- setRoot:(BOOL)rflag; + +- source; +- setSource:(id)src; + - (void)free; @end diff --git a/SchemeTypes.m b/SchemeTypes.m index aba34c0..204af3c 100644 --- a/SchemeTypes.m +++ b/SchemeTypes.m @@ -1,42 +1,6 @@ #import "SchemeTypes.h" -@implementation NSMutableArray (Wrap) - -- (void)addObjWRP:(id)anObject -{ - [anObject retain]; - [self addObject:anObject]; - return; -} - -- (void)replaceObjWRPAtIndex:(unsigned)index withObject:(id)anObject -{ - [anObject retain]; - [self replaceObjectAtIndex:index withObject:anObject]; - return; -} - -- (void)prependObjWRP:(id)anObject -{ - [anObject retain]; - [self insertObject:anObject atIndex:0]; - return; -} - -@end - -@implementation NSMutableDictionary (Wrap) - -- (void)setObjWRP:(id)anObject forKey:(id)aKey -{ - [anObject retain]; - [self setObject:anObject forKey:aKey]; - return; -} - -@end - @implementation SCMType static int allocatedAfterGC = 0; @@ -233,11 +197,11 @@ static int totalAllocated = 0; - setMarkToCurrent { - if([self mark]==currentMark){ + if(mark==currentMark){ return; } - [super setMarkToCurrent]; + mark = currentMark; if(MARKABLE(car)){ [car setMarkToCurrent]; } @@ -309,11 +273,11 @@ static int totalAllocated = 0; { int index; - if([self mark]==currentMark){ + if(mark==currentMark){ return; } - [super setMarkToCurrent]; + mark = currentMark; for(index=0; index - -@interface GSMutableDictionary : NSDictionary -{ -@public - GSIMapTable_t map; -} -@end - -typedef struct { - @defs(GSMutableDictionary) -} *GSMDictPtr; - - (void)free { - GSIMapEmptyMap(&(((GSMDictPtr)data)->map)); - while([data retainCount]>1){ - [data release]; - } - + NSFreeMapTable(data); [super free]; } @@ -549,7 +497,9 @@ typedef struct { + newTag:(int)tagval IntArg1:(int)arg1; { - NSNumber *num = [NSNumber numberWithInt:arg1]; + // NSNumber *num = [NSNumber numberWithInt:arg1]; + Int *num = [[Int alloc] initSCMInt:arg1]; + return [[super alloc] initTag:tagval Arg1:num Arg2:nil Arg3:nil]; @@ -581,9 +531,20 @@ typedef struct { { tag = tagval; - items[0] = arg1; [arg1 retain]; - items[1] = arg2; [arg2 retain]; - items[2] = arg3; [arg3 retain]; + items[0] = arg1; + if(arg1!=nil){ + [arg1 retain]; + } + + items[1] = arg2; + if(arg2!=nil){ + [arg2 retain]; + } + + items[2] = arg3; + if(arg3!=nil){ + [arg3 retain]; + } return self; } @@ -595,12 +556,14 @@ typedef struct { - (int)intarg1 { - return [items[0] intValue]; + return [items[0] intVal]; } - setIntArg1:(int)val { - items[0] = [NSNumber numberWithInt:val]; + // items[0] = [NSNumber numberWithInt:val]; + items[0] = [[Int alloc] initSCMInt:val]; + [items[0] retain]; return self; } @@ -621,11 +584,11 @@ typedef struct { - setMarkToCurrent { - if([self mark]==currentMark){ + if(mark==currentMark){ return; } - [super setMarkToCurrent]; + mark = currentMark; if(MARKABLE(items[0])){ [items[0] setMarkToCurrent]; } @@ -715,8 +678,10 @@ typedef struct { - initSCMSymbol:(char *)val { [super init]; + value = [NSString stringWithCString:val]; [value retain]; + return self; } @@ -735,7 +700,7 @@ typedef struct { @implementation String -- initSCMString:(char *)val +- initSCMStringLEX:(char *)val { char *cp, *buf, *from, *to; int len = strlen(val); @@ -762,6 +727,16 @@ typedef struct { return self; } +- initSCMString:(char *)val +{ + [super init]; + + value = [NSString stringWithCString:val]; + [value retain]; + + return self; +} + - (NSString *)strVal { return value; @@ -775,89 +750,143 @@ typedef struct { @end +#define BASE_CAPACITY 16 + @implementation ByteCodes + new { id inst = [super alloc]; - [inst initWithMutableArray:[NSMutableArray arrayWithCapacity:1]]; + [inst init]; return inst; } -- initWithMutableArray:(NSMutableArray *)theData +- init { [super init]; - data = theData; - [data retain]; + + capacity = BASE_CAPACITY; + length = 0; + data = (id *)NSZoneMalloc(NSDefaultMallocZone(), capacity*sizeof(id)); + + root = NO; + source = nil; return self; } - prependTriple:(Triple *)theTriple { - [data prependObjWRP:theTriple]; + if(length==capacity){ + capacity *= 2; + data = (id *)NSZoneRealloc(NSDefaultMallocZone(), data, capacity*sizeof(id)); + } + + memmove(data+1, data, length*sizeof(id)); + length++; + + data[0] = theTriple; + [theTriple retain]; + return self; } - addTriple:(Triple *)theTriple { - [data addObjWRP:theTriple]; + if(length==capacity){ + capacity *= 2; + data = (id *)NSZoneRealloc(NSDefaultMallocZone(), data, capacity*sizeof(id)); + } + + data[length++] = theTriple; + [theTriple retain]; + return self; } - appendByteCodes:(ByteCodes *)codes { - [data addObjectsFromArray:[codes codes]]; + unsigned int otherLength = [codes length]; + id *otherData = [codes codes]; + + if(length+otherLength>capacity){ + while(length+otherLength>capacity){ + capacity *= 2; + } + data = (id *)NSZoneRealloc(NSDefaultMallocZone(), data, capacity*sizeof(id)); + } + + unsigned int pos; + for(pos=0; pos_count = 0; - while([data retainCount]>1){ - [data release]; - } - + NSZoneFree(NSDefaultMallocZone(), data); [super free]; } diff --git a/TestScheme.app/Resources/Info-gnustep.plist b/TestScheme.app/Resources/Info-gnustep.plist deleted file mode 100644 index a1b1f52..0000000 --- a/TestScheme.app/Resources/Info-gnustep.plist +++ /dev/null @@ -1,6 +0,0 @@ -{ - NOTE = "Automatically generated, do not edit!"; - NSExecutable = "TestScheme"; - NSMainNibFile = ""; - NSPrincipalClass = "NSApplication"; -} diff --git a/TestScheme.app/Resources/TestScheme.desktop b/TestScheme.app/Resources/TestScheme.desktop deleted file mode 100644 index e651203..0000000 --- a/TestScheme.app/Resources/TestScheme.desktop +++ /dev/null @@ -1,5 +0,0 @@ -[Desktop Entry] -Encoding=UTF-8 -Type=Application -Exec=openapp TestScheme.app -#TryExec=TestScheme.app diff --git a/TestScheme.app/TestScheme b/TestScheme.app/TestScheme deleted file mode 100755 index 86f732b..0000000 --- a/TestScheme.app/TestScheme +++ /dev/null @@ -1,218 +0,0 @@ -#!/bin/sh -# -# Copyright (C) 1999 Free Software Foundation, Inc. -# -# Author: Adam Fedor -# Date: May 1999 -# -# This file is part of the GNUstep Makefile Package. -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# You should have received a copy of the GNU General Public -# License along with this library; see the file COPYING.LIB. -# If not, write to the Free Software Foundation, -# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -# This is a shell script which attempts to find the GNUstep executable -# of the same name based on the current host and library_combo. - -#-------------------------------------------------------------------------- -# Main body -#-------------------------------------------------------------------------- -if [ -z "$EXEEXT" ]; then - EXEEXT= -fi -if [ -z "$LIBRARY_COMBO" ]; then - LIBRARY_COMBO=gnu-gnu-gnu -fi - -# Process arguments -app=$0 -show_available_platforms=0 -show_relative_path=0 -show_full_path=0 -while true -do - case $1 in - - --script-help) - echo usage: `basename $0` [--library-combo=...] - echo " [--available-platforms][--full-executable-path]" - echo " [--relative-executable-path] [arguments...]" - echo - echo " --library-combo=... specifies a GNUstep backend to use." - echo " It overrides the default LIBRARY_COMBO environment variable." - echo - echo " --available-platforms displays a list of valid exec hosts" - echo " --full-executable-path displays full path to executable" - echo " --relative-executable-path displays subdirectory path" - echo " arguments... are the arguments to the application." - exit 0 - ;; - --library-combo=*) - LIBRARY_COMBO=`echo $1 | sed 's/--library-combo=//'` - shift - ;; - --available-platforms) - show_available_platforms=1 - exit 0 - ;; - --full-executable-path) - show_full_path=1 - break - ;; - --relative-executable-path) - show_relative_path=1 - break - ;; - *) - break;; - esac -done - -if [ "$LIBRARY_COMBO" = nx ]; then - LIBRARY_COMBO=nx-nx-nx -elif [ "$LIBRARY_COMBO" = gnu ]; then - LIBRARY_COMBO=gnu-gnu-gnu -elif [ "$LIBRARY_COMBO" = fd ]; then - LIBRARY_COMBO=gnu-fd-gnu -fi -export LIBRARY_COMBO - -# Find path to ourself -app=`echo $app | sed 's%/*$%%'` -dir=`dirname $app` - -case $app in - /*) # An absolute path. - full_appname=$dir;; - */*) # A relative path - full_appname=`(cd $dir; pwd)`;; - *) # A path that needs to be searched - if [ -n $GNUSTEP_PATHPREFIX_LIST ]; then - SPATH=$GNUSTEP_PATHPREFIX_LIST - else - SPATH=$PATH - fi - SPATH=.:$SPATH - IFS=: - for path_dir in $SPATH; do - if [ -d $path_dir/$dir ]; then - full_appname=`(cd $path_dir/$dir; pwd)` - break; - fi - if [ -d $path_dir/Applications/$dir ]; then - full_appname=`(cd $path_dir/Applications/$dir; pwd)` - break; - fi - done;; -esac - -if [ -z "$full_appname" ]; then - echo "Can't find absolute path for $app! Please specify full path when" - echo "invoking executable" - exit 1 -fi - -# -# get base app name -# -app=`echo $app | sed 's/\.[a-z]*$//'` -app=`basename $app` -appname= -if [ -f "$full_appname/Resources/Info-gnustep.plist" ]; then -# -n disable auto-print (for portability reasons) -# /^ *NSExecutable *=/ matches every line beginning with -# zero or more spaces, followed by 'NSExecutable', followed by zero or -# more spaces, followed by '=' -# to this line we apply the following commands: -# s/"//g; which deletes all " in the line. -# s/^ *NSExecutable *= *\([^ ;]*\) *;.*/\1/p; -# which replaces 'NSExecutable = Gorm; ' with 'Gorm', then, because -# of the 'p' at the end, prints out the result -# q; which quits sed since we know there must be only a single line -# to replace. - appname=`sed -n -e '/^ *NSExecutable *=/ \ - {s/"//g; s/^ *NSExecutable *= *\([^ ;]*\) *;.*/\1/p; q;}' \ - "$full_appname/Resources/Info-gnustep.plist"` -fi -if [ -z "$appname" ]; then - appname=$app -fi - -appname="$appname$EXEEXT" - -if [ $show_available_platforms = 1 ]; then - cd $full_appname - #available_platforms - exit 0 -fi - -# -# Determine the host information -# -if [ -z "$GNUSTEP_HOST" ]; then - GNUSTEP_HOST=`(cd /tmp; $GNUSTEP_SYSTEM_ROOT/Makefiles/config.guess)` - GNUSTEP_HOST=`(cd /tmp; $GNUSTEP_SYSTEM_ROOT/Makefiles/config.sub $GNUSTEP_HOST)` - export GNUSTEP_HOST -fi -if [ -z "$GNUSTEP_HOST_CPU" ]; then - GNUSTEP_HOST_CPU=`$GNUSTEP_SYSTEM_ROOT/Makefiles/cpu.sh $GNUSTEP_HOST` - GNUSTEP_HOST_CPU=`$GNUSTEP_SYSTEM_ROOT/Makefiles/clean_cpu.sh $GNUSTEP_HOST_CPU` - export GNUSTEP_HOST_CPU -fi -if [ -z "$GNUSTEP_HOST_VENDOR" ]; then - GNUSTEP_HOST_VENDOR=`$GNUSTEP_SYSTEM_ROOT/Makefiles/vendor.sh $GNUSTEP_HOST` - GNUSTEP_HOST_VENDOR=`$GNUSTEP_SYSTEM_ROOT/Makefiles/clean_vendor.sh $GNUSTEP_HOST_VENDOR` - export GNUSTEP_HOST_VENDOR -fi -if [ -z "$GNUSTEP_HOST_OS" ]; then - GNUSTEP_HOST_OS=`$GNUSTEP_SYSTEM_ROOT/Makefiles/os.sh $GNUSTEP_HOST` - GNUSTEP_HOST_OS=`$GNUSTEP_SYSTEM_ROOT/Makefiles/clean_os.sh $GNUSTEP_HOST_OS` - export GNUSTEP_HOST_OS -fi - -# -# Make sure the executable is there -# -if [ -x $full_appname/$GNUSTEP_HOST_CPU/$GNUSTEP_HOST_OS/$LIBRARY_COMBO/$appname ]; then - relative_path=$GNUSTEP_HOST_CPU/$GNUSTEP_HOST_OS/$LIBRARY_COMBO/$appname -elif [ -x $full_appname/$GNUSTEP_HOST_CPU/$GNUSTEP_HOST_OS/$appname ]; then - relative_path=$GNUSTEP_HOST_CPU/$GNUSTEP_HOST_OS/$appname -elif [ -x $full_appname/$GNUSTEP_HOST_CPU/$appname ]; then - relative_path=$GNUSTEP_HOST_CPU/$appname -elif [ $appname != $app -a -x $full_appname/$appname ]; then - relative_path=$appname -else - echo "$full_appname application does not have a binary for this kind of machine/operating system ($GNUSTEP_HOST_CPU/$GNUSTEP_HOST_OS)." - exit 1 -fi - -if [ $show_relative_path = 1 ]; then - echo $relative_path - exit 0 -fi -if [ $show_full_path = 1 ]; then - echo $full_appname/$relative_path - exit 0 -fi - -if [ "$LIBRARY_COMBO" = nx-nx-nx -a $GNUSTEP_HOST_OS = nextstep4 ]; then - if [ -f "$full_appname/library_paths.openapp" ]; then - additional_library_paths="`cat $full_appname/library_paths.openapp`" - fi -else - if [ -f "$full_appname/$GNUSTEP_HOST_CPU/$GNUSTEP_HOST_OS/$LIBRARY_COMBO/library_paths.openapp" ]; then - additional_library_paths="`cat $full_appname/$GNUSTEP_HOST_CPU/$GNUSTEP_HOST_OS/$LIBRARY_COMBO/library_paths.openapp`" - fi -fi - -# Load up LD_LIBRARY_PATH -. $GNUSTEP_SYSTEM_ROOT/Makefiles/ld_lib_path.sh - -exec $full_appname/$relative_path "$@" - diff --git a/VScheme.h b/VScheme.h index 83de895..c5f3148 100644 --- a/VScheme.h +++ b/VScheme.h @@ -7,15 +7,21 @@ #define GSCHEME @"GScheme by Marko Riedel, mriedel@neuearbeit.de\n" typedef enum { - MODE_INTERACTIVE, + MODE_INTERACTIVE = 0, MODE_EVALUATE, MODE_LOAD } PROCESS_MODE; typedef enum { - DRAW_MOVE, + DRAW_MOVE = 0, DRAW_LINE, - DRAW_COLOR + DRAW_COLOR, + DRAW_CIRCLE, + FILL_CIRCLE, + DRAW_RECT, + FILL_RECT, + DRAW_FONT, + DRAW_STRING } DRAW_INST; typedef struct _DrawInst { @@ -23,11 +29,16 @@ typedef struct _DrawInst { union { NSPoint coord; float color[3]; + float radius; + NSFont *font; + NSString *string; + NSSize size; } data; } DrawInst; @interface VScheme : NSObject { + int errpos; BOOL errflag; NSString *errmsg; @@ -36,10 +47,12 @@ typedef struct _DrawInst { NSMutableArray *argStack; NSMutableArray *envStack; - id curcodes; + id *curcodes; int curpc; + int curlength; - NSString *output; + BOOL hadOutput; + NSMutableString *output; int maxcode, maxpc, maxarg, maxenv; @@ -47,16 +60,18 @@ typedef struct _DrawInst { BOOL atImgStart; NSPoint imgMin, imgMax; + NSPoint imgCur; NSMutableArray *imgCodes; + NSFont *imgFont; - long int curRecDepth, maxRecDepth; + BOOL interrupted; } + (NSString *)valToString:(id)item seen:(NSMutableSet *)mem; + (NSString *)valToString:(id)item; + printInstr:(Triple *)instr; -+ printCodes:(NSMutableArray *)codes; ++ printCodes:(ByteCodes *)codes; - init; @@ -77,6 +92,7 @@ typedef struct _DrawInst { - (NSString *)output; - clearOutput; +- (NSSize)stringAtCurrentFont:(NSString *)str; - recordImgInst:(DrawInst)inst; - clearImage; - produceImage; @@ -86,12 +102,15 @@ typedef struct _DrawInst { - (NSMutableArray *)codeStack; - (BOOL)errflag; +- (int)errpos; - (NSString *)errmsg; - args2list:(int)lower; -- pushCodes:(NSMutableArray *)codes; -- (BOOL)run:(ByteCodes *)prog; +- pushByteCodes:(ByteCodes *)bcodes; + +- interrupt:(id)sender; +- (BOOL)run:(ByteCodes *)prog mode:(PROCESS_MODE)pmode; - special:(id)data output:(ByteCodes *)codes popenv:(int)ec; - sequence:(id)data output:(ByteCodes *)codes popenv:(int)ec; @@ -99,6 +118,7 @@ typedef struct _DrawInst { - (BOOL)compile:(id)data output:(ByteCodes *)codes; +- parse:(NSString *)scmText; - (BOOL)processString:(NSString *)data mode:(PROCESS_MODE)pmode; @end diff --git a/VScheme.m b/VScheme.m index eaeda14..6612d58 100644 --- a/VScheme.m +++ b/VScheme.m @@ -2,6 +2,14 @@ #import "VScheme.h" #import "SchemeDelegate.h" +/* #include +#include +#include */ + +extern id yyresultform; +extern BOOL yyschemeerrflag; + +NSMutableArray *positionStack = nil; static char *forms[] = { @@ -73,10 +81,10 @@ void print_tree(id item, int indent) printf("PAIR %s\n", [[VScheme valToString:item] cString]); } else if([item isKindOfClass:[Vector class]]){ - printf("PAIR %s\n", [[VScheme valToString:item] cString]); + printf("VECTOR %s\n", [[VScheme valToString:item] cString]); } else if([item isKindOfClass:[ByteCodes class]]){ - printf("CODES: %u\n", [[item codes] count]); + printf("CODES: %u\n", [item length]); } else{ printf("FORM %s\n", forms[[item tag]]); @@ -150,40 +158,60 @@ static char *codenames[] = { else{ format = @"#\\%c"; } - return [[NSString alloc] - initWithFormat:format locale: nil, c]; + return [NSString stringWithFormat:format, c]; } else if(isInt(item)){ - return [[NSString alloc] - initWithFormat:@"%d" locale: nil, [item intVal]]; + return [NSString stringWithFormat:@"%d", [item intVal]]; } else if(isDouble(item)){ - return [[NSString alloc] - initWithFormat:@"%le" locale: nil, [item doubleVal]]; + double v = [item doubleVal]; + NSString *vstr = [[NSNumber numberWithDouble:v] description]; + const char *buf = [vstr cString]; + + if(*buf && *buf=='-'){ + buf++; + } + while(*buf && isdigit(*buf++)); + if(!(*buf)){ + vstr = [vstr stringByAppendingString:@".0"]; + } + + return vstr; } else if(isSymbol(item)){ - return [[NSString alloc] - initWithFormat:@"%@" locale: nil, [item symVal]]; + return [NSString stringWithFormat:@"%@", [item symVal]]; } else if(isString(item)){ - return [[NSString alloc] - initWithFormat:@"\"%@\"" locale: nil, [item strVal]]; + NSString *str = [item strVal]; + int len = [str length]; + + const char *src; + char buf[2*len+1], *dst; + src = [str cString]; dst = buf; + while(*src){ + if(*src=='"'){ + *dst++ = '\\'; + } + *dst++ = *src++; + } + *dst = 0; + + return [NSString stringWithFormat:@"\"%s\"", buf]; } else if(isClosure(item)){ - return [[NSString alloc] - initWithFormat:@"" - locale: nil, + return [NSString + stringWithFormat:@"", [VScheme valToString:[item args] seen:mem]]; } else if(isPrimitive(item)){ - return [[NSString alloc] - initWithFormat:@"" - locale: nil, [item primName]]; + return [NSString + stringWithFormat:@"", + [item primName]]; } else if(isThunk(item)){ - return [[NSString alloc] - initWithFormat:@"" - locale: nil, [item argp], [item envp], [item codep]]; + return [NSString + stringWithFormat:@"", + [item argp], [item envp], [item codep]]; } else if(isPair(item)){ NSString *str; @@ -300,13 +328,13 @@ static char *codenames[] = { } -+ printCodes:(NSMutableArray *)codes ++ printCodes:(ByteCodes *)bc { - NSEnumerator *enumerator = [codes objectEnumerator]; - id instr; + id *data = [bc codes]; - while((instr = [enumerator nextObject])){ - [self printInstr:instr]; + unsigned int pos, len = [bc length]; + for(pos=0; posinst.data.coord.x){ imgMin.x = inst.data.coord.x; } @@ -461,6 +529,55 @@ static char *codenames[] = { if(imgMax.yminx){ + imgMin.x = minx; + } + if(imgMin.y>miny){ + imgMin.y = miny; + } + if(imgMax.xMAXL ? " (...)" : "")]; + break; + } + + [positionStack removeLastObject]; + + id evForms = yyresultform; + if(evForms==[NSNull null]){ + res = [NSNull null]; + break; + } + + // [SCMType addToMarkables:evForms]; + + ByteCodes *evCodes = [ByteCodes new]; + [evCodes setSource:evForms]; + errflag = [self compile:[evForms arg1] output:evCodes]; + if(errflag==NO){ + [evCodes setRoot:YES]; + [self pushByteCodes:evCodes]; + } + } + else if(isPrimitive(op)){ if([op evalVM:self Args:argStack offset:offs]==YES){ res = [op value]; } else{ errflag = YES; - errmsg = [op errmsg]; + errmsg = + [[NSString alloc] + initWithString:[(Primitive *)op errmsg]]; break; } } @@ -878,17 +1210,18 @@ static int imgCount = 0; curpc = [[pcStack lastObject] intValue]; [pcStack removeLastObject]; - curcodes = [codeStack lastObject]; + curcodes = [[codeStack lastObject] codes]; } else if(isClosure(op)){ - NSMutableDictionary *layer = - [NSMutableDictionary dictionaryWithCapacity:1]; + NSMapTable *layer = + NSCreateMapTable(NSObjectMapKeyCallBacks, + NSNonRetainedObjectMapValueCallBacks, 1); id argl = [op args]; id env; if(isSymbol(argl)){ - [layer setObjWRP:[self args2list:offs] - forKey:[argl symVal]]; + id list = [self args2list:offs]; [list retain]; + NSMapInsert(layer, [argl symVal], list); } else{ int symc = 0; @@ -896,41 +1229,33 @@ static int imgCount = 0; symc++; if(symc>argc){ errflag = YES; - errmsg = @"not enough arguments"; + errmsg = + [[NSString alloc] + initWithFormat:@"not enough arguments to %@", + [VScheme valToString:op]]; break; } - [layer setObjWRP:[argStack objectAtIndex:offs++] - forKey:[[argl car] symVal]]; + id obj = [argStack objectAtIndex:offs++]; [obj retain]; + NSMapInsert(layer, [[argl car] symVal], obj); argl = [argl cdr]; } if(symcmaxRecDepth){ - int cont = - NSRunAlertPanel(@"Alert", - @"Deep recursion. Continue?", - @"Yes", @"No", nil); - if(cont==NSAlertAlternateReturn){ - errflag = YES; - errmsg = @"abort on deep recursion"; - } - - maxRecDepth *= 4; - } + [envStack addObject:env]; + [self pushByteCodes:[op body]]; } if(isThunk(op)==NO){ @@ -941,24 +1266,27 @@ static int imgCount = 0; } if(res!=nil){ - [argStack addObjWRP:res]; + [argStack addObject:res]; } } break; case IN_DEFINE:{ int offs = [argStack count]-2; - NSMutableDictionary *layer = [[envStack lastObject] data]; - [layer setObjWRP:[argStack objectAtIndex:(offs+1)] - forKey:[[argStack objectAtIndex:offs] symVal]]; + NSMapTable *layer = + [(Environment *)[envStack lastObject] data]; + + id obj = [argStack objectAtIndex:(offs+1)]; [obj retain]; + NSMapInsert(layer, [[argStack objectAtIndex:offs] symVal], obj); + [argStack removeLastObject]; } break; case IN_SET:{ int offs = [argStack count]-2; NSString *sym = [[argStack objectAtIndex:offs] symVal]; id val = [argStack objectAtIndex:offs+1]; - NSMutableDictionary *layer = + NSMapTable *layer = [[envStack lastObject] lookup:sym]; - if(layer==nil){ + if(layer==NULL){ NSString *format = @"symbol %@ not bound; can't assign to it"; errflag = YES; @@ -969,8 +1297,9 @@ static int imgCount = 0; break; } - [layer setObjWRP:[argStack objectAtIndex:(offs+1)] - forKey:[[argStack objectAtIndex:offs] symVal]]; + id obj = [argStack objectAtIndex:(offs+1)]; [obj retain]; + NSMapInsert(layer, [[argStack objectAtIndex:offs] symVal], obj); + [argStack removeObjectAtIndex:offs]; } break; case IN_CLOSURE:{ @@ -981,24 +1310,25 @@ static int imgCount = 0; Env:[envStack lastObject]]; [argStack removeLastObject]; [argStack removeLastObject]; - [argStack addObjWRP:closure]; + [argStack addObject:closure]; } break; case IN_IF:{ BOOL isfalse = isFalse([argStack lastObject]); - [self pushCodes:[(isfalse==YES ? - [instr arg2] : [instr arg1]) codes]]; + [self pushByteCodes:(isfalse==YES ? + [instr arg2] : [instr arg1])]; [argStack removeLastObject]; } break; case IN_LAYER:{ int count = [instr intarg1]; int offs = [argStack count]-2; - NSMutableDictionary *layer = - [NSMutableDictionary dictionaryWithCapacity:1]; + NSMapTable *layer = + NSCreateMapTable(NSObjectMapKeyCallBacks, + NSNonRetainedObjectMapValueCallBacks, 1); id env; while(count--){ - [layer setObjWRP:[argStack objectAtIndex:(offs+1)] - forKey:[[argStack objectAtIndex:offs] symVal]]; + id obj = [argStack objectAtIndex:(offs+1)]; [obj retain]; + NSMapInsert(layer, [[argStack objectAtIndex:offs] symVal], obj); [argStack removeLastObject]; [argStack removeLastObject]; offs-=2; @@ -1006,7 +1336,7 @@ static int imgCount = 0; env = [Environment newParent:[envStack lastObject] Data:layer]; - [envStack addObjWRP:env]; + [envStack addObject:env]; } break; case IN_MEMQ:{ id list = [argStack lastObject]; @@ -1022,7 +1352,7 @@ static int imgCount = 0; list = [list cdr]; } - [argStack addObjWRP:list]; + [argStack addObject:list]; } break; case IN_DUP_ARG: { if([argStack count]<1){ @@ -1030,7 +1360,7 @@ static int imgCount = 0; errmsg = @"missing item (duplicate)"; } else{ - [argStack addObjWRP:[argStack lastObject]]; + [argStack addObject:[argStack lastObject]]; } } break; case IN_EXCH_ARGS: { @@ -1044,8 +1374,8 @@ static int imgCount = 0; [argStack removeLastObject]; item2 = [argStack lastObject]; [argStack removeLastObject]; - [argStack addObjWRP:item1]; - [argStack addObjWRP:item2]; + [argStack addObject:item1]; + [argStack addObject:item2]; } } break; case IN_STATE_TO_THUNK:{ @@ -1090,7 +1420,7 @@ static int imgCount = 0; if([SCMType totalAllocated]>4*[SCMType allocatedAfterGC]){ int ptotal = [SCMType totalAllocated]; NSString *msg, - *format = @"\nGC prev: %d now: %d\n", + *format = @"\n%@\nGC prev: %d now: %d\n", *cformat = @"%@ prev: %d now: %d\n"; struct { Class cl; @@ -1098,17 +1428,19 @@ static int imgCount = 0; } *cent, classes[] = { { [Pair class], 0 }, { [Environment class], 0 }, + { [Int class], 0 }, { [Closure class], 0 }, { [Vector class], 0 }, { [Triple class], 0 }, { [ByteCodes class], 0 }, - { [NSForm class], 0 }, - { [NSFormCell class], 0 }, + { [interruptDate class], 0 }, + { [NSTableView class], 0 }, + { [NSTableColumn class], 0 }, { [NSScrollView class], 0 }, + { [SCMTextView class], 0 }, { [NSWindow class], 0 }, { nil, 0 } }; - int argind, argmx; for(cent=classes; cent->cl!=nil; cent++){ cent->prev = GSDebugAllocationCount(cent->cl); @@ -1119,9 +1451,16 @@ static int imgCount = 0; // [source setMarkToCurrent]; - [prog setMarkToCurrent]; + int codeind, codemx = [codeStack count]; + for(codeind=0; codeind0){ + if(hadOutput==NO){ + [delegate output:@"\n"]; + } + [delegate output:output]; + } + if(atImgStart==NO){ + [self produceImage]; + } + } + + if(runResult==YES){ NSString *msg; - if(pmode==MODE_EVALUATE){ - [delegate - input:[NSString stringWithCString:second]]; - } - - if(pmode!=MODE_LOAD){ - if([output length]>0){ - [delegate output:@"\n"]; - [delegate output:output]; - } - if(atImgStart==NO){ - [delegate imageWindow:[self produceImage]]; - } - } - if(pmode!=MODE_LOAD){ [delegate result:[argStack lastObject]]; } @@ -1656,9 +2027,13 @@ NSMutableArray *positions = nil; [envStack count], maxenv]; [delegate statistics:msg]; } - - [self resetStacks]; } + + + [self resetStacks]; + [envStack + removeObjectsInRange: + NSMakeRange(1, [envStack count]-1)]; } free(first); @@ -1669,8 +2044,9 @@ NSMutableArray *positions = nil; break; } } - - [SCMType removeFromMarkables:yyresult]; + + [positionStack removeLastObject]; + [SCMType removeFromMarkables:yyrf]; if(errflag==YES){ [delegate result:[NSNull null]]; @@ -1708,6 +2084,8 @@ NSMutableArray *positions = nil; [image retain]; } [self setNeedsDisplay:YES]; + + return self; } - (void)drawRect:(NSRect)aRect diff --git a/examples/allocate1.scm b/examples/allocate1.scm new file mode 100644 index 0000000..936a793 --- /dev/null +++ b/examples/allocate1.scm @@ -0,0 +1,6 @@ + +(define print-it + (lambda () + (display '(1 2 3)) + (newline) + (print-it))) diff --git a/examples/args1.scm b/examples/args1.scm new file mode 100644 index 0000000..eef75d2 --- /dev/null +++ b/examples/args1.scm @@ -0,0 +1,6 @@ + +;; not enough arguments + +(define p (lambda (x y) (+ x y))) +(p 6) + diff --git a/examples/args2.scm b/examples/args2.scm new file mode 100644 index 0000000..9e941cd --- /dev/null +++ b/examples/args2.scm @@ -0,0 +1,6 @@ + +;; too many arguments + +(define p (lambda (x y) (+ x y))) +(p 6 7 8) + diff --git a/examples/browse.scm b/examples/browse.scm index 3ab8743..22654a7 100644 --- a/examples/browse.scm +++ b/examples/browse.scm @@ -7,7 +7,6 @@ (reduce + 0 '(2 3 4)) - (define factit (lambda (n) (letrec diff --git a/examples/eval.scm b/examples/eval.scm new file mode 100644 index 0000000..0f76491 --- /dev/null +++ b/examples/eval.scm @@ -0,0 +1,33 @@ +(define primes + (eval + ;;; check for composite numbers by testing the + ;;; most probable divisors first + '(let* ((start (list 2)) + (end start)) + (letrec + ((composite? + (lambda (v l) + (let ((d (car l))) + (if (> (* d d) v) #f + (if (zero? (remainder v d)) #t + (composite? v (cdr l))))))) + (findnext + (lambda (v) + (if (composite? v start) + (findnext (+ v 1)) v)))) + (lambda () + (let* ((current (car end)) + (next (findnext (+ current 1))) + (p (cons next '()))) + (set-cdr! end p) + (set! end p) + current)))))) + +(define displayprimes + (lambda (n) + (if (not (zero? n)) + (begin + (display (primes)) (newline) + (displayprimes (- n 1)))))) + +(displayprimes 14) diff --git a/examples/eval1.scm b/examples/eval1.scm new file mode 100644 index 0000000..6241314 --- /dev/null +++ b/examples/eval1.scm @@ -0,0 +1,56 @@ + +(define pi (* 2 (acos 0))) + +(define res 200) + +(define data + (letrec + ((delta (/ (* 2 pi) res)) + (vect (make-vector res)) + (iter + (lambda (q) + (if (< q res) + (begin + (vector-set! + vect q + (cons (cos (* q delta)) + (sin (* q delta)))) + (let ((ev (eval '(iter (+ 1 q))))) + ev)))))) + (iter 0) + vect)) + +(define draw-circle + (lambda (radius) + (letrec + ((iter + (lambda (q) + (if (< q res) + (begin + (draw-line + (* radius (car (vector-ref data q))) + (* radius (cdr (vector-ref data q)))) + (iter (+ 1 q))))))) + (draw-move radius 0) + (iter 0) + (draw-line radius 0)))) + +(define steps 8) + +(define circles + (lambda (maxrad) + (letrec + ((iter + (lambda (q) + (if (< q maxrad) + (begin + (draw-color 0 (/ (* 255.0 q) maxrad) 0) + (draw-circle q) + (iter (+ q steps))))))) + (iter 1)))) + +(circles 100) + + + + diff --git a/examples/library.scm b/examples/library.scm index b08daa4..ace7cca 100644 --- a/examples/library.scm +++ b/examples/library.scm @@ -107,3 +107,6 @@ (map-over-single-list car lists)) (apply for-each (cons proc (map-over-single-list cdr lists))))))) + +(define pow (lambda (x y) (exp (* y (log x))))) + diff --git a/examples/mandel.scm b/examples/mandel.scm new file mode 100644 index 0000000..ae5c95d --- /dev/null +++ b/examples/mandel.scm @@ -0,0 +1,37 @@ + +;; mandelbrot set + +(define mandel + (lambda (rmin rmax imin imax res) + (letrec + ((rdelta (- rmax rmin)) (idelta (- imax imin)) + (rdelta1 (/ rdelta res)) (idelta1 (/ idelta res)) + (pcolor + (lambda (re im cre cim n) + (if (or (> n 200) (> (+ (* re re) (* im im)) 4.0)) + (let + ((c (* 8 (remainder n 8))) + (x (* res (/ (- cre rmin) rdelta))) + (y (* res (/ (- cim imin) idelta)))) + (draw-color + (* 255 (remainder n 2)) + (* 255 (remainder (quotient n 2) 2)) + (* 255 (remainder (quotient n 4) 2))) + (draw-move x y) + (draw-line (+ x 1) (+ y 1))) + (pcolor + (+ (- (* re re) (* im im)) cre) + (+ (* 2 re im) cim) + cre cim (+ 1 n))))) + (iter + (lambda (rep imp) + (if (> rep rmax) + (if (> imp imax) '() + (iter rmin (+ imp idelta1))) + (begin + (pcolor 0 0 rep imp 0) + (iter (+ rep rdelta1) imp)))))) + (iter rmin imin)))) + +(mandel -1.5 0.5 -1.0 1.0 25) + diff --git a/examples/parse-error.scm b/examples/parse-error.scm new file mode 100644 index 0000000..0ffa877 --- /dev/null +++ b/examples/parse-error.scm @@ -0,0 +1,8 @@ + +;; missing parenthesis + +(define adder + (lambda (a) + (lambda (b) + (+ a b))) + diff --git a/examples/parse-error1.scm b/examples/parse-error1.scm new file mode 100644 index 0000000..0c5ae63 --- /dev/null +++ b/examples/parse-error1.scm @@ -0,0 +1,55 @@ + +(define pi (* 2 (acos 0))) + +(define res 200) + +(define data + (letrec + ((delta (/ (* 2 pi) res)) + (vect (make-vector res)) + (iter extra-sym + (lambda (q) + (if (< q res) + (begin + (vector-set! + vect q + (cons (cos (* q delta)) + (sin (* q delta)))) + (iter (+ 1 q))))))) + (iter 0) + vect)) + +(define draw-circle + (lambda (radius) + (letrec + ((iter + (lambda (q) + (if (< q res) + (begin + (draw-line + (* radius (car (vector-ref data q))) + (* radius (cdr (vector-ref data q)))) + (iter (+ 1 q))))))) + (draw-move radius 0) + (iter 0) + (draw-line radius 0)))) + +(define steps 8) + +(define circles + (lambda (maxrad) + (letrec + ((iter + (lambda (q) + (if (< q maxrad) + (begin + (draw-color 0 (/ (* 255.0 q) maxrad) 0) + (draw-circle q) + (iter (+ q steps))))))) + (iter 1)))) + +(circles 100) + + + + diff --git a/examples/parse-error2.scm b/examples/parse-error2.scm new file mode 100644 index 0000000..f51f12c --- /dev/null +++ b/examples/parse-error2.scm @@ -0,0 +1,28 @@ +(define koch + (let ((s (/ (sqrt 3) 2 3))) + (lambda (res depth) + (letrec + ((iter + (lambda (x1 y1 x2 y2 d) + (if (zero? d) + (draw-line x2 y2) + (let* ((dx (- x2 x1)) + (dy (- y2 y1)) + (^ test) + (thx (+ x1 (/ dx 3))) + (thy (+ y1 (/ dy 3))) + (thx2 (+ x1 (* 2 (/ dx 3)))) + (thy2 (+ y1 (* 2 (/ dy 3)))) + (mx (/ (+ x1 x2) 2)) + (my (/ (+ y1 y2) 2)) + (midx (+ mx (* (- dy) s))) + (midy (+ my (* dx s)))) + (iter x1 y1 thx thy (- d 1)) + (iter thx thy midx midy (- d 1)) + (iter midx midy thx2 thy2 (- d 1)) + (iter thx2 thy2 x2 y2 (- d 1))))))) + (draw-move 0 0) + (draw-color 0 255 0) + (iter 0 0 res 0 depth))))) + +(koch 200 4) diff --git a/examples/parse-error3.scm b/examples/parse-error3.scm new file mode 100644 index 0000000..18365fe --- /dev/null +++ b/examples/parse-error3.scm @@ -0,0 +1,6 @@ +(define testcond + (lambda (l) + (cond + ((assq 'a l) => (lambda (p) (set-car! p 'd))) + ((assq 'b l) extra-sym => (lambda (p) (set-car! p 'e))) + ((assq 'c l) => (lambda (p) (set-car! p 'f)))))) diff --git a/examples/parse-error4.scm b/examples/parse-error4.scm new file mode 100644 index 0000000..e6c8fb3 --- /dev/null +++ b/examples/parse-error4.scm @@ -0,0 +1,6 @@ + +;; an if with three alternatives + +(if (zero? 4) 'a 'b 'c) + +;; end diff --git a/examples/plotfancy.scm b/examples/plotfancy.scm new file mode 100644 index 0000000..ae9281e --- /dev/null +++ b/examples/plotfancy.scm @@ -0,0 +1,49 @@ +(define plotter + (lambda (fx res x1 x2 y1 y2) + (let* ((dx (- x2 x1)) (dy (- y2 y1)) (delta (/ dx res)) + (fstr (format "~a" fx)) + (f (eval (list 'lambda '(x) fx)))) + (letrec + ((scaled + (lambda (f x y) + (f + (* res (/ (- x x1) dx)) + (* res (/ (- y y1) dy))))) + (scaled-d + (lambda (f x y xd yd) + (f + (+ xd (* res (/ (- x x1) dx))) + (+ yd (* res (/ (- y y1) dy)))))) + (plotit + (lambda (x) + (scaled draw-line x (f x)) + (if (< x x2) (plotit (+ x delta)))))) + (draw-color 0 0 0) + (draw-font "Helvetica" 12) + (scaled draw-move 0 (* 1.1 y2)) (draw-string "y") + (scaled draw-move (* 1.1 x2) 0) (draw-string "x") + (draw-move + (- (/ res 2) + (/ (car (string-size fstr "Helvetica" 12)) 2)) + (+ 30 res)) + (draw-string (format "~a" fstr)) + (scaled draw-move 0 y1) + (scaled draw-line 0 y2) + (scaled-d draw-move 0 y2 -5 -7) + (scaled draw-line 0 y2) + (scaled-d draw-move 0 y2 +5 -7) + (scaled draw-line 0 y2) + (scaled draw-move x1 0) + (scaled draw-line x2 0) + (scaled-d draw-move x2 0 -7 -5) + (scaled draw-line x2 0) + (scaled-d draw-move x2 0 -7 +5) + (scaled draw-line x2 0) + (draw-color 255 0 0) + (scaled draw-move x1 (f x1)) + (plotit x1))))) + +(plotter '(* x x x) 70 -5.0 5.0 -50.0 50.0) +(plotter '(sin x) 50 -5.0 5.0 -1.0 1.0) +(plotter '(* x (sin x)) 100 -25.0 25.0 -25.0 25.0) +(plotter '(+ (* x x) (* -5 x) 6) 80 -1.0 5.0 -3.0 10.0) diff --git a/examples/qsort.scm b/examples/qsort.scm new file mode 100644 index 0000000..bebe203 --- /dev/null +++ b/examples/qsort.scm @@ -0,0 +1,143 @@ + +(define allperms + (lambda (n) + (if (= n 1) '((1)) + (letrec + ((allpos (list-n n)) + (insert + (lambda (pos el l) + (if (= pos 1) + (cons el l) + (cons (car l) + (insert (- pos 1) el (cdr l)))))) + (result '())) + (for-each + (lambda (p) + (for-each + (lambda (pos) + (set! + result + (cons + (insert pos n p) result))) + allpos)) + (allperms (- n 1))) + result)))) + + +(define make-cmp + (lambda () + (let ((count 0)) + (lambda (what . args) + (case what + ((count) count) + ((cmp) + (begin + (set! count (+ 1 count)) + (< (car args) (cadr args))))))))) + +(define qsort + (lambda (perm compare) + (if (null? perm) '() + (if (null? (cdr perm)) perm + (letrec + ((pivot (car perm)) + (left '()) (leftend '()) + (right '()) (rightend '()) + (split + (lambda (l) + (if (compare 'cmp (car l) pivot) + (if (null? leftend) + (begin + (set! left (list (car l))) + (set! leftend left)) + (begin + (set-cdr! leftend (list (car l))) + (set! leftend (cdr leftend)))) + (if (null? rightend) + (begin + (set! right (list (car l))) + (set! rightend right)) + (begin + (set-cdr! rightend (list (car l))) + (set! rightend (cdr rightend))))) + (if (not (null? (cdr l))) (split (cdr l)))))) + (split (cdr perm)) + (append + (qsort left compare) + (list pivot) + (qsort right compare))))))) + +(define qsort-stats + (lambda (n) + (map + (lambda (p) + (let ((c (make-cmp))) + (qsort p c) + (c 'count))) + (allperms n)))) + +(define ints2hist + (lambda (l) + (let* ((minv (apply min l)) + (maxv (apply max l)) + (v (make-vector (+ 1 (- maxv minv)) 0))) + (letrec + ((iter + (lambda (l) + (if (not (null? l)) + (begin + (vector-set! + v (- (car l) minv) + (+ 1 (vector-ref v (- (car l) minv)))) + (iter (cdr l))))))) + (iter l) + (map + (lambda (pos) + (cons pos (vector-ref v (- pos minv)))) + (make-range minv maxv)))))) + +(define drawhist + (lambda (h) + (letrec + ((len (length h)) (total (* 1.0 (apply + (map cdr h)))) + (mx (apply max (map cdr h))) (scale 400) + (colors + (list->vector + '((0 0 255) (0 255 0) (0 255 255) + (255 0 0) (255 0 255) (255 255 0)))) + (bars + (lambda (pos h) + (let ((frac (/ (cdar h) total))) + (apply draw-color (vector-ref colors (remainder pos 6))) + (draw-move (* pos 40) 0) + (fill-rect 30 (* scale frac)) + (if (not (null? (cdr h))) + (bars (+ 1 pos) (cdr h)))))) + (labels + (lambda (pos h) + (draw-move (* pos 40) -20) + (draw-string (format "~a" (caar h))) + (if (not (null? (cdr h))) + (labels (+ 1 pos) (cdr h))))) + (values + (lambda (pos h) + (let ((frac (/ (cdar h) total))) + (draw-move (* pos 40) (+ 10 (* scale frac))) + (draw-string (format "~a" (cdar h))) + (if (not (null? (cdr h))) + (values (+ 1 pos) (cdr h))))))) + (bars 0 h) + (draw-color 0 0 0) + (labels 0 h) + (values 0 h) + (draw-move -40 0) (draw-line (* (+ 1 len) 40) 0) + (draw-move -20 -20) (draw-line -20 (* scale (/ mx total)))))) + +(define qhist + (lambda (n) + (drawhist (ints2hist (qsort-stats n))))) + +(qhist 6) + + + diff --git a/examples/qsort1.scm b/examples/qsort1.scm new file mode 100644 index 0000000..e37a665 --- /dev/null +++ b/examples/qsort1.scm @@ -0,0 +1,181 @@ + +(define fact + (lambda (n) + (if (zero? n) 1 + (* n (fact (- n 1)))))) + +(define allperms + (lambda (n) + (let ((f (fact n)) + (res '()) (rm -1) (perm '())) + (letrec + ((remove + (lambda (l pos) + (if (zero? pos) + (begin + (set! rm (car l)) + (remove (cdr l) (- pos 1))) + (if (null? l) l + (cons (car l) (remove (cdr l) (- pos 1))))))) + (process + (lambda (v m dst src) + (if (zero? m) + (set! perm dst) + (let ((src1 (remove src (remainder v m)))) + (process + (quotient v m) + (- m 1) + src1 + (cons dst rm)))))) + (iter + (lambda (v) + (if (< v f) + (begin + (process v n '() (make-range 1 n)) + (set! res (cons perm res)) + (iter (+ v 1))))))) + (iter 0) res)))) + + +(define allperms + (lambda (n) + (if (= n 1) '((1)) + (letrec + ((allpos (list-n n)) + (insert + (lambda (pos el l) + (if (= pos 1) + (cons el l) + (cons (car l) + (insert (- pos 1) el (cdr l)))))) + (result '())) + (for-each + (lambda (p) + (for-each + (lambda (pos) + (set! + result + (cons + (insert pos n p) result))) + allpos)) + (allperms (- n 1))) + result)))) + + +(define make-cmp + (lambda () + (let ((count 0)) + (lambda (what . args) + (case what + ((count) count) + ((cmp) + (begin + (set! count (+ 1 count)) + (< (car args) (cadr args))))))))) + +(define qsort + (lambda (perm compare) + (if (null? perm) '() + (if (null? (cdr perm)) perm + (letrec + ((pivot (car perm)) + (left '()) (leftend '()) + (right '()) (rightend '()) + (split + (lambda (l) + (if (compare 'cmp (car l) pivot) + (if (null? leftend) + (begin + (set! left (list (car l))) + (set! leftend left)) + (begin + (set-cdr! leftend (list (car l))) + (set! leftend (cdr leftend)))) + (if (null? rightend) + (begin + (set! right (list (car l))) + (set! rightend right)) + (begin + (set-cdr! rightend (list (car l))) + (set! rightend (cdr rightend))))) + (if (not (null? (cdr l))) (split (cdr l)))))) + (split (cdr perm)) + (append + (qsort left compare) + (list pivot) + (qsort right compare))))))) + +(define qsort-stats + (lambda (n) + (map + (lambda (p) + (let ((c (make-cmp))) + (qsort p c) + (c 'count))) + (allperms n)))) + +(define ints2hist + (lambda (l) + (let* ((minv (apply min l)) + (maxv (apply max l)) + (v (make-vector (+ 1 (- maxv minv)) 0))) + (letrec + ((iter + (lambda (l) + (if (not (null? l)) + (begin + (vector-set! + v (- (car l) minv) + (+ 1 (vector-ref v (- (car l) minv)))) + (iter (cdr l))))))) + (iter l) + (map + (lambda (pos) + (cons pos (vector-ref v (- pos minv)))) + (make-range minv maxv)))))) + +(define drawhist + (lambda (h) + (letrec + ((len (length h)) (total (* 1.0 (apply + (map cdr h)))) + (mx (apply max (map cdr h))) (scale 400) + (colors + (list->vector + '((0 0 255) (0 255 0) (0 255 255) + (255 0 0) (255 0 255) (255 255 0)))) + (bars + (lambda (pos h) + (let ((frac (/ (cdar h) total))) + (apply draw-color (vector-ref colors (remainder pos 6))) + (draw-move (* pos 40) 0) + (fill-rect 30 (* scale frac)) + (if (not (null? (cdr h))) + (bars (+ 1 pos) (cdr h)))))) + (labels + (lambda (pos h) + (draw-move (* pos 40) -20) + (draw-string (format "~a" (caar h))) + (if (not (null? (cdr h))) + (labels (+ 1 pos) (cdr h))))) + (values + (lambda (pos h) + (let ((frac (/ (cdar h) total))) + (draw-move (* pos 40) (+ 10 (* scale frac))) + (draw-string (format "~a" (cdar h))) + (if (not (null? (cdr h))) + (values (+ 1 pos) (cdr h))))))) + (bars 0 h) + (draw-color 0 0 0) + (labels 0 h) + (values 0 h) + (draw-move -40 0) (draw-line (* (+ 1 len) 40) 0) + (draw-move -20 -20) (draw-line -20 (* scale (/ mx total)))))) + +(define qhist + (lambda (n) + (drawhist (ints2hist (qsort-stats n))))) + +(qhist 6) + + + diff --git a/examples/queenspic.scm b/examples/queenspic.scm new file mode 100644 index 0000000..5943fa0 --- /dev/null +++ b/examples/queenspic.scm @@ -0,0 +1,98 @@ + +(define allqueens + (lambda (n doneproc) + (letrec + ((diag1 + (lambda (board col) + (if (null? board) '() + (cons (+ col (car board)) + (diag1 (cdr board) (+ col 1)))))) + (diag2 + (lambda (board col) + (if (null? board) '() + (cons (- col (car board)) + (diag2 (cdr board) (+ col 1)))))) + (consistent? + (lambda (board col new) + (not + (or (member new board) + (member (+ col new) + (diag1 board 1)) + (member (- col new) + (diag2 board 1)))))) + (check + (lambda (board col) + (if (> col n) (doneproc board) + (for-each + (lambda (row) + (if (consistent? board col row) + (check (append board (list row)) + (+ 1 col)))) + (list-n n)))))) + (check '() 1)))) + +(define queens + (lambda (n) + (letrec + ((y-reflect reverse) + (rotate + (lambda (board) + (map + (lambda (row) + (- (+ 1 n) (length (member row board)))) + (list-n n)))) + (symmetries + (lambda (board) + (list + board + (rotate board) + (rotate (rotate board)) + (rotate (rotate (rotate board))) + (y-reflect board) + (rotate (y-reflect board)) + (rotate (rotate (y-reflect board))) + (rotate (rotate (rotate (y-reflect board))))))) + (result '()) + (new? + (lambda (rlist sol) + (if (null? rlist) #t + (if (member sol (car rlist)) #f + (new? (cdr rlist) sol)))))) + (allqueens + n + (lambda (sol) + (if (new? result sol) + (set! result (cons (symmetries sol) result))))) + (map car result)))) + +(define queenspic + (lambda (n) + (let* ((scale 30) (radius (/ scale 3))) + (for-each + (lambda (sol) + (letrec + ((drawqueens + (lambda (pos sol) + (if (not (null? sol)) + (begin + (draw-move pos (- (* (car sol) scale) (/ scale 2))) + (fill-circle radius) + (drawqueens (+ pos scale) (cdr sol)))))) + (drawlines + (lambda (m) + (draw-move 0 (* m scale)) + (draw-line (* n scale) (* m scale)) + (draw-move (* m scale) 0) + (draw-line (* m scale) (* n scale)) + (if (not (zero? m)) + (drawlines (- m 1)))))) + (draw-color 255 0 0) + (drawqueens 15 sol) + (draw-color 0 0 0) + (drawlines n) + (draw-show))) + (queens n))))) + +(queenspic 5) + + diff --git a/examples/randcircles.scm b/examples/randcircles.scm new file mode 100644 index 0000000..59a2ec0 --- /dev/null +++ b/examples/randcircles.scm @@ -0,0 +1,17 @@ + +(define randcircles + (lambda (n rmax lmax) + (let + ((x (random lmax)) (y (random lmax)) + (fill (random 2)) + (radius (+ (/ rmax 2) (random (/ rmax 2))))) + (draw-color + (random 256) + (random 256) + (random 256)) + (draw-move x y) + ((if (zero? fill) draw-circle fill-circle) radius) + (if (not (zero? n)) + (randcircles (- n 1) rmax lmax))))) + +(randcircles 25 30 250) diff --git a/examples/random.scm b/examples/random.scm new file mode 100644 index 0000000..c4a0c00 --- /dev/null +++ b/examples/random.scm @@ -0,0 +1,28 @@ + +(define randpoints + (lambda (count) + (letrec + ((scale 20) + (points + (lambda (n) + (draw-move + (* (- count n) scale) + (* scale (random count))) + (fill-circle (/ scale 2)) + (if (not (zero? n)) + (points (- n 1))))) + (grid + (lambda (n) + (draw-move 0 (* scale n)) + (draw-line (* scale count) (* scale n)) + (if (not (zero? n)) + (grid (- n 1)))))) + (grid count) + (draw-move 0 0) + (draw-color 255 255 0) + (points count)))) + + +(randpoints 15) +(randpoints 15.0) + diff --git a/examples/randrects.scm b/examples/randrects.scm new file mode 100644 index 0000000..6e4be13 --- /dev/null +++ b/examples/randrects.scm @@ -0,0 +1,18 @@ + +(define randrects + (lambda (n rmax lmax) + (let + ((x (random lmax)) (y (random lmax)) + (fill (random 2)) + (a (+ (/ rmax 2) (random (/ rmax 2)))) + (b (+ (/ rmax 2) (random (/ rmax 2))))) + (draw-color + (random 256) + (random 256) + (random 256)) + (draw-move x y) + ((if (zero? fill) draw-rect fill-rect) a b) + (if (not (zero? n)) + (randrects (- n 1) rmax lmax))))) + +(randrects 25 60 250) diff --git a/examples/strings.scm b/examples/strings.scm new file mode 100644 index 0000000..2bff33f --- /dev/null +++ b/examples/strings.scm @@ -0,0 +1,119 @@ + +(integer->char -20) +(integer->char 270) + +(char->integer #\N) +(char->integer #\+) +(char->integer #\#) + +(define table + (lambda (n) + (if (< n 128) + (begin + (display n) (display " ") + (display (integer->char n)) (display " ") + (display (char->integer (integer->char n))) + (newline) + (table (+ n 1)))))) + +(table 32) + +(list->string '()) +(list->string '(#\a #\b #\c)) +(list->string '(#\a #\b . #\c)) + +(define test1 + (lambda (n) + (let ((str + (list->string + (map + (lambda (pos) + (integer->char + (+ (char->integer #\A) pos -1))) + (reverse (list-n n)))))) + (map + (lambda (pos) + (string-ref str (- pos 1))) + (reverse (list-n n)))))) + +(test1 5) +(test1 10) +(test1 20) + +(define randletters + (lambda (n) + (if (zero? n) '() + (cons + (integer->char + (+ (char->integer #\A) (random 26))) + (randletters (- n 1)))))) + +(define test2 + (lambda (len) + (let* ((r (randletters len)) + (s (list->string r))) + (display r) (display " ") + (display s) (display " ") + (display (string->list s)) (newline)))) + +(test2 5) +(test2 10) +(test2 20) + +(string-append) +(apply string-append + (map symbol->string '(one two three four five))) +(make-string 0) + +(string->list (make-string 5)) +(string->list (make-string 15)) + +(define test3 + (lambda (len) + (if (zero? len) "" + (string-append + (make-string len) + (make-string + len + (integer->char + (+ (char->integer #\a) len -1))) + (test3 (- len 1)))))) + +(test3 1) +(test3 5) +(test3 7) + + +(number->string 123.456e7) +(number->string 678.456) +(map number->string (list-n 30)) + +(define test4 + (lambda (base) + (map + (lambda (n) + (number->string n base)) + (reverse (list-n 30))))) + +(test4 2) +(test4 3) +(test4 8) +(test4 10) +(test4 12) +(test4 16) + +(define test5 + (lambda (base) + (map + (lambda (n) + (number->string (+ (- n) 1) base)) + (reverse (list-n 30))))) + +(test5 2) +(test5 3) +(test5 8) +(test5 10) +(test5 12) +(test5 16) + + diff --git a/examples/text.scm b/examples/text.scm new file mode 100644 index 0000000..4f81278 --- /dev/null +++ b/examples/text.scm @@ -0,0 +1,31 @@ + +;; show some text + +(define text + (lambda (fsclist) + (for-each + (lambda (fsc) + (let + ((font (car fsc)) + (size (cadr fsc)) + (color (caddr fsc)) + (pos 0)) + (apply draw-color color) + (draw-font font size) + (for-each + (lambda (word) + (let ((dim (string-size word font size))) + (draw-move (- (/ (car dim) 2.0)) (* pos (cdr dim))) + (draw-string word) + (set! pos (- pos 1)))) + (map + symbol->string + '(The quick brown fox jumps over the lazy dog))) + (draw-show))) fsclist))) + +(text + '(("Courier" 36 (255 0 0)) + ("Helvetica-Bold" 24 (0 255 0)) + ("Lucida-Italic-Sans" 18 (0 0 255)))) + + \ No newline at end of file diff --git a/lex.yy.c b/lex.yy.c deleted file mode 100644 index bd210a7..0000000 --- a/lex.yy.c +++ /dev/null @@ -1,1939 +0,0 @@ -/* A lexical scanner generated by flex */ - -/* Scanner skeleton version: - * $Header: /home/daffy/u0/vern/flex/RCS/flex.skl,v 2.91 96/09/10 16:58:48 vern Exp $ - */ - -#define FLEX_SCANNER -#define YY_FLEX_MAJOR_VERSION 2 -#define YY_FLEX_MINOR_VERSION 5 - -#include - - -/* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */ -#ifdef c_plusplus -#ifndef __cplusplus -#define __cplusplus -#endif -#endif - - -#ifdef __cplusplus - -#include -#include - -/* Use prototypes in function declarations. */ -#define YY_USE_PROTOS - -/* The "const" storage-class-modifier is valid. */ -#define YY_USE_CONST - -#else /* ! __cplusplus */ - -#if __STDC__ - -#define YY_USE_PROTOS -#define YY_USE_CONST - -#endif /* __STDC__ */ -#endif /* ! __cplusplus */ - -#ifdef __TURBOC__ - #pragma warn -rch - #pragma warn -use -#include -#include -#define YY_USE_CONST -#define YY_USE_PROTOS -#endif - -#ifdef YY_USE_CONST -#define yyconst const -#else -#define yyconst -#endif - - -#ifdef YY_USE_PROTOS -#define YY_PROTO(proto) proto -#else -#define YY_PROTO(proto) () -#endif - -/* Returned upon end-of-file. */ -#define YY_NULL 0 - -/* Promotes a possibly negative, possibly signed char to an unsigned - * integer for use as an array index. If the signed char is negative, - * we want to instead treat it as an 8-bit unsigned char, hence the - * double cast. - */ -#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) - -/* Enter a start condition. This macro really ought to take a parameter, - * but we do it the disgusting crufty way forced on us by the ()-less - * definition of BEGIN. - */ -#define BEGIN yy_start = 1 + 2 * - -/* Translate the current start state into a value that can be later handed - * to BEGIN to return to the state. The YYSTATE alias is for lex - * compatibility. - */ -#define YY_START ((yy_start - 1) / 2) -#define YYSTATE YY_START - -/* Action number for EOF rule of a given start state. */ -#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) - -/* Special action meaning "start processing a new file". */ -#define YY_NEW_FILE yyrestart( yyin ) - -#define YY_END_OF_BUFFER_CHAR 0 - -/* Size of default input buffer. */ -#define YY_BUF_SIZE 16384 - -typedef struct yy_buffer_state *YY_BUFFER_STATE; - -extern int yyleng; -extern FILE *yyin, *yyout; - -#define EOB_ACT_CONTINUE_SCAN 0 -#define EOB_ACT_END_OF_FILE 1 -#define EOB_ACT_LAST_MATCH 2 - -/* The funky do-while in the following #define is used to turn the definition - * int a single C statement (which needs a semi-colon terminator). This - * avoids problems with code like: - * - * if ( condition_holds ) - * yyless( 5 ); - * else - * do_something_else(); - * - * Prior to using the do-while the compiler would get upset at the - * "else" because it interpreted the "if" statement as being all - * done when it reached the ';' after the yyless() call. - */ - -/* Return all but the first 'n' matched characters back to the input stream. */ - -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - *yy_cp = yy_hold_char; \ - YY_RESTORE_YY_MORE_OFFSET \ - yy_c_buf_p = yy_cp = yy_bp + n - YY_MORE_ADJ; \ - YY_DO_BEFORE_ACTION; /* set up yytext again */ \ - } \ - while ( 0 ) - -#define unput(c) yyunput( c, yytext_ptr ) - -/* The following is because we cannot portably get our hands on size_t - * (without autoconf's help, which isn't available because we want - * flex-generated scanners to compile on their own). - */ -typedef unsigned int yy_size_t; - - -struct yy_buffer_state - { - FILE *yy_input_file; - - char *yy_ch_buf; /* input buffer */ - char *yy_buf_pos; /* current position in input buffer */ - - /* Size of input buffer in bytes, not including room for EOB - * characters. - */ - yy_size_t yy_buf_size; - - /* Number of characters read into yy_ch_buf, not including EOB - * characters. - */ - int yy_n_chars; - - /* Whether we "own" the buffer - i.e., we know we created it, - * and can realloc() it to grow it, and should free() it to - * delete it. - */ - int yy_is_our_buffer; - - /* Whether this is an "interactive" input source; if so, and - * if we're using stdio for input, then we want to use getc() - * instead of fread(), to make sure we stop fetching input after - * each newline. - */ - int yy_is_interactive; - - /* Whether we're considered to be at the beginning of a line. - * If so, '^' rules will be active on the next match, otherwise - * not. - */ - int yy_at_bol; - - /* Whether to try to fill the input buffer when we reach the - * end of it. - */ - int yy_fill_buffer; - - int yy_buffer_status; -#define YY_BUFFER_NEW 0 -#define YY_BUFFER_NORMAL 1 - /* When an EOF's been seen but there's still some text to process - * then we mark the buffer as YY_EOF_PENDING, to indicate that we - * shouldn't try reading from the input source any more. We might - * still have a bunch of tokens to match, though, because of - * possible backing-up. - * - * When we actually see the EOF, we change the status to "new" - * (via yyrestart()), so that the user can continue scanning by - * just pointing yyin at a new input file. - */ -#define YY_BUFFER_EOF_PENDING 2 - }; - -static YY_BUFFER_STATE yy_current_buffer = 0; - -/* We provide macros for accessing buffer states in case in the - * future we want to put the buffer states in a more general - * "scanner state". - */ -#define YY_CURRENT_BUFFER yy_current_buffer - - -/* yy_hold_char holds the character lost when yytext is formed. */ -static char yy_hold_char; - -static int yy_n_chars; /* number of characters read into yy_ch_buf */ - - -int yyleng; - -/* Points to current character in buffer. */ -static char *yy_c_buf_p = (char *) 0; -static int yy_init = 1; /* whether we need to initialize */ -static int yy_start = 0; /* start state number */ - -/* Flag which is used to allow yywrap()'s to do buffer switches - * instead of setting up a fresh yyin. A bit of a hack ... - */ -static int yy_did_buffer_switch_on_eof; - -void yyrestart YY_PROTO(( FILE *input_file )); - -void yy_switch_to_buffer YY_PROTO(( YY_BUFFER_STATE new_buffer )); -void yy_load_buffer_state YY_PROTO(( void )); -YY_BUFFER_STATE yy_create_buffer YY_PROTO(( FILE *file, int size )); -void yy_delete_buffer YY_PROTO(( YY_BUFFER_STATE b )); -void yy_init_buffer YY_PROTO(( YY_BUFFER_STATE b, FILE *file )); -void yy_flush_buffer YY_PROTO(( YY_BUFFER_STATE b )); -#define YY_FLUSH_BUFFER yy_flush_buffer( yy_current_buffer ) - -YY_BUFFER_STATE yy_scan_buffer YY_PROTO(( char *base, yy_size_t size )); -YY_BUFFER_STATE yy_scan_string YY_PROTO(( yyconst char *yy_str )); -YY_BUFFER_STATE yy_scan_bytes YY_PROTO(( yyconst char *bytes, int len )); - -static void *yy_flex_alloc YY_PROTO(( yy_size_t )); -static void *yy_flex_realloc YY_PROTO(( void *, yy_size_t )); -static void yy_flex_free YY_PROTO(( void * )); - -#define yy_new_buffer yy_create_buffer - -#define yy_set_interactive(is_interactive) \ - { \ - if ( ! yy_current_buffer ) \ - yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \ - yy_current_buffer->yy_is_interactive = is_interactive; \ - } - -#define yy_set_bol(at_bol) \ - { \ - if ( ! yy_current_buffer ) \ - yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \ - yy_current_buffer->yy_at_bol = at_bol; \ - } - -#define YY_AT_BOL() (yy_current_buffer->yy_at_bol) - -typedef unsigned char YY_CHAR; -FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0; -typedef int yy_state_type; -extern char *yytext; -#define yytext_ptr yytext - -static yy_state_type yy_get_previous_state YY_PROTO(( void )); -static yy_state_type yy_try_NUL_trans YY_PROTO(( yy_state_type current_state )); -static int yy_get_next_buffer YY_PROTO(( void )); -static void yy_fatal_error YY_PROTO(( yyconst char msg[] )); - -/* Done after the current pattern has been matched and before the - * corresponding action - sets up yytext. - */ -#define YY_DO_BEFORE_ACTION \ - yytext_ptr = yy_bp; \ - yyleng = (int) (yy_cp - yy_bp); \ - yy_hold_char = *yy_cp; \ - *yy_cp = '\0'; \ - yy_c_buf_p = yy_cp; - -#define YY_NUM_RULES 37 -#define YY_END_OF_BUFFER 38 -static yyconst short int yy_accept[143] = - { 0, - 0, 0, 38, 36, 34, 35, 27, 36, 36, 2, - 31, 32, 27, 33, 26, 36, 27, 27, 27, 28, - 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, - 34, 0, 29, 0, 30, 0, 20, 0, 26, 22, - 0, 23, 0, 0, 27, 3, 28, 28, 28, 28, - 28, 28, 28, 28, 28, 10, 28, 28, 13, 28, - 28, 21, 21, 21, 21, 0, 0, 0, 24, 0, - 1, 12, 28, 28, 28, 28, 28, 28, 28, 28, - 17, 28, 28, 0, 0, 0, 0, 25, 28, 28, - 28, 14, 15, 28, 16, 28, 18, 28, 28, 8, - - 0, 0, 6, 11, 28, 28, 28, 28, 4, 0, - 0, 28, 7, 9, 19, 0, 28, 0, 28, 28, - 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, - 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, - 5, 0 - } ; - -static yyconst int yy_ec[256] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 2, 4, 5, 6, 1, 1, 1, 7, 8, - 9, 10, 11, 1, 12, 13, 14, 15, 15, 15, - 15, 15, 15, 15, 15, 15, 15, 1, 16, 17, - 18, 19, 20, 1, 21, 21, 21, 21, 22, 21, - 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, - 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, - 1, 23, 1, 1, 1, 1, 24, 25, 26, 27, - - 28, 29, 30, 31, 32, 21, 21, 33, 34, 35, - 36, 37, 38, 39, 40, 41, 42, 21, 43, 21, - 44, 21, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1 - } ; - -static yyconst int yy_meta[45] = - { 0, - 1, 2, 3, 4, 1, 1, 1, 1, 1, 4, - 4, 4, 1, 4, 4, 1, 4, 4, 4, 4, - 4, 4, 1, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4 - } ; - -static yyconst short int yy_base[148] = - { 0, - 0, 0, 341, 389, 334, 389, 389, 40, 38, 389, - 389, 389, 34, 319, 40, 0, 312, 295, 282, 38, - 40, 44, 46, 61, 63, 49, 64, 66, 70, 75, - 297, 86, 389, 88, 389, 59, 389, 281, 95, 103, - 76, 279, 109, 269, 389, 389, 77, 106, 109, 112, - 117, 118, 120, 123, 124, 125, 136, 140, 143, 147, - 149, 389, 240, 222, 228, 120, 150, 225, 210, 218, - 389, 156, 158, 162, 164, 165, 169, 167, 178, 182, - 185, 190, 199, 143, 156, 148, 156, 139, 191, 194, - 203, 198, 202, 206, 207, 210, 218, 222, 223, 224, - - 108, 113, 226, 229, 235, 237, 238, 243, 244, 81, - 74, 250, 246, 251, 257, 66, 263, 37, 264, 269, - 265, 266, 270, 277, 278, 282, 283, 295, 300, 291, - 302, 303, 308, 311, 309, 315, 322, 323, 328, 337, - 339, 389, 372, 376, 53, 380, 384 - } ; - -static yyconst short int yy_def[148] = - { 0, - 142, 1, 142, 142, 142, 142, 142, 143, 142, 142, - 142, 142, 142, 142, 142, 144, 142, 142, 142, 145, - 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, - 142, 143, 142, 142, 142, 146, 142, 142, 142, 142, - 142, 142, 142, 147, 142, 142, 145, 145, 145, 145, - 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, - 145, 142, 142, 142, 142, 142, 142, 142, 142, 147, - 142, 145, 145, 145, 145, 145, 145, 145, 145, 145, - 145, 145, 145, 142, 142, 142, 142, 142, 145, 145, - 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, - - 142, 142, 145, 145, 145, 145, 145, 145, 145, 142, - 142, 145, 145, 145, 145, 142, 145, 142, 145, 145, - 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, - 145, 145, 145, 145, 145, 145, 145, 145, 145, 145, - 145, 0, 142, 142, 142, 142, 142 - } ; - -static yyconst short int yy_nxt[434] = - { 0, - 4, 5, 6, 7, 8, 9, 10, 11, 12, 7, - 13, 13, 14, 7, 15, 16, 17, 18, 19, 7, - 20, 20, 4, 21, 22, 23, 24, 25, 20, 20, - 20, 26, 27, 20, 20, 28, 20, 29, 20, 30, - 20, 20, 20, 20, 33, 35, 38, 48, 39, 48, - 41, 41, 42, 48, 39, 48, 47, 48, 48, 48, - 36, 43, 34, 48, 62, 48, 37, 43, 48, 52, - 48, 51, 48, 48, 49, 48, 50, 56, 37, 48, - 48, 53, 48, 48, 48, 48, 48, 57, 54, 48, - 33, 58, 32, 63, 48, 55, 48, 43, 64, 65, - - 118, 62, 61, 43, 59, 41, 41, 42, 34, 39, - 32, 60, 116, 66, 66, 48, 43, 40, 48, 68, - 68, 48, 43, 69, 67, 48, 48, 48, 48, 48, - 67, 48, 48, 48, 48, 72, 48, 48, 111, 48, - 110, 67, 48, 48, 48, 48, 74, 67, 73, 48, - 75, 78, 48, 88, 77, 48, 48, 76, 48, 48, - 87, 87, 48, 79, 88, 48, 48, 48, 48, 80, - 88, 48, 62, 48, 48, 48, 48, 48, 48, 102, - 81, 48, 82, 48, 48, 101, 48, 48, 48, 83, - 89, 48, 92, 90, 97, 93, 91, 48, 94, 48, - - 48, 48, 100, 48, 48, 95, 96, 48, 48, 48, - 48, 48, 48, 48, 105, 48, 48, 48, 48, 48, - 71, 48, 48, 98, 69, 48, 48, 48, 104, 48, - 99, 48, 48, 48, 103, 48, 107, 48, 48, 69, - 106, 48, 48, 48, 48, 48, 48, 48, 48, 108, - 109, 86, 48, 48, 48, 48, 48, 48, 85, 48, - 48, 114, 48, 48, 113, 48, 48, 84, 115, 48, - 48, 71, 48, 48, 48, 48, 48, 112, 48, 48, - 121, 117, 48, 48, 48, 48, 48, 48, 48, 48, - 122, 48, 48, 40, 120, 40, 48, 48, 31, 45, - - 48, 48, 48, 119, 48, 126, 129, 123, 124, 48, - 48, 48, 48, 46, 48, 125, 127, 48, 48, 48, - 48, 48, 48, 128, 48, 130, 131, 48, 48, 45, - 48, 48, 48, 40, 48, 31, 132, 48, 137, 134, - 142, 48, 48, 133, 142, 135, 48, 48, 48, 142, - 136, 142, 142, 142, 139, 142, 48, 142, 48, 142, - 142, 142, 138, 140, 142, 142, 142, 142, 142, 142, - 142, 141, 32, 32, 142, 32, 44, 44, 142, 44, - 62, 142, 142, 62, 70, 70, 70, 70, 3, 142, - 142, 142, 142, 142, 142, 142, 142, 142, 142, 142, - - 142, 142, 142, 142, 142, 142, 142, 142, 142, 142, - 142, 142, 142, 142, 142, 142, 142, 142, 142, 142, - 142, 142, 142, 142, 142, 142, 142, 142, 142, 142, - 142, 142, 142 - } ; - -static yyconst short int yy_chk[434] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 8, 9, 13, 20, 13, 21, - 15, 15, 15, 22, 15, 23, 145, 20, 26, 21, - 9, 15, 8, 22, 118, 23, 9, 15, 26, 23, - 24, 22, 25, 27, 21, 28, 21, 26, 9, 29, - 24, 23, 25, 27, 30, 28, 47, 27, 24, 29, - 32, 27, 34, 36, 30, 25, 47, 41, 36, 36, - - 116, 111, 30, 41, 28, 39, 39, 39, 32, 39, - 34, 29, 110, 40, 40, 48, 39, 40, 49, 43, - 43, 50, 39, 43, 40, 48, 51, 52, 49, 53, - 40, 50, 54, 55, 56, 49, 51, 52, 102, 53, - 101, 66, 54, 55, 56, 57, 51, 66, 50, 58, - 52, 54, 59, 88, 53, 57, 60, 52, 61, 58, - 67, 67, 59, 55, 67, 72, 60, 73, 61, 57, - 87, 74, 86, 75, 76, 72, 78, 73, 77, 85, - 58, 74, 60, 75, 76, 84, 78, 79, 77, 61, - 73, 80, 76, 74, 81, 77, 75, 79, 78, 82, - - 89, 80, 83, 90, 81, 79, 80, 92, 83, 82, - 89, 93, 91, 90, 91, 94, 95, 92, 83, 96, - 70, 93, 91, 81, 69, 94, 95, 97, 90, 96, - 82, 98, 99, 100, 89, 103, 96, 97, 104, 68, - 94, 98, 99, 100, 105, 103, 106, 107, 104, 98, - 99, 65, 108, 109, 105, 113, 106, 107, 64, 112, - 114, 107, 108, 109, 106, 113, 115, 63, 108, 112, - 114, 44, 117, 119, 121, 122, 115, 105, 120, 123, - 120, 112, 117, 119, 121, 122, 124, 125, 120, 123, - 121, 126, 127, 42, 119, 38, 124, 125, 31, 19, - - 130, 126, 127, 117, 128, 125, 128, 122, 123, 129, - 130, 131, 132, 18, 128, 124, 126, 133, 135, 129, - 134, 131, 132, 127, 136, 129, 130, 133, 135, 17, - 134, 137, 138, 14, 136, 5, 131, 139, 136, 133, - 3, 137, 138, 132, 0, 134, 140, 139, 141, 0, - 135, 0, 0, 0, 138, 0, 140, 0, 141, 0, - 0, 0, 137, 139, 0, 0, 0, 0, 0, 0, - 0, 140, 143, 143, 0, 143, 144, 144, 0, 144, - 146, 0, 0, 146, 147, 147, 147, 147, 142, 142, - 142, 142, 142, 142, 142, 142, 142, 142, 142, 142, - - 142, 142, 142, 142, 142, 142, 142, 142, 142, 142, - 142, 142, 142, 142, 142, 142, 142, 142, 142, 142, - 142, 142, 142, 142, 142, 142, 142, 142, 142, 142, - 142, 142, 142 - } ; - -static yy_state_type yy_last_accepting_state; -static char *yy_last_accepting_cpos; - -/* The intent behind this definition is that it'll catch - * any uses of REJECT which flex missed. - */ -#define REJECT reject_used_but_not_detected -#define yymore() yymore_used_but_not_detected -#define YY_MORE_ADJ 0 -#define YY_RESTORE_YY_MORE_OFFSET -char *yytext; -#line 1 "scheme.flex" -#define INITIAL 0 -#line 2 "scheme.flex" -#import -#import - -#import "SchemeTypes.h" - -#define YYSTYPE id - -#include "scheme.tab.m.h" - -int yyinputline; -char *yyinputstr, *yyinputstart; -int yysofar; - -#define YY_INPUT(buf,result,max_size) \ - { \ - int c = *yyinputstr++; \ - result = (!c) ? YY_NULL : (buf[0] = c, 1); \ - } -#line 525 "lex.yy.c" - -/* Macros after this point can all be overridden by user definitions in - * section 1. - */ - -#ifndef YY_SKIP_YYWRAP -#ifdef __cplusplus -extern "C" int yywrap YY_PROTO(( void )); -#else -extern int yywrap YY_PROTO(( void )); -#endif -#endif - -#ifndef YY_NO_UNPUT -static void yyunput YY_PROTO(( int c, char *buf_ptr )); -#endif - -#ifndef yytext_ptr -static void yy_flex_strncpy YY_PROTO(( char *, yyconst char *, int )); -#endif - -#ifdef YY_NEED_STRLEN -static int yy_flex_strlen YY_PROTO(( yyconst char * )); -#endif - -#ifndef YY_NO_INPUT -#ifdef __cplusplus -static int yyinput YY_PROTO(( void )); -#else -static int input YY_PROTO(( void )); -#endif -#endif - -#if YY_STACK_USED -static int yy_start_stack_ptr = 0; -static int yy_start_stack_depth = 0; -static int *yy_start_stack = 0; -#ifndef YY_NO_PUSH_STATE -static void yy_push_state YY_PROTO(( int new_state )); -#endif -#ifndef YY_NO_POP_STATE -static void yy_pop_state YY_PROTO(( void )); -#endif -#ifndef YY_NO_TOP_STATE -static int yy_top_state YY_PROTO(( void )); -#endif - -#else -#define YY_NO_PUSH_STATE 1 -#define YY_NO_POP_STATE 1 -#define YY_NO_TOP_STATE 1 -#endif - -#ifdef YY_MALLOC_DECL -YY_MALLOC_DECL -#else -#if __STDC__ -#ifndef __cplusplus -#include -#endif -#else -/* Just try to get by without declaring the routines. This will fail - * miserably on non-ANSI systems for which sizeof(size_t) != sizeof(int) - * or sizeof(void*) != sizeof(int). - */ -#endif -#endif - -/* Amount of stuff to slurp up with each read. */ -#ifndef YY_READ_BUF_SIZE -#define YY_READ_BUF_SIZE 8192 -#endif - -/* Copy whatever the last rule matched to the standard output. */ - -#ifndef ECHO -/* This used to be an fputs(), but since the string might contain NUL's, - * we now use fwrite(). - */ -#define ECHO (void) fwrite( yytext, yyleng, 1, yyout ) -#endif - -/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, - * is returned in "result". - */ -#ifndef YY_INPUT -#define YY_INPUT(buf,result,max_size) \ - if ( yy_current_buffer->yy_is_interactive ) \ - { \ - int c = '*', n; \ - for ( n = 0; n < max_size && \ - (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ - buf[n] = (char) c; \ - if ( c == '\n' ) \ - buf[n++] = (char) c; \ - if ( c == EOF && ferror( yyin ) ) \ - YY_FATAL_ERROR( "input in flex scanner failed" ); \ - result = n; \ - } \ - else if ( ((result = fread( buf, 1, max_size, yyin )) == 0) \ - && ferror( yyin ) ) \ - YY_FATAL_ERROR( "input in flex scanner failed" ); -#endif - -/* No semi-colon after return; correct usage is to write "yyterminate();" - - * we don't want an extra ';' after the "return" because that will cause - * some compilers to complain about unreachable statements. - */ -#ifndef yyterminate -#define yyterminate() return YY_NULL -#endif - -/* Number of entries by which start-condition stack grows. */ -#ifndef YY_START_STACK_INCR -#define YY_START_STACK_INCR 25 -#endif - -/* Report a fatal error. */ -#ifndef YY_FATAL_ERROR -#define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) -#endif - -/* Default declaration of generated scanner - a define so the user can - * easily add parameters. - */ -#ifndef YY_DECL -#define YY_DECL int yylex YY_PROTO(( void )) -#endif - -/* Code executed at the beginning of each rule, after yytext and yyleng - * have been set up. - */ -#ifndef YY_USER_ACTION -#define YY_USER_ACTION -#endif - -/* Code executed at the end of each rule. */ -#ifndef YY_BREAK -#define YY_BREAK break; -#endif - -#define YY_RULE_SETUP \ - YY_USER_ACTION - -YY_DECL - { - register yy_state_type yy_current_state; - register char *yy_cp, *yy_bp; - register int yy_act; - -#line 32 "scheme.flex" - - -#line 679 "lex.yy.c" - - if ( yy_init ) - { - yy_init = 0; - -#ifdef YY_USER_INIT - YY_USER_INIT; -#endif - - if ( ! yy_start ) - yy_start = 1; /* first start state */ - - if ( ! yyin ) - yyin = stdin; - - if ( ! yyout ) - yyout = stdout; - - if ( ! yy_current_buffer ) - yy_current_buffer = - yy_create_buffer( yyin, YY_BUF_SIZE ); - - yy_load_buffer_state(); - } - - while ( 1 ) /* loops until end-of-file is reached */ - { - yy_cp = yy_c_buf_p; - - /* Support of yytext. */ - *yy_cp = yy_hold_char; - - /* yy_bp points to the position in yy_ch_buf of the start of - * the current run. - */ - yy_bp = yy_cp; - - yy_current_state = yy_start; -yy_match: - do - { - register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; - if ( yy_accept[yy_current_state] ) - { - yy_last_accepting_state = yy_current_state; - yy_last_accepting_cpos = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 143 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - ++yy_cp; - } - while ( yy_base[yy_current_state] != 389 ); - -yy_find_action: - yy_act = yy_accept[yy_current_state]; - if ( yy_act == 0 ) - { /* have to back up */ - yy_cp = yy_last_accepting_cpos; - yy_current_state = yy_last_accepting_state; - yy_act = yy_accept[yy_current_state]; - } - - YY_DO_BEFORE_ACTION; - - -do_action: /* This label is used only to access EOF actions. */ - - - switch ( yy_act ) - { /* beginning of action switch */ - case 0: /* must back up */ - /* undo the effects of YY_DO_BEFORE_ACTION */ - *yy_cp = yy_hold_char; - yy_cp = yy_last_accepting_cpos; - yy_current_state = yy_last_accepting_state; - goto yy_find_action; - -case 1: -*yy_cp = yy_hold_char; /* undo effects of setting up yytext */ -yy_c_buf_p = yy_cp -= 1; -YY_DO_BEFORE_ACTION; /* set up yytext again */ -YY_RULE_SETUP -#line 34 "scheme.flex" -{ /* skip comments */ - yyinputline++; - yysofar += yyleng; -} - YY_BREAK -case 2: -YY_RULE_SETUP -#line 39 "scheme.flex" -{ - yysofar += yyleng; return QUOTECHAR; -} - YY_BREAK -case 3: -YY_RULE_SETUP -#line 43 "scheme.flex" -{ - yysofar += yyleng; return ARROW; -} - YY_BREAK -case 4: -YY_RULE_SETUP -#line 47 "scheme.flex" -{ - yysofar += yyleng; return QUOTE; -} - YY_BREAK -case 5: -YY_RULE_SETUP -#line 51 "scheme.flex" -{ - yysofar += yyleng; return CALLCC; -} - YY_BREAK -case 6: -YY_RULE_SETUP -#line 55 "scheme.flex" -{ - yysofar += yyleng; return APPLY; -} - YY_BREAK -case 7: -YY_RULE_SETUP -#line 59 "scheme.flex" -{ - yysofar += yyleng; return DEFINE; -} - YY_BREAK -case 8: -YY_RULE_SETUP -#line 63 "scheme.flex" -{ - yysofar += yyleng; return SET; -} - YY_BREAK -case 9: -YY_RULE_SETUP -#line 67 "scheme.flex" -{ - yysofar += yyleng; return LAMBDA; -} - YY_BREAK -case 10: -YY_RULE_SETUP -#line 71 "scheme.flex" -{ - yysofar += yyleng; return IF; -} - YY_BREAK -case 11: -YY_RULE_SETUP -#line 75 "scheme.flex" -{ - yysofar += yyleng; return BEGINTOK; -} - YY_BREAK -case 12: -YY_RULE_SETUP -#line 79 "scheme.flex" -{ - yysofar += yyleng; return AND; -} - YY_BREAK -case 13: -YY_RULE_SETUP -#line 83 "scheme.flex" -{ - yysofar += yyleng; return OR; -} - YY_BREAK -case 14: -YY_RULE_SETUP -#line 87 "scheme.flex" -{ - yysofar += yyleng; return CASE; -} - YY_BREAK -case 15: -YY_RULE_SETUP -#line 91 "scheme.flex" -{ - yysofar += yyleng; return COND; -} - YY_BREAK -case 16: -YY_RULE_SETUP -#line 95 "scheme.flex" -{ - yysofar += yyleng; return ELSE; -} - YY_BREAK -case 17: -YY_RULE_SETUP -#line 99 "scheme.flex" -{ - yysofar += yyleng; return LET; -} - YY_BREAK -case 18: -YY_RULE_SETUP -#line 103 "scheme.flex" -{ - yysofar += yyleng; return LETSTAR; -} - YY_BREAK -case 19: -YY_RULE_SETUP -#line 107 "scheme.flex" -{ - yysofar += yyleng; return LETREC; -} - YY_BREAK -case 20: -YY_RULE_SETUP -#line 111 "scheme.flex" -{ - BOOL val = (yytext[1]=='t' ? YES : NO); - yylval = [[Boolean alloc] initSCMBoolean:val]; - yysofar += yyleng; return BOOLEAN; -} - YY_BREAK -case 21: -YY_RULE_SETUP -#line 117 "scheme.flex" -{ - char val; - if(!strcmp(yytext, "#\\newline")){ - val = '\n'; - } - else if(!strcmp(yytext, "#\\tab")){ - val = '\t'; - } - else if(!strcmp(yytext, "#\\space")){ - val = ' '; - } - else{ - val = yytext[2]; - } - - yylval = [[Char alloc] initSCMChar:val]; - yysofar += yyleng; return CHAR; -} - YY_BREAK -case 22: -YY_RULE_SETUP -#line 136 "scheme.flex" -{ - double val; - sscanf(yytext, "%le", &val); - yylval = [[Double alloc] initSCMDouble:val]; - yysofar += yyleng; return DOUBLE; -} - YY_BREAK -case 23: -YY_RULE_SETUP -#line 143 "scheme.flex" -{ - double val; - sscanf(yytext, "%le", &val); - yylval = [[Double alloc] initSCMDouble:val]; - yysofar += yyleng; return DOUBLE; -} - YY_BREAK -case 24: -YY_RULE_SETUP -#line 150 "scheme.flex" -{ - double val; - sscanf(yytext, "%le", &val); - yylval = [[Double alloc] initSCMDouble:val]; - yysofar += yyleng; return DOUBLE; -} - YY_BREAK -case 25: -YY_RULE_SETUP -#line 157 "scheme.flex" -{ - double val; - sscanf(yytext, "%le", &val); - yylval = [[Double alloc] initSCMDouble:val]; - yysofar += yyleng; return DOUBLE; -} - YY_BREAK -case 26: -YY_RULE_SETUP -#line 164 "scheme.flex" -{ - long int val; - sscanf(yytext, "%ld", &val); - yylval = [[Int alloc] initSCMInt:val]; - yysofar += yyleng; return INTEGER; -} - YY_BREAK -case 27: -YY_RULE_SETUP -#line 171 "scheme.flex" -{ - yylval = [[Symbol alloc] initSCMSymbol:yytext]; - yysofar += yyleng; return SYMBOL; -} - YY_BREAK -case 28: -YY_RULE_SETUP -#line 177 "scheme.flex" -{ - yylval = [[Symbol alloc] initSCMSymbol:yytext]; - yysofar += yyleng; return SYMBOL; -} - YY_BREAK -case 29: -YY_RULE_SETUP -#line 182 "scheme.flex" -{ - yylval = [[String alloc] initSCMString:yytext]; - yysofar += yyleng; return STRING; -} - YY_BREAK -case 30: -YY_RULE_SETUP -#line 187 "scheme.flex" -{ - yysofar += yyleng; return LVECTPAREN; -} - YY_BREAK -case 31: -YY_RULE_SETUP -#line 191 "scheme.flex" -{ - yysofar += yyleng; return LPAREN; -} - YY_BREAK -case 32: -YY_RULE_SETUP -#line 195 "scheme.flex" -{ - yysofar += yyleng; return RPAREN; -} - YY_BREAK -case 33: -YY_RULE_SETUP -#line 199 "scheme.flex" -{ - yysofar += yyleng; return DOT; -} - YY_BREAK -case 34: -YY_RULE_SETUP -#line 203 "scheme.flex" -yysofar += yyleng; /* eat up whitespace */ - YY_BREAK -case 35: -YY_RULE_SETUP -#line 205 "scheme.flex" -yysofar += yyleng; yyinputline++; - YY_BREAK -case 36: -YY_RULE_SETUP -#line 207 "scheme.flex" -printf( "Unrecognized character: %s\n", yytext); yysofar += yyleng; - YY_BREAK -case 37: -YY_RULE_SETUP -#line 209 "scheme.flex" -ECHO; - YY_BREAK -#line 1052 "lex.yy.c" -case YY_STATE_EOF(INITIAL): - yyterminate(); - - case YY_END_OF_BUFFER: - { - /* Amount of text matched not including the EOB char. */ - int yy_amount_of_matched_text = (int) (yy_cp - yytext_ptr) - 1; - - /* Undo the effects of YY_DO_BEFORE_ACTION. */ - *yy_cp = yy_hold_char; - YY_RESTORE_YY_MORE_OFFSET - - if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_NEW ) - { - /* We're scanning a new file or input source. It's - * possible that this happened because the user - * just pointed yyin at a new source and called - * yylex(). If so, then we have to assure - * consistency between yy_current_buffer and our - * globals. Here is the right place to do so, because - * this is the first action (other than possibly a - * back-up) that will match for the new input source. - */ - yy_n_chars = yy_current_buffer->yy_n_chars; - yy_current_buffer->yy_input_file = yyin; - yy_current_buffer->yy_buffer_status = YY_BUFFER_NORMAL; - } - - /* Note that here we test for yy_c_buf_p "<=" to the position - * of the first EOB in the buffer, since yy_c_buf_p will - * already have been incremented past the NUL character - * (since all states make transitions on EOB to the - * end-of-buffer state). Contrast this with the test - * in input(). - */ - if ( yy_c_buf_p <= &yy_current_buffer->yy_ch_buf[yy_n_chars] ) - { /* This was really a NUL. */ - yy_state_type yy_next_state; - - yy_c_buf_p = yytext_ptr + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state(); - - /* Okay, we're now positioned to make the NUL - * transition. We couldn't have - * yy_get_previous_state() go ahead and do it - * for us because it doesn't know how to deal - * with the possibility of jamming (and we don't - * want to build jamming into it because then it - * will run more slowly). - */ - - yy_next_state = yy_try_NUL_trans( yy_current_state ); - - yy_bp = yytext_ptr + YY_MORE_ADJ; - - if ( yy_next_state ) - { - /* Consume the NUL. */ - yy_cp = ++yy_c_buf_p; - yy_current_state = yy_next_state; - goto yy_match; - } - - else - { - yy_cp = yy_c_buf_p; - goto yy_find_action; - } - } - - else switch ( yy_get_next_buffer() ) - { - case EOB_ACT_END_OF_FILE: - { - yy_did_buffer_switch_on_eof = 0; - - if ( yywrap() ) - { - /* Note: because we've taken care in - * yy_get_next_buffer() to have set up - * yytext, we can now set up - * yy_c_buf_p so that if some total - * hoser (like flex itself) wants to - * call the scanner after we return the - * YY_NULL, it'll still work - another - * YY_NULL will get returned. - */ - yy_c_buf_p = yytext_ptr + YY_MORE_ADJ; - - yy_act = YY_STATE_EOF(YY_START); - goto do_action; - } - - else - { - if ( ! yy_did_buffer_switch_on_eof ) - YY_NEW_FILE; - } - break; - } - - case EOB_ACT_CONTINUE_SCAN: - yy_c_buf_p = - yytext_ptr + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state(); - - yy_cp = yy_c_buf_p; - yy_bp = yytext_ptr + YY_MORE_ADJ; - goto yy_match; - - case EOB_ACT_LAST_MATCH: - yy_c_buf_p = - &yy_current_buffer->yy_ch_buf[yy_n_chars]; - - yy_current_state = yy_get_previous_state(); - - yy_cp = yy_c_buf_p; - yy_bp = yytext_ptr + YY_MORE_ADJ; - goto yy_find_action; - } - break; - } - - default: - YY_FATAL_ERROR( - "fatal flex scanner internal error--no action found" ); - } /* end of action switch */ - } /* end of scanning one token */ - } /* end of yylex */ - - -/* yy_get_next_buffer - try to read in a new buffer - * - * Returns a code representing an action: - * EOB_ACT_LAST_MATCH - - * EOB_ACT_CONTINUE_SCAN - continue scanning from current position - * EOB_ACT_END_OF_FILE - end of file - */ - -static int yy_get_next_buffer() - { - register char *dest = yy_current_buffer->yy_ch_buf; - register char *source = yytext_ptr; - register int number_to_move, i; - int ret_val; - - if ( yy_c_buf_p > &yy_current_buffer->yy_ch_buf[yy_n_chars + 1] ) - YY_FATAL_ERROR( - "fatal flex scanner internal error--end of buffer missed" ); - - if ( yy_current_buffer->yy_fill_buffer == 0 ) - { /* Don't try to fill the buffer, so this is an EOF. */ - if ( yy_c_buf_p - yytext_ptr - YY_MORE_ADJ == 1 ) - { - /* We matched a single character, the EOB, so - * treat this as a final EOF. - */ - return EOB_ACT_END_OF_FILE; - } - - else - { - /* We matched some text prior to the EOB, first - * process it. - */ - return EOB_ACT_LAST_MATCH; - } - } - - /* Try to read more data. */ - - /* First move last chars to start of buffer. */ - number_to_move = (int) (yy_c_buf_p - yytext_ptr) - 1; - - for ( i = 0; i < number_to_move; ++i ) - *(dest++) = *(source++); - - if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_EOF_PENDING ) - /* don't do the read, it's not guaranteed to return an EOF, - * just force an EOF - */ - yy_current_buffer->yy_n_chars = yy_n_chars = 0; - - else - { - int num_to_read = - yy_current_buffer->yy_buf_size - number_to_move - 1; - - while ( num_to_read <= 0 ) - { /* Not enough room in the buffer - grow it. */ -#ifdef YY_USES_REJECT - YY_FATAL_ERROR( -"input buffer overflow, can't enlarge buffer because scanner uses REJECT" ); -#else - - /* just a shorter name for the current buffer */ - YY_BUFFER_STATE b = yy_current_buffer; - - int yy_c_buf_p_offset = - (int) (yy_c_buf_p - b->yy_ch_buf); - - if ( b->yy_is_our_buffer ) - { - int new_size = b->yy_buf_size * 2; - - if ( new_size <= 0 ) - b->yy_buf_size += b->yy_buf_size / 8; - else - b->yy_buf_size *= 2; - - b->yy_ch_buf = (char *) - /* Include room in for 2 EOB chars. */ - yy_flex_realloc( (void *) b->yy_ch_buf, - b->yy_buf_size + 2 ); - } - else - /* Can't grow it, we don't own it. */ - b->yy_ch_buf = 0; - - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( - "fatal error - scanner input buffer overflow" ); - - yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset]; - - num_to_read = yy_current_buffer->yy_buf_size - - number_to_move - 1; -#endif - } - - if ( num_to_read > YY_READ_BUF_SIZE ) - num_to_read = YY_READ_BUF_SIZE; - - /* Read in more data. */ - YY_INPUT( (&yy_current_buffer->yy_ch_buf[number_to_move]), - yy_n_chars, num_to_read ); - - yy_current_buffer->yy_n_chars = yy_n_chars; - } - - if ( yy_n_chars == 0 ) - { - if ( number_to_move == YY_MORE_ADJ ) - { - ret_val = EOB_ACT_END_OF_FILE; - yyrestart( yyin ); - } - - else - { - ret_val = EOB_ACT_LAST_MATCH; - yy_current_buffer->yy_buffer_status = - YY_BUFFER_EOF_PENDING; - } - } - - else - ret_val = EOB_ACT_CONTINUE_SCAN; - - yy_n_chars += number_to_move; - yy_current_buffer->yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR; - yy_current_buffer->yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR; - - yytext_ptr = &yy_current_buffer->yy_ch_buf[0]; - - return ret_val; - } - - -/* yy_get_previous_state - get the state just before the EOB char was reached */ - -static yy_state_type yy_get_previous_state() - { - register yy_state_type yy_current_state; - register char *yy_cp; - - yy_current_state = yy_start; - - for ( yy_cp = yytext_ptr + YY_MORE_ADJ; yy_cp < yy_c_buf_p; ++yy_cp ) - { - register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); - if ( yy_accept[yy_current_state] ) - { - yy_last_accepting_state = yy_current_state; - yy_last_accepting_cpos = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 143 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - } - - return yy_current_state; - } - - -/* yy_try_NUL_trans - try to make a transition on the NUL character - * - * synopsis - * next_state = yy_try_NUL_trans( current_state ); - */ - -#ifdef YY_USE_PROTOS -static yy_state_type yy_try_NUL_trans( yy_state_type yy_current_state ) -#else -static yy_state_type yy_try_NUL_trans( yy_current_state ) -yy_state_type yy_current_state; -#endif - { - register int yy_is_jam; - register char *yy_cp = yy_c_buf_p; - - register YY_CHAR yy_c = 1; - if ( yy_accept[yy_current_state] ) - { - yy_last_accepting_state = yy_current_state; - yy_last_accepting_cpos = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 143 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - yy_is_jam = (yy_current_state == 142); - - return yy_is_jam ? 0 : yy_current_state; - } - - -#ifndef YY_NO_UNPUT -#ifdef YY_USE_PROTOS -static void yyunput( int c, register char *yy_bp ) -#else -static void yyunput( c, yy_bp ) -int c; -register char *yy_bp; -#endif - { - register char *yy_cp = yy_c_buf_p; - - /* undo effects of setting up yytext */ - *yy_cp = yy_hold_char; - - if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 ) - { /* need to shift things up to make room */ - /* +2 for EOB chars. */ - register int number_to_move = yy_n_chars + 2; - register char *dest = &yy_current_buffer->yy_ch_buf[ - yy_current_buffer->yy_buf_size + 2]; - register char *source = - &yy_current_buffer->yy_ch_buf[number_to_move]; - - while ( source > yy_current_buffer->yy_ch_buf ) - *--dest = *--source; - - yy_cp += (int) (dest - source); - yy_bp += (int) (dest - source); - yy_current_buffer->yy_n_chars = - yy_n_chars = yy_current_buffer->yy_buf_size; - - if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 ) - YY_FATAL_ERROR( "flex scanner push-back overflow" ); - } - - *--yy_cp = (char) c; - - - yytext_ptr = yy_bp; - yy_hold_char = *yy_cp; - yy_c_buf_p = yy_cp; - } -#endif /* ifndef YY_NO_UNPUT */ - - -#ifdef __cplusplus -static int yyinput() -#else -static int input() -#endif - { - int c; - - *yy_c_buf_p = yy_hold_char; - - if ( *yy_c_buf_p == YY_END_OF_BUFFER_CHAR ) - { - /* yy_c_buf_p now points to the character we want to return. - * If this occurs *before* the EOB characters, then it's a - * valid NUL; if not, then we've hit the end of the buffer. - */ - if ( yy_c_buf_p < &yy_current_buffer->yy_ch_buf[yy_n_chars] ) - /* This was really a NUL. */ - *yy_c_buf_p = '\0'; - - else - { /* need more input */ - int offset = yy_c_buf_p - yytext_ptr; - ++yy_c_buf_p; - - switch ( yy_get_next_buffer() ) - { - case EOB_ACT_LAST_MATCH: - /* This happens because yy_g_n_b() - * sees that we've accumulated a - * token and flags that we need to - * try matching the token before - * proceeding. But for input(), - * there's no matching to consider. - * So convert the EOB_ACT_LAST_MATCH - * to EOB_ACT_END_OF_FILE. - */ - - /* Reset buffer status. */ - yyrestart( yyin ); - - /* fall through */ - - case EOB_ACT_END_OF_FILE: - { - if ( yywrap() ) - return EOF; - - if ( ! yy_did_buffer_switch_on_eof ) - YY_NEW_FILE; -#ifdef __cplusplus - return yyinput(); -#else - return input(); -#endif - } - - case EOB_ACT_CONTINUE_SCAN: - yy_c_buf_p = yytext_ptr + offset; - break; - } - } - } - - c = *(unsigned char *) yy_c_buf_p; /* cast for 8-bit char's */ - *yy_c_buf_p = '\0'; /* preserve yytext */ - yy_hold_char = *++yy_c_buf_p; - - - return c; - } - - -#ifdef YY_USE_PROTOS -void yyrestart( FILE *input_file ) -#else -void yyrestart( input_file ) -FILE *input_file; -#endif - { - if ( ! yy_current_buffer ) - yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); - - yy_init_buffer( yy_current_buffer, input_file ); - yy_load_buffer_state(); - } - - -#ifdef YY_USE_PROTOS -void yy_switch_to_buffer( YY_BUFFER_STATE new_buffer ) -#else -void yy_switch_to_buffer( new_buffer ) -YY_BUFFER_STATE new_buffer; -#endif - { - if ( yy_current_buffer == new_buffer ) - return; - - if ( yy_current_buffer ) - { - /* Flush out information for old buffer. */ - *yy_c_buf_p = yy_hold_char; - yy_current_buffer->yy_buf_pos = yy_c_buf_p; - yy_current_buffer->yy_n_chars = yy_n_chars; - } - - yy_current_buffer = new_buffer; - yy_load_buffer_state(); - - /* We don't actually know whether we did this switch during - * EOF (yywrap()) processing, but the only time this flag - * is looked at is after yywrap() is called, so it's safe - * to go ahead and always set it. - */ - yy_did_buffer_switch_on_eof = 1; - } - - -#ifdef YY_USE_PROTOS -void yy_load_buffer_state( void ) -#else -void yy_load_buffer_state() -#endif - { - yy_n_chars = yy_current_buffer->yy_n_chars; - yytext_ptr = yy_c_buf_p = yy_current_buffer->yy_buf_pos; - yyin = yy_current_buffer->yy_input_file; - yy_hold_char = *yy_c_buf_p; - } - - -#ifdef YY_USE_PROTOS -YY_BUFFER_STATE yy_create_buffer( FILE *file, int size ) -#else -YY_BUFFER_STATE yy_create_buffer( file, size ) -FILE *file; -int size; -#endif - { - YY_BUFFER_STATE b; - - b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); - - b->yy_buf_size = size; - - /* yy_ch_buf has to be 2 characters longer than the size given because - * we need to put in 2 end-of-buffer characters. - */ - b->yy_ch_buf = (char *) yy_flex_alloc( b->yy_buf_size + 2 ); - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); - - b->yy_is_our_buffer = 1; - - yy_init_buffer( b, file ); - - return b; - } - - -#ifdef YY_USE_PROTOS -void yy_delete_buffer( YY_BUFFER_STATE b ) -#else -void yy_delete_buffer( b ) -YY_BUFFER_STATE b; -#endif - { - if ( ! b ) - return; - - if ( b == yy_current_buffer ) - yy_current_buffer = (YY_BUFFER_STATE) 0; - - if ( b->yy_is_our_buffer ) - yy_flex_free( (void *) b->yy_ch_buf ); - - yy_flex_free( (void *) b ); - } - - -#ifndef YY_ALWAYS_INTERACTIVE -#ifndef YY_NEVER_INTERACTIVE -#include -#endif -#endif - -#ifdef YY_USE_PROTOS -void yy_init_buffer( YY_BUFFER_STATE b, FILE *file ) -#else -void yy_init_buffer( b, file ) -YY_BUFFER_STATE b; -FILE *file; -#endif - - - { - yy_flush_buffer( b ); - - b->yy_input_file = file; - b->yy_fill_buffer = 1; - -#if YY_ALWAYS_INTERACTIVE - b->yy_is_interactive = 1; -#else -#if YY_NEVER_INTERACTIVE - b->yy_is_interactive = 0; -#else - b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; -#endif -#endif - } - - -#ifdef YY_USE_PROTOS -void yy_flush_buffer( YY_BUFFER_STATE b ) -#else -void yy_flush_buffer( b ) -YY_BUFFER_STATE b; -#endif - - { - if ( ! b ) - return; - - b->yy_n_chars = 0; - - /* We always need two end-of-buffer characters. The first causes - * a transition to the end-of-buffer state. The second causes - * a jam in that state. - */ - b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; - b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; - - b->yy_buf_pos = &b->yy_ch_buf[0]; - - b->yy_at_bol = 1; - b->yy_buffer_status = YY_BUFFER_NEW; - - if ( b == yy_current_buffer ) - yy_load_buffer_state(); - } - - -#ifndef YY_NO_SCAN_BUFFER -#ifdef YY_USE_PROTOS -YY_BUFFER_STATE yy_scan_buffer( char *base, yy_size_t size ) -#else -YY_BUFFER_STATE yy_scan_buffer( base, size ) -char *base; -yy_size_t size; -#endif - { - YY_BUFFER_STATE b; - - if ( size < 2 || - base[size-2] != YY_END_OF_BUFFER_CHAR || - base[size-1] != YY_END_OF_BUFFER_CHAR ) - /* They forgot to leave room for the EOB's. */ - return 0; - - b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); - - b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ - b->yy_buf_pos = b->yy_ch_buf = base; - b->yy_is_our_buffer = 0; - b->yy_input_file = 0; - b->yy_n_chars = b->yy_buf_size; - b->yy_is_interactive = 0; - b->yy_at_bol = 1; - b->yy_fill_buffer = 0; - b->yy_buffer_status = YY_BUFFER_NEW; - - yy_switch_to_buffer( b ); - - return b; - } -#endif - - -#ifndef YY_NO_SCAN_STRING -#ifdef YY_USE_PROTOS -YY_BUFFER_STATE yy_scan_string( yyconst char *yy_str ) -#else -YY_BUFFER_STATE yy_scan_string( yy_str ) -yyconst char *yy_str; -#endif - { - int len; - for ( len = 0; yy_str[len]; ++len ) - ; - - return yy_scan_bytes( yy_str, len ); - } -#endif - - -#ifndef YY_NO_SCAN_BYTES -#ifdef YY_USE_PROTOS -YY_BUFFER_STATE yy_scan_bytes( yyconst char *bytes, int len ) -#else -YY_BUFFER_STATE yy_scan_bytes( bytes, len ) -yyconst char *bytes; -int len; -#endif - { - YY_BUFFER_STATE b; - char *buf; - yy_size_t n; - int i; - - /* Get memory for full buffer, including space for trailing EOB's. */ - n = len + 2; - buf = (char *) yy_flex_alloc( n ); - if ( ! buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); - - for ( i = 0; i < len; ++i ) - buf[i] = bytes[i]; - - buf[len] = buf[len+1] = YY_END_OF_BUFFER_CHAR; - - b = yy_scan_buffer( buf, n ); - if ( ! b ) - YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); - - /* It's okay to grow etc. this buffer, and we should throw it - * away when we're done. - */ - b->yy_is_our_buffer = 1; - - return b; - } -#endif - - -#ifndef YY_NO_PUSH_STATE -#ifdef YY_USE_PROTOS -static void yy_push_state( int new_state ) -#else -static void yy_push_state( new_state ) -int new_state; -#endif - { - if ( yy_start_stack_ptr >= yy_start_stack_depth ) - { - yy_size_t new_size; - - yy_start_stack_depth += YY_START_STACK_INCR; - new_size = yy_start_stack_depth * sizeof( int ); - - if ( ! yy_start_stack ) - yy_start_stack = (int *) yy_flex_alloc( new_size ); - - else - yy_start_stack = (int *) yy_flex_realloc( - (void *) yy_start_stack, new_size ); - - if ( ! yy_start_stack ) - YY_FATAL_ERROR( - "out of memory expanding start-condition stack" ); - } - - yy_start_stack[yy_start_stack_ptr++] = YY_START; - - BEGIN(new_state); - } -#endif - - -#ifndef YY_NO_POP_STATE -static void yy_pop_state() - { - if ( --yy_start_stack_ptr < 0 ) - YY_FATAL_ERROR( "start-condition stack underflow" ); - - BEGIN(yy_start_stack[yy_start_stack_ptr]); - } -#endif - - -#ifndef YY_NO_TOP_STATE -static int yy_top_state() - { - return yy_start_stack[yy_start_stack_ptr - 1]; - } -#endif - -#ifndef YY_EXIT_FAILURE -#define YY_EXIT_FAILURE 2 -#endif - -#ifdef YY_USE_PROTOS -static void yy_fatal_error( yyconst char msg[] ) -#else -static void yy_fatal_error( msg ) -char msg[]; -#endif - { - (void) fprintf( stderr, "%s\n", msg ); - exit( YY_EXIT_FAILURE ); - } - - - -/* Redefine yyless() so it works in section 3 code. */ - -#undef yyless -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - yytext[yyleng] = yy_hold_char; \ - yy_c_buf_p = yytext + n; \ - yy_hold_char = *yy_c_buf_p; \ - *yy_c_buf_p = '\0'; \ - yyleng = n; \ - } \ - while ( 0 ) - - -/* Internal utility routines. */ - -#ifndef yytext_ptr -#ifdef YY_USE_PROTOS -static void yy_flex_strncpy( char *s1, yyconst char *s2, int n ) -#else -static void yy_flex_strncpy( s1, s2, n ) -char *s1; -yyconst char *s2; -int n; -#endif - { - register int i; - for ( i = 0; i < n; ++i ) - s1[i] = s2[i]; - } -#endif - -#ifdef YY_NEED_STRLEN -#ifdef YY_USE_PROTOS -static int yy_flex_strlen( yyconst char *s ) -#else -static int yy_flex_strlen( s ) -yyconst char *s; -#endif - { - register int n; - for ( n = 0; s[n]; ++n ) - ; - - return n; - } -#endif - - -#ifdef YY_USE_PROTOS -static void *yy_flex_alloc( yy_size_t size ) -#else -static void *yy_flex_alloc( size ) -yy_size_t size; -#endif - { - return (void *) malloc( size ); - } - -#ifdef YY_USE_PROTOS -static void *yy_flex_realloc( void *ptr, yy_size_t size ) -#else -static void *yy_flex_realloc( ptr, size ) -void *ptr; -yy_size_t size; -#endif - { - /* The cast to (char *) in the following accommodates both - * implementations that use char* generic pointers, and those - * that use void* generic pointers. It works with the latter - * because both ANSI C and C++ allow castless assignment from - * any pointer type to void*, and deal with argument conversions - * as though doing an assignment. - */ - return (void *) realloc( (char *) ptr, size ); - } - -#ifdef YY_USE_PROTOS -static void yy_flex_free( void *ptr ) -#else -static void yy_flex_free( ptr ) -void *ptr; -#endif - { - free( ptr ); - } - -#if YY_MAIN -int main() - { - yylex(); - return 0; - } -#endif -#line 209 "scheme.flex" - - diff --git a/scheme.flex b/scheme.flex index 453ef20..05760d5 100644 --- a/scheme.flex +++ b/scheme.flex @@ -180,7 +180,7 @@ STRING "\""([^\n\"\\]|"\\\\"|"\\\"")*"\"" } {STRING} { - yylval = [[String alloc] initSCMString:yytext]; + yylval = [[String alloc] initSCMStringLEX:yytext]; yysofar += yyleng; return STRING; } diff --git a/scheme.lex.m b/scheme.lex.m index bd210a7..93f23ef 100644 --- a/scheme.lex.m +++ b/scheme.lex.m @@ -996,7 +996,7 @@ case 29: YY_RULE_SETUP #line 182 "scheme.flex" { - yylval = [[String alloc] initSCMString:yytext]; + yylval = [[String alloc] initSCMStringLEX:yytext]; yysofar += yyleng; return STRING; } YY_BREAK diff --git a/scheme.tab.m b/scheme.tab.m index 45b7e4f..72c2781 100644 --- a/scheme.tab.m +++ b/scheme.tab.m @@ -41,9 +41,10 @@ YYSTYPE yyresult; int yyinputitem; +id yyresultform; extern int yysofar; -extern NSMutableArray *positions; +extern NSMutableArray *positionStack; #ifndef YYSTYPE #define YYSTYPE int #endif @@ -57,11 +58,11 @@ extern NSMutableArray *positions; -#define YYFINAL 164 +#define YYFINAL 206 #define YYFLAG -32768 #define YYNTBASE 31 -#define YYTRANSLATE(x) ((unsigned)(x) <= 284 ? yytranslate[x] : 66) +#define YYTRANSLATE(x) ((unsigned)(x) <= 284 ? yytranslate[x] : 72) static const char yytranslate[] = { 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, @@ -98,61 +99,75 @@ static const char yytranslate[] = { 0, #if YYDEBUG != 0 static const short yyprhs[] = { 0, 0, 1, 4, 10, 16, 18, 20, 23, 25, 28, - 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, - 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, - 70, 72, 77, 84, 88, 93, 99, 104, 106, 109, - 111, 114, 120, 127, 132, 138, 143, 147, 152, 156, - 161, 167, 173, 179, 186, 192, 198, 201, 206, 211, - 213, 216, 224, 232, 240, 243, 245, 249, 252, 254, - 257, 261, 263, 265, 269, 272, 274, 278, 281, 285, - 287 + 30, 32, 34, 36, 38, 40, 42, 44, 47, 49, + 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, + 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, + 91, 93, 95, 97, 99, 101, 103, 105, 107, 109, + 111, 113, 115, 117, 119, 121, 123, 125, 130, 137, + 141, 146, 152, 157, 159, 162, 164, 167, 173, 180, + 185, 191, 196, 200, 205, 209, 214, 220, 226, 232, + 239, 245, 251, 254, 259, 264, 266, 269, 277, 285, + 293, 296, 298, 302, 305, 307, 311, 314, 316, 319, + 321, 324, 328, 332, 334, 336, 338, 340, 344, 347, + 351, 354, 356, 360, 363, 367, 369 }; static const short yyrhs[] = { -1, - 32, 31, 0, 3, 6, 27, 35, 5, 0, 3, - 6, 64, 33, 5, 0, 35, 0, 35, 0, 35, - 33, 0, 35, 0, 34, 35, 0, 23, 0, 24, - 0, 25, 0, 26, 0, 27, 0, 28, 0, 61, - 0, 62, 0, 50, 0, 49, 0, 54, 0, 55, - 0, 56, 0, 51, 0, 48, 0, 47, 0, 46, - 0, 44, 0, 45, 0, 42, 0, 43, 0, 36, - 0, 3, 16, 35, 5, 0, 3, 3, 33, 5, - 33, 5, 0, 3, 35, 5, 0, 3, 35, 33, - 5, 0, 3, 35, 15, 35, 5, 0, 3, 14, - 33, 5, 0, 37, 0, 40, 37, 0, 38, 0, - 41, 38, 0, 3, 12, 35, 40, 5, 0, 3, - 12, 35, 40, 39, 5, 0, 3, 13, 41, 5, - 0, 3, 13, 41, 39, 5, 0, 3, 10, 34, - 5, 0, 3, 10, 5, 0, 3, 11, 34, 5, - 0, 3, 11, 5, 0, 3, 9, 33, 5, 0, - 3, 7, 27, 35, 5, 0, 3, 17, 35, 35, - 5, 0, 3, 18, 35, 35, 5, 0, 3, 18, - 35, 35, 35, 5, 0, 3, 8, 27, 33, 5, - 0, 3, 8, 65, 33, 5, 0, 29, 35, 0, - 3, 30, 35, 5, 0, 3, 27, 35, 5, 0, - 52, 0, 52, 53, 0, 3, 19, 3, 53, 5, - 33, 5, 0, 3, 20, 3, 53, 5, 33, 5, - 0, 3, 21, 3, 53, 5, 33, 5, 0, 3, - 5, 0, 35, 0, 35, 22, 35, 0, 35, 58, - 0, 35, 0, 35, 59, 0, 3, 58, 5, 0, - 60, 0, 57, 0, 4, 59, 5, 0, 4, 5, - 0, 27, 0, 27, 22, 27, 0, 27, 63, 0, - 3, 63, 5, 0, 64, 0, 57, 0 + 32, 31, 0, 3, 6, 27, 36, 5, 0, 3, + 6, 70, 33, 5, 0, 36, 0, 36, 0, 36, + 33, 0, 36, 0, 34, 36, 0, 23, 0, 24, + 0, 25, 0, 26, 0, 27, 0, 28, 0, 66, + 0, 68, 0, 29, 35, 0, 15, 0, 30, 0, + 16, 0, 17, 0, 6, 0, 7, 0, 8, 0, + 18, 0, 9, 0, 10, 0, 11, 0, 12, 0, + 13, 0, 14, 0, 19, 0, 20, 0, 21, 0, + 23, 0, 24, 0, 25, 0, 26, 0, 27, 0, + 28, 0, 65, 0, 67, 0, 51, 0, 50, 0, + 55, 0, 56, 0, 57, 0, 52, 0, 49, 0, + 48, 0, 47, 0, 45, 0, 46, 0, 43, 0, + 44, 0, 37, 0, 3, 16, 36, 5, 0, 3, + 3, 33, 5, 33, 5, 0, 3, 36, 5, 0, + 3, 36, 33, 5, 0, 3, 36, 15, 36, 5, + 0, 3, 14, 33, 5, 0, 38, 0, 41, 38, + 0, 39, 0, 42, 39, 0, 3, 12, 36, 41, + 5, 0, 3, 12, 36, 41, 40, 5, 0, 3, + 13, 42, 5, 0, 3, 13, 42, 40, 5, 0, + 3, 10, 34, 5, 0, 3, 10, 5, 0, 3, + 11, 34, 5, 0, 3, 11, 5, 0, 3, 9, + 33, 5, 0, 3, 7, 27, 36, 5, 0, 3, + 17, 36, 36, 5, 0, 3, 18, 36, 36, 5, + 0, 3, 18, 36, 36, 36, 5, 0, 3, 8, + 27, 33, 5, 0, 3, 8, 71, 33, 5, 0, + 29, 35, 0, 3, 30, 35, 5, 0, 3, 27, + 36, 5, 0, 53, 0, 53, 54, 0, 3, 19, + 3, 54, 5, 33, 5, 0, 3, 20, 3, 54, + 5, 33, 5, 0, 3, 21, 3, 54, 5, 33, + 5, 0, 3, 5, 0, 36, 0, 36, 22, 36, + 0, 36, 59, 0, 35, 0, 35, 22, 35, 0, + 35, 60, 0, 36, 0, 36, 61, 0, 35, 0, + 35, 62, 0, 3, 59, 5, 0, 3, 60, 5, + 0, 63, 0, 58, 0, 64, 0, 58, 0, 4, + 61, 5, 0, 4, 5, 0, 4, 62, 5, 0, + 4, 5, 0, 27, 0, 27, 22, 27, 0, 27, + 69, 0, 3, 69, 5, 0, 70, 0, 58, 0 }; #endif #if YYDEBUG != 0 static const short yyrline[] = { 0, - 55, 59, 66, 74, 82, 92, 95, 100, 103, 108, - 111, 114, 117, 120, 123, 126, 129, 132, 135, 138, - 141, 144, 147, 150, 153, 156, 159, 162, 165, 168, - 171, 175, 179, 183, 186, 189, 193, 197, 200, 205, - 208, 213, 216, 221, 224, 228, 231, 235, 238, 242, - 246, 250, 254, 257, 261, 264, 268, 271, 276, 280, - 283, 287, 291, 295, 299, 304, 307, 310, 315, 318, - 323, 328, 331, 336, 339, 344, 347, 350, 355, 360, - 363 + 56, 60, 68, 76, 84, 94, 97, 102, 105, 110, + 113, 116, 119, 122, 125, 128, 131, 134, 138, 141, + 144, 147, 150, 153, 156, 159, 162, 165, 168, 171, + 174, 177, 180, 183, 186, 191, 194, 197, 200, 203, + 206, 209, 212, 215, 218, 221, 224, 227, 230, 233, + 236, 239, 242, 245, 248, 251, 254, 259, 264, 269, + 272, 275, 280, 285, 288, 293, 296, 301, 304, 310, + 313, 318, 321, 326, 329, 334, 339, 344, 349, 352, + 357, 360, 365, 368, 373, 378, 381, 386, 391, 396, + 401, 406, 409, 412, 417, 420, 423, 428, 431, 436, + 439, 444, 449, 454, 457, 462, 465, 470, 473, 478, + 481, 486, 489, 492, 497, 502, 505 }; #endif @@ -163,10 +178,11 @@ static const char * const yytname[] = { "$","error","$undefined.","LPAREN", "LVECTPAREN","RPAREN","DEFINE","SET","LAMBDA","BEGINTOK","AND","OR","CASE","COND", "ELSE","ARROW","CALLCC","APPLY","IF","LET","LETSTAR","LETREC","DOT","INTEGER", "CHAR","BOOLEAN","DOUBLE","SYMBOL","STRING","QUOTECHAR","QUOTE","top","topitem", -"sequence","revsequence","form","callcc","singlecase","singlecond","elsecasecond", +"sequence","revsequence","qform","form","callcc","singlecase","singlecond","elsecasecond", "cases","conditions","case","cond","and","or","begin","set","apply","if","lambda", "quote","singlebinding","listofbindings","let","letstar","letrec","emptylist", -"nonemptylistdata","nonemptyvectdata","nonemptylist","list","vector","nonemptysymlistdata", +"nonemptylistdata","qnonemptylistdata","nonemptyvectdata","qnonemptyvectdata", +"nonemptylist","qnonemptylist","list","qlist","vector","qvector","nonemptysymlistdata", "nonemptysymlist","symlist", NULL }; #endif @@ -175,154 +191,196 @@ static const short yyr1[] = { 0, 31, 31, 32, 32, 32, 33, 33, 34, 34, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, - 35, 36, 37, 38, 38, 38, 39, 40, 40, 41, - 41, 42, 42, 43, 43, 44, 44, 45, 45, 46, - 47, 48, 49, 49, 50, 50, 51, 51, 52, 53, - 53, 54, 55, 56, 57, 58, 58, 58, 59, 59, - 60, 61, 61, 62, 62, 63, 63, 63, 64, 65, - 65 + 35, 35, 35, 35, 35, 36, 36, 36, 36, 36, + 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, + 36, 36, 36, 36, 36, 36, 36, 37, 38, 39, + 39, 39, 40, 41, 41, 42, 42, 43, 43, 44, + 44, 45, 45, 46, 46, 47, 48, 49, 50, 50, + 51, 51, 52, 52, 53, 54, 54, 55, 56, 57, + 58, 59, 59, 59, 60, 60, 60, 61, 61, 62, + 62, 63, 64, 65, 65, 66, 66, 67, 67, 68, + 68, 69, 69, 69, 70, 71, 71 }; static const short yyr2[] = { 0, 0, 2, 5, 5, 1, 1, 2, 1, 2, 1, + 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 4, 6, 3, 4, 5, 4, 1, 2, 1, - 2, 5, 6, 4, 5, 4, 3, 4, 3, 4, - 5, 5, 5, 6, 5, 5, 2, 4, 4, 1, - 2, 7, 7, 7, 2, 1, 3, 2, 1, 2, - 3, 1, 1, 3, 2, 1, 3, 2, 3, 1, - 1 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 4, 6, 3, + 4, 5, 4, 1, 2, 1, 2, 5, 6, 4, + 5, 4, 3, 4, 3, 4, 5, 5, 5, 6, + 5, 5, 2, 4, 4, 1, 2, 7, 7, 7, + 2, 1, 3, 2, 1, 3, 2, 1, 2, 1, + 2, 3, 3, 1, 1, 1, 1, 3, 2, 3, + 2, 1, 3, 2, 3, 1, 1 }; static const short yydefact[] = { 1, - 0, 0, 10, 11, 12, 13, 14, 15, 0, 1, - 5, 31, 29, 30, 27, 28, 26, 25, 24, 19, - 18, 23, 20, 21, 22, 73, 72, 16, 17, 0, - 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 66, 0, 75, 69, - 0, 57, 2, 0, 0, 0, 0, 0, 0, 81, - 80, 0, 0, 6, 47, 0, 8, 49, 0, 0, - 0, 40, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 68, 71, 70, 74, 76, 0, 0, 0, 0, - 0, 0, 50, 7, 46, 9, 48, 0, 38, 0, - 0, 0, 44, 41, 0, 32, 0, 0, 0, 60, - 0, 0, 0, 58, 67, 0, 78, 79, 3, 4, - 51, 55, 56, 0, 0, 42, 39, 0, 34, 0, - 0, 0, 45, 52, 53, 0, 0, 61, 0, 0, - 0, 77, 0, 43, 0, 35, 0, 54, 0, 0, - 0, 0, 0, 36, 37, 59, 62, 63, 64, 0, - 33, 0, 0, 0 + 0, 0, 36, 37, 38, 39, 40, 41, 0, 1, + 5, 57, 55, 56, 53, 54, 52, 51, 50, 45, + 44, 49, 46, 47, 48, 105, 104, 42, 43, 0, + 91, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 92, 0, 109, 98, + 0, 0, 0, 23, 24, 25, 27, 28, 29, 30, + 31, 32, 19, 21, 22, 26, 33, 34, 35, 10, + 11, 12, 13, 14, 15, 0, 20, 83, 107, 106, + 16, 17, 2, 0, 0, 0, 0, 0, 0, 117, + 116, 0, 0, 6, 73, 0, 8, 75, 0, 0, + 0, 66, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 94, 102, 99, 108, 95, 0, 111, 100, 0, + 18, 112, 0, 0, 0, 0, 0, 0, 76, 7, + 72, 9, 74, 0, 64, 0, 0, 0, 70, 67, + 0, 58, 0, 0, 0, 86, 0, 0, 0, 84, + 93, 0, 97, 103, 101, 110, 0, 114, 115, 3, + 4, 77, 81, 82, 0, 0, 68, 65, 0, 60, + 0, 0, 0, 71, 78, 79, 0, 0, 87, 0, + 0, 0, 96, 113, 0, 69, 0, 61, 0, 80, + 0, 0, 0, 0, 0, 62, 63, 85, 88, 89, + 90, 0, 59, 0, 0, 0 }; -static const short yydefgoto[] = { 53, - 10, 63, 66, 64, 12, 99, 72, 105, 100, 73, - 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, - 110, 111, 23, 24, 25, 26, 48, 51, 27, 28, - 29, 87, 56, 62 +static const short yydefgoto[] = { 83, + 10, 93, 96, 116, 94, 12, 135, 102, 141, 136, + 103, 13, 14, 15, 16, 17, 18, 19, 20, 21, + 22, 146, 147, 23, 24, 25, 26, 48, 117, 51, + 120, 27, 80, 28, 81, 29, 82, 123, 86, 92 }; -static const short yypact[] = { 267, - 115, 60,-32768,-32768,-32768,-32768,-32768,-32768, 294, 267, +static const short yypact[] = { 139, + 288, 344,-32768,-32768,-32768,-32768,-32768,-32768, 260, 139, -32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768, --32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768, 143, --32768, 2, -15, 4, 294, 178, 185, 294, 15, 294, - 294, 294, 21, 22, 23, 294, 212, 27,-32768, 294, - 28,-32768,-32768, 7, 294, 294, 294, 1, 294,-32768, --32768, 294, 34, 294,-32768, 219,-32768,-32768, 226, 24, - 294,-32768, 10, 38, 294, 294, 41, 41, 41, 40, - 294,-32768,-32768,-32768,-32768, -11, 43, 44, 46, 47, - 48, 49,-32768,-32768,-32768,-32768,-32768, 53,-32768, 18, - 171, 253,-32768,-32768, 55,-32768, 56, 260, 31, 41, - 57, 62, 63,-32768,-32768, 45,-32768,-32768,-32768,-32768, --32768,-32768,-32768, 294, 5,-32768,-32768, 65,-32768, 294, - 68, 294,-32768,-32768,-32768, 69, 294,-32768, 294, 294, - 294,-32768, 72,-32768, 73,-32768, 74,-32768, 75, 86, - 87, 88, 294,-32768,-32768,-32768,-32768,-32768,-32768, 89, --32768, 95, 96,-32768 -}; - -static const short yypgoto[] = { 100, --32768, -42, 64, 0,-32768, 3, 32, 6,-32768,-32768, +-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768, 316, +-32768, 1, -13, 4, 433, 351, 358, 433, 12, 433, + 433, 433, 15, 20, 23, 260, 385, 27,-32768, 433, + 29, 176, 204,-32768,-32768,-32768,-32768,-32768,-32768,-32768, -32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768, --32768, -75,-32768,-32768,-32768, 70, 66, 59,-32768,-32768, --32768, 26, 76,-32768 +-32768,-32768,-32768,-32768,-32768, 260,-32768,-32768,-32768,-32768, +-32768,-32768,-32768, 8, 433, 433, 433, -2, 433,-32768, +-32768, 433, 34, 433,-32768, 392,-32768,-32768, 399, 41, + 433,-32768, 19, 44, 433, 433, 43, 43, 43, 48, + 433,-32768,-32768,-32768,-32768, 232, 49,-32768, 260, 51, +-32768, -10, 52, 53, 54, 55, 56, 57,-32768,-32768, +-32768,-32768,-32768, 60,-32768, 24, 132, 100,-32768,-32768, + 61,-32768, 62, 426, 38, 43, 63, 64, 65,-32768, +-32768, 260,-32768,-32768,-32768,-32768, 45,-32768,-32768,-32768, +-32768,-32768,-32768,-32768, 433, 6,-32768,-32768, 66,-32768, + 433, 68, 433,-32768,-32768,-32768, 69, 433,-32768, 433, + 433, 433,-32768,-32768, 71,-32768, 72,-32768, 74,-32768, + 75, 76, 77, 78, 433,-32768,-32768,-32768,-32768,-32768, +-32768, 79,-32768, 86, 88,-32768 +}; + +static const short yypgoto[] = { 89, +-32768, -73, 58, 2, 0,-32768, -46, -12, -43,-32768, +-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768, +-32768,-32768, -103,-32768,-32768,-32768, -1, 47, -19, 67, + -21,-32768,-32768,-32768,-32768,-32768,-32768, -20, 82,-32768 }; -#define YYLAST 323 +#define YYLAST 462 static const short yytable[] = { 11, - 47, 50, 112, 113, 54, 31, 58, 124, 52, 11, - 116, 57, 102, 89, 103, 86, 91, 71, 132, 92, - 125, 94, 126, 77, 78, 79, 98, 86, 55, 47, - 59, 83, 85, 86, 138, 67, 67, 70, 93, 74, - 75, 76, 106, 109, 114, 80, 47, 118, 119, 50, - 120, 121, 122, 123, 88, 124, 90, 137, 131, 133, - 134, 139, 30, 2, 49, 96, 140, 141, 96, 144, - 101, 142, 146, 148, 107, 108, 153, 154, 155, 156, - 115, 143, 3, 4, 5, 6, 7, 8, 9, 147, - 157, 158, 159, 161, 163, 164, 150, 151, 152, 162, - 69, 101, 127, 60, 104, 128, 0, 136, 84, 61, - 160, 117, 82, 0, 0, 0, 0, 30, 2, 31, - 32, 33, 34, 35, 36, 37, 38, 39, 0, 145, - 40, 41, 42, 43, 44, 45, 149, 3, 4, 5, - 6, 7, 8, 9, 46, 30, 2, 31, 0, 33, - 34, 35, 36, 37, 38, 39, 0, 0, 40, 41, - 42, 43, 44, 45, 0, 3, 4, 5, 6, 7, - 8, 9, 46, 30, 2, 129, 0, 0, 0, 0, - 30, 2, 65, 0, 0, 130, 0, 30, 2, 68, - 0, 0, 0, 3, 4, 5, 6, 7, 8, 9, - 3, 4, 5, 6, 7, 8, 9, 3, 4, 5, - 6, 7, 8, 9, 30, 2, 0, 0, 0, 0, - 0, 30, 2, 95, 0, 0, 0, 0, 30, 2, - 97, 0, 0, 81, 3, 4, 5, 6, 7, 8, - 9, 3, 4, 5, 6, 7, 8, 9, 3, 4, - 5, 6, 7, 8, 9, 30, 2, 0, 0, 0, - 0, 0, 30, 2, 135, 0, 132, 0, 0, 1, - 2, 0, 0, 0, 0, 3, 4, 5, 6, 7, - 8, 9, 3, 4, 5, 6, 7, 8, 9, 3, - 4, 5, 6, 7, 8, 9, 30, 2, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 3, 4, 5, 6, - 7, 8, 9 + 47, 50, 31, 84, 148, 149, 88, 79, 165, 11, + 78, 157, 125, 87, 101, 127, 122, 107, 128, 173, + 130, 138, 108, 139, 122, 109, 166, 85, 167, 47, + 89, 113, 90, 115, 122, 97, 97, 100, 129, 104, + 105, 106, 179, 134, 79, 145, 47, 110, 142, 50, + 79, 79, 150, 154, 119, 156, 159, 160, 161, 162, + 163, 164, 165, 172, 178, 174, 175, 180, 181, 182, + 186, 184, 188, 190, 79, 195, 196, 121, 197, 198, + 199, 200, 201, 203, 124, 205, 126, 206, 204, 168, + 140, 185, 169, 112, 99, 132, 153, 155, 132, 189, + 137, 158, 30, 2, 143, 144, 192, 193, 194, 0, + 151, 0, 0, 173, 79, 91, 114, 79, 0, 0, + 119, 202, 3, 4, 5, 6, 7, 8, 9, 0, + 0, 0, 0, 0, 30, 2, 170, 137, 0, 0, + 0, 1, 2, 177, 0, 0, 171, 0, 0, 0, + 79, 0, 0, 183, 3, 4, 5, 6, 7, 8, + 9, 3, 4, 5, 6, 7, 8, 9, 0, 0, + 187, 0, 0, 0, 0, 0, 0, 191, 52, 53, + 31, 54, 55, 56, 57, 58, 59, 60, 61, 62, + 63, 64, 65, 66, 67, 68, 69, 0, 70, 71, + 72, 73, 74, 75, 76, 77, 52, 53, 118, 54, + 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, + 65, 66, 67, 68, 69, 0, 70, 71, 72, 73, + 74, 75, 76, 77, 52, 53, 0, 54, 55, 56, + 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, + 67, 68, 69, 152, 70, 71, 72, 73, 74, 75, + 76, 77, 52, 53, 0, 54, 55, 56, 57, 58, + 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, + 69, 0, 70, 71, 72, 73, 74, 75, 76, 77, + 30, 2, 31, 32, 33, 34, 35, 36, 37, 38, + 39, 0, 0, 40, 41, 42, 43, 44, 45, 0, + 3, 4, 5, 6, 7, 8, 9, 46, 30, 2, + 31, 0, 33, 34, 35, 36, 37, 38, 39, 0, + 0, 40, 41, 42, 43, 44, 45, 0, 3, 4, + 5, 6, 7, 8, 9, 46, 30, 2, 49, 0, + 0, 0, 0, 30, 2, 95, 0, 0, 0, 0, + 30, 2, 98, 0, 0, 0, 3, 4, 5, 6, + 7, 8, 9, 3, 4, 5, 6, 7, 8, 9, + 3, 4, 5, 6, 7, 8, 9, 30, 2, 0, + 0, 0, 0, 0, 30, 2, 131, 0, 0, 0, + 0, 30, 2, 133, 0, 0, 111, 3, 4, 5, + 6, 7, 8, 9, 3, 4, 5, 6, 7, 8, + 9, 3, 4, 5, 6, 7, 8, 9, 30, 2, + 176, 0, 0, 0, 0, 30, 2, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, + 5, 6, 7, 8, 9, 3, 4, 5, 6, 7, + 8, 9 }; static const short yycheck[] = { 0, - 1, 2, 78, 79, 3, 5, 3, 3, 9, 10, - 22, 27, 3, 56, 5, 27, 59, 3, 14, 62, - 3, 64, 5, 3, 3, 3, 3, 27, 27, 30, - 27, 5, 5, 27, 110, 36, 37, 38, 5, 40, - 41, 42, 5, 3, 5, 46, 47, 5, 5, 50, - 5, 5, 5, 5, 55, 3, 57, 27, 101, 5, - 5, 5, 3, 4, 5, 66, 5, 5, 69, 5, - 71, 27, 5, 5, 75, 76, 5, 5, 5, 5, - 81, 124, 23, 24, 25, 26, 27, 28, 29, 132, - 5, 5, 5, 5, 0, 0, 139, 140, 141, 0, - 37, 102, 100, 34, 73, 100, -1, 108, 50, 34, - 153, 86, 47, -1, -1, -1, -1, 3, 4, 5, - 6, 7, 8, 9, 10, 11, 12, 13, -1, 130, - 16, 17, 18, 19, 20, 21, 137, 23, 24, 25, - 26, 27, 28, 29, 30, 3, 4, 5, -1, 7, - 8, 9, 10, 11, 12, 13, -1, -1, 16, 17, - 18, 19, 20, 21, -1, 23, 24, 25, 26, 27, - 28, 29, 30, 3, 4, 5, -1, -1, -1, -1, - 3, 4, 5, -1, -1, 15, -1, 3, 4, 5, - -1, -1, -1, 23, 24, 25, 26, 27, 28, 29, - 23, 24, 25, 26, 27, 28, 29, 23, 24, 25, - 26, 27, 28, 29, 3, 4, -1, -1, -1, -1, - -1, 3, 4, 5, -1, -1, -1, -1, 3, 4, - 5, -1, -1, 22, 23, 24, 25, 26, 27, 28, - 29, 23, 24, 25, 26, 27, 28, 29, 23, 24, - 25, 26, 27, 28, 29, 3, 4, -1, -1, -1, - -1, -1, 3, 4, 5, -1, 14, -1, -1, 3, - 4, -1, -1, -1, -1, 23, 24, 25, 26, 27, - 28, 29, 23, 24, 25, 26, 27, 28, 29, 23, - 24, 25, 26, 27, 28, 29, 3, 4, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 23, 24, 25, 26, - 27, 28, 29 + 1, 2, 5, 3, 108, 109, 3, 9, 3, 10, + 9, 22, 86, 27, 3, 89, 27, 3, 92, 14, + 94, 3, 3, 5, 27, 3, 3, 27, 5, 30, + 27, 5, 34, 5, 27, 36, 37, 38, 5, 40, + 41, 42, 146, 3, 46, 3, 47, 46, 5, 50, + 52, 53, 5, 5, 53, 5, 5, 5, 5, 5, + 5, 5, 3, 137, 27, 5, 5, 5, 5, 5, + 5, 27, 5, 5, 76, 5, 5, 76, 5, 5, + 5, 5, 5, 5, 85, 0, 87, 0, 0, 136, + 103, 165, 136, 47, 37, 96, 116, 119, 99, 173, + 101, 122, 3, 4, 105, 106, 180, 181, 182, -1, + 111, -1, -1, 14, 116, 34, 50, 119, -1, -1, + 119, 195, 23, 24, 25, 26, 27, 28, 29, -1, + -1, -1, -1, -1, 3, 4, 5, 138, -1, -1, + -1, 3, 4, 144, -1, -1, 15, -1, -1, -1, + 152, -1, -1, 152, 23, 24, 25, 26, 27, 28, + 29, 23, 24, 25, 26, 27, 28, 29, -1, -1, + 171, -1, -1, -1, -1, -1, -1, 178, 3, 4, + 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, -1, 23, 24, + 25, 26, 27, 28, 29, 30, 3, 4, 5, 6, + 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 17, 18, 19, 20, 21, -1, 23, 24, 25, 26, + 27, 28, 29, 30, 3, 4, -1, 6, 7, 8, + 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, + 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, + 29, 30, 3, 4, -1, 6, 7, 8, 9, 10, + 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, + 21, -1, 23, 24, 25, 26, 27, 28, 29, 30, + 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, + 13, -1, -1, 16, 17, 18, 19, 20, 21, -1, + 23, 24, 25, 26, 27, 28, 29, 30, 3, 4, + 5, -1, 7, 8, 9, 10, 11, 12, 13, -1, + -1, 16, 17, 18, 19, 20, 21, -1, 23, 24, + 25, 26, 27, 28, 29, 30, 3, 4, 5, -1, + -1, -1, -1, 3, 4, 5, -1, -1, -1, -1, + 3, 4, 5, -1, -1, -1, 23, 24, 25, 26, + 27, 28, 29, 23, 24, 25, 26, 27, 28, 29, + 23, 24, 25, 26, 27, 28, 29, 3, 4, -1, + -1, -1, -1, -1, 3, 4, 5, -1, -1, -1, + -1, 3, 4, 5, -1, -1, 22, 23, 24, 25, + 26, 27, 28, 29, 23, 24, 25, 26, 27, 28, + 29, 23, 24, 25, 26, 27, 28, 29, 3, 4, + 5, -1, -1, -1, -1, 3, 4, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 23, 24, + 25, 26, 27, 28, 29, 23, 24, 25, 26, 27, + 28, 29 }; /* -*-C-*- Note some compilers choke on comments on `#line' lines. */ #line 3 "/usr/share/bison.simple" @@ -879,506 +937,724 @@ yyreduce: switch (yyn) { case 1: -#line 55 "scheme.y" +#line 56 "scheme.y" { - yyresult = - yyval = [NSNull null]; + yyval = [NSNull null]; + yyresultform = yyval; ; break;} case 2: -#line 59 "scheme.y" +#line 60 "scheme.y" { - yyresult = - yyval = [Triple newTag:FORM_TOP Arg1:yyvsp[-1] Arg2:yyvsp[0]]; + yyval = [Triple newTag:FORM_TOP Arg1:yyvsp[-1] Arg2:yyvsp[0]]; + yyresultform = yyval; + yyinputitem++; ; break;} case 3: -#line 66 "scheme.y" +#line 68 "scheme.y" { NSValue *entry = [NSValue valueWithRange:NSMakeRange(yysofar, 0)]; yyval = [Triple newTag:FORM_DEFINE1 Arg1:yyvsp[-2] Arg2:yyvsp[-1]]; - [positions addObject:entry]; + [[positionStack lastObject] addObject:entry]; ; break;} case 4: -#line 74 "scheme.y" +#line 76 "scheme.y" { NSValue *entry = [NSValue valueWithRange:NSMakeRange(yysofar, 0)]; yyval = [Triple newTag:FORM_DEFINE2 Arg1:yyvsp[-2] Arg2:yyvsp[-1]]; - [positions addObject:entry]; + [[positionStack lastObject] addObject:entry]; ; break;} case 5: -#line 82 "scheme.y" +#line 84 "scheme.y" { NSValue *entry = [NSValue valueWithRange:NSMakeRange(yysofar, 0)]; yyval = yyvsp[0]; - [positions addObject:entry]; + [[positionStack lastObject] addObject:entry]; ; break;} case 6: -#line 92 "scheme.y" +#line 94 "scheme.y" { yyval = [Pair newCar:yyvsp[0] Cdr:[NSNull null]]; ; break;} case 7: -#line 95 "scheme.y" +#line 97 "scheme.y" { yyval = [Pair newCar:yyvsp[-1] Cdr:yyvsp[0]]; ; break;} case 8: -#line 100 "scheme.y" +#line 102 "scheme.y" { yyval = [Pair newCar:yyvsp[0] Cdr:[NSNull null]]; ; break;} case 9: -#line 103 "scheme.y" +#line 105 "scheme.y" { yyval = [Pair newCar:yyvsp[0] Cdr:yyvsp[-1]]; ; break;} case 10: -#line 108 "scheme.y" +#line 110 "scheme.y" { yyval = yyvsp[0]; ; break;} case 11: -#line 111 "scheme.y" +#line 113 "scheme.y" { yyval = yyvsp[0]; ; break;} case 12: -#line 114 "scheme.y" +#line 116 "scheme.y" { yyval = yyvsp[0]; ; break;} case 13: -#line 117 "scheme.y" +#line 119 "scheme.y" { yyval = yyvsp[0]; ; break;} case 14: -#line 120 "scheme.y" +#line 122 "scheme.y" { yyval = yyvsp[0]; ; break;} case 15: -#line 123 "scheme.y" +#line 125 "scheme.y" { yyval = yyvsp[0]; ; break;} case 16: -#line 126 "scheme.y" +#line 128 "scheme.y" { yyval = yyvsp[0]; ; break;} case 17: -#line 129 "scheme.y" +#line 131 "scheme.y" { yyval = yyvsp[0]; ; break;} case 18: -#line 132 "scheme.y" +#line 134 "scheme.y" { - yyval = yyvsp[0]; + yyval = [Pair newCar:[[Symbol alloc] initSCMSymbol:"quote"] + Cdr:[Pair newCar:yyvsp[0] Cdr:[NSNull null]]]; ; break;} case 19: -#line 135 "scheme.y" +#line 138 "scheme.y" { - yyval = yyvsp[0]; + yyval = [[Symbol alloc] initSCMSymbol:"=>"]; ; break;} case 20: -#line 138 "scheme.y" +#line 141 "scheme.y" { - yyval = yyvsp[0]; + yyval = [[Symbol alloc] initSCMSymbol:"quote"]; ; break;} case 21: -#line 141 "scheme.y" +#line 144 "scheme.y" { - yyval = yyvsp[0]; + yyval = [[Symbol alloc] initSCMSymbol:"call-with-current-continuation"]; ; break;} case 22: -#line 144 "scheme.y" +#line 147 "scheme.y" { - yyval = yyvsp[0]; + yyval = [[Symbol alloc] initSCMSymbol:"apply"]; ; break;} case 23: -#line 147 "scheme.y" +#line 150 "scheme.y" { - yyval = yyvsp[0]; + yyval = [[Symbol alloc] initSCMSymbol:"define"]; ; break;} case 24: -#line 150 "scheme.y" +#line 153 "scheme.y" { - yyval = yyvsp[0]; + yyval = [[Symbol alloc] initSCMSymbol:"set!"]; ; break;} case 25: -#line 153 "scheme.y" +#line 156 "scheme.y" { - yyval = yyvsp[0]; + yyval = [[Symbol alloc] initSCMSymbol:"lambda"]; ; break;} case 26: -#line 156 "scheme.y" +#line 159 "scheme.y" { - yyval = yyvsp[0]; + yyval = [[Symbol alloc] initSCMSymbol:"if"]; ; break;} case 27: -#line 159 "scheme.y" +#line 162 "scheme.y" { - yyval = yyvsp[0]; + yyval = [[Symbol alloc] initSCMSymbol:"begin"]; ; break;} case 28: -#line 162 "scheme.y" +#line 165 "scheme.y" { - yyval = yyvsp[0]; + yyval = [[Symbol alloc] initSCMSymbol:"and"]; ; break;} case 29: -#line 165 "scheme.y" +#line 168 "scheme.y" { - yyval = yyvsp[0]; + yyval = [[Symbol alloc] initSCMSymbol:"or"]; ; break;} case 30: -#line 168 "scheme.y" +#line 171 "scheme.y" { - yyval = yyvsp[0]; + yyval = [[Symbol alloc] initSCMSymbol:"case"]; ; break;} case 31: -#line 171 "scheme.y" +#line 174 "scheme.y" { - yyval = yyvsp[0]; + yyval = [[Symbol alloc] initSCMSymbol:"cond"]; ; break;} case 32: -#line 175 "scheme.y" +#line 177 "scheme.y" { - yyval = [Triple newTag:FORM_CALLCC Arg1:yyvsp[-1]]; + yyval = [[Symbol alloc] initSCMSymbol:"else"]; ; break;} case 33: -#line 179 "scheme.y" +#line 180 "scheme.y" { - yyval = [Pair newCar:yyvsp[-3] Cdr:yyvsp[-1]]; + yyval = [[Symbol alloc] initSCMSymbol:"let"]; ; break;} case 34: #line 183 "scheme.y" { - yyval = [Triple newTag:FORM_SCOND1 Arg1:yyvsp[-1]]; + yyval = [[Symbol alloc] initSCMSymbol:"let*"]; ; break;} case 35: #line 186 "scheme.y" { - yyval = [Triple newTag:FORM_SCOND2 Arg1:yyvsp[-2] Arg2:yyvsp[-1]]; + yyval = [[Symbol alloc] initSCMSymbol:"letrec"]; ; break;} case 36: -#line 189 "scheme.y" +#line 191 "scheme.y" { - yyval = [Triple newTag:FORM_SCOND3 Arg1:yyvsp[-3] Arg2:yyvsp[-1]]; + yyval = yyvsp[0]; ; break;} case 37: -#line 193 "scheme.y" +#line 194 "scheme.y" { - yyval = [Pair newCar:[NSNull null] Cdr:yyvsp[-1]]; + yyval = yyvsp[0]; ; break;} case 38: #line 197 "scheme.y" { - yyval = [Pair newCar:yyvsp[0] Cdr:[NSNull null]]; + yyval = yyvsp[0]; ; break;} case 39: #line 200 "scheme.y" { - yyval = [Pair newCar:yyvsp[0] Cdr:yyvsp[-1]]; + yyval = yyvsp[0]; ; break;} case 40: -#line 205 "scheme.y" +#line 203 "scheme.y" +{ + yyval = yyvsp[0]; +; + break;} +case 41: +#line 206 "scheme.y" +{ + yyval = yyvsp[0]; +; + break;} +case 42: +#line 209 "scheme.y" +{ + yyval = yyvsp[0]; +; + break;} +case 43: +#line 212 "scheme.y" +{ + yyval = yyvsp[0]; +; + break;} +case 44: +#line 215 "scheme.y" +{ + yyval = yyvsp[0]; +; + break;} +case 45: +#line 218 "scheme.y" +{ + yyval = yyvsp[0]; +; + break;} +case 46: +#line 221 "scheme.y" +{ + yyval = yyvsp[0]; +; + break;} +case 47: +#line 224 "scheme.y" +{ + yyval = yyvsp[0]; +; + break;} +case 48: +#line 227 "scheme.y" +{ + yyval = yyvsp[0]; +; + break;} +case 49: +#line 230 "scheme.y" +{ + yyval = yyvsp[0]; +; + break;} +case 50: +#line 233 "scheme.y" +{ + yyval = yyvsp[0]; +; + break;} +case 51: +#line 236 "scheme.y" +{ + yyval = yyvsp[0]; +; + break;} +case 52: +#line 239 "scheme.y" +{ + yyval = yyvsp[0]; +; + break;} +case 53: +#line 242 "scheme.y" +{ + yyval = yyvsp[0]; +; + break;} +case 54: +#line 245 "scheme.y" +{ + yyval = yyvsp[0]; +; + break;} +case 55: +#line 248 "scheme.y" +{ + yyval = yyvsp[0]; +; + break;} +case 56: +#line 251 "scheme.y" +{ + yyval = yyvsp[0]; +; + break;} +case 57: +#line 254 "scheme.y" +{ + yyval = yyvsp[0]; +; + break;} +case 58: +#line 259 "scheme.y" +{ + yyval = [Triple newTag:FORM_CALLCC Arg1:yyvsp[-1]]; +; + break;} +case 59: +#line 264 "scheme.y" +{ + yyval = [Pair newCar:yyvsp[-3] Cdr:yyvsp[-1]]; +; + break;} +case 60: +#line 269 "scheme.y" +{ + yyval = [Triple newTag:FORM_SCOND1 Arg1:yyvsp[-1]]; +; + break;} +case 61: +#line 272 "scheme.y" +{ + yyval = [Triple newTag:FORM_SCOND2 Arg1:yyvsp[-2] Arg2:yyvsp[-1]]; +; + break;} +case 62: +#line 275 "scheme.y" +{ + yyval = [Triple newTag:FORM_SCOND3 Arg1:yyvsp[-3] Arg2:yyvsp[-1]]; +; + break;} +case 63: +#line 280 "scheme.y" +{ + yyval = [Pair newCar:[NSNull null] Cdr:yyvsp[-1]]; +; + break;} +case 64: +#line 285 "scheme.y" { yyval = [Pair newCar:yyvsp[0] Cdr:[NSNull null]]; ; break;} -case 41: -#line 208 "scheme.y" +case 65: +#line 288 "scheme.y" { yyval = [Pair newCar:yyvsp[0] Cdr:yyvsp[-1]]; ; break;} -case 42: -#line 213 "scheme.y" -{ - yyval = [Triple newTag:FORM_CASE Arg1:yyvsp[-2] Arg2:yyvsp[-1]]; -; - break;} -case 43: -#line 216 "scheme.y" -{ - yyval = [Triple newTag:FORM_CASE Arg1:yyvsp[-3] - Arg2:[Pair newCar:yyvsp[-1] Cdr:yyvsp[-2]]]; -; - break;} -case 44: -#line 221 "scheme.y" -{ - yyval = [Triple newTag:FORM_COND Arg1:yyvsp[-1]]; -; - break;} -case 45: -#line 224 "scheme.y" -{ - yyval = [Triple newTag:FORM_COND Arg1:[Pair newCar:yyvsp[-1] Cdr:yyvsp[-2]]]; -; - break;} -case 46: -#line 228 "scheme.y" -{ - yyval = [Triple newTag:FORM_AND Arg1:yyvsp[-1]]; -; - break;} -case 47: -#line 231 "scheme.y" -{ - yyval = [Triple newTag:FORM_AND Arg1:[NSNull null]]; -; - break;} -case 48: -#line 235 "scheme.y" -{ - yyval = [Triple newTag:FORM_OR Arg1:yyvsp[-1]]; -; - break;} -case 49: -#line 238 "scheme.y" -{ - yyval = [Triple newTag:FORM_OR Arg1:[NSNull null]]; -; - break;} -case 50: -#line 242 "scheme.y" -{ - yyval = [Triple newTag:FORM_BEGIN Arg1:yyvsp[-1]]; -; - break;} -case 51: -#line 246 "scheme.y" -{ - yyval = [Triple newTag:FORM_SET Arg1:yyvsp[-2] Arg2:yyvsp[-1]]; -; - break;} -case 52: -#line 250 "scheme.y" -{ - yyval = [Triple newTag:FORM_APPLY Arg1:yyvsp[-2] Arg2:yyvsp[-1]]; -; - break;} -case 53: -#line 254 "scheme.y" -{ - yyval = [Triple newTag:FORM_IF1 Arg1:yyvsp[-2] Arg2:yyvsp[-1]]; -; - break;} -case 54: -#line 257 "scheme.y" -{ - yyval = [Triple newTag:FORM_IF2 Arg1:yyvsp[-3] Arg2:yyvsp[-2] Arg3:yyvsp[-1]]; -; - break;} -case 55: -#line 261 "scheme.y" -{ - yyval = [Triple newTag:FORM_LAMBDA1 Arg1:yyvsp[-2] Arg2:yyvsp[-1]]; -; - break;} -case 56: -#line 264 "scheme.y" -{ - yyval = [Triple newTag:FORM_LAMBDA2 Arg1:yyvsp[-2] Arg2:yyvsp[-1]]; -; - break;} -case 57: -#line 268 "scheme.y" -{ - yyval = [Triple newTag:FORM_QUOTE Arg1:yyvsp[0]]; -; - break;} -case 58: -#line 271 "scheme.y" -{ - yyval = [Triple newTag:FORM_QUOTE Arg1:yyvsp[-1]]; -; - break;} -case 59: -#line 276 "scheme.y" -{ - yyval = [Triple newTag:FORM_BINDING Arg1:yyvsp[-2] Arg2:yyvsp[-1]]; -; - break;} -case 60: -#line 280 "scheme.y" -{ - yyval = [Pair newCar:yyvsp[0] Cdr:[NSNull null]]; -; - break;} -case 61: -#line 283 "scheme.y" -{ - yyval = [Pair newCar:yyvsp[-1] Cdr:yyvsp[0]]; -; - break;} -case 62: -#line 287 "scheme.y" -{ - yyval = [Triple newTag:FORM_LET Arg1:yyvsp[-3] Arg2:yyvsp[-1]]; -; - break;} -case 63: -#line 291 "scheme.y" -{ - yyval = [Triple newTag:FORM_LETSTAR Arg1:yyvsp[-3] Arg2:yyvsp[-1]]; -; - break;} -case 64: -#line 295 "scheme.y" -{ - yyval = [Triple newTag:FORM_LETREC Arg1:yyvsp[-3] Arg2:yyvsp[-1]]; -; - break;} -case 65: -#line 299 "scheme.y" -{ - yyval = [NSNull null]; -; - break;} case 66: -#line 304 "scheme.y" +#line 293 "scheme.y" { yyval = [Pair newCar:yyvsp[0] Cdr:[NSNull null]]; ; break;} case 67: -#line 307 "scheme.y" +#line 296 "scheme.y" { - yyval = [Pair newCar:yyvsp[-2] Cdr:yyvsp[0]]; + yyval = [Pair newCar:yyvsp[0] Cdr:yyvsp[-1]]; ; break;} case 68: -#line 310 "scheme.y" +#line 301 "scheme.y" { - yyval = [Pair newCar:yyvsp[-1] Cdr:yyvsp[0]]; + yyval = [Triple newTag:FORM_CASE Arg1:yyvsp[-2] Arg2:yyvsp[-1]]; ; break;} case 69: -#line 315 "scheme.y" +#line 304 "scheme.y" +{ + yyval = [Triple newTag:FORM_CASE Arg1:yyvsp[-3] + Arg2:[Pair newCar:yyvsp[-1] Cdr:yyvsp[-2]]]; +; + break;} +case 70: +#line 310 "scheme.y" +{ + yyval = [Triple newTag:FORM_COND Arg1:yyvsp[-1]]; +; + break;} +case 71: +#line 313 "scheme.y" +{ + yyval = [Triple newTag:FORM_COND Arg1:[Pair newCar:yyvsp[-1] Cdr:yyvsp[-2]]]; +; + break;} +case 72: +#line 318 "scheme.y" +{ + yyval = [Triple newTag:FORM_AND Arg1:yyvsp[-1]]; +; + break;} +case 73: +#line 321 "scheme.y" +{ + yyval = [Triple newTag:FORM_AND Arg1:[NSNull null]]; +; + break;} +case 74: +#line 326 "scheme.y" +{ + yyval = [Triple newTag:FORM_OR Arg1:yyvsp[-1]]; +; + break;} +case 75: +#line 329 "scheme.y" +{ + yyval = [Triple newTag:FORM_OR Arg1:[NSNull null]]; +; + break;} +case 76: +#line 334 "scheme.y" +{ + yyval = [Triple newTag:FORM_BEGIN Arg1:yyvsp[-1]]; +; + break;} +case 77: +#line 339 "scheme.y" +{ + yyval = [Triple newTag:FORM_SET Arg1:yyvsp[-2] Arg2:yyvsp[-1]]; +; + break;} +case 78: +#line 344 "scheme.y" +{ + yyval = [Triple newTag:FORM_APPLY Arg1:yyvsp[-2] Arg2:yyvsp[-1]]; +; + break;} +case 79: +#line 349 "scheme.y" +{ + yyval = [Triple newTag:FORM_IF1 Arg1:yyvsp[-2] Arg2:yyvsp[-1]]; +; + break;} +case 80: +#line 352 "scheme.y" +{ + yyval = [Triple newTag:FORM_IF2 Arg1:yyvsp[-3] Arg2:yyvsp[-2] Arg3:yyvsp[-1]]; +; + break;} +case 81: +#line 357 "scheme.y" +{ + yyval = [Triple newTag:FORM_LAMBDA1 Arg1:yyvsp[-2] Arg2:yyvsp[-1]]; +; + break;} +case 82: +#line 360 "scheme.y" +{ + yyval = [Triple newTag:FORM_LAMBDA2 Arg1:yyvsp[-2] Arg2:yyvsp[-1]]; +; + break;} +case 83: +#line 365 "scheme.y" +{ + yyval = [Triple newTag:FORM_QUOTE Arg1:yyvsp[0]]; +; + break;} +case 84: +#line 368 "scheme.y" +{ + yyval = [Triple newTag:FORM_QUOTE Arg1:yyvsp[-1]]; +; + break;} +case 85: +#line 373 "scheme.y" +{ + yyval = [Triple newTag:FORM_BINDING Arg1:yyvsp[-2] Arg2:yyvsp[-1]]; +; + break;} +case 86: +#line 378 "scheme.y" { yyval = [Pair newCar:yyvsp[0] Cdr:[NSNull null]]; ; break;} -case 70: -#line 318 "scheme.y" +case 87: +#line 381 "scheme.y" { yyval = [Pair newCar:yyvsp[-1] Cdr:yyvsp[0]]; ; break;} -case 71: -#line 323 "scheme.y" +case 88: +#line 386 "scheme.y" +{ + yyval = [Triple newTag:FORM_LET Arg1:yyvsp[-3] Arg2:yyvsp[-1]]; +; + break;} +case 89: +#line 391 "scheme.y" +{ + yyval = [Triple newTag:FORM_LETSTAR Arg1:yyvsp[-3] Arg2:yyvsp[-1]]; +; + break;} +case 90: +#line 396 "scheme.y" +{ + yyval = [Triple newTag:FORM_LETREC Arg1:yyvsp[-3] Arg2:yyvsp[-1]]; +; + break;} +case 91: +#line 401 "scheme.y" +{ + yyval = [NSNull null]; +; + break;} +case 92: +#line 406 "scheme.y" +{ + yyval = [Pair newCar:yyvsp[0] Cdr:[NSNull null]]; +; + break;} +case 93: +#line 409 "scheme.y" +{ + yyval = [Pair newCar:yyvsp[-2] Cdr:yyvsp[0]]; +; + break;} +case 94: +#line 412 "scheme.y" +{ + yyval = [Pair newCar:yyvsp[-1] Cdr:yyvsp[0]]; +; + break;} +case 95: +#line 417 "scheme.y" +{ + yyval = [Pair newCar:yyvsp[0] Cdr:[NSNull null]]; +; + break;} +case 96: +#line 420 "scheme.y" +{ + yyval = [Pair newCar:yyvsp[-2] Cdr:yyvsp[0]]; +; + break;} +case 97: +#line 423 "scheme.y" +{ + yyval = [Pair newCar:yyvsp[-1] Cdr:yyvsp[0]]; +; + break;} +case 98: +#line 428 "scheme.y" +{ + yyval = [Pair newCar:yyvsp[0] Cdr:[NSNull null]]; +; + break;} +case 99: +#line 431 "scheme.y" +{ + yyval = [Pair newCar:yyvsp[-1] Cdr:yyvsp[0]]; +; + break;} +case 100: +#line 436 "scheme.y" +{ + yyval = [Pair newCar:yyvsp[0] Cdr:[NSNull null]]; +; + break;} +case 101: +#line 439 "scheme.y" +{ + yyval = [Pair newCar:yyvsp[-1] Cdr:yyvsp[0]]; +; + break;} +case 102: +#line 444 "scheme.y" { yyval = yyvsp[-1]; ; break;} -case 72: -#line 328 "scheme.y" +case 103: +#line 449 "scheme.y" +{ + yyval = yyvsp[-1]; +; + break;} +case 104: +#line 454 "scheme.y" { yyval = yyvsp[0]; ; break;} -case 73: -#line 331 "scheme.y" +case 105: +#line 457 "scheme.y" { yyval = yyvsp[0]; ; break;} -case 74: -#line 336 "scheme.y" +case 106: +#line 462 "scheme.y" +{ + yyval = yyvsp[0]; +; + break;} +case 107: +#line 465 "scheme.y" +{ + yyval = yyvsp[0]; +; + break;} +case 108: +#line 470 "scheme.y" { yyval = [Vector newFromList:yyvsp[-1]]; ; break;} -case 75: -#line 339 "scheme.y" +case 109: +#line 473 "scheme.y" { yyval = [Vector newFromList:(Pair *)[NSNull null]]; ; break;} -case 76: -#line 344 "scheme.y" +case 110: +#line 478 "scheme.y" +{ + yyval = [Vector newFromList:yyvsp[-1]]; +; + break;} +case 111: +#line 481 "scheme.y" +{ + yyval = [Vector newFromList:(Pair *)[NSNull null]]; +; + break;} +case 112: +#line 486 "scheme.y" { yyval = [Pair newCar:yyvsp[0] Cdr:[NSNull null]]; ; break;} -case 77: -#line 347 "scheme.y" +case 113: +#line 489 "scheme.y" { yyval = [Pair newCar:yyvsp[-2] Cdr:yyvsp[0]]; ; break;} -case 78: -#line 350 "scheme.y" +case 114: +#line 492 "scheme.y" { yyval = [Pair newCar:yyvsp[-1] Cdr:yyvsp[0]]; ; break;} -case 79: -#line 355 "scheme.y" +case 115: +#line 497 "scheme.y" { yyval = yyvsp[-1]; ; break;} -case 80: -#line 360 "scheme.y" +case 116: +#line 502 "scheme.y" { yyval = yyvsp[0]; ; break;} -case 81: -#line 363 "scheme.y" +case 117: +#line 505 "scheme.y" { yyval = yyvsp[0]; ; @@ -1609,6 +1885,6 @@ yyerrhandle: #endif return 1; } -#line 368 "scheme.y" +#line 510 "scheme.y" diff --git a/scheme.y b/scheme.y index 27a5f9b..5a3698f 100644 --- a/scheme.y +++ b/scheme.y @@ -5,9 +5,10 @@ YYSTYPE yyresult; int yyinputitem; +id yyresultform; extern int yysofar; -extern NSMutableArray *positions; +extern NSMutableArray *positionStack; %} %token LPAREN @@ -53,12 +54,13 @@ extern NSMutableArray *positions; %% top: /* empty */ { - yyresult = - $$ = [NSNull null]; + $$ = [NSNull null]; + yyresultform = $$; } | topitem top { - yyresult = - $$ = [Triple newTag:FORM_TOP Arg1:$1 Arg2:$2]; + $$ = [Triple newTag:FORM_TOP Arg1:$1 Arg2:$2]; + yyresultform = $$; + yyinputitem++; } ; @@ -69,7 +71,7 @@ topitem: LPAREN DEFINE SYMBOL form RPAREN { $$ = [Triple newTag:FORM_DEFINE1 Arg1:$3 Arg2:$4]; - [positions addObject:entry]; + [[positionStack lastObject] addObject:entry]; } | LPAREN DEFINE nonemptysymlist sequence RPAREN { NSValue *entry = @@ -77,7 +79,7 @@ topitem: LPAREN DEFINE SYMBOL form RPAREN { $$ = [Triple newTag:FORM_DEFINE2 Arg1:$3 Arg2:$4]; - [positions addObject:entry]; + [[positionStack lastObject] addObject:entry]; } | form { NSValue *entry = @@ -85,7 +87,7 @@ topitem: LPAREN DEFINE SYMBOL form RPAREN { $$ = $1; - [positions addObject:entry]; + [[positionStack lastObject] addObject:entry]; } ; @@ -105,6 +107,87 @@ revsequence: form { } ; +qform: INTEGER { + $$ = $1; +} +| CHAR { + $$ = $1; +} +| BOOLEAN { + $$ = $1; +} +| DOUBLE { + $$ = $1; +} +| SYMBOL { + $$ = $1; +} +| STRING { + $$ = $1; +} +| qlist { + $$ = $1; +} +| qvector { + $$ = $1; +} +| QUOTECHAR qform { + $$ = [Pair newCar:[[Symbol alloc] initSCMSymbol:"quote"] + Cdr:[Pair newCar:$2 Cdr:[NSNull null]]]; +} +| ARROW { + $$ = [[Symbol alloc] initSCMSymbol:"=>"]; +} +| QUOTE { + $$ = [[Symbol alloc] initSCMSymbol:"quote"]; +} +| CALLCC { + $$ = [[Symbol alloc] initSCMSymbol:"call-with-current-continuation"]; +} +| APPLY { + $$ = [[Symbol alloc] initSCMSymbol:"apply"]; +} +| DEFINE { + $$ = [[Symbol alloc] initSCMSymbol:"define"]; +} +| SET { + $$ = [[Symbol alloc] initSCMSymbol:"set!"]; +} +| LAMBDA { + $$ = [[Symbol alloc] initSCMSymbol:"lambda"]; +} +| IF { + $$ = [[Symbol alloc] initSCMSymbol:"if"]; +} +| BEGINTOK { + $$ = [[Symbol alloc] initSCMSymbol:"begin"]; +} +| AND { + $$ = [[Symbol alloc] initSCMSymbol:"and"]; +} +| OR { + $$ = [[Symbol alloc] initSCMSymbol:"or"]; +} +| CASE { + $$ = [[Symbol alloc] initSCMSymbol:"case"]; +} +| COND { + $$ = [[Symbol alloc] initSCMSymbol:"cond"]; +} +| ELSE { + $$ = [[Symbol alloc] initSCMSymbol:"else"]; +} +| LET { + $$ = [[Symbol alloc] initSCMSymbol:"let"]; +} +| LETSTAR { + $$ = [[Symbol alloc] initSCMSymbol:"let*"]; +} +| LETREC { + $$ = [[Symbol alloc] initSCMSymbol:"letrec"]; +} +; + form: INTEGER { $$ = $1; } @@ -171,14 +254,17 @@ form: INTEGER { | callcc { $$ = $1; } +; callcc: LPAREN CALLCC form RPAREN { $$ = [Triple newTag:FORM_CALLCC Arg1:$3]; } +; singlecase: LPAREN LPAREN sequence RPAREN sequence RPAREN { $$ = [Pair newCar:$3 Cdr:$5]; } +; singlecond: LPAREN form RPAREN { $$ = [Triple newTag:FORM_SCOND1 Arg1:$2]; @@ -189,10 +275,12 @@ singlecond: LPAREN form RPAREN { | LPAREN form ARROW form RPAREN { $$ = [Triple newTag:FORM_SCOND3 Arg1:$2 Arg2:$4]; } +; elsecasecond: LPAREN ELSE sequence RPAREN { $$ = [Pair newCar:[NSNull null] Cdr:$3]; } +; cases: singlecase { $$ = [Pair newCar:$1 Cdr:[NSNull null]]; @@ -217,6 +305,7 @@ case: LPAREN CASE form cases RPAREN { $$ = [Triple newTag:FORM_CASE Arg1:$3 Arg2:[Pair newCar:$5 Cdr:$4]]; } +; cond: LPAREN COND conditions RPAREN { $$ = [Triple newTag:FORM_COND Arg1:$3]; @@ -224,6 +313,7 @@ cond: LPAREN COND conditions RPAREN { | LPAREN COND conditions elsecasecond RPAREN { $$ = [Triple newTag:FORM_COND Arg1:[Pair newCar:$4 Cdr:$3]]; } +; and: LPAREN AND revsequence RPAREN { $$ = [Triple newTag:FORM_AND Arg1:$3]; @@ -231,6 +321,7 @@ and: LPAREN AND revsequence RPAREN { | LPAREN AND RPAREN { $$ = [Triple newTag:FORM_AND Arg1:[NSNull null]]; } +; or: LPAREN OR revsequence RPAREN { $$ = [Triple newTag:FORM_OR Arg1:$3]; @@ -238,18 +329,22 @@ or: LPAREN OR revsequence RPAREN { | LPAREN OR RPAREN { $$ = [Triple newTag:FORM_OR Arg1:[NSNull null]]; } +; begin: LPAREN BEGINTOK sequence RPAREN { $$ = [Triple newTag:FORM_BEGIN Arg1:$3]; } +; set: LPAREN SET SYMBOL form RPAREN { $$ = [Triple newTag:FORM_SET Arg1:$3 Arg2:$4]; } +; apply: LPAREN APPLY form form RPAREN { $$ = [Triple newTag:FORM_APPLY Arg1:$3 Arg2:$4]; } +; if: LPAREN IF form form RPAREN { $$ = [Triple newTag:FORM_IF1 Arg1:$3 Arg2:$4]; @@ -257,6 +352,7 @@ if: LPAREN IF form form RPAREN { | LPAREN IF form form form RPAREN { $$ = [Triple newTag:FORM_IF2 Arg1:$3 Arg2:$4 Arg3:$5]; } +; lambda: LPAREN LAMBDA SYMBOL sequence RPAREN { $$ = [Triple newTag:FORM_LAMBDA1 Arg1:$3 Arg2:$4]; @@ -264,18 +360,20 @@ lambda: LPAREN LAMBDA SYMBOL sequence RPAREN { | LPAREN LAMBDA symlist sequence RPAREN { $$ = [Triple newTag:FORM_LAMBDA2 Arg1:$3 Arg2:$4]; } +; -quote: QUOTECHAR form { +quote: QUOTECHAR qform { $$ = [Triple newTag:FORM_QUOTE Arg1:$2]; } -| LPAREN QUOTE form RPAREN { +| LPAREN QUOTE qform RPAREN { $$ = [Triple newTag:FORM_QUOTE Arg1:$3]; } - +; singlebinding: LPAREN SYMBOL form RPAREN { $$ = [Triple newTag:FORM_BINDING Arg1:$2 Arg2:$3]; } +; listofbindings: singlebinding { $$ = [Pair newCar:$1 Cdr:[NSNull null]]; @@ -283,18 +381,22 @@ listofbindings: singlebinding { | singlebinding listofbindings { $$ = [Pair newCar:$1 Cdr:$2]; } +; let: LPAREN LET LPAREN listofbindings RPAREN sequence RPAREN { $$ = [Triple newTag:FORM_LET Arg1:$4 Arg2:$6]; } +; letstar: LPAREN LETSTAR LPAREN listofbindings RPAREN sequence RPAREN { $$ = [Triple newTag:FORM_LETSTAR Arg1:$4 Arg2:$6]; } +; letrec: LPAREN LETREC LPAREN listofbindings RPAREN sequence RPAREN { $$ = [Triple newTag:FORM_LETREC Arg1:$4 Arg2:$6]; } +; emptylist: LPAREN RPAREN { $$ = [NSNull null]; @@ -312,6 +414,17 @@ nonemptylistdata: form { } ; +qnonemptylistdata: qform { + $$ = [Pair newCar:$1 Cdr:[NSNull null]]; +} +| qform DOT qform { + $$ = [Pair newCar:$1 Cdr:$3]; +} +| qform qnonemptylistdata { + $$ = [Pair newCar:$1 Cdr:$2]; +} +; + nonemptyvectdata: form { $$ = [Pair newCar:$1 Cdr:[NSNull null]]; } @@ -320,11 +433,24 @@ nonemptyvectdata: form { } ; +qnonemptyvectdata: qform { + $$ = [Pair newCar:$1 Cdr:[NSNull null]]; +} +| qform qnonemptyvectdata { + $$ = [Pair newCar:$1 Cdr:$2]; +} +; + nonemptylist: LPAREN nonemptylistdata RPAREN { $$ = $2; } ; +qnonemptylist: LPAREN qnonemptylistdata RPAREN { + $$ = $2; +} +; + list: nonemptylist { $$ = $1; } @@ -333,6 +459,14 @@ list: nonemptylist { } ; +qlist: qnonemptylist { + $$ = $1; +} +| emptylist { + $$ = $1; +} +; + vector: LVECTPAREN nonemptyvectdata RPAREN { $$ = [Vector newFromList:$2]; } @@ -341,6 +475,14 @@ vector: LVECTPAREN nonemptyvectdata RPAREN { } ; +qvector: LVECTPAREN qnonemptyvectdata RPAREN { + $$ = [Vector newFromList:$2]; +} +| LVECTPAREN RPAREN { + $$ = [Vector newFromList:(Pair *)[NSNull null]]; +} +; + nonemptysymlistdata: SYMBOL { $$ = [Pair newCar:$1 Cdr:[NSNull null]]; }