Skip to content

Commit ab33378

Browse files
committed
Fix build errors: resolve VM pointer/struct mismatch and duplicate case in vm.c; perform general cleanup
1 parent b3d25dc commit ab33378

File tree

9 files changed

+92
-148
lines changed

9 files changed

+92
-148
lines changed

CMakeLists.txt

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cmake_minimum_required(VERSION 3.15)
2-
project(ProXPL VERSION 1.2.0 LANGUAGES C CXX)
2+
project(ProXPL VERSION 1.3.0 LANGUAGES C CXX)
33

44
# Enable C and C++
55
enable_language(C CXX)
@@ -9,11 +9,25 @@ set(CMAKE_CXX_STANDARD 17)
99
set(CMAKE_CXX_STANDARD_REQUIRED ON)
1010

1111
if (MSVC)
12-
add_compile_options(/W4 /wd4244 /wd4245 /wd4267 /wd4100)
12+
add_compile_options(/W4 /wd4244 /wd4245 /wd4267 /wd4100 /wd4200)
13+
add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE)
1314
else()
1415
add_compile_options(-Wall -Wextra -Wno-sign-compare -Wno-unused-variable -Wno-unused-parameter)
1516
endif()
1617

18+
# --- Build Configuration ---
19+
option(PROX_STATIC_BUILD "Build as a single static executable" ON)
20+
21+
if(PROX_STATIC_BUILD)
22+
add_definitions(-DPROX_STATIC)
23+
if(MSVC)
24+
# Set dynamic/static CRT for the whole project before targets are added
25+
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
26+
# Also add flags for older CMake versions or explicit control
27+
add_compile_options($<$<CONFIG:Release>:/MT> $<$<CONFIG:Debug>:/MTd>)
28+
endif()
29+
endif()
30+
1731
# --- LLVM Configuration ---
1832
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules")
1933

@@ -183,9 +197,6 @@ list(REMOVE_ITEM LIB_SOURCES
183197
"${CMAKE_CURRENT_SOURCE_DIR}/src/instr_handlers_template.c"
184198
)
185199

186-
# --- Build Configuration ---
187-
option(PROX_STATIC_BUILD "Build as a single static executable" ON)
188-
189200
# Define the core library that all tools link against
190201
add_library(prox_core STATIC ${LIB_SOURCES})
191202
target_include_directories(prox_core PUBLIC include src)
@@ -201,14 +212,6 @@ if (LIBFFI_FOUND)
201212
target_link_libraries(prox_core PUBLIC ${LIBFFI_LIBRARIES})
202213
endif()
203214

204-
if(PROX_STATIC_BUILD)
205-
add_definitions(-DPROX_STATIC)
206-
if(MSVC)
207-
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
208-
add_compile_options($<$<CONFIG:Release>:/MT> $<$<CONFIG:Debug>:/MTd>)
209-
endif()
210-
endif()
211-
212215
# Main executable
213216
add_executable(proxpl src/main.c)
214217
target_link_libraries(proxpl PRIVATE prox_core)

