Skip to content

Commit 73a90ab

Browse files
committed
feat: Implement the core virtual machine with opcode dispatch and runtime execution.
1 parent d35f7b5 commit 73a90ab

1 file changed

Lines changed: 6 additions & 26 deletions

File tree

src/runtime/vm.c

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,37 +1129,17 @@ static InterpretResult run(VM* vm) {
11291129
}
11301130
case OP_IMPLEMENT: {
11311131
Value interfaceVal = pop(vm);
1132-
Value classVal = peek(vm, 0);
1132+
Value classVal = peek(vm, 0); // Class remains on stack
1133+
11331134
if (!IS_INTERFACE(interfaceVal)) {
1134-
// runtimeError(vm, "Expected interface.");
1135-
// IS_INTERFACE macro needs to be defined?
1136-
// object.h: #define IS_INTERFACE(value) isObjType(value, OBJ_INTERFACE)
1137-
// I should double check object.h if I added the macro. I didn't add the macro IS_INTERFACE! I added OBJ_INTERFACE enum.
1138-
// I should add IS_INTERFACE macro to object.h.
1139-
// For now, I'll use isObjType(interfaceVal, OBJ_INTERFACE).
1140-
if (!isObjType(interfaceVal, OBJ_INTERFACE)) {
1141-
runtimeError(vm, "Superclass must be a class."); // Reuse error or new one
1142-
return INTERPRET_RUNTIME_ERROR;
1143-
}
1135+
runtimeError(vm, "Expected interface.");
1136+
return INTERPRET_RUNTIME_ERROR;
11441137
}
1145-
// Add interface to class
1146-
// ObjClass has interfaces array.
1147-
// Assume simple append for now.
1138+
11481139
ObjClass* klass = AS_CLASS(classVal);
1149-
// Resize logic?
1150-
// Using GC allocator or manual realloc?
1151-
// Memory.h has GROW_ARRAY.
1152-
// But ObjClass interfaces is Value*.
1153-
// Need to update interfaceCount.
1154-
// I need to use the memory manager.
1155-
// REALLOCATE uses vm.
1156-
// I'll assume simple realloc or max limit for now to avoid complexity?
1157-
// Or properly use GROW_ARRAY.
1158-
1159-
// Proper:
11601140
int oldCapacity = klass->interfaceCount;
11611141
int newCapacity = oldCapacity + 1;
1162-
klass->interfaces = (Value*)realloc(klass->interfaces, sizeof(Value) * newCapacity);
1142+
klass->interfaces = GROW_ARRAY(Value, klass->interfaces, oldCapacity, newCapacity);
11631143
klass->interfaces[oldCapacity] = interfaceVal;
11641144
klass->interfaceCount = newCapacity;
11651145

0 commit comments

Comments
 (0)