Follow Smalltalk convention to return the receiver from a method

without an explicit return statement.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/steptalk/trunk@36421 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Wolfgang Lux 2013-03-24 17:24:11 +00:00
parent fd46046983
commit 1fc2e5fb63
2 changed files with 21 additions and 6 deletions

View file

@ -1,3 +1,9 @@
2013-03-24 Wolfgang Lux <wolfgang.lux@gmail.com>
* STCompiler.m (-compileMethod:): Follow Smalltalk convention to
return the receiver from a method without an explicit return
statement.
2013-03-24 Wolfgang Lux <wolfgang.lux@gmail.com> 2013-03-24 Wolfgang Lux <wolfgang.lux@gmail.com>
* STExecutionContext.h: Change type of instruction pointer attribute * STExecutionContext.h: Change type of instruction pointer attribute

View file

@ -332,6 +332,15 @@ extern int STCparse(void *context);
messagePattern = [STMessage messageWithSelector:@"_unnamed_method" messagePattern = [STMessage messageWithSelector:@"_unnamed_method"
arguments:nil]; arguments:nil];
} }
else if (![[method statements] returnExpression])
{
/* A Smalltalk method (but not plain code) without a return expression
returns the receiver itself. */
STCPrimary *selfPrimary = [STCPrimary primaryWithVariable:@"self"];
STCExpression *returnExpression =
[STCExpression primaryExpressionWithObject:selfPrimary];
[[method statements] setReturnExpression:returnExpression];
}
NSDebugLLog(@"STCompiler", @"Compile method %@", [messagePattern selector]); NSDebugLLog(@"STCompiler", @"Compile method %@", [messagePattern selector]);