jetcrab\bytecode\statements/
try_catch.rs

1use crate::ast::Node;
2use crate::vm::instructions::Instruction;
3
4use super::ControlFlowCore;
5
6pub fn generate_try_statement<T>(this: &mut T, node: &Node)
7where
8    T: ControlFlowCore,
9{
10    if let Node::TryStatement(stmt) = node {
11        // For now, implement a simplified version
12        // Generate try block
13        this.visit_node(&stmt.block);
14
15        // Generate catch clause if present
16        if let Some(handler) = &stmt.handler {
17            generate_catch_clause(this, handler);
18        }
19
20        // Generate finally block if present
21        if let Some(finalizer) = &stmt.finalizer {
22            this.visit_node(finalizer);
23        }
24    }
25}
26
27pub fn generate_catch_clause<T>(this: &mut T, node: &Node)
28where
29    T: ControlFlowCore,
30{
31    if let Node::CatchClause(clause) = node {
32        // For now, implement a simplified version
33        // Generate catch parameter
34        this.visit_node(&clause.param);
35
36        // Generate catch body
37        this.visit_node(&clause.body);
38    }
39}
40
41pub fn generate_throw_statement<T>(this: &mut T, node: &Node)
42where
43    T: ControlFlowCore,
44{
45    if let Node::ThrowStatement(stmt) = node {
46        this.visit_node(&stmt.argument);
47        this.instructions().push(Instruction::Throw);
48    }
49}