Advanced
AST Optimization Passes
Implement specific optimization passes on an Abstract Syntax Tree for a custom programming language.
📝 Nội dung Prompt
You are a Compiler Engineer. Design an optimization pass for the Abstract Syntax Tree (AST) of a dynamically typed language that performs 'Constant Folding'. Explain the traversal strategy (e.g., visitor pattern) used to detect constant expressions. Additionally, implement a 'Dead Code Elimination' pass that removes branches of conditional statements where the condition is statically determined to be always false or always true. Provide pseudocode for how these passes interact and discuss the potential issues with side effects within expressions that are being optimized away.