Fixed exception reporting in STCompiler

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/steptalk/trunk@16377 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Stefan Urbanek 2003-04-06 12:59:13 +00:00
parent dda7d608e5
commit 03e911003b
7 changed files with 79 additions and 40 deletions

View file

@ -1,3 +1,8 @@
2003 Apr 6 Stefan Urbanek <urbanek@host.sk>
* STCompiler: compileString: fixed exception reporting.
2003 Apr 04 David Ayers <d.ayers@inode.at> 2003 Apr 04 David Ayers <d.ayers@inode.at>
* GNUmakefile: Added flags to show all warnings except for import. * GNUmakefile: Added flags to show all warnings except for import.
@ -8,28 +13,28 @@
Initialzed variables to supress compiler warnings. Initialzed variables to supress compiler warnings.
* STExecutionContext.m: Unified name for private categories. * STExecutionContext.m: Unified name for private categories.
2003 Mar 25 2003 Mar 25 Stefan Urbanek <urbanek@host.sk>
* STSourceReader: added missing [super dealloc] * STSourceReader: added missing [super dealloc]
* STCompiledCode: do not retain bytecode data * STCompiledCode: do not retain bytecode data
* STCompiler: various memory leak fixes * STCompiler: various memory leak fixes
* SmalltalkEngine: guard compilation exception and release the compiler * SmalltalkEngine: guard compilation exception and release the compiler
2003 Mar 23 2003 Mar 23 Stefan Urbanek <urbanek@host.sk>
* STSourceReader: added some end of string checks * STSourceReader: added some end of string checks
2003 Feb 3 2003 Feb 3 Stefan Urbanek <urbanek@host.sk>
* Version 0.7.0 * Version 0.7.0
2003 Feb 3 2003 Feb 3 Stefan Urbanek <urbanek@host.sk>
* STSourceReader: fixed reading of a number terminated with '.', we treat * STSourceReader: fixed reading of a number terminated with '.', we treat
it as an integer. Reader was complaining about i := 1.; fixed reading of it as an integer. Reader was complaining about i := 1.; fixed reading of
var:=something. It was terating 'var:' as a selector keyword. var:=something. It was terating 'var:' as a selector keyword.
2003 Jan 30 2003 Jan 30 Stefan Urbanek <urbanek@host.sk>
* ChangeLog, STBlock.m, STBytecodes.h, * ChangeLog, STBlock.m, STBytecodes.h,
STBytecodes.m, STCompiledMethod.m, STBytecodes.m, STCompiledMethod.m,
@ -39,28 +44,28 @@
STMethodContext.h, STSourceReader.h, SmalltalkEngine.m: STMethodContext.h, STSourceReader.h, SmalltalkEngine.m:
Cleanup of compiler warnings Cleanup of compiler warnings
2002 Dec 25 2002 Dec 25 Stefan Urbanek <urbanek@host.sk>
* Version 0.6.2 * Version 0.6.2
2002 Dec 21 2002 Dec 21 Stefan Urbanek <urbanek@host.sk>
* STSourceReader, STCompiler, STGrammar: Added real number parsing * STSourceReader, STCompiler, STGrammar: Added real number parsing
2002 Sep 15 2002 Sep 15 Stefan Urbanek <urbanek@host.sk>
* Version 0.6.1 * Version 0.6.1
2002 Aug 30 2002 Aug 30 Stefan Urbanek <urbanek@host.sk>
* Code cleanup. * Code cleanup.
2002 Jun 14 2002 Jun 14 Stefan Urbanek <urbanek@host.sk>
* STMethodContext: Raise exception on invalid reference, not on undefined * STMethodContext: Raise exception on invalid reference, not on undefined
object object
2002 Jun 13 2002 Jun 13 Stefan Urbanek <urbanek@host.sk>
* STCompiledMethod: Removed unused methods * STCompiledMethod: Removed unused methods
* STBytecodeInterpreter: rewritten context handling; removed unused methods * STBytecodeInterpreter: rewritten context handling; removed unused methods
@ -68,71 +73,71 @@
* STGrammar.y: fixed empty arrays #() * STGrammar.y: fixed empty arrays #()
* STExecutionContext: removed parent context as it is longer used * STExecutionContext: removed parent context as it is longer used
2002 Jun 7 2002 Jun 7 Stefan Urbanek <urbanek@host.sk>
* STBytecodeInterpreter: fixed debug-log bug * STBytecodeInterpreter: fixed debug-log bug
2002 Jun 6 2002 Jun 6 Stefan Urbanek <urbanek@host.sk>
* STSourceReader: fixed bug in reading number token type and binary * STSourceReader: fixed bug in reading number token type and binary
selectors beginning with the '-' character. selectors beginning with the '-' character.
* Moved NSObject-additions to the StepTalk sources * Moved NSObject-additions to the StepTalk sources
2002 May 29 2002 May 29 Stefan Urbanek <urbanek@host.sk>
* STCompiledScript: assign return value on executing single-method script * STCompiledScript: assign return value on executing single-method script
2002 May 15 2002 May 15 Stefan Urbanek <urbanek@host.sk>
* STCompiler, Externs, STGrammar: fixed undefined exceptions (reported by * STCompiler, Externs, STGrammar: fixed undefined exceptions (reported by
Björn Gohla <b.gohla@gmx.de>) Björn Gohla <b.gohla@gmx.de>)
2002 Mar 17 2002 Mar 17 Stefan Urbanek <urbanek@host.sk>
* STCompiler, STGrammar: changed grammar to be able to have "methods" or * STCompiler, STGrammar: changed grammar to be able to have "methods" or
"just statements" in source "just statements" in source
2002 Feb 14 2002 Feb 14 Stefan Urbanek <urbanek@host.sk>
* STSourceReader: Retain character sets * STSourceReader: Retain character sets
2002 Feb 5 2002 Feb 5 Stefan Urbanek <urbanek@host.sk>
* STSelector+additions.[hm]: new files * STSelector+additions.[hm]: new files
* STCompiler: use STSelector class for symbol literals * STCompiler: use STSelector class for symbol literals
2002 Feb 3 2002 Feb 3 Stefan Urbanek <urbanek@host.sk>
* STScriptObject: handle special method 'exit' * STScriptObject: handle special method 'exit'
* STBytecodeInterpreter: added code to halt the interpreter and return from * STBytecodeInterpreter: added code to halt the interpreter and return from
all contexts all contexts
2002 Jan 31 2002 Jan 31 Stefan Urbanek <urbanek@host.sk>
* STBlock: small speed improvements * STBlock: small speed improvements
* STBlockContext: removed evaluateWithArguments:count:, and moved code * STBlockContext: removed evaluateWithArguments:count:, and moved code
into STBLock into STBLock
2002 Jan 23 2002 Jan 23 Stefan Urbanek <urbanek@host.sk>
* NSNumber+additions: moved arithmetic code to the library * NSNumber+additions: moved arithmetic code to the library
2002 Jan 22 2002 Jan 22 Stefan Urbanek <urbanek@host.sk>
* STCompiler: create one more duplicate of stack top when assigning to a * STCompiler: create one more duplicate of stack top when assigning to a
variable. variable.
2002 Jan 9 2002 Jan 9 Stefan Urbanek <urbanek@host.sk>
* SmalltalkEngine: implemented executeScript:inEnvironment: * SmalltalkEngine: implemented executeScript:inEnvironment:
2001 Dec 8 2001 Dec 8 Stefan Urbanek <urbanek@host.sk>
* Fixed temporary variable compilation * Fixed temporary variable compilation
* Added special handling of nil, YES and NO constants; added corresponding * Added special handling of nil, YES and NO constants; added corresponding
bytecodes bytecodes
2001 Dec 8 2001 Dec 8 Stefan Urbanek <urbanek@host.sk>
* CahgeLog started * CahgeLog started

