feat: treat null as falsey in conditional and logical operator branches

Update the VM interpreter to treat null as falsey alongside false in if, while, for, and logical AND/OR operations. Remove the TODO comment and adjust short-circuit logic in OP_JUMP_IF and OP_JUMP_IF_NOT branches. Refactor existing test files into subdirectories (if/, logical_operator/, while/) and add dedicated truthiness tests for each construct. Remove old test/if.wren and update and/or tests to exclude null/0/"" truthiness checks now that null is falsey.
This commit is contained in:
Bob Nystrom
2014-01-21 02:12:55 +00:00
parent a696c060fc
commit a5c4918a75
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();