mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-18 13:49:59 +01:00
Invert the return value for finishBloc().
Thanks, Michel!
This commit is contained in:
@ -1440,14 +1440,14 @@ static void patchJump(Compiler* compiler, int offset)
|
|||||||
|
|
||||||
// Parses a block body, after the initial "{" has been consumed.
|
// Parses a block body, after the initial "{" has been consumed.
|
||||||
//
|
//
|
||||||
// Returns true if it was a statement body, false if it was an expression body.
|
// Returns true if it was a expression body, false if it was an statement body.
|
||||||
// (More precisely, returns false if a value was left on the stack. An empty
|
// (More precisely, returns true if a value was left on the stack. An empty
|
||||||
// block returns true.)
|
// block returns false.)
|
||||||
static bool finishBlock(Compiler* compiler)
|
static bool finishBlock(Compiler* compiler)
|
||||||
{
|
{
|
||||||
// Empty blocks do nothing.
|
// Empty blocks do nothing.
|
||||||
if (match(compiler, TOKEN_RIGHT_BRACE)) {
|
if (match(compiler, TOKEN_RIGHT_BRACE)) {
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there's no line after the "{", it's a single-expression body.
|
// If there's no line after the "{", it's a single-expression body.
|
||||||
@ -1455,12 +1455,12 @@ static bool finishBlock(Compiler* compiler)
|
|||||||
{
|
{
|
||||||
expression(compiler);
|
expression(compiler);
|
||||||
consume(compiler, TOKEN_RIGHT_BRACE, "Expect '}' at end of block.");
|
consume(compiler, TOKEN_RIGHT_BRACE, "Expect '}' at end of block.");
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Empty blocks (with just a newline inside) do nothing.
|
// Empty blocks (with just a newline inside) do nothing.
|
||||||
if (match(compiler, TOKEN_RIGHT_BRACE)) {
|
if (match(compiler, TOKEN_RIGHT_BRACE)) {
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compile the definition list.
|
// Compile the definition list.
|
||||||
@ -1474,23 +1474,23 @@ static bool finishBlock(Compiler* compiler)
|
|||||||
consumeLine(compiler, "Expect newline after statement.");
|
consumeLine(compiler, "Expect newline after statement.");
|
||||||
}
|
}
|
||||||
while (!match(compiler, TOKEN_RIGHT_BRACE));
|
while (!match(compiler, TOKEN_RIGHT_BRACE));
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parses a method or function body, after the initial "{" has been consumed.
|
// Parses a method or function body, after the initial "{" has been consumed.
|
||||||
static void finishBody(Compiler* compiler, bool isConstructor)
|
static void finishBody(Compiler* compiler, bool isConstructor)
|
||||||
{
|
{
|
||||||
bool isStatementBody = finishBlock(compiler);
|
bool isExpressionBody = finishBlock(compiler);
|
||||||
|
|
||||||
if (isConstructor)
|
if (isConstructor)
|
||||||
{
|
{
|
||||||
// If the constructor body evaluates to a value, discard it.
|
// If the constructor body evaluates to a value, discard it.
|
||||||
if (!isStatementBody) emit(compiler, CODE_POP);
|
if (isExpressionBody) emit(compiler, CODE_POP);
|
||||||
|
|
||||||
// The receiver is always stored in the first local slot.
|
// The receiver is always stored in the first local slot.
|
||||||
emit(compiler, CODE_LOAD_LOCAL_0);
|
emit(compiler, CODE_LOAD_LOCAL_0);
|
||||||
}
|
}
|
||||||
else if (isStatementBody)
|
else if (!isExpressionBody)
|
||||||
{
|
{
|
||||||
// Implicitly return null in statement bodies.
|
// Implicitly return null in statement bodies.
|
||||||
emit(compiler, CODE_NULL);
|
emit(compiler, CODE_NULL);
|
||||||
@ -2517,7 +2517,7 @@ void block(Compiler* compiler)
|
|||||||
if (match(compiler, TOKEN_LEFT_BRACE))
|
if (match(compiler, TOKEN_LEFT_BRACE))
|
||||||
{
|
{
|
||||||
pushScope(compiler);
|
pushScope(compiler);
|
||||||
if (!finishBlock(compiler))
|
if (finishBlock(compiler))
|
||||||
{
|
{
|
||||||
// Block was an expression, so discard it.
|
// Block was an expression, so discard it.
|
||||||
emit(compiler, CODE_POP);
|
emit(compiler, CODE_POP);
|
||||||
|
|||||||
Reference in New Issue
Block a user