View file

@ -39,6 +39,7 @@
unsigned stackSize; unsigned stackSize;
STBlockContext *cachedContext; STBlockContext *cachedContext;
BOOL usingCachedContext;
} }
- initWithInterpreter:(STBytecodeInterpreter *)anInterpreter - initWithInterpreter:(STBytecodeInterpreter *)anInterpreter

View file

@ -35,9 +35,13 @@
#import <Foundation/NSDebug.h> #import <Foundation/NSDebug.h>
#import <Foundation/NSException.h> #import <Foundation/NSException.h>
Class STBlockContextClass = nil;
@implementation STBlock @implementation STBlock
+ (void)initialize
{
STBlockContextClass = [STBlockContext class];
}
- initWithInterpreter:(STBytecodeInterpreter *)anInterpreter - initWithInterpreter:(STBytecodeInterpreter *)anInterpreter
homeContext:(STMethodContext *)context homeContext:(STMethodContext *)context
initialIP:(unsigned)ptr initialIP:(unsigned)ptr
@ -108,9 +112,9 @@
- valueWithArgs:(id *)args count:(unsigned)count; - valueWithArgs:(id *)args count:(unsigned)count;
{ {
STExecutionContext *parentContext; STExecutionContext *parentContext;
STBlockContext *savedContext;
STBlockContext *context; STBlockContext *context;
STStack *stack; STStack *stack;
BOOL usingShared = NO;
unsigned int i; unsigned int i;
id retval; id retval;
@ -122,19 +126,31 @@
return nil; return nil;
} }
if(cachedContext) if(!usingCachedContext)
{ {
/* In case of recursive block nesting */
usingCachedContext = YES;
if(!cachedContext)
{
cachedContext = [[STBlockContextClass alloc]
initWithInterpreter:interpreter
initialIP:initialIP
stackSize:stackSize];
}
/* Avoid allocation */
context = cachedContext; context = cachedContext;
savedContext = cachedContext;
cachedContext = nil;
[[context stack] empty]; [[context stack] empty];
[context resetInstructionPointer]; [context resetInstructionPointer];
} }
else else
{ {
context = [[STBlockContext alloc] initWithInterpreter:interpreter /* Create new context */
initialIP:initialIP context = [[STBlockContextClass alloc] initWithInterpreter:interpreter
stackSize:stackSize]; initialIP:initialIP
stackSize:stackSize];
AUTORELEASE(context); AUTORELEASE(context);
} }
@ -154,6 +170,12 @@
retval = [interpreter interpret]; retval = [interpreter interpret];
[interpreter setContext:parentContext]; [interpreter setContext:parentContext];
/* Release cached context */
if(usingCachedContext)
{
usingCachedContext = NO;
}
return retval; return retval;
} }

