Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New parser (pest) #45

Merged
merged 7 commits into from
Jun 30, 2024
Merged

New parser (pest) #45

merged 7 commits into from
Jun 30, 2024

Conversation

sbillig
Copy link
Collaborator

@sbillig sbillig commented May 13, 2024

This replaces the old parser with a pest-derived parser. It currently implements all text-format functionality required for the tests to pass, meaning that there may be syntax that the old parser supported that the new one doesn't (I'm not sure if there is, actually). The goal is to extend this parser to support some new functionality required for sonatina to be a useful evm backend ("objects", contract constructor functions, etc), but that'll happen in future PRs.

Some minimal error checking is performed (duplicate values definitions, referring to undefined identifiers, etc).

I also made some minor syntax changes:

  • function bodies are wrapped in braces
  • the i1 "true" value is now 1, instead of -1

Note that there are a couple small changes to the optimization passes, to make them work with alias values, though I made no attempt to ensure they function correctly in all situations involving alias values, just the particular situations that arose during testing. (I haven't thought about a more general solution to this problem, but perhaps we could discuss this.) The parser introduces an alias when a value is used before it's defined (in the textual form of the program, not the actual execution flow of course). For example:

v0.i8 = phi (v1 block1) (10.i8 block2)
...
v1.i8 = ...

In this case, the name v1 will first be marked as undefined, and given a new value id with a dummy value, say Value(5). When the definition of v1 is reached, we create a new value id for the definition, say Value(6), associate the name v1 with Value(6), and change Value(5) to be an alias of Value(6). (Note that unlike in the old parser, the name "v1" isn't guaranteed to be associated with ir::Value(0))

TODO:

  • type defs
  • fix number parsing failure in interpreter test
  • move value_names bimap
  • filecheck fork with regex change and failure print fix (I'll do this later)
  • xxxes
  • discuss value alias usage, fixes in optimizations

@sbillig sbillig force-pushed the pest-parser branch 3 times, most recently from cdafe8a to 045421e Compare June 21, 2024 03:43
@sbillig sbillig marked this pull request as ready for review June 23, 2024 05:25
Copy link
Collaborator

@Y-Nak Y-Nak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean and neat! Awesome work!

crates/filecheck/fixtures/insn_simplify/or.sntn Outdated Show resolved Hide resolved
crates/filecheck/fixtures/licm/basic.sntn Outdated Show resolved Hide resolved
crates/ir/Cargo.toml Outdated Show resolved Hide resolved
crates/ir/src/builder/func_builder.rs Outdated Show resolved Hide resolved
crates/parser/Cargo.toml Outdated Show resolved Hide resolved
@sbillig
Copy link
Collaborator Author

sbillig commented Jun 30, 2024

Thanks for the cleanup hints. I have some followup work in mind, but I'll open a new PR.

@sbillig sbillig merged commit f078e81 into fe-lang:main Jun 30, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants