harn_vm/compiler/mod.rs
1use harn_parser::{Node, SNode, TypeExpr};
2
3mod closures;
4mod concurrency;
5mod decls;
6mod error;
7mod error_handling;
8mod expressions;
9mod hitl;
10mod optimizer;
11mod patterns;
12mod pipe;
13mod state;
14mod statements;
15#[cfg(test)]
16mod tests;
17mod type_facts;
18mod yield_scan;
19
20pub use error::CompileError;
21
22use crate::chunk::{Chunk, Constant, Op};
23
24/// Jump operands are 16-bit chunk offsets (`emit_jump`, `patch_jump`,
25/// backward loop jumps), so a chunk whose code grows past `u16::MAX`
26/// bytes would silently truncate jump targets and land somewhere wild at
27/// runtime. Every finalized chunk (the program chunk and each compiled
28/// function's chunk) must pass through this guard so oversized bodies
29/// fail compilation instead of miscompiling.
30pub(crate) fn ensure_chunk_addressable(
31 chunk: &Chunk,
32 what: &str,
33 line: u32,
34) -> Result<(), CompileError> {
35 if chunk.code.len() > u16::MAX as usize {
36 return Err(CompileError {
37 message: format!(
38 "{what} compiled to {} bytes of bytecode, more than the 64 KiB a jump \
39 operand can address; split it into smaller functions",
40 chunk.code.len()
41 ),
42 line,
43 });
44 }
45 Ok(())
46}
47
48/// Environment variable that disables optional compiler optimizations.
49///
50/// The VM still emits structurally required bytecode, such as parameter
51/// slots, but skips semantic-preserving optimizer passes. This gives tests
52/// and benchmarks a stable optimized-vs-unoptimized comparison switch.
53pub const HARN_DISABLE_OPTIMIZATIONS_ENV: &str = "HARN_DISABLE_OPTIMIZATIONS";
54
55/// Controls semantic-preserving compiler optimizations.
56#[derive(Clone, Copy, Debug, PartialEq, Eq)]
57pub struct CompilerOptions {
58 optimize: bool,
59}
60
61impl CompilerOptions {
62 pub fn optimized() -> Self {
63 Self { optimize: true }
64 }
65
66 pub fn without_optimizations() -> Self {
67 Self { optimize: false }
68 }
69
70 pub fn from_env() -> Self {
71 if std::env::var_os(HARN_DISABLE_OPTIMIZATIONS_ENV).is_some() {
72 Self::without_optimizations()
73 } else {
74 Self::optimized()
75 }
76 }
77
78 pub fn optimizations_enabled(self) -> bool {
79 self.optimize
80 }
81}
82
83impl Default for CompilerOptions {
84 fn default() -> Self {
85 Self::optimized()
86 }
87}
88
89/// Look through an `AttributedDecl` wrapper to the inner declaration.
90/// `compile_named` / `compile` use this so attributed declarations like
91/// `@test pipeline foo(...)` are still discoverable by name.
92fn peel_node(sn: &SNode) -> &Node {
93 match &sn.node {
94 Node::AttributedDecl { inner, .. } => &inner.node,
95 other => other,
96 }
97}
98
99/// Entry in the compiler's pending-finally stack. See the field-level doc on
100/// `Compiler::finally_bodies` for the unwind semantics each variant encodes.
101#[derive(Clone, Debug)]
102enum FinallyEntry {
103 Finally(Vec<SNode>),
104 CatchBarrier,
105}
106
107/// Tracks loop context for break/continue compilation.
108struct LoopContext {
109 /// Offset of the loop start (for continue).
110 start_offset: usize,
111 /// Positions of break jumps that need patching to the loop end.
112 break_patches: Vec<usize>,
113 /// True if this is a for-in loop (has an iterator to clean up on break).
114 has_iterator: bool,
115 /// Number of exception handlers active at loop entry.
116 handler_depth: usize,
117 /// Number of pending finally bodies at loop entry.
118 finally_depth: usize,
119 /// Lexical scope depth at loop entry.
120 scope_depth: usize,
121}
122
123#[derive(Clone, Copy, Debug)]
124struct LocalBinding {
125 slot: u16,
126 mutable: bool,
127}
128
129/// Compiles an AST into bytecode.
130pub struct Compiler {
131 options: CompilerOptions,
132 chunk: Chunk,
133 line: u32,
134 column: u32,
135 /// Track enum type names so PropertyAccess on them can produce EnumVariant.
136 enum_names: std::collections::HashSet<String>,
137 /// Variant name → owning enum names. Lets a bare call-shaped match
138 /// pattern (`Ok(v)`, `Some(x)`) resolve to its enum without
139 /// qualification when the variant name is unambiguous.
140 enum_variant_owners: std::collections::HashMap<String, Vec<String>>,
141 /// Track struct type names to declared field order for indexed instances.
142 struct_layouts: std::collections::HashMap<String, Vec<String>>,
143 /// Track interface names → method names for runtime enforcement.
144 interface_methods: std::collections::HashMap<String, Vec<String>>,
145 /// Stack of active loop contexts for break/continue.
146 loop_stack: Vec<LoopContext>,
147 /// Current depth of exception handlers (for cleanup on break/continue).
148 handler_depth: usize,
149 /// Stack of pending finally bodies plus catch-handler barriers for
150 /// unwind-aware lowering of `throw`, `return`, `break`, and `continue`.
151 ///
152 /// A `Finally` entry is a pending finally body that must execute when
153 /// control exits its enclosing try block. A `CatchBarrier` marks the
154 /// boundary of an active `try/catch` handler: throws emitted inside
155 /// the try body are caught locally, so pre-running finallys *beyond*
156 /// the barrier would wrongly fire side effects for outer blocks the
157 /// throw never actually escapes. Throw lowering stops at the innermost
158 /// barrier; `return`/`break`/`continue`, which do transfer past local
159 /// handlers, still run every pending `Finally` up to their target.
160 finally_bodies: Vec<FinallyEntry>,
161 /// Counter for unique temp variable names.
162 temp_counter: usize,
163 /// Number of lexical block scopes currently active in this compiled frame.
164 scope_depth: usize,
165 /// Top-level `type` aliases, used to lower `schema_of(T)` and
166 /// `output_schema: T` into constant JSON-Schema dicts at compile time.
167 type_aliases: std::collections::HashMap<String, TypeExpr>,
168 /// Lightweight compiler-side type facts used only for conservative
169 /// bytecode specialization. This mirrors lexical scopes and is separate
170 /// from the parser's diagnostic type checker so compile-only callers keep
171 /// working without a required type-check pass.
172 type_scopes: Vec<std::collections::HashMap<String, TypeExpr>>,
173 /// `(span.start, span.end)` of every mutable binding (`var` / `for`-item)
174 /// proven *monomorphic*: its value keeps a single primitive type across its
175 /// initializer and every reassignment in scope. Only these bindings may
176 /// carry an initializer-inferred primitive type fact into typed-opcode
177 /// specialization (`AddInt`, `LessInt`, …), which hard-errors on a runtime
178 /// operand-type mismatch. A mutable binding that is reassigned through an
179 /// `any`-typed (or otherwise non-matching) value is *not* recorded here, so
180 /// the compiler keeps it on the generic adaptive path that re-checks operand
181 /// shapes at runtime — see [`Compiler::record_monomorphic_var_bindings`].
182 /// Populated per lexical scope before that scope's statements are compiled;
183 /// keyed by byte span because `Span` is not `Hash`.
184 monomorphic_bindings: std::collections::HashSet<(usize, usize)>,
185 /// Current-chunk string constant index. This avoids repeatedly scanning the
186 /// constant pool while compiling name-heavy scripts.
187 string_constants: std::collections::HashMap<String, u16>,
188 /// Lexical variable slots for the current compiled frame. The compiler
189 /// only consults this for names declared inside the current function-like
190 /// body; all unresolved names stay on the existing dynamic/name path.
191 local_scopes: Vec<std::collections::HashMap<String, LocalBinding>>,
192 /// True when this compiler is emitting code outside any function-like
193 /// scope (module top-level statements). `try*` is rejected here
194 /// because the rethrow has no enclosing function to live in.
195 /// Pipeline bodies and nested `Compiler::new()` instances (fn,
196 /// closure, tool, etc.) flip this to false before compiling.
197 module_level: bool,
198}
199
200impl Compiler {
201 /// Compile a single AST node. Most arm bodies live in per-category
202 /// submodules (expressions, statements, closures, decls, patterns,
203 /// error_handling, concurrency); this function is a thin dispatcher.
204 fn compile_node(&mut self, snode: &SNode) -> Result<(), CompileError> {
205 self.line = snode.span.line as u32;
206 self.column = snode.span.column as u32;
207 self.chunk.set_column(self.column);
208 if self.options.optimizations_enabled() {
209 if let Some(folded) = optimizer::fold_constant_expr(snode) {
210 if folded.node != snode.node {
211 return self.compile_node(&folded);
212 }
213 }
214 }
215 match &snode.node {
216 Node::IntLiteral(n) => {
217 let idx = self.chunk.add_constant(Constant::Int(*n));
218 self.chunk.emit_u16(Op::Constant, idx, self.line);
219 }
220 Node::FloatLiteral(n) => {
221 let idx = self.chunk.add_constant(Constant::Float(*n));
222 self.chunk.emit_u16(Op::Constant, idx, self.line);
223 }
224 Node::StringLiteral(s) | Node::RawStringLiteral(s) => {
225 let idx = self.string_constant(s);
226 self.chunk.emit_u16(Op::Constant, idx, self.line);
227 }
228 Node::BoolLiteral(true) => self.chunk.emit(Op::True, self.line),
229 Node::BoolLiteral(false) => self.chunk.emit(Op::False, self.line),
230 Node::NilLiteral => self.chunk.emit(Op::Nil, self.line),
231 Node::DurationLiteral(ms) => {
232 let ms = i64::try_from(*ms).map_err(|_| CompileError {
233 message: "duration literal is too large".to_string(),
234 line: self.line,
235 })?;
236 let idx = self.chunk.add_constant(Constant::Duration(ms));
237 self.chunk.emit_u16(Op::Constant, idx, self.line);
238 }
239 Node::Identifier(name) => {
240 self.emit_get_binding(name);
241 }
242 Node::LetBinding { pattern, value, .. } => {
243 let binding_type = match &snode.node {
244 Node::LetBinding {
245 type_ann: Some(type_ann),
246 ..
247 } => Some(type_ann.clone()),
248 _ => self.infer_expr_type(value),
249 };
250 self.compile_node(value)?;
251 self.compile_destructuring(pattern, false)?;
252 self.record_binding_type(pattern, binding_type.clone());
253 self.maybe_register_owned_drop(pattern, binding_type.as_ref(), snode.span);
254 }
255 Node::VarBinding { pattern, value, .. } => {
256 let binding_type = match &snode.node {
257 Node::VarBinding {
258 type_ann: Some(type_ann),
259 ..
260 } => Some(type_ann.clone()),
261 _ => self.infer_expr_type(value),
262 };
263 self.compile_node(value)?;
264 self.compile_destructuring(pattern, true)?;
265 // A `var` is reassignable, so its initializer-inferred primitive
266 // type is only safe for typed-opcode specialization when the
267 // binding is provably monomorphic (proven by
268 // `record_monomorphic_var_bindings`, run before this scope's
269 // statements). Otherwise drop the primitive fact so arithmetic
270 // stays on the generic adaptive path, which re-checks operand
271 // shapes at runtime instead of hard-committing to `AddInt` etc.
272 let binding_type = self.gate_mutable_primitive_type(snode.span, binding_type);
273 self.record_binding_type(pattern, binding_type.clone());
274 self.maybe_register_owned_drop(pattern, binding_type.as_ref(), snode.span);
275 }
276 Node::ConstBinding {
277 name,
278 type_ann,
279 value,
280 } => {
281 // `const` lowers to the same bytecode as a let-binding
282 // over a simple identifier. The compile-time const-eval
283 // pass in the typechecker has already proven the
284 // initializer is pure and within budget, so re-running
285 // it through the VM is guaranteed to produce the same
286 // value byte-for-byte.
287 let binding_type = type_ann.clone().or_else(|| self.infer_expr_type(value));
288 self.compile_node(value)?;
289 let pattern = harn_parser::BindingPattern::Identifier(name.clone());
290 self.compile_destructuring(&pattern, false)?;
291 self.record_binding_type(&pattern, binding_type.clone());
292 self.maybe_register_owned_drop(&pattern, binding_type.as_ref(), snode.span);
293 }
294 Node::Assignment {
295 target, value, op, ..
296 } => {
297 self.compile_assignment(target, value, op)?;
298 }
299 Node::BinaryOp { op, left, right } => {
300 self.compile_binary_op(op, left, right)?;
301 }
302 Node::UnaryOp { op, operand } => {
303 self.compile_node(operand)?;
304 match op.as_str() {
305 "-" => self.chunk.emit(Op::Negate, self.line),
306 "!" => self.chunk.emit(Op::Not, self.line),
307 _ => {}
308 }
309 }
310 Node::Ternary {
311 condition,
312 true_expr,
313 false_expr,
314 } => {
315 self.compile_node(condition)?;
316 let else_jump = self.chunk.emit_jump(Op::JumpIfFalse, self.line);
317 self.chunk.emit(Op::Pop, self.line);
318 self.compile_node(true_expr)?;
319 let end_jump = self.chunk.emit_jump(Op::Jump, self.line);
320 self.chunk.patch_jump(else_jump);
321 self.chunk.emit(Op::Pop, self.line);
322 self.compile_node(false_expr)?;
323 self.chunk.patch_jump(end_jump);
324 }
325 Node::FunctionCall { name, args, .. } => {
326 self.compile_function_call(name, args)?;
327 }
328 Node::MethodCall {
329 object,
330 method,
331 args,
332 } => {
333 self.compile_method_call(object, method, args)?;
334 }
335 Node::OptionalMethodCall {
336 object,
337 method,
338 args,
339 } => {
340 self.compile_node(object)?;
341 for arg in args {
342 self.compile_node(arg)?;
343 }
344 let name_idx = self.string_constant(method);
345 self.chunk
346 .emit_method_call_opt(name_idx, args.len() as u8, self.line);
347 }
348 Node::PropertyAccess { object, property } => {
349 self.compile_property_access(object, property)?;
350 }
351 Node::OptionalPropertyAccess { object, property } => {
352 self.compile_node(object)?;
353 let idx = self.string_constant(property);
354 self.chunk.emit_u16(Op::GetPropertyOpt, idx, self.line);
355 }
356 Node::SubscriptAccess { object, index } => {
357 self.compile_node(object)?;
358 self.compile_node(index)?;
359 self.chunk.emit(Op::Subscript, self.line);
360 }
361 Node::OptionalSubscriptAccess { object, index } => {
362 self.compile_node(object)?;
363 self.compile_node(index)?;
364 self.chunk.emit(Op::SubscriptOpt, self.line);
365 }
366 Node::SliceAccess { object, start, end } => {
367 self.compile_node(object)?;
368 if let Some(s) = start {
369 self.compile_node(s)?;
370 } else {
371 self.chunk.emit(Op::Nil, self.line);
372 }
373 if let Some(e) = end {
374 self.compile_node(e)?;
375 } else {
376 self.chunk.emit(Op::Nil, self.line);
377 }
378 self.chunk.emit(Op::Slice, self.line);
379 }
380 Node::IfElse {
381 condition,
382 then_body,
383 else_body,
384 } => {
385 self.compile_if_else(condition, then_body, else_body)?;
386 }
387 Node::WhileLoop { condition, body } => {
388 self.compile_while_loop(condition, body)?;
389 }
390 Node::ForIn {
391 pattern,
392 iterable,
393 body,
394 } => {
395 self.compile_for_in(pattern, iterable, body)?;
396 }
397 Node::ReturnStmt { value } => {
398 self.compile_return_stmt(value)?;
399 }
400 Node::BreakStmt => {
401 self.compile_break_stmt()?;
402 }
403 Node::ContinueStmt => {
404 self.compile_continue_stmt()?;
405 }
406 Node::ListLiteral(elements) => {
407 self.compile_list_literal(elements)?;
408 }
409 Node::DictLiteral(entries) => {
410 self.compile_dict_literal(entries)?;
411 }
412 Node::InterpolatedString(segments) => {
413 self.compile_interpolated_string(segments)?;
414 }
415 Node::FnDecl {
416 name,
417 type_params,
418 params,
419 body,
420 is_stream,
421 ..
422 } => {
423 self.compile_fn_decl(name, type_params, params, body, *is_stream)?;
424 }
425 Node::ToolDecl {
426 name,
427 description,
428 params,
429 return_type,
430 body,
431 ..
432 } => {
433 self.compile_tool_decl(name, description, params, return_type, body)?;
434 }
435 Node::SkillDecl { name, fields, .. } => {
436 self.compile_skill_decl(name, fields)?;
437 }
438 Node::EvalPackDecl {
439 binding_name,
440 pack_id,
441 fields,
442 body,
443 summarize,
444 ..
445 } => {
446 self.compile_eval_pack_decl(binding_name, pack_id, fields, body, summarize, true)?;
447 }
448 Node::Closure { params, body, .. } => {
449 self.compile_closure(params, body)?;
450 }
451 Node::ThrowStmt { value } => {
452 self.compile_throw_stmt(value)?;
453 }
454 Node::MatchExpr { value, arms } => {
455 self.compile_match_expr(value, arms)?;
456 }
457 Node::RangeExpr {
458 start,
459 end,
460 inclusive,
461 } => {
462 let name_idx = self.string_constant("__range__");
463 self.chunk.emit_u16(Op::Constant, name_idx, self.line);
464 self.compile_node(start)?;
465 self.compile_node(end)?;
466 if *inclusive {
467 self.chunk.emit(Op::True, self.line);
468 } else {
469 self.chunk.emit(Op::False, self.line);
470 }
471 self.chunk.emit_u8(Op::Call, 3, self.line);
472 }
473 Node::GuardStmt {
474 condition,
475 else_body,
476 } => {
477 self.compile_guard_stmt(condition, else_body)?;
478 }
479 Node::RequireStmt { condition, message } => {
480 self.compile_node(condition)?;
481 let ok_jump = self.chunk.emit_jump(Op::JumpIfTrue, self.line);
482 self.chunk.emit(Op::Pop, self.line);
483 if let Some(message) = message {
484 self.compile_node(message)?;
485 } else {
486 let idx = self.string_constant("require condition failed");
487 self.chunk.emit_u16(Op::Constant, idx, self.line);
488 }
489 self.chunk.emit(Op::Throw, self.line);
490 self.chunk.patch_jump(ok_jump);
491 self.chunk.emit(Op::Pop, self.line);
492 }
493 Node::Block(stmts) => {
494 self.compile_scoped_block(stmts)?;
495 }
496 Node::DeadlineBlock { duration, body } => {
497 self.compile_node(duration)?;
498 self.chunk.emit(Op::DeadlineSetup, self.line);
499 self.compile_scoped_block(body)?;
500 self.chunk.emit(Op::DeadlineEnd, self.line);
501 }
502 Node::MutexBlock { key, body } => {
503 self.begin_scope();
504 let finally_floor = self.finally_bodies.len();
505 match key {
506 // `mutex(resource) { ... }`: evaluate the resource and key
507 // the lock on its structural value at runtime.
508 Some(key_expr) => {
509 self.compile_node(key_expr)?;
510 self.chunk.emit(Op::SyncMutexEnterKeyed, self.line);
511 }
512 // `mutex { ... }`: key on the lexical call-site (computed in
513 // the VM from the chunk + instruction pointer) so distinct
514 // blocks don't contend on one global lock.
515 None => {
516 self.chunk.emit(Op::SyncMutexEnter, self.line);
517 }
518 }
519 for sn in body {
520 self.compile_discarded_stmt(sn)?;
521 }
522 self.drain_finallys_to_floor(finally_floor)?;
523 self.chunk.emit(Op::Nil, self.line);
524 self.end_scope();
525 }
526 Node::ScopeBlock { body } => {
527 // Structured-concurrency nursery. `TaskScopeEnter` pushes a task
528 // scope; tasks spawned inside register to it. `TaskScopeExit`
529 // joins them (propagating the first error, cancelling the rest).
530 // On `throw`/early exit the scope is unwound and its tasks
531 // cancelled by the frame/handler teardown, mirroring
532 // `held_sync_guards`.
533 self.begin_scope();
534 let finally_floor = self.finally_bodies.len();
535 self.chunk.emit(Op::TaskScopeEnter, self.line);
536 for sn in body {
537 self.compile_discarded_stmt(sn)?;
538 }
539 self.drain_finallys_to_floor(finally_floor)?;
540 self.chunk.emit(Op::TaskScopeExit, self.line);
541 self.chunk.emit(Op::Nil, self.line);
542 self.end_scope();
543 }
544 Node::DeferStmt { body } => {
545 // Register the body to run on return/throw/scope-exit. The
546 // statement emits no bytecode of its own — the deferred body
547 // is inlined later by the finally-draining machinery — so it
548 // leaves the operand stack untouched, matching
549 // `produces_value` == false. Emitting a `Nil` here instead
550 // leaked an unpopped slot per execution, which in a loop body
551 // grew the operand stack without bound (surfaced by the
552 // #2622 balance assertion).
553 self.finally_bodies
554 .push(FinallyEntry::Finally(body.clone()));
555 }
556 Node::YieldExpr { value } => {
557 if let Some(val) = value {
558 self.compile_node(val)?;
559 } else {
560 self.chunk.emit(Op::Nil, self.line);
561 }
562 self.chunk.emit(Op::Yield, self.line);
563 }
564 Node::EmitExpr { value } => {
565 self.compile_node(value)?;
566 self.chunk.emit(Op::Yield, self.line);
567 }
568 Node::EnumConstruct {
569 enum_name,
570 variant,
571 args,
572 } => {
573 self.compile_enum_construct(enum_name, variant, args)?;
574 }
575 Node::StructConstruct {
576 struct_name,
577 fields,
578 } => {
579 self.compile_struct_construct(struct_name, fields)?;
580 }
581 Node::ImportDecl { path, .. } => {
582 let idx = self.string_constant(path);
583 self.chunk.emit_u16(Op::Import, idx, self.line);
584 }
585 Node::SelectiveImport { names, path, .. } => {
586 let path_idx = self.string_constant(path);
587 let names_str = names.join(",");
588 let names_idx = self.owned_string_constant(names_str);
589 self.chunk
590 .emit_u16(Op::SelectiveImport, path_idx, self.line);
591 let hi = (names_idx >> 8) as u8;
592 let lo = names_idx as u8;
593 self.chunk.code.push(hi);
594 self.chunk.code.push(lo);
595 self.chunk.lines.push(self.line);
596 self.chunk.columns.push(self.column);
597 self.chunk.lines.push(self.line);
598 self.chunk.columns.push(self.column);
599 }
600 Node::TryOperator { operand } => {
601 self.compile_node(operand)?;
602 self.chunk.emit(Op::TryUnwrap, self.line);
603 }
604 // `try* EXPR`: evaluate EXPR; on throw, run pending finally
605 // blocks up to the innermost catch barrier and rethrow the
606 // original value. On success, leave EXPR's value on the stack.
607 //
608 // Per the issue-#26 desugaring:
609 // { let _r = try { EXPR }
610 // guard is_ok(_r) else { throw unwrap_err(_r) }
611 // unwrap(_r) }
612 //
613 // The bytecode realizes this directly: install a try handler
614 // around EXPR so a throw lands in our catch path, where we
615 // pre-run pending finallys and re-emit `Throw`. Skipping the
616 // intermediate Result.Ok/Err wrapping that `TryExpr` does
617 // keeps the success path a no-op (operand value passes through
618 // as-is).
619 Node::TryStar { operand } => {
620 self.compile_try_star(operand)?;
621 }
622 Node::ImplBlock { type_name, methods } => {
623 self.compile_impl_block(type_name, methods)?;
624 }
625 Node::StructDecl { name, fields, .. } => {
626 self.compile_struct_decl(name, fields)?;
627 }
628 // Metadata-only declarations: resolved entirely at compile time
629 // (enum names, type aliases, struct/interface layouts are
630 // pre-scanned), so they emit no bytecode and leave the operand
631 // stack untouched. `produces_value` classifies them as
632 // non-value-producing to match; contexts that require a block to
633 // yield a value (last statement of a block, match-arm body) emit
634 // their own `Nil` placeholder. Emitting one here instead left an
635 // unpopped `Nil` on the stack in every value-discarding context
636 // (`compile_top_level_declarations` pops nothing) — a latent
637 // imbalance surfaced by the #2622 balance assertion.
638 Node::Pipeline { .. }
639 | Node::OverrideDecl { .. }
640 | Node::TypeDecl { .. }
641 | Node::EnumDecl { .. }
642 | Node::InterfaceDecl { .. } => {}
643 Node::TryCatch {
644 has_catch: _,
645 body,
646 error_var,
647 error_type,
648 catch_body,
649 finally_body,
650 } => {
651 self.compile_try_catch(body, error_var, error_type, catch_body, finally_body)?;
652 }
653 Node::TryExpr { body } => {
654 self.compile_try_expr(body)?;
655 }
656 Node::Retry { count, body } => {
657 self.compile_retry(count, body)?;
658 }
659 Node::CostRoute { options, body } => {
660 self.compile_cost_route(options, body)?;
661 }
662 Node::Parallel {
663 mode,
664 expr,
665 variable,
666 body,
667 options,
668 } => {
669 self.compile_parallel(mode, expr, variable, body, options)?;
670 }
671 Node::SpawnExpr { body } => {
672 self.compile_spawn_expr(body)?;
673 }
674 Node::HitlExpr { kind, args } => {
675 self.compile_hitl_expr(*kind, args)?;
676 }
677 Node::SelectExpr {
678 cases,
679 timeout,
680 default_body,
681 } => {
682 self.compile_select_expr(cases, timeout, default_body)?;
683 }
684 Node::Spread(_) => {
685 return Err(CompileError {
686 message: "spread (...) can only be used inside list literals, dict literals, or function call arguments".into(),
687 line: self.line,
688 });
689 }
690 Node::AttributedDecl { attributes, inner } => {
691 self.compile_attributed_decl(attributes, inner)?;
692 }
693 Node::OrPattern(_) => {
694 return Err(CompileError {
695 message: "or-pattern (|) can only appear as a match arm pattern".into(),
696 line: self.line,
697 });
698 }
699 }
700 Ok(())
701 }
702}