Skip to content

Commit 584c6f9

Browse files
committed
Merge branch 'origin/main' and finalize VM performance optimizations
2 parents c3cec54 + d06ffba commit 584c6f9

44 files changed

Lines changed: 2219 additions & 496 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ yarn-error.log
128128
package-lock.json
129129

130130
# ============================================
131-
# Project-Specific
131+
# Project-Specific & UI Transpiler
132132
# ============================================
133133
.internal_ignore
134134
*.prox.bak
@@ -138,6 +138,8 @@ logs/
138138
tests/bin/
139139
tests/temp_src/
140140
build/obj/
141+
dist_*/
142+
.prm-cache/
141143

142144
# ============================================
143145
# Preprocessed / Build Artifacts

CHANGELOG.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
Title: ProXPL Changelog
2+
Version: 1.0
3+
Date: 2025-12-11
4+
Author: ProgrammerKR
5+
16
# ProXPL Changelog
27

38
All notable changes to the ProXPL project are documented in this file.
@@ -6,6 +11,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
611

712
---
813

14+
## [1.3.3] - 2026-04-26
15+
16+
### Fixed
17+
- **VM Safety**: Comprehensive fix of 15 bugs in `vm.c` including stack overflow/underflow, tensor dimension handling, and use-after-free in `freeVM`.
18+
- **Semantics**: Corrected module application in `OP_USE`, inheritance stack behavior in `OP_INHERIT`, and NaN equality semantics in `OP_EQUAL`.
19+
- **Type Checking**: Added numeric type guards to arithmetic and bitwise opcodes to ensure runtime type safety.
20+
- **Tensors**: Implemented division-by-zero checks for tensor operations and fixed sign extension issues in bytecode reading.
21+
922
## [1.3.1] - 2026-04-22
1023

1124
### Fixed
@@ -62,7 +75,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6275
- **Exception Handling**: Introduced `try`/`catch` blocks for robust error management and runtime safety.
6376

6477
### Changed
65-
- **Versioning**: Synchronized project version to 1.1.0 across the core VM, CLI, VS Code extension, and installer scripts.
78+
- **Versioning**: Synchronized project version to 1.3.3 across the core VM, CLI, VS Code extension, and installer scripts.
6679
- **Roadmap**: Marked v1.1.0 features as completed and released in the main documentation.
6780

6881
## [1.0.0] - 2026-01-06
@@ -412,6 +425,6 @@ This project is licensed under the MIT License.
412425

413426
---
414427

415-
**Current Version**: 1.3.0
416-
**Last Updated**: January 27, 2026
417-
**Next Release**: 1.3.0 (Q1 2026)
428+
**Current Version**: 1.3.3
429+
**Last Updated**: April 26, 2026
430+
**Next Release**: 1.4.0 (Q2 2026)

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
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.3 LANGUAGES C CXX)
33

44
# Enable C and C++
55
enable_language(C CXX)

Makefile

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Complete build system for the C-based ProXPL interpreter
33

44
CC = gcc
5-
CFLAGS = -Wall -Wextra -std=c99 -O2 -I../include
5+
CFLAGS = -Wall -Wextra -Wno-unused-parameter -Wpedantic -std=c99 -O2 -I../include
66
LDFLAGS = -lm
77
TARGET = prox
88
SRCDIR = .
@@ -28,7 +28,8 @@ SOURCES = main.c \
2828
stdlib/math_native.c \
2929
stdlib/string_native.c \
3030
stdlib/convert_native.c \
31-
stdlib/system_native.c
31+
stdlib/system_native.c \
32+
src/proxpl_api.c
3233

3334
# Object files
3435
OBJECTS = $(patsubst %.c,$(OBJDIR)/%.o,$(SOURCES))
@@ -43,9 +44,11 @@ $(OBJDIR):
4344
@mkdir -p $(OBJDIR)/parser
4445
@mkdir -p $(OBJDIR)/runtime
4546
@mkdir -p $(OBJDIR)/stdlib
47+
@mkdir -p $(OBJDIR)/src
48+
@touch $(OBJDIR)/.stamp
4649

4750
# Link the executable
48-
$(TARGET): $(OBJDIR) $(OBJECTS)
51+
$(TARGET): $(OBJDIR) $(OBJDIR)/.stamp $(OBJECTS)
4952
$(CC) $(OBJECTS) -o $(TARGET) $(LDFLAGS)
5053
@echo "Build complete: $(TARGET)"
5154

@@ -68,7 +71,12 @@ repl: $(TARGET)
6871

6972
# Run a test file
7073
test: $(TARGET)
71-
./$(TARGET) ../examples/hello.prox
74+
@if [ -f ../examples/hello.prox ]; then \
75+
./$(TARGET) ../examples/hello.prox; \
76+
else \
77+
echo "Error: ../examples/hello.prox not found. Please ensure examples are present."; \
78+
exit 1; \
79+
fi
7280

