Skip to content

astx

Modules:

Classes:

Functions:

AddBinOp

Bases: BinaryOp

ArrowInt32ArrayLength

ArrowInt32ArrayLength(values: list[AST])

Bases: DataType

Build an Arrow int32 array using the IRX runtime, then return its length. attributes: values: type: list[astx.AST] type_: type: astx.Int32

Methods:

Source code in src/irx/astx/arrow.py
25
26
27
28
29
30
31
32
33
34
def __init__(self, values: list[astx.AST]) -> None:
    """
    title: Initialize ArrowInt32ArrayLength.
    parameters:
      values:
        type: list[astx.AST]
    """
    super().__init__()
    self.values = values
    self.type_ = astx.Int32()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in src/irx/astx/arrow.py
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
def get_struct(self, simplified: bool = False) -> astx.base.ReprStruct:
    """
    title: Return the structured representation of the Arrow helper.
    parameters:
      simplified:
        type: bool
    returns:
      type: astx.base.ReprStruct
    """
    key = "ArrowInt32ArrayLength"
    value = cast(
        astx.base.ReprStruct,
        [item.get_struct(simplified) for item in self.values],
    )
    return self._prepare_struct(key, value, simplified)

AssignmentBinOp

Bases: BinaryOp

BitAndBinOp

Bases: BinaryOp

BitOrBinOp

Bases: BinaryOp

BitXorBinOp

Bases: BinaryOp

Cast

Cast(value: AST, target_type: Any)

Bases: Expr

Methods:

Source code in src/irx/astx/system.py
68
69
70
71
72
73
74
75
76
77
78
79
def __init__(self, value: astx.AST, target_type: Any) -> None:
    """
    title: Initialize Cast.
    parameters:
      value:
        type: astx.AST
      target_type:
        type: Any
    """
    super().__init__()
    self.value = value
    self.target_type = target_type

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in src/irx/astx/system.py
81
82
83
84
85
86
87
88
89
90
91
92
def get_struct(self, simplified: bool = False) -> astx.base.ReprStruct:
    """
    title: Return the structured representation of the cast expression.
    parameters:
      simplified:
        type: bool
    returns:
      type: astx.base.ReprStruct
    """
    key = f"Cast[{self.target_type}]"
    value = self.value.get_struct(simplified)
    return self._prepare_struct(key, value, simplified)

DivBinOp

Bases: BinaryOp

EqBinOp

Bases: BinaryOp

GeBinOp

Bases: BinaryOp

GtBinOp

Bases: BinaryOp

LeBinOp

Bases: BinaryOp

LogicalAndBinOp

Bases: BinaryOp

LogicalOrBinOp

Bases: BinaryOp

LtBinOp

Bases: BinaryOp

ModBinOp

Bases: BinaryOp

MulBinOp

Bases: BinaryOp

NeBinOp

Bases: BinaryOp

PrintExpr

PrintExpr(message: Expr)

Bases: Expr

It would be nice to support more arguments similar to the ones supported by Python (*args, sep=' ', end='', file=None, flush=False).

Methods:

Source code in src/irx/astx/system.py
29
30
31
32
33
34
35
36
37
38
def __init__(self, message: astx.Expr) -> None:
    """
    title: Initialize the PrintExpr.
    parameters:
      message:
        type: astx.Expr
    """
    super().__init__()
    self.message = message
    self._name = f"print_msg_{next(PrintExpr._counter)}"

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in src/irx/astx/system.py
40
41
42
43
44
45
46
47
48
49
50
51
def get_struct(self, simplified: bool = False) -> astx.base.ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: astx.base.ReprStruct
    """
    key = f"FunctionCall[{self}]"
    value = self.message.get_struct(simplified)
    return self._prepare_struct(key, value, simplified)

SubBinOp

Bases: BinaryOp

binary_op_type_for_opcode

binary_op_type_for_opcode(op_code: str) -> type[BinaryOp]
Source code in src/irx/astx/binary_op.py
137
138
139
140
141
142
143
144
145
146
def binary_op_type_for_opcode(op_code: str) -> type[astx.BinaryOp]:
    """
    title: Return the specialized BinaryOp subclass for an opcode.
    parameters:
      op_code:
        type: str
    returns:
      type: type[astx.BinaryOp]
    """
    return _BINARY_OP_TYPES.get(op_code, astx.BinaryOp)

specialize_binary_op

specialize_binary_op(node: BinaryOp) -> BinaryOp
Source code in src/irx/astx/binary_op.py
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
def specialize_binary_op(node: astx.BinaryOp) -> astx.BinaryOp:
    """
    title: Return a specialized BinaryOp instance for the given opcode.
    parameters:
      node:
        type: astx.BinaryOp
    returns:
      type: astx.BinaryOp
    """
    target_type = binary_op_type_for_opcode(node.op_code)
    if target_type is astx.BinaryOp or isinstance(node, target_type):
        return node

    specialized = target_type(
        node.op_code,
        node.lhs,
        node.rhs,
        loc=node.loc,
        parent=node.parent,
    )
    specialized.__dict__.update(vars(node))
    return specialized