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

Support for constants issue208 #279

Merged
merged 28 commits into from
Sep 24, 2021
Merged

Conversation

riederm
Copy link
Collaborator

@riederm riederm commented Sep 8, 2021

No description provided.

@codecov
Copy link

codecov bot commented Sep 8, 2021

Codecov Report

Merging #279 (1909771) into master (ab1d310) will decrease coverage by 0.43%.
The diff coverage is 89.75%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
src/codegen/generators/struct_generator.rs 88.42% <67.50%> (-10.49%) ⬇️
src/resolver.rs 96.15% <73.68%> (-0.43%) ⬇️
src/compile_error.rs 51.85% <75.00%> (+13.75%) ⬆️
src/index.rs 92.36% <77.14%> (-4.17%) ⬇️
src/codegen/generators/expression_generator.rs 88.36% <86.66%> (-0.06%) ⬇️
src/resolver/const_evaluator.rs 89.34% <89.34%> (ø)
src/codegen/generators/variable_generator.rs 98.36% <92.30%> (-1.64%) ⬇️
src/index/const_expressions.rs 93.93% <94.38%> (+0.60%) ⬆️
src/codegen.rs 100.00% <100.00%> (ø)
src/codegen/generators/data_type_generator.rs 96.96% <100.00%> (+0.03%) ⬆️
... and 15 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ab1d310...1909771. Read the comment docs.

@@ -12,126 +12,126 @@ pub enum Token {
#[token("@EXTERNAL")]
PropertyExternal,

#[token("PROGRAM", ignore(case))]
#[token("PROGRAM")]
Copy link
Collaborator

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

@riederm riederm force-pushed the support_for_constants_issue208 branch from dc7c09e to 6373018 Compare September 12, 2021 20:26
riederm and others added 19 commits September 15, 2021 20:39
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.
@riederm riederm force-pushed the support_for_constants_issue208 branch from 4eb3ce6 to 2a35b70 Compare September 18, 2021 18:59
@riederm riederm force-pushed the support_for_constants_issue208 branch from e970f97 to 6241639 Compare September 20, 2021 08:14
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
@riederm
Copy link
Collaborator Author

riederm commented Sep 20, 2021

introduces parts of #208

@riederm riederm requested a review from ghaith September 20, 2021 20:01
@riederm riederm marked this pull request as ready for review September 20, 2021 20:04
Copy link
Collaborator

@ghaith ghaith left a 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?

@@ -661,6 +661,7 @@ fn multi_named_keywords_without_underscore_test() {
assert_eq!(d2.get_location(), SourceRange::new(191..200));
}

#[ignore = "reason"]
Copy link
Collaborator

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
@riederm riederm force-pushed the support_for_constants_issue208 branch from 86182d8 to 024c767 Compare September 22, 2021 20:48
ghaith
ghaith previously approved these changes Sep 23, 2021
@riederm riederm force-pushed the support_for_constants_issue208 branch 2 times, most recently from 582ca8e to 2a03ed4 Compare September 23, 2021 18:39
@riederm riederm force-pushed the support_for_constants_issue208 branch from 2a03ed4 to 1909771 Compare September 23, 2021 18:49
@riederm
Copy link
Collaborator Author

riederm commented Sep 23, 2021

@ghaith can you re-approve plz
I had to merge some stuff

@riederm riederm requested a review from ghaith September 23, 2021 19:30
@ghaith ghaith merged commit 6f3e63c into master Sep 24, 2021
@ghaith ghaith deleted the support_for_constants_issue208 branch September 24, 2021 09:22
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