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 if let Some(schema) = self.schema_value_for_alias(name) {
241 self.emit_vm_value_literal(&schema);
242 return Ok(());
243 }
244 self.emit_get_binding(name);
245 }
246 Node::LetBinding { pattern, value, .. } => {
247 let binding_type = match &snode.node {
248 Node::LetBinding {
249 type_ann: Some(type_ann),
250 ..
251 } => Some(type_ann.clone()),
252 _ => self.infer_expr_type(value),
253 };
254 self.compile_node(value)?;
255 self.compile_destructuring(pattern, true)?;
256 // A `let` is reassignable, so its initializer-inferred primitive
257 // type is only safe for typed-opcode specialization when the
258 // binding is provably monomorphic (proven by
259 // `record_monomorphic_var_bindings`, run before this scope's
260 // statements). Otherwise drop the primitive fact so arithmetic
261 // stays on the generic adaptive path, which re-checks operand
262 // shapes at runtime instead of hard-committing to `AddInt` etc.
263 let binding_type = self.gate_mutable_primitive_type(snode.span, binding_type);
264 self.record_binding_type(pattern, binding_type.clone());
265 self.maybe_register_owned_drop(pattern, binding_type.as_ref(), snode.span);
266 }
267 Node::ConstBinding { pattern, value, .. } => {
268 // `const` is an immutable binding. When its initializer is in
269 // the pure const-eval subset over a plain identifier, the
270 // typechecker has already folded it; either way the VM
271 // re-evaluates the same expression, producing the folded value
272 // byte-for-byte. Lowered immutable (destructuring allowed).
273 let binding_type = match &snode.node {
274 Node::ConstBinding {
275 type_ann: Some(type_ann),
276 ..
277 } => Some(type_ann.clone()),
278 _ => self.infer_expr_type(value),
279 };
280 self.compile_node(value)?;
281 self.compile_destructuring(pattern, false)?;
282 self.record_binding_type(pattern, binding_type.clone());
283 self.maybe_register_owned_drop(pattern, binding_type.as_ref(), snode.span);
284 }
285 Node::Assignment {
286 target, value, op, ..
287 } => {
288 self.compile_assignment(target, value, op)?;
289 }
290 Node::BinaryOp { op, left, right } => {
291 self.compile_binary_op(op, left, right)?;
292 }
293 Node::UnaryOp { op, operand } => {
294 self.compile_node(operand)?;
295 match op.as_str() {
296 "-" => self.chunk.emit(Op::Negate, self.line),
297 "!" => self.chunk.emit(Op::Not, self.line),
298 _ => {}
299 }
300 }
301 Node::Ternary {
302 condition,
303 true_expr,
304 false_expr,
305 } => {
306 self.compile_node(condition)?;
307 let else_jump = self.chunk.emit_jump(Op::JumpIfFalse, self.line);
308 self.chunk.emit(Op::Pop, self.line);
309 self.compile_node(true_expr)?;
310 let end_jump = self.chunk.emit_jump(Op::Jump, self.line);
311 self.chunk.patch_jump(else_jump);
312 self.chunk.emit(Op::Pop, self.line);
313 self.compile_node(false_expr)?;
314 self.chunk.patch_jump(end_jump);
315 }
316 Node::FunctionCall { name, args, .. } => {
317 self.compile_function_call(name, args)?;
318 }
319 Node::MethodCall {
320 object,
321 method,
322 args,
323 } => {
324 self.compile_method_call(object, method, args)?;
325 }
326 Node::OptionalMethodCall {
327 object,
328 method,
329 args,
330 } => {
331 self.compile_node(object)?;
332 for arg in args {
333 self.compile_node(arg)?;
334 }
335 let name_idx = self.string_constant(method);
336 self.chunk
337 .emit_method_call_opt(name_idx, args.len() as u8, self.line);
338 }
339 Node::PropertyAccess { object, property } => {
340 self.compile_property_access(object, property)?;
341 }
342 Node::OptionalPropertyAccess { object, property } => {
343 self.compile_node(object)?;
344 let idx = self.string_constant(property);
345 self.chunk.emit_u16(Op::GetPropertyOpt, idx, self.line);
346 }
347 Node::SubscriptAccess { object, index } => {
348 self.compile_node(object)?;
349 self.compile_node(index)?;
350 self.chunk.emit(Op::Subscript, self.line);
351 }
352 Node::OptionalSubscriptAccess { object, index } => {
353 self.compile_node(object)?;
354 self.compile_node(index)?;
355 self.chunk.emit(Op::SubscriptOpt, self.line);
356 }
357 Node::SliceAccess { object, start, end } => {
358 self.compile_node(object)?;
359 if let Some(s) = start {
360 self.compile_node(s)?;
361 } else {
362 self.chunk.emit(Op::Nil, self.line);
363 }
364 if let Some(e) = end {
365 self.compile_node(e)?;
366 } else {
367 self.chunk.emit(Op::Nil, self.line);
368 }
369 self.chunk.emit(Op::Slice, self.line);
370 }
371 Node::IfElse {
372 condition,
373 then_body,
374 else_body,
375 } => {
376 self.compile_if_else(condition, then_body, else_body)?;
377 }
378 Node::WhileLoop { condition, body } => {
379 self.compile_while_loop(condition, body)?;
380 }
381 Node::ForIn {
382 pattern,
383 iterable,
384 body,
385 } => {
386 self.compile_for_in(pattern, iterable, body)?;
387 }
388 Node::ReturnStmt { value } => {
389 self.compile_return_stmt(value)?;
390 }
391 Node::BreakStmt => {
392 self.compile_break_stmt()?;
393 }
394 Node::ContinueStmt => {
395 self.compile_continue_stmt()?;
396 }
397 Node::ListLiteral(elements) => {
398 self.compile_list_literal(elements)?;
399 }
400 Node::DictLiteral(entries) => {
401 self.compile_dict_literal(entries)?;
402 }
403 Node::InterpolatedString(segments) => {
404 self.compile_interpolated_string(segments)?;
405 }
406 Node::FnDecl {
407 name,
408 type_params,
409 params,
410 body,
411 is_stream,
412 ..
413 } => {
414 self.compile_fn_decl(name, type_params, params, body, *is_stream)?;
415 }
416 Node::ToolDecl {
417 name,
418 description,
419 params,
420 return_type,
421 body,
422 ..
423 } => {
424 self.compile_tool_decl(name, description, params, return_type, body)?;
425 }
426 Node::SkillDecl { name, fields, .. } => {
427 self.compile_skill_decl(name, fields)?;
428 }
429 Node::EvalPackDecl {
430 binding_name,
431 pack_id,
432 fields,
433 body,
434 summarize,
435 ..
436 } => {
437 self.compile_eval_pack_decl(binding_name, pack_id, fields, body, summarize, true)?;
438 }
439 Node::Closure { params, body, .. } => {
440 self.compile_closure(params, body)?;
441 }
442 Node::ThrowStmt { value } => {
443 self.compile_throw_stmt(value)?;
444 }
445 Node::MatchExpr { value, arms } => {
446 self.compile_match_expr(value, arms)?;
447 }
448 Node::RangeExpr {
449 start,
450 end,
451 inclusive,
452 } => {
453 let name_idx = self.string_constant("__range__");
454 self.chunk.emit_u16(Op::Constant, name_idx, self.line);
455 self.compile_node(start)?;
456 self.compile_node(end)?;
457 if *inclusive {
458 self.chunk.emit(Op::True, self.line);
459 } else {
460 self.chunk.emit(Op::False, self.line);
461 }
462 self.chunk.emit_u8(Op::Call, 3, self.line);
463 }
464 Node::GuardStmt {
465 condition,
466 else_body,
467 } => {
468 self.compile_guard_stmt(condition, else_body)?;
469 }
470 Node::RequireStmt { condition, message } => {
471 self.compile_node(condition)?;
472 let ok_jump = self.chunk.emit_jump(Op::JumpIfTrue, self.line);
473 self.chunk.emit(Op::Pop, self.line);
474 if let Some(message) = message {
475 self.compile_node(message)?;
476 } else {
477 let idx = self.string_constant("require condition failed");
478 self.chunk.emit_u16(Op::Constant, idx, self.line);
479 }
480 self.chunk.emit(Op::Throw, self.line);
481 self.chunk.patch_jump(ok_jump);
482 self.chunk.emit(Op::Pop, self.line);
483 }
484 Node::Block(stmts) => {
485 self.compile_scoped_block(stmts)?;
486 }
487 Node::DeadlineBlock { duration, body } => {
488 self.compile_node(duration)?;
489 self.chunk.emit(Op::DeadlineSetup, self.line);
490 self.compile_scoped_block(body)?;
491 self.chunk.emit(Op::DeadlineEnd, self.line);
492 }
493 Node::MutexBlock { key, body } => {
494 self.begin_scope();
495 let finally_floor = self.finally_bodies.len();
496 match key {
497 // `mutex(resource) { ... }`: evaluate the resource and key
498 // the lock on its structural value at runtime.
499 Some(key_expr) => {
500 self.compile_node(key_expr)?;
501 self.chunk.emit(Op::SyncMutexEnterKeyed, self.line);
502 }
503 // `mutex { ... }`: key on the lexical call-site (computed in
504 // the VM from the chunk + instruction pointer) so distinct
505 // blocks don't contend on one global lock.
506 None => {
507 self.chunk.emit(Op::SyncMutexEnter, self.line);
508 }
509 }
510 for sn in body {
511 self.compile_discarded_stmt(sn)?;
512 }
513 self.drain_finallys_to_floor(finally_floor)?;
514 self.chunk.emit(Op::Nil, self.line);
515 self.end_scope();
516 }
517 Node::ScopeBlock { body } => {
518 // Structured-concurrency nursery. `TaskScopeEnter` pushes a task
519 // scope; tasks spawned inside register to it. `TaskScopeExit`
520 // joins them (propagating the first error, cancelling the rest).
521 // On `throw`/early exit the scope is unwound and its tasks
522 // cancelled by the frame/handler teardown, mirroring
523 // `held_sync_guards`.
524 self.begin_scope();
525 let finally_floor = self.finally_bodies.len();
526 self.chunk.emit(Op::TaskScopeEnter, self.line);
527 for sn in body {
528 self.compile_discarded_stmt(sn)?;
529 }
530 self.drain_finallys_to_floor(finally_floor)?;
531 self.chunk.emit(Op::TaskScopeExit, self.line);
532 self.chunk.emit(Op::Nil, self.line);
533 self.end_scope();
534 }
535 Node::DeferStmt { body } => {
536 // Register the body to run on return/throw/scope-exit. The
537 // statement emits no bytecode of its own — the deferred body
538 // is inlined later by the finally-draining machinery — so it
539 // leaves the operand stack untouched, matching
540 // `produces_value` == false. Emitting a `Nil` here instead
541 // leaked an unpopped slot per execution, which in a loop body
542 // grew the operand stack without bound (surfaced by the
543 // #2622 balance assertion).
544 self.finally_bodies
545 .push(FinallyEntry::Finally(body.clone()));
546 }
547 Node::YieldExpr { value } => {
548 if let Some(val) = value {
549 self.compile_node(val)?;
550 } else {
551 self.chunk.emit(Op::Nil, self.line);
552 }
553 self.chunk.emit(Op::Yield, self.line);
554 }
555 Node::EmitExpr { value } => {
556 self.compile_node(value)?;
557 self.chunk.emit(Op::Yield, self.line);
558 }
559 Node::EnumConstruct {
560 enum_name,
561 variant,
562 args,
563 } => {
564 self.compile_enum_construct(enum_name, variant, args)?;
565 }
566 Node::StructConstruct {
567 struct_name,
568 fields,
569 } => {
570 self.compile_struct_construct(struct_name, fields)?;
571 }
572 Node::ImportDecl { path, .. } => {
573 let idx = self.string_constant(path);
574 self.chunk.emit_u16(Op::Import, idx, self.line);
575 }
576 Node::SelectiveImport { names, path, .. } => {
577 let path_idx = self.string_constant(path);
578 let names_str = names.join(",");
579 let names_idx = self.owned_string_constant(names_str);
580 self.chunk
581 .emit_u16(Op::SelectiveImport, path_idx, self.line);
582 let hi = (names_idx >> 8) as u8;
583 let lo = names_idx as u8;
584 self.chunk.code.push(hi);
585 self.chunk.code.push(lo);
586 self.chunk.lines.push(self.line);
587 self.chunk.columns.push(self.column);
588 self.chunk.lines.push(self.line);
589 self.chunk.columns.push(self.column);
590 }
591 Node::TryOperator { operand } => {
592 self.compile_node(operand)?;
593 self.chunk.emit(Op::TryUnwrap, self.line);
594 }
595 // `try* EXPR`: evaluate EXPR; on throw, run pending finally
596 // blocks up to the innermost catch barrier and rethrow the
597 // original value. On success, leave EXPR's value on the stack.
598 //
599 // Per the issue-#26 desugaring:
600 // { let _r = try { EXPR }
601 // guard is_ok(_r) else { throw unwrap_err(_r) }
602 // unwrap(_r) }
603 //
604 // The bytecode realizes this directly: install a try handler
605 // around EXPR so a throw lands in our catch path, where we
606 // pre-run pending finallys and re-emit `Throw`. Skipping the
607 // intermediate Result.Ok/Err wrapping that `TryExpr` does
608 // keeps the success path a no-op (operand value passes through
609 // as-is).
610 Node::TryStar { operand } => {
611 self.compile_try_star(operand)?;
612 }
613 Node::ImplBlock { type_name, methods } => {
614 self.compile_impl_block(type_name, methods)?;
615 }
616 Node::StructDecl { name, fields, .. } => {
617 self.compile_struct_decl(name, fields)?;
618 }
619 // Metadata-only declarations: enum names, struct/interface
620 // layouts, and type aliases are pre-scanned, so they emit no
621 // bytecode and leave the operand stack untouched. Type-alias names
622 // in expression position lower directly to schema constants in the
623 // `Identifier` arm above; eagerly binding every alias at top level
624 // bloats large module init chunks past the VM's 64 KiB jump limit.
625 // `produces_value` classifies them as non-value-producing to match;
626 // contexts that require a block to yield a value (last statement of
627 // a block, match-arm body) emit their own `Nil` placeholder.
628 // Emitting one here instead left an unpopped `Nil` on the stack in
629 // every value-discarding context (`compile_top_level_declarations`
630 // pops nothing) — a latent imbalance surfaced by the #2622 balance
631 // assertion.
632 Node::Pipeline { .. }
633 | Node::OverrideDecl { .. }
634 | Node::TypeDecl { .. }
635 | Node::EnumDecl { .. }
636 | Node::InterfaceDecl { .. } => {}
637 Node::TryCatch {
638 has_catch: _,
639 body,
640 error_var,
641 error_type,
642 catch_body,
643 finally_body,
644 } => {
645 self.compile_try_catch(body, error_var, error_type, catch_body, finally_body)?;
646 }
647 Node::TryExpr { body } => {
648 self.compile_try_expr(body)?;
649 }
650 Node::Retry { count, body } => {
651 self.compile_retry(count, body)?;
652 }
653 Node::CostRoute { options, body } => {
654 self.compile_cost_route(options, body)?;
655 }
656 Node::Parallel {
657 mode,
658 expr,
659 variable,
660 body,
661 options,
662 } => {
663 self.compile_parallel(mode, expr, variable, body, options)?;
664 }
665 Node::SpawnExpr { body } => {
666 self.compile_spawn_expr(body)?;
667 }
668 Node::HitlExpr { kind, args } => {
669 self.compile_hitl_expr(*kind, args)?;
670 }
671 Node::SelectExpr {
672 cases,
673 timeout,
674 default_body,
675 } => {
676 self.compile_select_expr(cases, timeout, default_body)?;
677 }
678 Node::Spread(_) => {
679 return Err(CompileError {
680 message: "spread (...) can only be used inside list literals, dict literals, or function call arguments".into(),
681 line: self.line,
682 });
683 }
684 Node::AttributedDecl { attributes, inner } => {
685 self.compile_attributed_decl(attributes, inner)?;
686 }
687 Node::OrPattern(_) => {
688 return Err(CompileError {
689 message: "or-pattern (|) can only appear as a match arm pattern".into(),
690 line: self.line,
691 });
692 }
693 }
694 Ok(())
695 }
696}