1
0
forked from Mirror/wren

wren/vm: Add wrenIsFalsyValue. (#866)

This commit is contained in:
Michel Hermier
2021-04-08 07:54:49 +02:00
committed by GitHub
parent 041f1bab8d
commit e4052a25d7
2 changed files with 8 additions and 3 deletions

View File

@ -1140,7 +1140,7 @@ static WrenInterpretResult runInterpreter(WrenVM* vm, register ObjFiber* fiber)
uint16_t offset = READ_SHORT();
Value condition = POP();
if (IS_FALSE(condition) || IS_NULL(condition)) ip += offset;
if (wrenIsFalsyValue(condition)) ip += offset;
DISPATCH();
}
@ -1149,7 +1149,7 @@ static WrenInterpretResult runInterpreter(WrenVM* vm, register ObjFiber* fiber)
uint16_t offset = READ_SHORT();
Value condition = PEEK();
if (IS_FALSE(condition) || IS_NULL(condition))
if (wrenIsFalsyValue(condition))
{
// Short-circuit the right hand side.
ip += offset;
@ -1167,7 +1167,7 @@ static WrenInterpretResult runInterpreter(WrenVM* vm, register ObjFiber* fiber)
uint16_t offset = READ_SHORT();
Value condition = PEEK();
if (IS_FALSE(condition) || IS_NULL(condition))
if (wrenIsFalsyValue(condition))
{
// Discard the condition and evaluate the right hand side.
DROP();

View File

@ -243,4 +243,9 @@ static inline bool wrenIsLocalName(const char* name)
return name[0] >= 'a' && name[0] <= 'z';
}
static inline bool wrenIsFalsyValue(Value value)
{
return IS_FALSE(value) || IS_NULL(value);
}
#endif