-
Notifications
You must be signed in to change notification settings - Fork 56
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
Support for constants issue208 #279
Conversation
Codecov Report
@@ Coverage Diff @@
## master #279 +/- ##
==========================================
- Coverage 95.27% 94.83% -0.44%
==========================================
Files 44 45 +1
Lines 12051 12784 +733
==========================================
+ Hits 11481 12124 +643
- Misses 570 660 +90
Continue to review full report at Codecov.
|
src/lexer/tokens.rs
Outdated
@@ -12,126 +12,126 @@ pub enum Token { | |||
#[token("@EXTERNAL")] | |||
PropertyExternal, | |||
|
|||
#[token("PROGRAM", ignore(case))] | |||
#[token("PROGRAM")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you revert this?
I suggest we add the lexer to a separate crate later to avoid the issues
dc7c09e
to
6373018
Compare
const expressions are no longer stored directly in the index but they are stored in an arena. This way it is easier to replace them later when we want to resolve the expressions into literals.
the index now offers a arena for const rexpressions so they can be later evaluated and replaced (with the same id) so validation and codegen can use numbers that are available at compile-time const expressions include: - intializers x : INT := LEN - 1 ------- - array-dimensions x : ARRAY[0..LEN-1] OF INT; - ----- - String-length x : STRING(LEN-1); -----
the TypeSize enum can either represent a const-expression that is meant to be evaluated at compile time (e.g. LEN - 1) or a compile time literal (e.g. the default length of a String). adresses review commentss
literals and refrences to ints and bools
special handling for unsigned numbers!
Dimensions keep the ast-statements as start and end which eventually will be replaced by a LiteralInteger if it can be evaluated. this allows to collect types and constants in the visit-phase and following that, replace the dimensions that consist of complex expressoins (e.g. "a + b") with a literal-integer once all constants are known.
4eb3ce6
to
2a35b70
Compare
e970f97
to
6241639
Compare
improve test coverage qualified references for now can be of the form: POU.variable referencing fields of const structs (E.g. a.b.c) are not supported yet
introduces parts of #208 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, but I think one big topic we are missing is using constants in the implementation
What happens to a load expression for that variable? Will it behave like a normal reference? Does this reference exist? Could you add some codegen and correctness tests where constants have been used? What happens if we try to write to a constant value? I didn't see a test for that, but maybe I missed it?
src/lexer/tests/lexer_tests.rs
Outdated
@@ -661,6 +661,7 @@ fn multi_named_keywords_without_underscore_test() { | |||
assert_eq!(d2.get_location(), SourceRange::new(191..200)); | |||
} | |||
|
|||
#[ignore = "reason"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reactivate
tests that shows that constants can be used in body the current implementation creates global variables for constants and references these variables in expressions. global's could be inlined to create more efficient code see issue #291
86182d8
to
024c767
Compare
582ca8e
to
2a03ed4
Compare
…_for_constants_issue208
2a03ed4
to
1909771
Compare
@ghaith can you re-approve plz |
No description provided.