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

Name resolution #23

Merged
merged 24 commits into from
Oct 29, 2023
Merged

Name resolution #23

merged 24 commits into from
Oct 29, 2023

Conversation

pepplejoshua
Copy link
Owner

No description provided.

pepplejoshua and others added 24 commits July 20, 2023 10:11
Merging recent Pipeline and workspace changes into this branch so I can use them
Cleaned up frontend and removed redundancies (InsRef and ExprRef). Improved parser errors and add some more syntax (extending a type). Added a directive for registering a C++ level function from runtime.h as a proto level function using function prototypes.
Decided to combine name resolution and type checking into one pass (SemanticAnalyzr)
Added bindings for C++ types along with other minor changes
This allows me to partially evaluate the PIRIns and PIRExpr nodes and prepare them for type checking. More complex directives will be evaluated in a later pass (@run and @inline)
After spending some time working on it, it is clear that I don't need to even evaluate the directives in 2 passes since I can resolve the types pretty easily during name resolution and type checking pass
Register will now work on a single prototype vs a whole block. I will add the ability to specify a whole block later as well as better error checking for what is being register (maybe in parser. or even in future partial evaluation pass)
Made some progress on Variable declarations and Struct declarations. Also added methods to make using symbol table a lot easier
- Added SourceRef to all nodes.
- Got basic type checking and inference working for assignment statements and function bodies.
- Replaced SemanticType with TypeReference object on ast nodes.
- Also implemented basics for converting from a PIRType (which is the object in the symbol table which is referenced by TypeReference) to a TypeReference to get inference working.
For some reason, it has been working this whole time. The .combine() function had been wrong this whole time. It was not apparent to me that when you combine 2 source refs, start line and start col are perpetually bound together (as are end line and end col). It is obvious now, but.I was combining source references wrong this whole time.

For example:
```rs
fn returns_i8() i8 { // start line 0, start col 19 end line 0 end col 20
} // start line 1, start col 0, end line 1 end col 1
```

Previously, when I combine these 2 Source Refs for the `{` and `}`, it would produce:
start line 0 start col 0 (it has now misaligned the coordinates) end line 1 end col 20 (will throw an error for sure)

This would select all of the text on line 0 and through an error on line 2 since it is only 1 character long but we require about 20 characters from it. 😆

To fix, just exploit the idea that line and col are always pair together. Start line and start col must come from the same object.
With the fix, combining them gives:
start line 0 start col 19 end line 1 end col 1

We have now gotten reference of the code block boundaries
This will allow comments be skipped over. I will need to rewrite the PIR to exclude comments. Formatting does not depend on any output from the analysis phase. This means once it passes, I can reformat the AST, which would already contain comments.
Ditching old PIR. Will eventually bring the array based technique to AST generated by parser. For now, I will focus on trying out the zig way of doing things. Cannot wait to have something I can write in zig
Added untyped IR and generation from basic AST. This will allow me run the code through a partial evaluator and have typed and type verified code by the end of the run. Fingers crossed.
@pepplejoshua pepplejoshua merged commit 2ca3bcf into main Oct 29, 2023
1 check 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.

1 participant