isVarType falsly returning VAR_NULL fix

This commit is contained in:
Thakee Nathees 2022-05-27 01:01:48 +05:30
parent fb1e1099c7
commit b020e249aa
4 changed files with 25 additions and 9 deletions

View File

@ -769,7 +769,12 @@ static void eatString(Compiler* compiler, bool single_quote) {
} break;
case '\r':
if (matchChar(parser, '\n')) break;
// Else fallthrough.
default:
semanticError(compiler, makeErrToken(parser),
"Invalid escape character.");
break;

View File

@ -1629,7 +1629,7 @@ bool varContains(PKVM* vm, Var elem, Var container) {
bool varIsType(PKVM* vm, Var inst, Var type) {
if (!IS_OBJ_TYPE(type, OBJ_CLASS)) {
VM_SET_ERROR(vm, newString(vm, "Right operand must be a class."));
return VAR_NULL;
return false;
}
Class* cls = (Class*)AS_OBJ(type);

View File

@ -860,6 +860,7 @@ bool pkNewInstance(PKVM* vm, int cls, int index, int argc, int argv) {
bool pkCallFunction(PKVM* vm, int fn, int argc, int argv, int ret) {
CHECK_FIBER_EXISTS(vm);
ASSERT(IS_OBJ_TYPE(SLOT(fn), OBJ_CLOSURE), "Slot value wasn't a function");
if (argc != 0) {
VALIDATE_SLOT_INDEX(argv);
VALIDATE_SLOT_INDEX(argv + argc - 1);
@ -868,7 +869,7 @@ bool pkCallFunction(PKVM* vm, int fn, int argc, int argv, int ret) {
// Calls a class == construct.
if (IS_OBJ_TYPE(SLOT(fn), OBJ_CLASS)) {
Var inst = _newInstance(vm, (Class*) AS_OBJ(fn), argc,
Var inst = _newInstance(vm, (Class*) AS_OBJ(SLOT(fn)), argc,
vm->fiber->ret + argv);
if (ret >= 0) SET_SLOT(ret, inst);
return !VM_HAS_ERROR(vm);

View File

@ -321,8 +321,11 @@ PkResult vmCallMethod(PKVM* vm, Var self, Closure* fn,
fiber->self = self;
vmPushTempRef(vm, &fiber->_super); // fiber.
bool success = vmPrepareFiber(vm, fiber, argc, argv);
if (!success) {
vmPopTempRef(vm); // fiber.
if (!success) return PK_RESULT_RUNTIME_ERROR;
return PK_RESULT_RUNTIME_ERROR;
}
PkResult result;
@ -345,7 +348,10 @@ PkResult vmCallMethod(PKVM* vm, Var self, Closure* fn,
result = vmRunFiber(vm, fiber);
}
}
if (last != NULL) vmPopTempRef(vm); // last.
vmPopTempRef(vm); // fiber.
vm->fiber = last;
if (ret != NULL) *ret = *fiber->ret;
@ -515,7 +521,11 @@ static inline void pushCallFrame(PKVM* vm, const Closure* closure) {
// Grow the stack frame if needed.
if (vm->fiber->frame_count + 1 > vm->fiber->frame_capacity) {
// Native functions doesn't allocate a frame initially.
int new_capacity = vm->fiber->frame_capacity << 1;
if (new_capacity == 0) new_capacity = 1;
vm->fiber->frames = (CallFrame*)vmRealloc(vm, vm->fiber->frames,
sizeof(CallFrame) * vm->fiber->frame_capacity,
sizeof(CallFrame) * new_capacity);
@ -693,7 +703,7 @@ PkResult vmRunFiber(PKVM* vm, Fiber* fiber_) {
#if DEBUG
#define PUSH(value) \
do { \
ASSERT(fiber->sp < (fiber->stack + (fiber->stack_size - 1)), \
ASSERT(fiber->sp < (fiber->stack + ((intptr_t) fiber->stack_size - 1)), \
OOPS); \
(*fiber->sp++ = (value)); \
} while (false)