Implement Phase 2 (atom types) and Phase 4 (Elbo compiler) from feature plan#9
Conversation
…ments) Phase 2 — New Atom Types: - ExecutionLink: triggers GroundedSchemaNode execution - ContextLink: scoped evaluation context - PredictiveImplicationLink: temporal implication with decay - AtTimeLink: event at specific timestamp - TimeNode: stores timestamp value - GroundedSchemaNode: callable atom with function pointer - GroundedPredicateNode: callable predicate evaluation Phase 4 — Elbo Compiler Completeness: - 4.1: let/define forms for variable bindings - 4.2: Conditionals (if/cond/when/unless) with JEQ/JNE opcodes - 4.4: Lambda/defun/fn forms with call-return frames - 4.5: Float literal parsing and LOAD opcode emission - 4.6: elbo_compile_file() for .elbo → .elm compilation Also: - Added elm_load_file declaration to elm_types.h - Fixed unknown form handling to skip nested expressions - Added elbo-module form support
- Fix cond form to properly compile test expressions instead of emitting OP_NOP - Add ELBO_MAX_COND_CLAUSES constant (64) with bounds checking and warning - Use strtof() instead of strtod() to avoid double→float precision loss - Add ELBO_MAX_SOURCE_SIZE constant (1MB) for file size limit
- Use toupper() instead of magic number -32 for case conversion - Add errno checking for strtof() with endptr validation - Fix cond clause overflow to break loop and skip remaining clauses - Add errno.h include
- Better strtof() error handling: check endptr first, then ERANGE - Add diagnostic message for malloc failure - Check for short reads in elbo_compile_file
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 5 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit d0e125f. Configure here.
| /* f will be HUGE_VALF or 0.0, use it anyway */ | ||
| } | ||
| bb_emit(b, OP_LOAD); | ||
| bb_emit_float(b, f); |
There was a problem hiding this comment.
Float literals misalign bytecode
High Severity
The compiler emits OP_LOAD followed by a 4-byte float for number literals. However, the Dis VM's OP_LOAD instruction doesn't expect an immediate operand. This causes the float's bytes to be incorrectly executed as instructions, corrupting program flow.
Reviewed by Cursor Bugbot for commit d0e125f. Configure here.
| * Compile: test → JEQ else_label → then → JMP end_label → else → end | ||
| */ | ||
| compile_expr(l, b); /* compile test */ | ||
| bb_emit(b, OP_JEQ); /* jump if false (regs[0] == 0) */ |
There was a problem hiding this comment.
Conditional jumps compare two registers
High Severity
The compiler's conditional forms (if, when, unless, cond) emit OP_JEQ/OP_JNE opcodes. The VM's branching logic for these opcodes compares regs[0] against regs[1], but the compiler only populates regs[0] with the test expression's result. This leaves regs[1] uninitialized, causing conditional branches to rely on arbitrary register state instead of the intended test outcome.
Reviewed by Cursor Bugbot for commit d0e125f. Configure here.
| lex_atom(l, varname, sizeof(varname)); | ||
| (void)varname; | ||
| compile_expr(l, b); | ||
| bb_emit(b, OP_STORE); |
There was a problem hiding this comment.
Bindings store without heap address
Medium Severity
The let and define forms compile to OP_STORE but ignore binding names and don't set a distinct heap address in regs[1]. This means variables lack unique storage, potentially overwriting each other or writing to an invalid location.
Reviewed by Cursor Bugbot for commit d0e125f. Configure here.
| } else { | ||
| /* Symbol - emit NOP for now (would be a LOAD from symbol table) */ | ||
| bb_emit(b, OP_NOP); | ||
| } |
There was a problem hiding this comment.
File compile truncates embedded NUL
Medium Severity
elbo_compile_file reads the full file with fread, but elbo_compile initializes the lexer length with strlen(source). Any NUL byte inside the buffer ends parsing there, so the rest of the file is silently dropped without an error.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit d0e125f. Configure here.
| break; | ||
| } | ||
|
|
||
| bb_patch_u64(b, next_clause, bb_offset(b)); |
There was a problem hiding this comment.
Cond overflow leaves jump holes
Medium Severity
When a cond has more than ELBO_MAX_COND_CLAUSES branches, the compiler logs an error and breaks out of parsing but skips bb_patch_u64 for the current clause’s OP_JEQ placeholder. That leaves a zero jump target in the bytecode while earlier clauses may still be patched, producing unpredictable control flow.
Reviewed by Cursor Bugbot for commit d0e125f. Configure here.


Implements high-priority items from the CogDiod Exhaustive Feature Implementation Plan.
Phase 2 — New Atom Types
7 new package stubs following the existing
elm_build_stub()pattern:Phase 4 — Elbo Compiler Completeness
Extended the S-expression → Dis bytecode compiler:
if/cond/when/unlesswith JEQ/JNE + backpatchinglet/defineformsfn/defun/lambdawith OP_CALL/OP_RET framesis_number()+strtof()with ERANGE handlingelbo_compile_file()for .elbo → .elmBug Fixes
elm_load_filedeclaration toelm_types.h— implicit declaration was truncating 64-bit pointer to int causing segfaultsOther Changes
ELBO_MAX_COND_CLAUSES(64) with bounds checkingELBO_MAX_SOURCE_SIZE(1MB) constantstrtof(),malloc, andfreadNote
Medium Risk
Large compiler/parser changes and new inference/execution atom stubs affect core VM bytecode paths;
elm_load_filedeclaration fixes a prior segfault but loader usage remains sensitive.Overview
Adds seven new atom-type Elm stub packages (execution, context, predictive implication, at-time/time, grounded schema/predicate) and wires them into the Makefile build.
Extends the Elbo compiler with conditionals (
if/cond/when/unless+ jump backpatching), binding stubs (let/define), lambda-style forms (fn/lambda/defun), float literals viaOP_LOAD, andelbo-module. Unknown forms now compile nested expressions instead of looping. Addselbo_compile_file(.elbo →.elm, CamelCase type name from basename, 1MB cap) and declareselm_load_fileinelm_types.hfor correct 64-bit pointer typing.Reviewed by Cursor Bugbot for commit d0e125f. Bugbot is set up for automated code reviews on this repo. Configure here.