Main
main
¶
RESERVED_KEYWORDS = ['let', 'if', 'else', 'true', 'false']
module-attribute
¶
IDENT = re.compile('[a-zA-Z_][a-zA-Z0-9_]*')
module-attribute
¶
INTEGER = re.compile('[0-9]+')
module-attribute
¶
LET = Punctuation(re.compile('let'), "'let'")
module-attribute
¶
EQUAL = Punctuation(re.compile('='), 'equal')
module-attribute
¶
SEMICOLON = Punctuation(re.compile(';'), 'semicolon')
module-attribute
¶
SINGLE_PERIOD = Punctuation(re.compile('\\.(?!\\.)'), 'period')
module-attribute
¶
COMMA = Punctuation(re.compile(','), 'comma')
module-attribute
¶
IF = Punctuation(re.compile('if'), "'if'")
module-attribute
¶
ELSE = Punctuation(re.compile('else'), "'else'")
module-attribute
¶
TRUE = Punctuation(re.compile('true'), "'true'")
module-attribute
¶
FALSE = Punctuation(re.compile('false'), "'false'")
module-attribute
¶
STAR = Punctuation(re.compile('\\*'), 'star')
module-attribute
¶
PLUS = Punctuation(re.compile('\\+'), 'plus')
module-attribute
¶
RANGE = Punctuation(re.compile('\\.\\.'), 'range')
module-attribute
¶
PIPE = Punctuation(re.compile('\\|'), 'pipe')
module-attribute
¶
EQUAL_CMP = Punctuation(re.compile('=='), 'equality comparator')
module-attribute
¶
LT_CMP = Punctuation(re.compile('<'), 'less than comparator')
module-attribute
¶
GT_CMP = Punctuation(re.compile('>'), 'greater than comparator')
module-attribute
¶
LTE_CMP = Punctuation(re.compile('<='), 'less than or equal comparator')
module-attribute
¶
GTE_CMP = Punctuation(re.compile('>='), 'greater than or equal comparator')
module-attribute
¶
NEQ_CMP = Punctuation(re.compile('!='), 'not equal comparator')
module-attribute
¶
BOOL_AND = Punctuation(re.compile('&&'), 'boolean and')
module-attribute
¶
BOOL_OR = Punctuation(re.compile('\\|\\|'), 'boolean or')
module-attribute
¶
BOOL_NEG = Punctuation(re.compile('!'), 'boolean negation')
module-attribute
¶
LPAREN = Punctuation(re.compile('\\('), 'left parenthesis')
module-attribute
¶
RPAREN = Punctuation(re.compile('\\)'), 'right parenthesis')
module-attribute
¶
LCURL = Punctuation(re.compile('\\{'), 'left curly bracket')
module-attribute
¶
RCURL = Punctuation(re.compile('\\}'), 'right curly bracket')
module-attribute
¶
T = TypeVar('T')
module-attribute
¶
PARSE_BINOP_PRIORITY: tuple[tuple[BinaryOp, ...], ...] = ((Multiplication(),), (Addition(),), (ListRange(), Comparator(EQUAL_CMP, 'eq'), Comparator(LTE_CMP, 'ule'), Comparator(GTE_CMP, 'uge'), Comparator(GT_CMP, 'ugt'), Comparator(LT_CMP, 'ult'), Comparator(NEQ_CMP, 'ne')), (BoolAnd(), BoolOr()))
module-attribute
¶
arg_parser = argparse.ArgumentParser(prog='list-lang', description='Parses list-lang programs and transforms them.')
module-attribute
¶
args = arg_parser.parse_args()
module-attribute
¶
code = args.filename.read()
module-attribute
¶
module = program_to_mlir_module(code)
module-attribute
¶
ctx = Context()
module-attribute
¶
Punctuation
dataclass
¶
Binding
dataclass
¶
ParsingContext
¶
BinaryOp
¶
Source code in xdsl/frontend/listlang/main.py
parse_opt_glyph(ctx: ParsingContext) -> Located[bool]
¶
Multiplication
¶
Bases: BinaryOp
Source code in xdsl/frontend/listlang/main.py
parse_opt_glyph(ctx: ParsingContext) -> Located[bool]
¶
build(builder: Builder, lhs: Located[TypedExpression], rhs: Located[TypedExpression]) -> TypedExpression
¶
Source code in xdsl/frontend/listlang/main.py
Addition
¶
Bases: BinaryOp
Source code in xdsl/frontend/listlang/main.py
parse_opt_glyph(ctx: ParsingContext) -> Located[bool]
¶
build(builder: Builder, lhs: Located[TypedExpression], rhs: Located[TypedExpression]) -> TypedExpression
¶
Source code in xdsl/frontend/listlang/main.py
ListRange
¶
Bases: BinaryOp
Source code in xdsl/frontend/listlang/main.py
parse_opt_glyph(ctx: ParsingContext) -> Located[bool]
¶
build(builder: Builder, lhs: Located[TypedExpression], rhs: Located[TypedExpression]) -> TypedExpression
¶
Source code in xdsl/frontend/listlang/main.py
Comparator
dataclass
¶
Bases: BinaryOp
Source code in xdsl/frontend/listlang/main.py
glyph: Punctuation
instance-attribute
¶
arith_code: str
instance-attribute
¶
__init__(glyph: Punctuation, arith_code: str) -> None
¶
parse_opt_glyph(ctx: ParsingContext) -> Located[bool]
¶
build(builder: Builder, lhs: Located[TypedExpression], rhs: Located[TypedExpression]) -> TypedExpression
¶
Source code in xdsl/frontend/listlang/main.py
BoolAnd
¶
Bases: BinaryOp
Source code in xdsl/frontend/listlang/main.py
parse_opt_glyph(ctx: ParsingContext) -> Located[bool]
¶
build(builder: Builder, lhs: Located[TypedExpression], rhs: Located[TypedExpression]) -> TypedExpression
¶
Source code in xdsl/frontend/listlang/main.py
BoolOr
¶
Bases: BinaryOp
Source code in xdsl/frontend/listlang/main.py
parse_opt_glyph(ctx: ParsingContext) -> Located[bool]
¶
build(builder: Builder, lhs: Located[TypedExpression], rhs: Located[TypedExpression]) -> TypedExpression
¶
Source code in xdsl/frontend/listlang/main.py
parse_opt_punct(ctx: ParsingContext, punct: Punctuation) -> Located[bool]
¶
Returns True if the punctuation was successfully parsed.
Source code in xdsl/frontend/listlang/main.py
parse_punct(ctx: ParsingContext, punct: Punctuation) -> Location
¶
parse_opt_identifier(ctx: ParsingContext) -> Located[str | None]
¶
parse_identifier(ctx: ParsingContext) -> Located[str]
¶
parse_opt_integer(ctx: ParsingContext) -> Located[int | None]
¶
parse_integer(ctx: ParsingContext) -> Located[int]
¶
name_hint_without_prefix(value: SSAValue) -> str
¶
Get the name hint of a value, removing a possible underscore prefix if needed.
Source code in xdsl/frontend/listlang/main.py
compose_name_hints(*names: SSAValue | str) -> str
¶
Create a new name hint by composing multiple strings and name hints. The new name hint starts with an underscore, as it is a temporary.
Source code in xdsl/frontend/listlang/main.py
parse_comma_separated(ctx: ParsingContext, p: Callable[[], Located[T | None]]) -> Sequence[Located[T]]
¶
Source code in xdsl/frontend/listlang/main.py
parse_opt_expr(ctx: ParsingContext, builder: Builder) -> Located[TypedExpression | None]
¶
Source code in xdsl/frontend/listlang/main.py
parse_expr(ctx: ParsingContext, builder: Builder) -> Located[TypedExpression]
¶
parse_opt_let_statement(ctx: ParsingContext, builder: Builder) -> Located[bool]
¶
Parses a let statement and adds its binding to the provided context if it is there. Returns True if a binding was found, False otherwise.
Source code in xdsl/frontend/listlang/main.py
parse_opt_statement(ctx: ParsingContext, builder: Builder) -> Located[bool]
¶
parse_block_content(ctx: ParsingContext, builder: Builder) -> Located[Located[TypedExpression | None]]
¶
Parses the content of a block and returns its trailing expression, if there is one. The first location is the start of the block content, while the second location is the start of where the trailing expression is or would be.
Source code in xdsl/frontend/listlang/main.py
parse_opt_block(ctx: ParsingContext, builder: Builder) -> Located[Located[TypedExpression | None] | None]
¶
Parses a block and returns its trailing expression, if there is one. The first location is the start of the block, while the second location is the start of where the trailing expression is or would be.
The scope of bindings within the block is contained, meaning a new scope level is added to the binding dictionary when parsing the block.
Source code in xdsl/frontend/listlang/main.py
parse_block(ctx: ParsingContext, builder: Builder) -> Located[Located[TypedExpression | None]]
¶
Parses a block and returns its trailing expression, if there is one. The first location is the start of the block, while the second location is the start of where the trailing expression is or would be.
The scope of bindings within the block is contained, meaning a new scope level is added to the binding dictionary when parsing the block.
Source code in xdsl/frontend/listlang/main.py
parse_program(code: str, builder: Builder)
¶
Parses a program. Builds the operations associated with the program, and prints the final expression.