Skip to content

bug: partially wired stdlib functions across 5 modules #1580

@SchoolyB

Description

@SchoolyB

Summary

Source code audit found 7 stdlib functions across 5 modules that are partially wired across the compiler pipeline, meaning they either silently fail, produce broken C output, or are documented in the standard but never implemented. All need to be fully implemented end-to-end.


1. random.seed() — codegen only, missing 3 layers

  • Header (ez_random.h): No ez_random_seed() declaration
  • Implementation (ez_random.c): No user-facing seed function (only an internal ensure_seed() that auto-seeds with srand(time(NULL)))
  • Typechecker: Not registered — rejected as unknown function before reaching codegen
  • Codegen: Listed in func_to_mod[] mapping table (codegen.c), so codegen would attempt to emit ez_random_seed() if it ever got there

Impact: Typechecker rejects the call, so users get an error. The codegen entry is dead code pointing at a function that doesn't exist.

Fix: Implement random.seed() end-to-end:

  1. Add void ez_random_seed(int64_t value) to ez_random.h
  2. Implement it in ez_random.c — call srand((unsigned)value) and set _seeded = true
  3. Register in typechecker under the random module section (void return)
  4. Codegen entry already exists

2. json.format() — typechecker only, no codegen handler

  • Header (ez_json.h): No dedicated format function
  • Implementation (ez_json.c): No format function
  • Typechecker (typechecker.c): Accepted — returns string type
  • Codegen (emit_json_call): No case for "format" — falls through, returns false, and hits the generic fallback path producing broken C

Impact: User can write json.format(value) and the typechecker accepts it, but codegen produces broken or incorrect C output.

Fix: Wire json.format() in codegen as an alias for json.encode() (the standard describes them as doing the same thing). Add a strcmp(func, "format") == 0 case in emit_json_call that dispatches identically to the encode path.


3. csv.format() — typechecker only, no codegen handler

  • Typechecker: Accepted — returns string type
  • Codegen (emit_csv_call): No case for "format" — falls through and produces broken C

Impact: Same class as json.format(). Typechecker accepts csv.format() but codegen has no handler.

Fix: Add a strcmp(func, "format") == 0 case in emit_csv_call, likely as an alias for csv.encode() / csv.stringify().


4. csv.headers() — typechecker only, no codegen handler

  • Typechecker: Accepted
  • Codegen (emit_csv_call): No case for "headers" — falls through and produces broken C

Impact: Typechecker accepts csv.headers() but codegen has no handler.

Fix: Implement ez_csv_headers() in the C layer and wire the codegen case.


5. server.cors() — typechecker only, no codegen handler

  • Typechecker: Accepted
  • Codegen (emit_server_call): No case for "cors" — falls through and produces broken C

Impact: Typechecker accepts server.cors() but codegen has no handler.

Fix: Implement ez_server_cors() in the C layer and wire the codegen case.


6. server.use() — typechecker only, no codegen handler

  • Typechecker: Accepted
  • Codegen (emit_server_call): No case for "use" — falls through and produces broken C

Impact: Typechecker accepts server.use() but codegen has no handler.

Fix: Implement ez_server_use() in the C layer and wire the codegen case.


7. sync.try_lock() — missing entirely

  • Header (ez_sync.h): No try_lock declaration
  • Implementation (ez_sync.c): No try_lock function
  • Typechecker: Not registered
  • Codegen: Not handled
  • Standard (STANDARD.md): Documents sync.try_lock() as an existing function

Impact: Standard says it exists but it was never built. Users reading the docs will try to use it and get an error.

Fix: Implement sync.try_lock() end-to-end across all 4 layers. Should wrap pthread_mutex_trylock() and return a bool.


Bug Class

All 7 fall into the same pattern: the compiler pipeline is incomplete for these functions. Items 2-6 are the most dangerous — the typechecker accepts the call, so the user thinks it's valid, but codegen produces broken C. Items 1 and 7 are less dangerous since the typechecker rejects them, but the standard/codegen entries create confusion.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcodegenRelated to C code generationstdlibGeneral standard library issuestypecheckerRelated to type checking and validation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions