-
Notifications
You must be signed in to change notification settings - Fork 14
Description
Description
The current implementation of the try/catch mechanism contains two logic gaps that prevent examples/error_handling_demo.ks from executing correctly:
- eBPF Control Flow: In the eBPF backend,
throw(viaIRThrow) only assigned a value to the error variable but did not interrupt the execution of thetryblock. Subsequent instructions in thetryblock were still executed. - Userspace Code Generation: The userspace backend generated a C
switchstatement with a placeholder comment (/* Handle error here */) instead of recursing into the actual instructions defined within thecatchblock.
Technical Breakdown
eBPF Backend (src/ebpf_c_codegen.ml)
-
Context Variable: Added
current_catch_labelto thec_contexttype. -
Label Management:
-
IRTrynow generates a uniquecatch_labeland stores it in the context before processing thetryinstructions. -
A label definition (
label:) is now emitted after thetryblock but before thecatchlogic. -
Jump Logic:
IRThrownow emits agotostatement targeting thecatch_label, ensuring immediate exit from thetryblock upon an error.
Userspace Backend (src/userspace_codegen.ml)
- Recursive Generation: Replaced the static placeholder string in the
catchcase with a mapping ofgenerate_c_instruction_from_irover thecatch_bodylist. - String Integration: The generated instructions are now concatenated and properly indented within the C
casestatement.
These changes ensure that:
-
In eBPF programs, a throw effectively skips the remainder of the try block.
-
In Userspace programs, the logic defined inside a catch block is actually compiled into the final C code.