Implement $call output handling and $try semantics#3
Open
ikskuh wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
$callbehave like$yieldby supporting optional$tryerror propagation and optional-> $state / -> ${state}output assignment so procedure return values are consumed by callers.sm.data.<Proc>) happens exactly once and that invalid usages (e.g. capturing fromvoidor unknown state) produce compiler errors.Description
Callto includeoutput_variable: ?[]const u8anduse_try: booland updated dumper output to show these flags.$tryshould apply (only when procedure returns an error union), detect void returns and reject->usage, resolve-> $statevs-> ${out}targets, create state variables when needed, and emit.callinstructions carrying the new fields.parse_state_reference,is_void_type, anderror_union_payloadto parse/validate output targets and return types during lowering.CALLhopstate that consumes the callee's return storage by optionally performingtryonsm.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.Datastruct so scoped state entries keep their error-union payload type where needed to allow correcttryemission for$call $try.examples/call_output.zigsmcontaining tests for new behaviors and registered it inbuild.zig.Testing
zig build testwhich compiled the generated example code and executed the example unit tests; the build and tests completed successfully.Codex Task