Skip to content

Commit 513d4b3

Browse files
committed
fixed
1 parent d87ec8f commit 513d4b3

3 files changed

Lines changed: 56 additions & 3 deletions

File tree

compile.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@echo off
2-
clang -o proxpl.exe -Iinclude -Isrc -D_CRT_SECURE_NO_WARNINGS -DPROX_STATIC ^
2+
clang -o proxpl.exe -Iinclude -Isrc -D_CRT_SECURE_NO_WARNINGS -DPROX_STATIC -DDEBUG_SUBSTR -DDEBUG_PROPERTY_ACCESS ^
33
src/main.c ^
44
src/compiler/lexer/scanner.c ^
55
src/compiler/parser/ast.c ^

src/runtime/vm.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,10 +398,29 @@ static InterpretResult run(VM* vm) {
398398
Value target = peek(vm, 0);
399399
ObjString* name = READ_STRING();
400400

401+
#ifdef DEBUG_PROPERTY_ACCESS
402+
printf("[DEBUG_PROP] OP_GET_PROPERTY: property=%s\n", name->chars);
403+
printf("[DEBUG_PROP] target: IS_INST=%d IS_MOD=%d\n",
404+
IS_INSTANCE(target), IS_MODULE(target));
405+
#endif
406+
401407
if (IS_INSTANCE(target)) {
402408
struct ObjInstance* instance = AS_INSTANCE(target);
403409
Value value;
404410
if (tableGet(&instance->fields, name, &value)) {
411+
#ifdef DEBUG_PROPERTY_ACCESS
412+
printf("[DEBUG_PROP] Found field '%s': IS_OBJ=%d IS_STRING=%d\n",
413+
name->chars, IS_OBJ(value), IS_STRING(value));
414+
if (IS_OBJ(value)) {
415+
Obj* obj = AS_OBJ(value);
416+
printf("[DEBUG_PROP] Field obj: type=%d ptr=%p\n", obj->type, (void*)obj);
417+
if (IS_STRING(value)) {
418+
ObjString* str = AS_STRING(value);
419+
printf("[DEBUG_PROP] Field string: len=%d ptr=%p hash=%u\n",
420+
str->length, (void*)str, str->hash);
421+
}
422+
}
423+
#endif
405424
pop(vm); // Instance
406425
push(vm, value);
407426
DISPATCH();

src/stdlib/stdlib_core.c

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,54 @@ static Value native_pop(int argCount, Value* args) {
7373
}
7474

7575
static Value native_substr(int argCount, Value* args) {
76+
// DEBUG: Track substr calls
77+
#ifdef DEBUG_SUBSTR
78+
printf("[DEBUG_SUBSTR] Called with %d args\n", argCount);
79+
if (argCount >= 1) {
80+
printf("[DEBUG_SUBSTR] arg[0]: IS_OBJ=%d IS_STRING=%d\n",
81+
IS_OBJ(args[0]), IS_STRING(args[0]));
82+
if (IS_OBJ(args[0])) {
83+
Obj* obj = AS_OBJ(args[0]);
84+
printf("[DEBUG_SUBSTR] arg[0] obj type=%d ptr=%p\n", obj->type, (void*)obj);
85+
if (IS_STRING(args[0])) {
86+
ObjString* str = AS_STRING(args[0]);
87+
printf("[DEBUG_SUBSTR] arg[0] string: len=%d ptr=%p hash=%u\n",
88+
str->length, (void*)str, str->hash);
89+
}
90+
}
91+
}
92+
#endif
93+
7694
if (argCount < 3) return NIL_VAL;
77-
if (!IS_STRING(args[0]) || !IS_NUMBER(args[1]) || !IS_NUMBER(args[2])) return NIL_VAL;
95+
if (!IS_STRING(args[0]) || !IS_NUMBER(args[1]) || !IS_NUMBER(args[2])) {
96+
#ifdef DEBUG_SUBSTR
97+
printf("[DEBUG_SUBSTR] Type check failed: IS_STRING=%d IS_NUM[1]=%d IS_NUM[2]=%d\n",
98+
IS_STRING(args[0]), IS_NUMBER(args[1]), IS_NUMBER(args[2]));
99+
#endif
100+
return NIL_VAL;
101+
}
78102

79103
ObjString* source = AS_STRING(args[0]);
80104
int start = (int)AS_NUMBER(args[1]);
81105
int length = (int)AS_NUMBER(args[2]);
82106

107+
#ifdef DEBUG_SUBSTR
108+
printf("[DEBUG_SUBSTR] source string: len=%d start=%d length=%d\n",
109+
source->length, start, length);
110+
#endif
111+
83112
if (start < 0 || start >= source->length) {
84113
return OBJ_VAL(copyString("", 0));
85114
}
86115
if (length < 0) length = 0;
87116
if (start + length > source->length) length = source->length - start;
88117

89-
return OBJ_VAL(copyString(source->chars + start, length));
118+
ObjString* result = copyString(source->chars + start, length);
119+
#ifdef DEBUG_SUBSTR
120+
printf("[DEBUG_SUBSTR] result string: len=%d ptr=%p\n", result->length, (void*)result);
121+
#endif
122+
123+
return OBJ_VAL(result);
90124
}
91125

92126
/*

0 commit comments

Comments
 (0)