How programmerkr/proxpl works
1. Repository Purpose and Entrypoints
ProXPL is a C/C++ implementation of a statically typed systems language: it compiles .prox source to stack-VM bytecode or LLVM-backed native output. The native executable entrypoints are main.c and src/main.c; public subsystem contracts are in include/compiler.h and include/vm.h. Build orchestration is CMake-based through CMakeLists.txt.
A Node.js developer CLI wraps execution, builds, and REPL workflows: src/cli/index.js, src/cli/commands/run.js, and src/cli/commands/build.js.
2. Frontend: Source to Validated AST
The compiler frontend tokenizes ProX syntax, constructs ASTs, resolves imports, and performs static semantic/type validation. This is the primary language-definition boundary: syntax and semantic changes normally span scanner, parser/AST, and checker.
• Lexer: src/compiler/lexer/scanner.c
• AST/parser: src/compiler/parser/ast.c, src/compiler/parser/parser.c
• Imports and typing: src/compiler/importer.c, src/compiler/type_checker.c
Source modules may draw on language-level standard-library modules under std/lib/, such as std/lib/math.prox and std/lib/io.prox.
3. Lowering and Compilation Backends
Validated ASTs lower into an intermediate representation, which is optimized before selecting a code-generation path. This creates the key boundary between language semantics and executable representation.
• IR construction and optimization: src/compiler/ir_gen.c, src/compiler/ir.c, src/compiler/ir_opt.c
• VM bytecode emission: src/compiler/bytecode_gen.c
• LLVM AOT backend: src/compiler/backend_llvm.cpp
The usual flow is .prox → tokens → AST → type check → IR → optimized IR → bytecode/LLVM. LLVM is an optional material external dependency for AOT compilation; the ordinary VM path remains native C/C++ runtime code.
4. Bytecode VM and Execution Semantics
Bytecode is represented, decoded, dispatched, and executed by the VM layer. It is the runtime control boundary for stack execution, function/object behavior, intent/context dispatch, and exception/recovery mechanisms.
• Bytecode representation/disassembly: src/vm/bytecode.c, src/vm/disasm.c
• VM dispatch/core implementations: src/vm/vm_dispatch.c, src/vm/vm_core_opt.c, src/vm/vm_v2.c
• Runtime VM integration: src/runtime/vm.c, src/runtime/compiler.c
The architecture documentation for instruction and VM contracts lives at docs/architecture/BYTECODE_SPEC.md and docs/architecture/VM_ARCHITECTURE.md.
5. Managed Runtime, Native Interop, and ASR
The runtime owns object/value representation, allocation, mark-and-sweep garbage collection, scheduling/supervision, and foreign-function bridging. These are cross-cutting services consumed by VM instructions and native library functions.
• Objects, values, memory, and GC: src/runtime/object.c, src/runtime/value.c, src/runtime/gc.c
• Scheduling and supervision: src/runtime/scheduler.c, src/runtime/supervisor.c
• Dynamic-library FFI: src/runtime/ffi_bridge.c, include/ffi_bridge.h
Autonomic Self-Healing (ASR) has a separate C++ runtime implementation, including lock-free queues and supervision: runtime/asr_runtime.cpp, runtime/asr_supervisor.cpp, and runtime/asr_lockfree_queue.cpp.
6. Standard Library and Package Boundary
Language-facing standard modules are implemented partly in ProX and partly as VM-registered native C functions. This boundary exposes filesystem, network, process, JSON, collections, and system capabilities to user programs.
• Native registration/core: src/stdlib/stdlib_core.c, src/stdlib/core_native.c
• Capability examples: src/stdlib/fs_native.c, src/stdlib/net_native.c, src/stdlib/process_native.c
• ProX module surface: std/lib/, std/lib/collections.prox
PRM manages project manifests, dependencies, and package-related commands: src/prm/builder.c, src/prm/manifest.c, and src/prm/commands/cmd_core.c.
7. Developer Ecosystem
The VS Code extension provides syntax configuration, editor integration, and a Node/TypeScript language server; it is separate from compiler execution but depends on language syntax/contracts.
• Extension activation: extension/src/extension.ts
• Language server: extension/server/src/server.ts
• Grammar: extension/syntaxes/proxpl.tmLanguage.json
Cross-platform CI, releases, and security scanning run through GitHub Actions: .github/workflows/build.yml, .github/workflows/release.yml, and .github/workflows/snyk-security.yml.
Main entry points: vm_dispatch.c Stack VM dispatch · math.prox ProX source modules · ir_opt.c IR optimizer · parser.c Parser and AST
Components 21
Developer Tooling
- Node developer CLI · Wraps run, build, and REPL workflows.
src/cli/index.js - Native compiler entry
src/main.c - CMake build
CMakeLists.txt - PRM packages · Manages manifests, dependencies, and package commands.
src/prm/builder.c
Compiler Pipeline
- ProX source modules
std/lib/math.prox - Scanner
src/compiler/lexer/scanner.c - Parser and AST
src/compiler/parser/parser.c - Imports and type checker
src/compiler/type_checker.c - IR construction
src/compiler/ir_gen.c - IR optimizer
src/compiler/ir_opt.c - Bytecode generator
src/compiler/bytecode_gen.c - LLVM AOT backend · Optional LLVM-backed native output.
src/compiler/backend_llvm.cpp
VM and Runtime
- Bytecode representation
src/vm/bytecode.c - Stack VM dispatch · Executes bytecode and implements stack control semantics.
src/vm/vm_dispatch.c - Managed runtime · Owns values, allocation, garbage collection, and supervision.
src/runtime/gc.c - Native FFI bridge
src/runtime/ffi_bridge.c - ASR runtime · Provides lock-free queues and autonomous supervision.
runtime/asr_runtime.cpp
Language Ecosystem
- Standard library · Registers native capabilities exposed to language modules.
src/stdlib/stdlib_core.c - VS Code extension
extension/src/extension.ts - Language server
extension/server/src/server.ts - GitHub Actions
.github/workflows/build.yml
Connections 20
- CMake build → Native compiler entry: builds
- Node developer CLI → Native compiler entry: invokes
- PRM packages → ProX source modules: resolves packages
- ProX source modules → Scanner: tokenizes
- Scanner → Parser and AST: tokens
- Parser and AST → Imports and type checker: AST
- Imports and type checker → IR construction: validated AST
- IR construction → IR optimizer: IR
- IR optimizer → Bytecode generator: optimized IR
- IR optimizer → LLVM AOT backend: optimized IR
- Bytecode generator → Bytecode representation: emits
- Bytecode representation → Stack VM dispatch: decoded and executed
- Stack VM dispatch → Managed runtime: uses objects, GC, scheduling
- Stack VM dispatch → Native FFI bridge: native calls
- Managed runtime → ASR runtime: supervision support
- Standard library → Stack VM dispatch: registers native functions
- ProX source modules → Standard library: imports modules
- VS Code extension → Language server: activates
- Language server → Parser and AST: uses language contracts
- GitHub Actions → CMake build: builds and validates