Class AstToIrCompiler
Compiles an Abstract Syntax Tree (AST) into Intermediate Representation (IR) nodes.
Implements
Inherited Members
Namespace: VM.Core.IR
Assembly: VM.dll
Syntax
public class AstToIrCompiler : IAstVisitor<List<IrNode>>
Remarks
Implements the visitor pattern to traverse the AST and generate corresponding IR nodes. Handles all major language constructs including statements, expressions, and control flow.
Methods
Visit(AssignIndexStmt)
Compiles an array index assignment into IR nodes.
Declaration
public List<IrNode> Visit(AssignIndexStmt node)
Parameters
| Type | Name | Description |
|---|---|---|
| AssignIndexStmt | node | The index assignment node to compile. |
Returns
| Type | Description |
|---|---|
| List<IrNode> | A list containing a single IrStoreIndex node. |
Visit(BinaryExpr)
Declaration
public List<IrNode> Visit(BinaryExpr node)
Parameters
| Type | Name | Description |
|---|---|---|
| BinaryExpr | node |
Returns
| Type | Description |
|---|---|
| List<IrNode> |
Visit(ContinueStmt)
Compiles a continue statement into IR nodes.
Declaration
public List<IrNode> Visit(ContinueStmt node)
Parameters
| Type | Name | Description |
|---|---|---|
| ContinueStmt | node | The continue statement node to compile. |
Returns
| Type | Description |
|---|---|
| List<IrNode> | A list containing a single IrGoto node with "continue" label. |
Visit(CustomCallExpr)
Declaration
public List<IrNode> Visit(CustomCallExpr node)
Parameters
| Type | Name | Description |
|---|---|---|
| CustomCallExpr | node |
Returns
| Type | Description |
|---|---|
| List<IrNode> |
Visit(ExitStmt)
Compiles a break statement into IR nodes.
Declaration
public List<IrNode> Visit(ExitStmt node)
Parameters
| Type | Name | Description |
|---|---|---|
| ExitStmt | node | The break statement node to compile. |
Returns
| Type | Description |
|---|---|
| List<IrNode> | A list containing a single IrGoto node with "break" label. |
Visit(ExprNode)
Visits an expression node by delegating to its specific Accept method.
Declaration
public List<IrNode> Visit(ExprNode node)
Parameters
| Type | Name | Description |
|---|---|---|
| ExprNode | node | The expression node to visit. |
Returns
| Type | Description |
|---|---|
| List<IrNode> | The result of visiting the specific expression type. |
Visit(ForStmt)
Compiles a for loop into IR nodes.
Declaration
public List<IrNode> Visit(ForStmt node)
Parameters
| Type | Name | Description |
|---|---|---|
| ForStmt | node | The for statement node to compile. |
Returns
| Type | Description |
|---|---|
| List<IrNode> | A list containing a single IrFor node. |
Visit(FuncCallExpr)
Declaration
public List<IrNode> Visit(FuncCallExpr node)
Parameters
| Type | Name | Description |
|---|---|---|
| FuncCallExpr | node |
Returns
| Type | Description |
|---|---|
| List<IrNode> |
Visit(IfStmt)
Compiles an if statement into IR nodes.
Declaration
public List<IrNode> Visit(IfStmt node)
Parameters
| Type | Name | Description |
|---|---|---|
| IfStmt | node | The if statement node to compile. |
Returns
| Type | Description |
|---|---|
| List<IrNode> | A list containing a single IrIf node. |
Visit(IndexExpr)
Throws NotSupportedException as IndexExpr should be handled by CompileExpr.
Declaration
public List<IrNode> Visit(IndexExpr node)
Parameters
| Type | Name | Description |
|---|---|---|
| IndexExpr | node |
Returns
| Type | Description |
|---|---|
| List<IrNode> |
Visit(InputStmt)
Compiles an input statement into IR nodes.
Declaration
public List<IrNode> Visit(InputStmt node)
Parameters
| Type | Name | Description |
|---|---|---|
| InputStmt | node | The input statement node to compile. |
Returns
| Type | Description |
|---|---|
| List<IrNode> | A list containing a single IrInput node. |
Visit(LetStmt)
Compiles a variable declaration (let statement) into IR nodes.
Declaration
public List<IrNode> Visit(LetStmt node)
Parameters
| Type | Name | Description |
|---|---|---|
| LetStmt | node | The let statement node to compile. |
Returns
| Type | Description |
|---|---|
| List<IrNode> | A list containing a single IrLet node. |
Visit(NewArrayExpr)
Compiles a new array expression into IR nodes.
Declaration
public List<IrNode> Visit(NewArrayExpr node)
Parameters
| Type | Name | Description |
|---|---|---|
| NewArrayExpr | node | The new array expression node to compile. |
Returns
| Type | Description |
|---|---|
| List<IrNode> | A list containing a single IrNewArray node. |
Visit(NumberExpr)
Declaration
public List<IrNode> Visit(NumberExpr node)
Parameters
| Type | Name | Description |
|---|---|---|
| NumberExpr | node |
Returns
| Type | Description |
|---|---|
| List<IrNode> |
Visit(PrintStmt)
Compiles a print statement into IR nodes.
Declaration
public List<IrNode> Visit(PrintStmt node)
Parameters
| Type | Name | Description |
|---|---|---|
| PrintStmt | node | The print statement node to compile. |
Returns
| Type | Description |
|---|---|
| List<IrNode> | A list containing a single IrPrint node. |
Visit(ProgramNode)
Visits a ProgramNode and compiles all its statements into IR nodes.
Declaration
public List<IrNode> Visit(ProgramNode node)
Parameters
| Type | Name | Description |
|---|---|---|
| ProgramNode | node | The program node to compile. |
Returns
| Type | Description |
|---|---|
| List<IrNode> | A list of IR nodes representing the program. |
Visit(RepeatStmt)
Compiles a repeat-until loop into IR nodes.
Declaration
public List<IrNode> Visit(RepeatStmt node)
Parameters
| Type | Name | Description |
|---|---|---|
| RepeatStmt | node | The repeat statement node to compile. |
Returns
| Type | Description |
|---|---|
| List<IrNode> | A list containing a single IrRepeat node. |
Visit(StringExpr)
Declaration
public List<IrNode> Visit(StringExpr node)
Parameters
| Type | Name | Description |
|---|---|---|
| StringExpr | node |
Returns
| Type | Description |
|---|---|
| List<IrNode> |
Visit(UnaryExpr)
Declaration
public List<IrNode> Visit(UnaryExpr node)
Parameters
| Type | Name | Description |
|---|---|---|
| UnaryExpr | node |
Returns
| Type | Description |
|---|---|
| List<IrNode> |
Visit(VarExpr)
Declaration
public List<IrNode> Visit(VarExpr node)
Parameters
| Type | Name | Description |
|---|---|---|
| VarExpr | node |
Returns
| Type | Description |
|---|---|
| List<IrNode> |
Visit(WhileStmt)
Compiles a while loop into IR nodes.
Declaration
public List<IrNode> Visit(WhileStmt node)
Parameters
| Type | Name | Description |
|---|---|---|
| WhileStmt | node | The while statement node to compile. |
Returns
| Type | Description |
|---|---|
| List<IrNode> | A list containing a single IrWhile node. |