Skip to content

base

Define the public irx API.

Builder

Builder()

Bases: ABC

ASTx Builder.

Source code in src/irx/builders/base.py
120
121
122
123
124
125
126
127
128
129
130
131
def __init__(self) -> None:
    """Initialize Builder object."""
    self.translator = BuilderVisitor()
    self.tmp_path = ""
    self.output_file = ""
    self.sh_args: Dict[str, Any] = dict(
        _in=sys.stdin,
        _out=sys.stdout,
        _err=sys.stderr,
        _env=os.environ,
        # _new_session=True,
    )

build abstractmethod

build(expr: AST, output_file: str) -> None

Transpile ASTx to LLVM-IR and build an executable file.

Source code in src/irx/builders/base.py
141
142
143
144
145
146
147
148
@abstractmethod
def build(
    self,
    expr: astx.AST,
    output_file: str,  # noqa: F841, RUF100
) -> None:
    """Transpile ASTx to LLVM-IR and build an executable file."""
    ...

module

module() -> Module

Create a new ASTx Module.

Source code in src/irx/builders/base.py
133
134
135
def module(self) -> astx.Module:
    """Create a new ASTx Module."""
    return astx.Module()

run abstractmethod

run() -> None

Run the generated executable.

Source code in src/irx/builders/base.py
150
151
152
153
@abstractmethod
def run(self) -> None:
    """Run the generated executable."""
    ...

translate

translate(expr: AST) -> str

Transpile ASTx to LLVM-IR.

Source code in src/irx/builders/base.py
137
138
139
def translate(self, expr: astx.AST) -> str:
    """Transpile ASTx to LLVM-IR."""
    return self.translator.translate(expr)

BuilderVisitor

Builder translator visitor.

translate

translate(expr: AST) -> str

Translate an ASTx expression to string.

Example of how it could be implemented:

self.visit(expr)
return str(self.result)
Source code in src/irx/builders/base.py
19
20
21
22
23
24
25
26
27
28
def translate(self, expr: astx.AST) -> str:
    """
    Translate an ASTx expression to string.

    Example of how it could be implemented:

        self.visit(expr)
        return str(self.result)
    """
    raise Exception("Not implemented yet.")

visit

visit(expr: VariableDeclaration) -> None

Translate an ASTx VariableDeclaration expression.

Source code in src/irx/builders/base.py
105
106
107
108
@dispatch  # type: ignore[no-redef]
def visit(self, expr: astx.VariableDeclaration) -> None:
    """Translate an ASTx VariableDeclaration expression."""
    raise Exception("Not implemented yet.")