Skip to content

Implement $call output handling and $try semantics#3

Open
ikskuh wants to merge 1 commit into
mainfrom
codex/implement-call-output-handling-and-error-propagation
Open

Implement $call output handling and $try semantics#3
ikskuh wants to merge 1 commit into
mainfrom
codex/implement-call-output-handling-and-error-propagation

Conversation

@ikskuh

@ikskuh ikskuh commented Jan 30, 2026

Copy link
Copy Markdown
Contributor

Motivation

  • Make $call behave like $yield by supporting optional $try error propagation and optional -> $state / -> ${state} output assignment so procedure return values are consumed by callers.
  • Ensure caller-side consumption of procedure return storage (sm.data.<Proc>) happens exactly once and that invalid usages (e.g. capturing from void or unknown state) produce compiler errors.

Description

  • Extended IR Call to include output_variable: ?[]const u8 and use_try: bool and updated dumper output to show these flags.
  • Updated CodeGen lowering to validate call targets, determine whether $try should apply (only when procedure returns an error union), detect void returns and reject -> usage, resolve -> $state vs -> ${out} targets, create state variables when needed, and emit .call instructions carrying the new fields.
  • Added helpers parse_state_reference, is_void_type, and error_union_payload to parse/validate output targets and return types during lowering.
  • Updated the Renderer to emit code after a CALL hopstate that consumes the callee's return storage by optionally performing try on sm.data.<Proc> and assigning the result into the requested output state (or discarding with _ = try ... when no output was requested), and preserved the runtime recursion guard and branch/resume behavior.
  • Adjusted generation of the Data struct so scoped state entries keep their error-union payload type where needed to allow correct try emission for $call $try.
  • Added examples/call_output.zigsm containing tests for new behaviors and registered it in build.zig.

Testing

  • Ran the project test suite with zig build test which compiled the generated example code and executed the example unit tests; the build and tests completed successfully.

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant