Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .claude/rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ Existing bridges: `regex-bridge.c`, `yyjson-bridge.c`, `os-bridge.c`, `child-pro
5. **Type cast field order must match FULL struct layout** — when the type extends a parent interface, the struct includes ALL parent fields. `as { name, closureInfo }` on a `LiftedFunction extends FunctionNode` (10 fields) reads index 1 instead of index 9. Include every field.
6. **`ret void` not `unreachable`** at end of void functions
7. **Class structs: boolean is `i1`; Interface structs: boolean is `double`**
8. **Set feature flags when emitting gated extern calls** — runtime declarations for C bridges (yyjson, curl, etc.) are conditionally emitted behind flags like `usesJson`, `usesCurl`. Any code path that emits `call @csyyjson_*` must call `ctx.setUsesJson(true)`, etc. Missing this causes "undefined value" errors from `opt` because the `declare` is never emitted.

## Interface Field Iteration

Expand Down
3 changes: 3 additions & 0 deletions src/codegen/expressions/access/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface IndexAccessGeneratorContext {
isStringExpression(expr: Expression): boolean;
readonly stringGen: IStringGenerator;
ensureDouble(value: string): string;
setUsesJson(value: boolean): void;
}

/**
Expand Down Expand Up @@ -427,6 +428,7 @@ export class IndexAccessGenerator {
}

private generateJSONArrayIndex(expr: IndexAccessNode, params: string[]): string {
this.ctx.setUsesJson(true);
// Load JSON array pointer
const varName = (expr.object as VariableNode).name;
const jsonPtrPtr = this.ctx.getVariableAlloca(varName)!;
Expand Down Expand Up @@ -514,6 +516,7 @@ export class IndexAccessGenerator {
}

private generateJSONMemberArrayIndex(expr: IndexAccessNode, params: string[]): string {
this.ctx.setUsesJson(true);
const jsonPtr = this.ctx.generateExpression(expr.object, params);

const ptrType = this.ctx.getVariableType(jsonPtr);
Expand Down
6 changes: 6 additions & 0 deletions src/codegen/llvm-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ import type { TypeChecker } from "../typescript/type-checker.js";
import { InterfaceStructGenerator } from "./types/interface-struct-generator.js";
import { JsonObjectMeta } from "./expressions/access/member.js";
import type { TargetInfo } from "../target-types.js";
import { checkClosureMutations } from "../semantic/closure-mutation-checker.js";
import { checkUnionTypes } from "../semantic/union-type-checker.js";

export interface SemaSymbolData {
names: string[];
Expand Down Expand Up @@ -2340,6 +2342,10 @@ export class LLVMGenerator extends BaseGenerator implements IGeneratorContext {
}

generateParts(): string[] {
// Run semantic checks before emitting any IR.
checkClosureMutations(this.ast);
checkUnionTypes(this.ast);

const irParts: string[] = [];

const interfaceStructDefs = this.interfaceStructGen.generateStructTypeDefinitions();
Expand Down
Loading
Loading