Make null falsey.

This commit is contained in:
Bob Nystrom
2014-01-20 18:12:55 -08:00
parent 8c5ef693d0
commit 90d1ed6aa6
13 changed files with 118 additions and 58 deletions
+8 -14
View File
@@ -997,9 +997,7 @@ static bool runInterpreter(WrenVM* vm)
int offset = READ_SHORT();
Value condition = POP();
// False is the only falsey value.
// TODO: Null should be falsey too.
if (IS_FALSE(condition)) ip += offset;
if (IS_FALSE(condition) || IS_NULL(condition)) ip += offset;
DISPATCH();
}
@@ -1008,18 +1006,16 @@ static bool runInterpreter(WrenVM* vm)
int offset = READ_SHORT();
Value condition = PEEK();
// False is the only falsey value.
// TODO: Null should be falsey too.
if (!IS_FALSE(condition))
{
// Discard the condition and evaluate the right hand side.
POP();
}
else
if (IS_FALSE(condition) || IS_NULL(condition))
{
// Short-circuit the right hand side.
ip += offset;
}
else
{
// Discard the condition and evaluate the right hand side.
POP();
}
DISPATCH();
}
@@ -1028,9 +1024,7 @@ static bool runInterpreter(WrenVM* vm)
int offset = READ_SHORT();
Value condition = PEEK();
// False is the only falsey value.
// TODO: Null should be falsey too.
if (IS_FALSE(condition))
if (IS_FALSE(condition) || IS_NULL(condition))
{
// Discard the condition and evaluate the right hand side.
POP();