7381
# Show help
7482
help:

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
1010
[![ProXPL CI](https://github.com/ProgrammerKR/ProXPL/actions/workflows/build.yml/badge.svg)](https://github.com/ProgrammerKR/ProXPL/actions/workflows/build.yml)
11-
[![Version](https://img.shields.io/badge/version-1.3.1-green.svg)](https://github.com/ProgrammerKR/ProXPL/releases)
11+
[![Version](https://img.shields.io/badge/version-1.3.3-green.svg)](https://github.com/ProgrammerKR/ProXPL/releases)
1212
[![Platform](https://img.shields.io/badge/platform-win%20%7C%20linux%20%7C%20macos-lightgrey.svg)]()
1313

1414

@@ -591,7 +591,7 @@ See [BENCHMARKS.md](BENCHMARKS.md) for detailed performance comparisons.
591591
- **Keywords**: `class`, `new`, `this`, `extends`, `interface`. ✅
592592
- **Runtime**: Optimized VM with Object Support. ✅
593593
- **v1.3.0 (Current)**:
594-
- **v1.2.0**:
594+
- **v1.3.3**:
595595
- **The 10 Operational Pillars**: Full frontend implementation of Intent-Oriented, Context-Aware, ASR, Intrinsic Security, Chrono-Native, Event-Concurreny, AI-Native, Quantum-Ready, Hardware-Math, and Zero-Trust features. ✅
596596
- **Frontend Feature Complete**: Lexer, Parser, AST, and Type Checker support all 10 pillars. ✅
597597

@@ -600,7 +600,7 @@ See [BENCHMARKS.md](BENCHMARKS.md) for detailed performance comparisons.
600600
-**AI-Native Primitives**: Native `tensor` type support with multi-dimensional declaration (e.g., `tensor<float, 2x2>`).
601601
-**Syntax**: Enhanced parser for tensor literals and dimension syntax.
602602

603-
### v1.2.0
603+
### v1.3.3
604604
**Status**: Released (Frontend)
605605
-**10 Pillars Implementation**: Correctly parsing and semantically validating all revolutionary syntax constructs.
606606
-**AI & Quantum**: `model`, `train`, `quantum`, `qubit` primitives.

compile.bat

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ clang -o build/proxpl.exe -static -fms-runtime-lib=static -Iinclude -Isrc -D_CRT
1313
src/compiler/ir.c ^
1414
src/compiler/ir_gen.c ^
1515
src/compiler/ir_opt.c ^
16+
src/compiler/optimizer.c ^
1617
src/compiler/type_checker.c ^
1718
src/runtime/chunk.c ^
1819
src/runtime/compiler.c ^
@@ -27,6 +28,7 @@ clang -o build/proxpl.exe -static -fms-runtime-lib=static -Iinclude -Isrc -D_CRT
2728
src/runtime/vm.c ^
2829
src/runtime/vm_helpers.c ^
2930
src/utils/error_report.c ^
31+
src/utils/file_utils.c ^
3032
src/utils/pxcf.c ^
3133
src/stdlib/collections_native.c ^
3234
src/stdlib/convert_native.c ^
@@ -39,6 +41,9 @@ clang -o build/proxpl.exe -static -fms-runtime-lib=static -Iinclude -Isrc -D_CRT
3941
src/stdlib/math_native.c ^
4042
src/stdlib/net_native.c ^
4143
src/stdlib/os_native.c ^
44+
src/stdlib/path_native.c ^
45+
src/stdlib/process_native.c ^
46+
src/stdlib/buffer_native.c ^
4247
src/stdlib/reflect_native.c ^
4348
src/stdlib/stdlib_core.c ^
4449
src/stdlib/string_native.c ^

docs/BYTECODE_SPEC.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Title: ProXPL Bytecode Specification
22
Version: 1.0
3-
Date: 2025-12-11
3+
Date: 2025-12-11
4+
Author: ProgrammerKR
45

56
Overview
67
- Purpose: Define a compact, extensible, and fast binary bytecode format and runtime instruction semantics for the ProXPL language.

docs/compiler_backend_fixes.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Title: ProXPL Compiler Backend Fixes
2+
Version: 1.0
3+
Date: 2025-12-11
4+
Author: ProgrammerKR
5+
6+
# ProXPL v1.3.3 Compiler Backend Fixes
7+
8+
## Overview
9+
Version 1.3.3 includes critical stability and correctness fixes across the ProXPL compiler's Intermediate Representation (IR) generation, optimization passes, and the LLVM backend. These fixes address malformed control-flow graphs, memory bounds errors, and strictly enforce LLVM IR validator constraints for PHI nodes.
10+
11+
## Detailed Fixes
12+
13+
### 1. Control-Flow Graph (CFG) Integrity (`ir.c`)
14+
- **`addEdge()` Logic:** The edge creation logic has been re-implemented to correctly handle bidirectional links (successors and predecessors) without aborting early on overlapping edge inserts. This ensures accurate graph traversal for dominator and SSA passes.
15+
- **Conditional Branches (`computeCFGLinks`):** `IR_OP_JUMP_IF` parsing was updated to explicitly bind both the `Then` and `Else` successor branches to the CFG, fixing lost control-flow paths.
16+
17+
### 2. IR Generation (`ir_gen.c`)
18+
- **Function Calls (`EXPR_CALL`):** Added complete generation logic to recursively evaluate callee and argument expressions, finally emitting valid `IR_OP_CALL` instructions.
19+
- **Terminator Strictness:** Rewrote `STMT_IF` and `STMT_WHILE` jump logic to construct single 3-operand conditional terminators (`IR_OP_JUMP_IF(Cond, Then, Else)`) instead of relying on subsequent redundant unconditional jumps, which violated LLVM basic block rules.
20+
21+
### 3. Optimization and Memory Safety (`ir_opt.c`)
22+
- **Heap Overflow Prevention:** The memory-to-register promotion pass (`promoteMemoryToRegisters`) was upgraded to dynamically resize (`realloc`) tracking buffers for variable allocations instead of hitting a hard 1024-slot limit, preventing buffer overflows on large functions.
23+
- **Zero-Initialization:** The `isConst` tracking array in the constant folding pass is now safely zero-initialized using `memset` during reallocation.
24+
- **Phi Node Operands:** When variables lack a reaching definition from a predecessor (`currentVersion == -1`), the optimizer now intentionally pushes a `-1` placeholder into the Phi operand list instead of dropping the operand entirely, preserving the structural integrity required by LLVM.
25+
26+
### 4. LLVM Backend Validity (`backend_llvm.cpp`)
27+
- **Dummy NIL Values:** The LLVM emitter's Pass 3 (`addIncoming`) has been fortified to intercept `-1` (uninitialized) SSA references and inject a dummy `NIL` LLVM constant (`0x7ffc000000000001`). This ensures that every LLVM `PHINode` receives exactly one incoming value per predecessor, completely resolving LLVM IR Verifier rejections.
28+
29+
## Future Performance Roadmap
30+
The architectural foundation has been reviewed for future performance milestones, specifically targeting compilation speed:
31+
1. Translating string-based token operators to native Enums (`ast.h`).
32+
2. Adopting O(1) hash maps for variable symbol lookups.
33+
3. Replacing iterative dataflow algorithms with Lengauer-Tarjan dominator trees.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
Title: ProXPL Bug Fix Log 2026-04
2+
Version: 1.0
3+
Date: 2025-12-11
4+
Author: ProgrammerKR
5+
6+
# ProXPL VM Bug Fix Log - April 2026
7+
8+
This document details the comprehensive audit and subsequent fixes applied to the ProXPL Virtual Machine (`src/runtime/vm.c`) to improve memory safety, runtime stability, and semantic correctness.
9+
10+
## Summary of Changes
11+
12+
A total of 15 bugs were addressed, ranging from critical memory corruption issues to logic errors in opcode implementations.
13+
14+
### 🔴 Critical Memory Safety Fixes
15+
16+
1. **Stack Overflow Protection**: Added explicit `exit(1)` in the `push()` function to halt execution upon stack overflow, preventing out-of-bounds memory writes.
17+
2. **Stack Underflow Guard**: Implemented bounds checking in `pop()` to prevent the stack pointer from decrementing below the stack base.
18+
3. **Runtime Error Frame Guard**: Added a check in `runtimeError()` to ensure `frameCount > 0` before accessing call frames, preventing crashes during early initialization or edge-case errors.
19+
4. **Tensor Dimension Overflow**: Increased the internal `dims` array size in `OP_MAKE_TENSOR` from 16 to 256 to accommodate the full range of `uint8_t` dimension counts.
20+
5. **Sign Extension UB**: Fixed undefined behavior in 32-bit integer reconstruction from bytecode by casting `uint8_t` reads to `uint32_t` before bitwise shifting.
21+
6. **Use-After-Free in freeVM**: Ensured `initString` is set to `NULL` before freeing objects to prevent the GC or free-loop from accessing a dangling pointer.
22+
7. **resolveContextualMethod Tombstone Detection**: Fixed a regression where tombstone entries in the context method table could cause crashes by restoring the `IS_BOOL` check.
23+
24+
### 🟠 Logic and Semantic Improvements
25+
26+
7. **Numeric Type Guards**: Added `IS_NUMBER` checks to `OP_GREATER`, `OP_LESS`, `OP_MODULO`, and all bitwise opcodes (`AND`, `OR`, `XOR`, `LSHIFT`, `RSHIFT`) to ensure type safety before numeric extraction.
27+
8. **Global Variable Semantics**: Replaced the "insert-then-delete" hack in `OP_SET_GLOBAL` with a proper existence check via `tableGet`, ensuring standard Lox-style global variable behavior.
28+
9. **Tombstone Handling**: Fixed the tombstone detection logic in `resolveContextualMethod()` to correctly identify empty slots by checking for `NULL` keys.
29+
10. **Module Loading Fix**: Corrected `OP_USE` to actually push the loaded module onto the stack, allowing user scripts to interact with imported modules.
30+
11. **Inheritance Stack Management**: Fixed `OP_INHERIT` to only pop the subclass, keeping the superclass on the stack as required for `super` method lookups.
31+
12. **Division/Modulo Safety**: Implemented runtime error reporting for division and modulo by zero in scalar operations, matching existing tensor safety.
32+
13. **Bitwise Shift Safety**:
33+
- Added checks to `OP_LEFT_SHIFT` and `OP_RIGHT_SHIFT` to ensure shift amounts are between 0 and 31.
34+
- Implemented unsigned casts in `OP_LEFT_SHIFT` to prevent undefined behavior when shifting negative signed integers.
35+
14. **Tensor Build Safety**:
36+
- Implemented integer overflow protection for `totalSize` calculation in `OP_MAKE_TENSOR`.
37+
- Added stack underflow bounds checking before adjusting the stack pointer during tensor initialization.
38+
- Removed redundant dead code guards.
39+
40+
### 🟡 Structural and Minor Fixes
41+
42+
15. **Dead Code Elimination**: Removed an unreachable `DISPATCH()` call at the end of the `OP_CALL` implementation.
43+
16. **interpretChunk Safety**:
44+
- Enhanced documentation and ensured `initChunk` calls in `interpretChunk()` safely detach transient function objects from caller-owned memory.
45+
- Added a GC guard (`pvm->nextGC = SIZE_MAX`) during `interpretChunk` execution to prevent the collector from freeing transient chunk data during the run.
46+
17. **NaN Equality**: Updated `OP_EQUAL` to respect IEEE 754 NaN semantics (`NaN != NaN`) for NaN-boxed numeric values.
47+
18. **Foreign Function Safety**: Added `IS_STRING` guards to `OP_MAKE_FOREIGN` to prevent crashes when non-string values are passed as library or symbol names.
48+
19. **List Build Safety**: Added a stack underflow check to `OP_BUILD_LIST` to prevent memory corruption from malformed bytecode.
49+
50+
## System-Wide Fixes (CLI, API, & Build)
51+
52+
### 🔴 CLI & Lifecycle Security (`src/main.c`)
53+
20. **Token Array Bounds**: Implemented strict look-ahead bounds checking for token arrays in both REPL (256 tokens) and file execution (4096 tokens) to prevent buffer overflows.
54+
21. **Buffer Security**: Replaced unsafe `sprintf` calls with `snprintf` when generating UI transpilation output directories.
55+
22. **Error Path Cleanup**: Corrected the order of resource deallocation in `runFile` to ensure `TypeChecker`, `StmtList`, and source buffers are freed even on failure paths.
56+
23. **CLI Extension Guard**: Added length verification to `argv` indexing to prevent out-of-bounds reads on short filenames.
57+
24. **ftell Sign Error**: Added checks for negative return values from `ftell()` to prevent massive erroneous memory allocations on file I/O failure.
58+
59+
### 🟠 Public API & Integration (`src/proxpl_api.c`)
60+
25. **Lifecycle Guards**: Added NULL pointer verification to `proxpl_vm_init`, `proxpl_vm_free`, and `proxpl_interpret_file` for integration safety.
61+
26. **Include Standardization**: Reordered headers to ensure system libraries are prioritized over local project headers, preventing macro conflicts.
62+
63+
### 🟡 Build System & Workspace (`Makefile`, `.gitignore`)
64+
27. **Strict Compilation**: Enabled `-Wpedantic` and `-Wno-unused-parameter` to catch standards violations and silence intentional suppression warnings.
65+
28. **Missing Sources**: Added `src/proxpl_api.c` to the `SOURCES` list to ensure the public API is correctly linked into the binary.
66+
29. **Workspace Hygiene**: Updated `.gitignore` to track UI transpiler output (`dist_*/`) and PRM caches (`.prm-cache/`), and verified correct file naming.
67+
68+
---
69+
**Version Update**: These fixes are included in ProXPL version **1.3.2**.
70+
**Date**: April 26, 2026
71+
**Lead Engineer**: Antigravity (AI Assistant)

0 commit comments

Comments
 (0)