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
377 378 379 380 381 382 383 384 385 386 387 388 389 | |
parse_opt_glyph(ctx: ParsingContext) -> Located[bool]
Returns true if the expected glyph was found.
Source code in xdsl/frontend/listlang/main.py
378 379 380 381 382 | |
build(builder: Builder, lhs: Located[TypedExpression], rhs: Located[TypedExpression]) -> TypedExpression
Source code in xdsl/frontend/listlang/main.py
384 385 386 387 388 389 | |
Multiplication
Bases: BinaryOp
Source code in xdsl/frontend/listlang/main.py
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 419 420 | |
parse_opt_glyph(ctx: ParsingContext) -> Located[bool]
Source code in xdsl/frontend/listlang/main.py
393 394 | |
build(builder: Builder, lhs: Located[TypedExpression], rhs: Located[TypedExpression]) -> TypedExpression
Source code in xdsl/frontend/listlang/main.py
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 | |
Addition
Bases: BinaryOp
Source code in xdsl/frontend/listlang/main.py
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 450 451 | |
parse_opt_glyph(ctx: ParsingContext) -> Located[bool]
Source code in xdsl/frontend/listlang/main.py
424 425 | |
build(builder: Builder, lhs: Located[TypedExpression], rhs: Located[TypedExpression]) -> TypedExpression
Source code in xdsl/frontend/listlang/main.py
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 | |
ListRange
Bases: BinaryOp
Source code in xdsl/frontend/listlang/main.py
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 489 490 | |
parse_opt_glyph(ctx: ParsingContext) -> Located[bool]
Source code in xdsl/frontend/listlang/main.py
455 456 | |
build(builder: Builder, lhs: Located[TypedExpression], rhs: Located[TypedExpression]) -> TypedExpression
Source code in xdsl/frontend/listlang/main.py
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 489 490 | |
Comparator
dataclass
Bases: BinaryOp
Source code in xdsl/frontend/listlang/main.py
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 526 527 | |
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
498 499 | |
build(builder: Builder, lhs: Located[TypedExpression], rhs: Located[TypedExpression]) -> TypedExpression
Source code in xdsl/frontend/listlang/main.py
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 526 527 | |
BoolAnd
Bases: BinaryOp
Source code in xdsl/frontend/listlang/main.py
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 557 558 | |
parse_opt_glyph(ctx: ParsingContext) -> Located[bool]
Source code in xdsl/frontend/listlang/main.py
531 532 | |
build(builder: Builder, lhs: Located[TypedExpression], rhs: Located[TypedExpression]) -> TypedExpression
Source code in xdsl/frontend/listlang/main.py
534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 | |
BoolOr
Bases: BinaryOp
Source code in xdsl/frontend/listlang/main.py
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 588 589 | |
parse_opt_glyph(ctx: ParsingContext) -> Located[bool]
Source code in xdsl/frontend/listlang/main.py
562 563 | |
build(builder: Builder, lhs: Located[TypedExpression], rhs: Located[TypedExpression]) -> TypedExpression
Source code in xdsl/frontend/listlang/main.py
565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 | |
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
164 165 166 167 168 169 170 171 172 | |
parse_opt_expr(ctx: ParsingContext, builder: Builder) -> Located[TypedExpression | None]
Source code in xdsl/frontend/listlang/main.py
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 642 643 | |
parse_expr(ctx: ParsingContext, builder: Builder) -> Located[TypedExpression]
Source code in xdsl/frontend/listlang/main.py
646 647 648 649 | |
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
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 680 681 | |
parse_opt_statement(ctx: ParsingContext, builder: Builder) -> Located[bool]
Source code in xdsl/frontend/listlang/main.py
684 685 | |
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
691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 | |
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
710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 | |
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
734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 | |
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
755 756 757 758 759 760 761 762 763 764 | |
program_to_mlir_module(code: str) -> builtin.ModuleOp
Source code in xdsl/frontend/listlang/main.py
767 768 769 770 771 772 773 | |
program_to_mlir_string(code: str)
Source code in xdsl/frontend/listlang/main.py
776 777 778 779 | |
lower_down_to(target: str | None)
Source code in xdsl/frontend/listlang/main.py
824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 | |