src/compiler/ir_opt.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ void constantFold(IRFunction* func) {
205205
} else if (instr->opcode == IR_OP_ADD || instr->opcode == IR_OP_SUB ||
206206
instr->opcode == IR_OP_MUL || instr->opcode == IR_OP_DIV) {
207207

208-
Value left, right;
208+
Value left = NIL_VAL, right = NIL_VAL;
209209
bool c1 = false, c2 = false;
210210

211211
if (instr->operands[0].type == OPERAND_CONST) {
@@ -225,7 +225,7 @@ void constantFold(IRFunction* func) {
225225
}
226226

227227
if (c1 && c2) {
228-
Value v_result;
228+
Value v_result = NIL_VAL;
229229
bool folded = false;
230230
if (IS_NUMBER(left) && IS_NUMBER(right)) {
231231
double l = AS_NUMBER(left);

src/compiler/type_checker.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ static TypeInfo checkExpr(TypeChecker* checker, Expr* expr) {
377377

378378
case EXPR_INDEX: {
379379
// Array/Matrix indexing returns tainted values (IFC)
380-
TypeInfo target = checkExpr(checker, expr->as.index.target);
380+
checkExpr(checker, expr->as.index.target);
381381
TypeInfo index = checkExpr(checker, expr->as.index.index);
382382

383383
// Index should be numeric

src/proxpl_api.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,30 +49,30 @@ static char* readFile(const char* path) {
4949
return buffer;
5050
}
5151

52-
void proxpl_vm_init(VM *vm) {
52+
void proxpl_vm_init(VM *pvm) {
5353
// Standard CLOX uses a global VM instance, so we ignore the pointer for now
5454
// or assume 'vm' points to the global one.
55-
initVM(vm);
55+
initVM(pvm);
5656
}
5757

58-
void proxpl_vm_free(VM *vm) {
59-
freeVM(vm);
58+
void proxpl_vm_free(VM *pvm) {
59+
freeVM(pvm);
6060
}
6161

62-
InterpretResult proxpl_interpret_chunk(VM *vm, const Chunk *chunk) {
63-
(void)vm; (void)chunk;
62+
InterpretResult proxpl_interpret_chunk(VM *pvm, const Chunk *chunk) {
63+
(void)pvm; (void)chunk;
6464
// ERROR: The standard VM interprets Source Code strings, not raw Chunks.
6565
// To support this, you would need to expose the internal run() function.
6666
fprintf(stderr, "API Error: interpreting raw chunks is not supported in this version.\n");
6767
return INTERPRET_RUNTIME_ERROR;
6868
}
6969

70-
InterpretResult proxpl_interpret_file(VM *vm, const char *path) {
70+
InterpretResult proxpl_interpret_file(VM *pvm, const char *path) {
7171
char* source = readFile(path);
7272
if (source == NULL) return INTERPRET_COMPILE_ERROR;
7373

7474
// Pass the source string to interpret
75-
InterpretResult result = interpret(vm, source);
75+
InterpretResult result = interpret(pvm, source);
7676

7777
free(source);
7878
return result;

src/runtime/gc.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ static void reset_nursery() {
7777
// Access the global VM instance
7878
extern VM vm;
7979

80-
void initGC(VM* vm) {
81-
vm->grayCount = 0;
82-
vm->grayCapacity = 0;
83-
vm->grayStack = NULL;
84-
vm->bytesAllocated = 0;
85-
vm->nextGC = 1024 * 1024;
80+
void initGC(VM* pvm) {
81+
pvm->grayCount = 0;
82+
pvm->grayCapacity = 0;
83+
pvm->grayStack = NULL;
84+
pvm->bytesAllocated = 0;
85+
pvm->nextGC = 1024 * 1024;
8686

8787
initNursery();
8888
}

src/runtime/vm.c

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,14 @@ void runtimeError(VM* pvm, const char* format, ...) {
7272
reportRuntimeError(pvm->source, line, message);
7373

7474
for (int i = pvm->frameCount - 1; i >= 0; i--) {
75-
CallFrame* frame = &pvm->frames[i];
76-
ObjFunction* function = frame->closure->function;
77-
size_t instruction = frame->ip - function->chunk.code - 1;
78-
fprintf(stderr, " [line %d] in ", function->chunk.lines[instruction]);
79-
if (function->name == NULL) {
75+
CallFrame* f = &pvm->frames[i];
76+
ObjFunction* fn = f->closure->function;
77+
size_t inst = f->ip - fn->chunk.code - 1;
78+
fprintf(stderr, " [line %d] in ", fn->chunk.lines[inst]);
79+
if (fn->name == NULL) {
8080
fprintf(stderr, "script\n");
8181
} else {
82-
fprintf(stderr, "%s()\n", function->name->chars);
82+
fprintf(stderr, "%s()\n", fn->name->chars);
8383
}
8484
}
8585

@@ -113,9 +113,9 @@ bool isFalsey(Value value) {
113113
return IS_NULL(value) || (IS_BOOL(value) && !AS_BOOL(value));
114114
}
115115

116-
static bool performTensorArithmetic(VM* vm, char op) {
117-
Value bVal = peek(vm, 0);
118-
Value aVal = peek(vm, 1);
116+
static bool performTensorArithmetic(VM* pvm, char op) {
117+
Value bVal = peek(pvm, 0);
118+
Value aVal = peek(pvm, 1);
119119

120120
// Case 1: Tensor op Tensor
121121
if (IS_TENSOR(aVal) && IS_TENSOR(bVal)) {
@@ -124,23 +124,23 @@ static bool performTensorArithmetic(VM* vm, char op) {
124124

125125
// Element-wise arithmetic requires matching size
126126
if (a->size != b->size) {
127-
runtimeError(vm, "Tensor size mismatch: %d vs %d.", a->size, b->size);
127+
runtimeError(pvm, "Tensor size mismatch: %d vs %d.", a->size, b->size);
128128
return true;
129129
}
130130

131131
if (a->dimCount != b->dimCount) {
132-
runtimeError(vm, "Tensor rank mismatch.");
132+
runtimeError(pvm, "Tensor rank mismatch.");
133133
return true;
134134
}
135135
for (int i=0; i<a->dimCount; i++) {
136136
if (a->dims[i] != b->dims[i]) {
137-
runtimeError(vm, "Tensor dimension mismatch at axis %d: %d vs %d.", i, a->dims[i], b->dims[i]);
137+
runtimeError(pvm, "Tensor dimension mismatch at axis %d: %d vs %d.", i, a->dims[i], b->dims[i]);
138138
return true;
139139
}
140140
}
141141

142142
ObjTensor* res = newTensor(a->dimCount, a->dims, NULL);
143-
push(vm, OBJ_VAL(res));
143+
push(pvm, OBJ_VAL(res));
144144

145145
for (int i = 0; i < a->size; i++) {
146146
double vA = a->data[i];
@@ -153,10 +153,10 @@ static bool performTensorArithmetic(VM* vm, char op) {
153153
}
154154
}
155155

156-
Value resVal = pop(vm);
157-
pop(vm); // b
158-
pop(vm); // a
159-
push(vm, resVal);
156+
Value resVal = pop(pvm);
157+
pop(pvm); // b
158+
pop(pvm); // a
159+
push(pvm, resVal);
160160
return true;
161161
}
162162

@@ -166,7 +166,7 @@ static bool performTensorArithmetic(VM* vm, char op) {
166166
double b = AS_NUMBER(bVal);
167167

168168
ObjTensor* res = newTensor(a->dimCount, a->dims, NULL);
169-
push(vm, OBJ_VAL(res));
169+
push(pvm, OBJ_VAL(res));
170170

171171
for (int i = 0; i < a->size; i++) {
172172
double vA = a->data[i];
@@ -177,8 +177,8 @@ static bool performTensorArithmetic(VM* vm, char op) {
177177
case '/': res->data[i] = vA / b; break;
178178
}
179179
}
180-
Value resVal = pop(vm);
181-
pop(vm); pop(vm); push(vm, resVal);
180+
Value resVal = pop(pvm);
181+
pop(pvm); pop(pvm); push(pvm, resVal);
182182
return true;
183183
}
184184

@@ -188,7 +188,7 @@ static bool performTensorArithmetic(VM* vm, char op) {
188188
ObjTensor* b = AS_TENSOR(bVal);
189189

190190
ObjTensor* res = newTensor(b->dimCount, b->dims, NULL);
191-
push(vm, OBJ_VAL(res));
191+
push(pvm, OBJ_VAL(res));
192192

193193
for (int i = 0; i < b->size; i++) {
194194
double vB = b->data[i];
@@ -199,8 +199,8 @@ static bool performTensorArithmetic(VM* vm, char op) {
199199
case '/': res->data[i] = a / vB; break;
200200
}
201201
}
202-
Value resVal = pop(vm);
203-
pop(vm); pop(vm); push(vm, resVal);
202+
Value resVal = pop(pvm);
203+
pop(pvm); pop(pvm); push(pvm, resVal);
204204
return true;
205205
}
206206

@@ -1730,7 +1730,7 @@ static InterpretResult run(VM* vm) {
17301730
ObjTensor *tensor = newTensor(dimCount, dims, NULL);
17311731
if (elementCount == 0 && totalSize > 0) {
17321732
memset(tensor->data, 0, totalSize * sizeof(double));
1733-
} else if (elementCount == totalSize) {
1733+
} else if (elementCount == (uint32_t)totalSize) {
17341734
// Pop elements (reverse order as they were pushed in order, stack top is last)
17351735
for (int i = totalSize - 1; i >= 0; i--) {
17361736
Value val = pop(vm);

0 commit comments

Comments
 (0)