Python Compilation API#
cutile_basic#
BASIC to CUDA Tile IR compiler.
- cutile_basic.compile_basic_to_cubin(
- source: str,
- *,
- gpu_arch: str | None = None,
- array_size: int | None = None,
- num_ctas: int | None = None,
Compile BASIC source to a .cubin via the bytecode backend.
- Parameters:
source – BASIC source code.
gpu_arch – Target GPU architecture (e.g.
"sm_120").Noneauto-detects from the current device.array_size – Total elements per array;
Noneinfers from DIM.num_ctas – CTAs-per-CGA optimisation hint;
Nonedisables.
- Returns:
A
CompilationResultwithcubin_pathand kernelmeta.
cutile_basic.bytecode#
Bytecode backend: AST → cuTile bytecode.
- class cutile_basic.bytecode.BytecodeBackend(
- analyzed: AnalyzedProgram,
- gpu_arch: str = 'sm_120',
- array_size: int | None = None,
- num_ctas: int | None = None,
Compile an AnalyzedProgram directly to cuTile bytecode.
- class cutile_basic.bytecode.CompilationResult(cubin_path: str, meta: dict)[source]#
Result of compiling BASIC source to a .cubin file.
- cutile_basic.bytecode.compile_basic_to_cubin(
- source: str,
- *,
- gpu_arch: str | None = None,
- array_size: int | None = None,
- num_ctas: int | None = None,
Compile BASIC source to a .cubin via the bytecode backend.
- Parameters:
source – BASIC source code.
gpu_arch – Target GPU architecture (e.g.
"sm_120").Noneauto-detects from the current device.array_size – Total elements per array;
Noneinfers from DIM.num_ctas – CTAs-per-CGA optimisation hint;
Nonedisables.
- Returns:
A
CompilationResultwithcubin_pathand kernelmeta.
cutile_basic.gpu#
GPU utilities (architecture detection, etc.).
cutile_basic.cli#
CLI entry point for the BASIC to CUDA Tile IR compiler.
Internals#
These modules implement the compiler pipeline stages. They are used by the public API and CLI but can also be imported directly.
cutile_basic.tokens#
Token types and Token dataclass for the BASIC lexer.
- class cutile_basic.tokens.TokenType(*values)[source]#
- INTEGER = 1#
- FLOAT = 2#
- STRING = 3#
- IDENTIFIER = 4#
- LET = 5#
- PRINT = 6#
- INPUT = 7#
- IF = 8#
- THEN = 9#
- ELSE = 10#
- ENDIF = 11#
- FOR = 12#
- TO = 13#
- STEP = 14#
- NEXT = 15#
- WHILE = 16#
- WEND = 17#
- GOTO = 18#
- GOSUB = 19#
- RETURN = 20#
- DIM = 21#
- REM = 22#
- DATA = 23#
- READ = 24#
- END = 25#
- STOP = 26#
- AND = 27#
- OR = 28#
- NOT = 29#
- MOD = 30#
- OUTPUT = 31#
- TILE = 32#
- BID = 33#
- PLUS = 34#
- MINUS = 35#
- STAR = 36#
- SLASH = 37#
- CARET = 38#
- EQ = 39#
- NEQ = 40#
- LT = 41#
- GT = 42#
- LE = 43#
- GE = 44#
- LPAREN = 45#
- RPAREN = 46#
- COMMA = 47#
- SEMICOLON = 48#
- NEWLINE = 49#
- EOF = 50#
- COLON = 51#
cutile_basic.lexer#
Lexer for BASIC source code.
cutile_basic.ast_nodes#
AST node classes for the BASIC parser.
- class cutile_basic.ast_nodes.NumberLiteral(value: 'float | int', line: 'int' = 0)[source]#
- value: float | int#
- line: int = 0#
- class cutile_basic.ast_nodes.StringLiteral(value: 'str', line: 'int' = 0)[source]#
- value: str#
- line: int = 0#
- class cutile_basic.ast_nodes.Variable(name: 'str', line: 'int' = 0)[source]#
- name: str#
- line: int = 0#
- class cutile_basic.ast_nodes.ArrayAccess(
- name: 'str',
- index: 'Expression',
- index2: 'Expression | None' = None,
- line: 'int' = 0,
- name: str#
- index: NumberLiteral | StringLiteral | Variable | ArrayAccess | UnaryOp | BinaryOp | FunctionCall#
- index2: NumberLiteral | StringLiteral | Variable | ArrayAccess | UnaryOp | BinaryOp | FunctionCall | None = None#
- line: int = 0#
- class cutile_basic.ast_nodes.UnaryOp(op: 'str', operand: 'Expression', line: 'int' = 0)[source]#
- op: str#
- operand: NumberLiteral | StringLiteral | Variable | ArrayAccess | UnaryOp | BinaryOp | FunctionCall#
- line: int = 0#
- class cutile_basic.ast_nodes.BinaryOp(
- op: 'str',
- left: 'Expression',
- right: 'Expression',
- line: 'int' = 0,
- op: str#
- left: NumberLiteral | StringLiteral | Variable | ArrayAccess | UnaryOp | BinaryOp | FunctionCall#
- right: NumberLiteral | StringLiteral | Variable | ArrayAccess | UnaryOp | BinaryOp | FunctionCall#
- line: int = 0#
- class cutile_basic.ast_nodes.FunctionCall(name: 'str', args: 'list[Expression]', line: 'int' = 0)[source]#
- name: str#
- args: list[NumberLiteral | StringLiteral | Variable | ArrayAccess | UnaryOp | BinaryOp | FunctionCall]#
- line: int = 0#
- class cutile_basic.ast_nodes.LetStatement(
- target: 'Variable | ArrayAccess',
- value: 'Expression',
- line: 'int' = 0,
- target: Variable | ArrayAccess#
- value: NumberLiteral | StringLiteral | Variable | ArrayAccess | UnaryOp | BinaryOp | FunctionCall#
- line: int = 0#
- class cutile_basic.ast_nodes.PrintStatement(
- items: 'list[Expression]',
- newline: 'bool' = True,
- line: 'int' = 0,
- items: list[NumberLiteral | StringLiteral | Variable | ArrayAccess | UnaryOp | BinaryOp | FunctionCall]#
- newline: bool = True#
- line: int = 0#
- class cutile_basic.ast_nodes.InputStatement(
- prompt: 'Optional[str]',
- variables: 'list[Variable]',
- is_array: 'list[bool]' = <factory>,
- line: 'int' = 0,
- prompt: str | None#
- is_array: list[bool]#
- line: int = 0#
- class cutile_basic.ast_nodes.IfStatement(
- condition: 'Expression',
- then_body: 'list[Statement]',
- else_body: 'list[Statement]',
- line: 'int' = 0,
- condition: NumberLiteral | StringLiteral | Variable | ArrayAccess | UnaryOp | BinaryOp | FunctionCall#
- then_body: list[LetStatement | PrintStatement | InputStatement | IfStatement | ForStatement | WhileStatement | GotoStatement | GosubStatement | ReturnStatement | DimStatement | RemStatement | DataStatement | ReadStatement | EndStatement | StopStatement | TileStatement | OutputStatement]#
- else_body: list[LetStatement | PrintStatement | InputStatement | IfStatement | ForStatement | WhileStatement | GotoStatement | GosubStatement | ReturnStatement | DimStatement | RemStatement | DataStatement | ReadStatement | EndStatement | StopStatement | TileStatement | OutputStatement]#
- line: int = 0#
- class cutile_basic.ast_nodes.ForStatement(
- var: 'Variable',
- start: 'Expression',
- end: 'Expression',
- step: 'Optional[Expression]',
- body: 'list[Statement]',
- line: 'int' = 0,
-
- start: NumberLiteral | StringLiteral | Variable | ArrayAccess | UnaryOp | BinaryOp | FunctionCall#
- end: NumberLiteral | StringLiteral | Variable | ArrayAccess | UnaryOp | BinaryOp | FunctionCall#
- step: NumberLiteral | StringLiteral | Variable | ArrayAccess | UnaryOp | BinaryOp | FunctionCall | None#
- body: list[LetStatement | PrintStatement | InputStatement | IfStatement | ForStatement | WhileStatement | GotoStatement | GosubStatement | ReturnStatement | DimStatement | RemStatement | DataStatement | ReadStatement | EndStatement | StopStatement | TileStatement | OutputStatement]#
- line: int = 0#
- class cutile_basic.ast_nodes.WhileStatement(
- condition: 'Expression',
- body: 'list[Statement]',
- line: 'int' = 0,
- condition: NumberLiteral | StringLiteral | Variable | ArrayAccess | UnaryOp | BinaryOp | FunctionCall#
- body: list[LetStatement | PrintStatement | InputStatement | IfStatement | ForStatement | WhileStatement | GotoStatement | GosubStatement | ReturnStatement | DimStatement | RemStatement | DataStatement | ReadStatement | EndStatement | StopStatement | TileStatement | OutputStatement]#
- line: int = 0#
- class cutile_basic.ast_nodes.GotoStatement(target: 'int', line: 'int' = 0)[source]#
- target: int#
- line: int = 0#
- class cutile_basic.ast_nodes.GosubStatement(target: 'int', line: 'int' = 0)[source]#
- target: int#
- line: int = 0#
- class cutile_basic.ast_nodes.DimStatement(name: 'str', sizes: 'list[Expression]', line: 'int' = 0)[source]#
- name: str#
- sizes: list[NumberLiteral | StringLiteral | Variable | ArrayAccess | UnaryOp | BinaryOp | FunctionCall]#
- line: int = 0#
- class cutile_basic.ast_nodes.RemStatement(comment: 'str', line: 'int' = 0)[source]#
- comment: str#
- line: int = 0#
- class cutile_basic.ast_nodes.DataStatement(values: 'list[float | int | str]', line: 'int' = 0)[source]#
- values: list[float | int | str]#
- line: int = 0#
- class cutile_basic.ast_nodes.ReadStatement(variables: 'list[Variable]', line: 'int' = 0)[source]#
-
- line: int = 0#
- class cutile_basic.ast_nodes.TileStatement(name: 'str', sizes: 'list[Expression]', line: 'int' = 0)[source]#
- name: str#
- sizes: list[NumberLiteral | StringLiteral | Variable | ArrayAccess | UnaryOp | BinaryOp | FunctionCall]#
- line: int = 0#
- class cutile_basic.ast_nodes.OutputStatement(variables: 'list[Variable]', line: 'int' = 0)[source]#
-
- line: int = 0#
- class cutile_basic.ast_nodes.Program(
- statements: 'list[Statement]',
- line_map: 'dict[int,
- int]'=<factory>,
- statements: list[LetStatement | PrintStatement | InputStatement | IfStatement | ForStatement | WhileStatement | GotoStatement | GosubStatement | ReturnStatement | DimStatement | RemStatement | DataStatement | ReadStatement | EndStatement | StopStatement | TileStatement | OutputStatement]#
- line_map: dict[int, int]#
cutile_basic.parser#
Recursive descent parser for BASIC.
- class cutile_basic.parser.Parser(tokens: list[Token])[source]#
-
- parse_statement() LetStatement | PrintStatement | InputStatement | IfStatement | ForStatement | WhileStatement | GotoStatement | GosubStatement | ReturnStatement | DimStatement | RemStatement | DataStatement | ReadStatement | EndStatement | StopStatement | TileStatement | OutputStatement[source]#
- parse_let() LetStatement[source]#
- parse_implicit_let() LetStatement[source]#
- parse_lvalue() Variable | ArrayAccess[source]#
- parse_print() PrintStatement[source]#
- parse_input() InputStatement[source]#
- parse_if() IfStatement[source]#
- parse_for() ForStatement[source]#
- parse_while() WhileStatement[source]#
- parse_goto() GotoStatement[source]#
- parse_gosub() GosubStatement[source]#
- parse_dim() DimStatement | list[DimStatement][source]#
- parse_data() DataStatement[source]#
- parse_output() OutputStatement[source]#
- parse_tile() TileStatement | list[TileStatement][source]#
- parse_read() ReadStatement[source]#
- parse_expression() NumberLiteral | StringLiteral | Variable | ArrayAccess | UnaryOp | BinaryOp | FunctionCall[source]#
- parse_or() NumberLiteral | StringLiteral | Variable | ArrayAccess | UnaryOp | BinaryOp | FunctionCall[source]#
- parse_and() NumberLiteral | StringLiteral | Variable | ArrayAccess | UnaryOp | BinaryOp | FunctionCall[source]#
- parse_not() NumberLiteral | StringLiteral | Variable | ArrayAccess | UnaryOp | BinaryOp | FunctionCall[source]#
- parse_comparison() NumberLiteral | StringLiteral | Variable | ArrayAccess | UnaryOp | BinaryOp | FunctionCall[source]#
- parse_addition() NumberLiteral | StringLiteral | Variable | ArrayAccess | UnaryOp | BinaryOp | FunctionCall[source]#
- parse_multiplication() NumberLiteral | StringLiteral | Variable | ArrayAccess | UnaryOp | BinaryOp | FunctionCall[source]#
- parse_power() NumberLiteral | StringLiteral | Variable | ArrayAccess | UnaryOp | BinaryOp | FunctionCall[source]#
- parse_unary() NumberLiteral | StringLiteral | Variable | ArrayAccess | UnaryOp | BinaryOp | FunctionCall[source]#
- parse_primary() NumberLiteral | StringLiteral | Variable | ArrayAccess | UnaryOp | BinaryOp | FunctionCall[source]#
cutile_basic.analyzer#
Semantic analyzer: type inference, INPUT/OUTPUT tracking, DATA/READ collection.
- class cutile_basic.analyzer.SymbolInfo(
- name: 'str',
- type: 'BasicType',
- is_array: 'bool' = False,
- array_size: 'int | None' = None,
- tile_shape: 'list[int] | None' = None,
- name: str#
- is_array: bool = False#
- array_size: int | None = None#
- tile_shape: list[int] | None = None#
- class cutile_basic.analyzer.AnalyzedProgram(
- statements: 'list[ast.Statement]',
- symbols: 'dict[str, SymbolInfo]',
- data_values: 'list[float | int]',
- input_vars: 'list[str]',
- output_vars: 'list[str]' = None,
- has_goto: 'bool' = False,
- statements: list[LetStatement | PrintStatement | InputStatement | IfStatement | ForStatement | WhileStatement | GotoStatement | GosubStatement | ReturnStatement | DimStatement | RemStatement | DataStatement | ReadStatement | EndStatement | StopStatement | TileStatement | OutputStatement]#
- symbols: dict[str, SymbolInfo]#
- data_values: list[float | int]#
- input_vars: list[str]#
- output_vars: list[str] = None#
- has_goto: bool = False#
- class cutile_basic.analyzer.Analyzer[source]#
- symbols: dict[str, SymbolInfo]#
- data_values: list[float | int]#
- input_vars: list[str]#
- output_vars: list[str]#
- goto_targets: set[int]#
- analyze(
- program: Program,
- cutile_basic.analyzer.analyze(
- program: Program,
Analyze a parsed BASIC program.