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
Source code in xdsl/frontend/listlang/main.py
33 34 35 36 | |
rg: re.Pattern[str]
instance-attribute
name: str
instance-attribute
__init__(rg: re.Pattern[str], name: str) -> None
Binding
dataclass
Source code in xdsl/frontend/listlang/main.py
73 74 75 76 | |
value: SSAValue
instance-attribute
typ: ListLangType
instance-attribute
__init__(value: SSAValue, typ: ListLangType) -> None
ParsingContext
Source code in xdsl/frontend/listlang/main.py
79 80 81 82 83 84 85 86 87 88 | |
cursor: CodeCursor = CodeCursor(code)
instance-attribute
bindings: ScopedDict[str, Binding] = ScopedDict()
instance-attribute
__init__(code: str)
Source code in xdsl/frontend/listlang/main.py
83 84 85 | |
error(msg: str) -> ParseError
Source code in xdsl/frontend/listlang/main.py
87 88 | |
BinaryOp
Source code in xdsl/frontend/listlang/main.py
375 376 377 378 379 380 381 382 383 384 385 386 387 | |
parse_opt_glyph(ctx: ParsingContext) -> Located[bool]
Returns true if the expected glyph was found.
Source code in xdsl/frontend/listlang/main.py
376 377 378 379 380 | |
build(builder: Builder, lhs: Located[TypedExpression], rhs: Located[TypedExpression]) -> TypedExpression
Source code in xdsl/frontend/listlang/main.py
382 383 384 385 386 387 | |
Multiplication
Bases: BinaryOp
Source code in xdsl/frontend/listlang/main.py
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 | |
parse_opt_glyph(ctx: ParsingContext) -> Located[bool]
Source code in xdsl/frontend/listlang/main.py
391 392 | |
build(builder: Builder, lhs: Located[TypedExpression], rhs: Located[TypedExpression]) -> TypedExpression
Source code in xdsl/frontend/listlang/main.py
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 | |
Addition
Bases: BinaryOp
Source code in xdsl/frontend/listlang/main.py
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 | |
parse_opt_glyph(ctx: ParsingContext) -> Located[bool]
Source code in xdsl/frontend/listlang/main.py
422 423 | |
build(builder: Builder, lhs: Located[TypedExpression], rhs: Located[TypedExpression]) -> TypedExpression
Source code in xdsl/frontend/listlang/main.py
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 | |
ListRange
Bases: BinaryOp
Source code in xdsl/frontend/listlang/main.py
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 | |
parse_opt_glyph(ctx: ParsingContext) -> Located[bool]
Source code in xdsl/frontend/listlang/main.py
453 454 | |
build(builder: Builder, lhs: Located[TypedExpression], rhs: Located[TypedExpression]) -> TypedExpression
Source code in xdsl/frontend/listlang/main.py
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 | |
Comparator
dataclass
Bases: BinaryOp
Source code in xdsl/frontend/listlang/main.py
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 | |
glyph: Punctuation
instance-attribute
arith_code: str
instance-attribute
__init__(glyph: Punctuation, arith_code: str) -> None
parse_opt_glyph(ctx: ParsingContext) -> Located[bool]
Source code in xdsl/frontend/listlang/main.py
496 497 | |
build(builder: Builder, lhs: Located[TypedExpression], rhs: Located[TypedExpression]) -> TypedExpression
Source code in xdsl/frontend/listlang/main.py
499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 | |
BoolAnd
Bases: BinaryOp
Source code in xdsl/frontend/listlang/main.py
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 | |
parse_opt_glyph(ctx: ParsingContext) -> Located[bool]
Source code in xdsl/frontend/listlang/main.py
529 530 | |
build(builder: Builder, lhs: Located[TypedExpression], rhs: Located[TypedExpression]) -> TypedExpression
Source code in xdsl/frontend/listlang/main.py
532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 | |
BoolOr
Bases: BinaryOp
Source code in xdsl/frontend/listlang/main.py
559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 | |
parse_opt_glyph(ctx: ParsingContext) -> Located[bool]
Source code in xdsl/frontend/listlang/main.py
560 561 | |
build(builder: Builder, lhs: Located[TypedExpression], rhs: Located[TypedExpression]) -> TypedExpression
Source code in xdsl/frontend/listlang/main.py
563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 | |
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
94 95 96 97 98 99 | |
parse_punct(ctx: ParsingContext, punct: Punctuation) -> Location
Source code in xdsl/frontend/listlang/main.py
102 103 104 105 | |
parse_opt_identifier(ctx: ParsingContext) -> Located[str | None]
Source code in xdsl/frontend/listlang/main.py
108 109 110 111 112 113 | |
parse_identifier(ctx: ParsingContext) -> Located[str]
Source code in xdsl/frontend/listlang/main.py
116 117 118 119 | |
parse_opt_integer(ctx: ParsingContext) -> Located[int | None]
Source code in xdsl/frontend/listlang/main.py
122 123 124 125 126 127 | |
parse_integer(ctx: ParsingContext) -> Located[int]
Source code in xdsl/frontend/listlang/main.py
130 131 132 133 | |
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
136 137 138 139 140 141 142 143 144 145 | |
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
148 149 150 151 152 153 154 155 156 | |
parse_comma_separated(ctx: ParsingContext, p: Callable[[], Located[T | None]]) -> Sequence[Located[T]]
Source code in xdsl/frontend/listlang/main.py
162 163 164 165 166 167 168 169 170 | |
parse_opt_expr(ctx: ParsingContext, builder: Builder) -> Located[TypedExpression | None]
Source code in xdsl/frontend/listlang/main.py
612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 | |
parse_expr(ctx: ParsingContext, builder: Builder) -> Located[TypedExpression]
Source code in xdsl/frontend/listlang/main.py
644 645 646 647 | |
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
653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 | |
parse_opt_statement(ctx: ParsingContext, builder: Builder) -> Located[bool]
Source code in xdsl/frontend/listlang/main.py
682 683 | |
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
689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 | |
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
708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 | |
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
732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 | |
parse_program(code: str, builder: Builder)
Parses a program. Builds the operations associated with the program, and prints the final expression.
Source code in xdsl/frontend/listlang/main.py
753 754 755 756 757 758 759 760 761 762 | |
program_to_mlir_module(code: str) -> builtin.ModuleOp
Source code in xdsl/frontend/listlang/main.py
765 766 767 768 769 770 771 | |
program_to_mlir_string(code: str)
Source code in xdsl/frontend/listlang/main.py
774 775 776 777 | |
lower_down_to(target: str | None)
Source code in xdsl/frontend/listlang/main.py
822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 | |