View file

@ -39,12 +39,14 @@
initialIP:(unsigned)pointer initialIP:(unsigned)pointer
stackSize:(unsigned)size stackSize:(unsigned)size
{ {
[super initWithStackSize:size];
interpreter = RETAIN(anInterpreter); interpreter = RETAIN(anInterpreter);
initialIP = pointer; initialIP = pointer;
[self setInstructionPointer:initialIP]; instructionPointer = initialIP;
return [super initWithStackSize:size]; return self;
} }
- (void)dealloc - (void)dealloc
{ {
@ -111,6 +113,6 @@
- (void)resetInstructionPointer - (void)resetInstructionPointer
{ {
[self setInstructionPointer:initialIP]; instructionPointer = initialIP;
} }
@end @end

View file

@ -341,6 +341,8 @@ static Class NSInvocation_class = nil;
NSStringFromClass([target class]), NSStringFromClass([target class]),
selector); selector);
/* FIXME: this is too slow */
selector = [environment translateSelector:selector forReceiver:target]; selector = [environment translateSelector:selector forReceiver:target];
invocation = [NSInvocation_class invocationWithTarget:target invocation = [NSInvocation_class invocationWithTarget:target

View file

@ -157,15 +157,21 @@ extern int STCparse(void *context);
{ {
if ([[localException name] isEqualToString: STCompilerSyntaxException]) if ([[localException name] isEqualToString: STCompilerSyntaxException])
{ {
NSString *tokenString;
int line;
tokenString = [reader tokenString];
line = [reader currentLine];
RELEASE(reader); RELEASE(reader);
RELEASE(receiverVars); RELEASE(receiverVars);
receiverVars = nil; receiverVars = nil;
reader = nil; reader = nil;
[NSException raise:STCompilerSyntaxException [NSException raise:STCompilerSyntaxException
format:exceptionFmt, format:exceptionFmt,
[reader currentLine], line,
[reader tokenString], tokenString,
[localException reason]]; [localException reason]];
} }

View file

@ -25,11 +25,12 @@ static unsigned nextId = 1;
@implementation STExecutionContext @implementation STExecutionContext
- initWithStackSize:(unsigned)stackSize - initWithStackSize:(unsigned)stackSize
{ {
stack = [[STStack alloc] initWithSize:stackSize]; [super init];
stack = [[STStack alloc] initWithSize:stackSize];
contextId = nextId ++; contextId = nextId ++;
return [super init]; return self;
} }
- (void)dealloc - (void)dealloc
{ {