-
Notifications
You must be signed in to change notification settings - Fork 160
Constant folding of Int, Float, String, and Bool #1896
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
Merged
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
48aea60
initial constant folding of string, int, boolean
b94ae11
make rand and srand impure
18217af
remove MINT from constant folding
0bee268
don't fold impure functions
0407ca5
constant folding of tokens
6391730
add helper function to FloatBuiltin
c70bacf
float hooks
55a57c6
fix whitespace
57abe2e
make field static
a4c198f
make hooks package-private
ce43411
add unit tests for STRING, BOOL, INT
8aec44c
add setLoc function
8fae2ca
fix STRING.length
5970031
fix STRING.ord
a0a8235
some fixes where nonnegative integers are expected
7f42e6a
fix find, rfind, findChar, rfindChar
d5aee49
fix float2string
8d5b5f0
fix ediv and emod
8e26e00
fix bitRange
67a0d93
add hashCode and equals for FloatBuiltin
0cdb84d
fix bugs in indexOfAny and lastIndexOfAny
a37cd0a
fix whitespace
5778ad0
fix float2int
8531e8c
add some useful functions to FloatBuiltin
b906b4b
add tests for FLOAT hooks
26e5fb7
add comment
2c871aa
add integration tests
ae1c165
Merge branch 'master' into folding
rv-jenkins File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
k-distribution/tests/regression-new/checks/invalidConstantExp.k
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| module INVALIDCONSTANTEXP | ||
| imports INT | ||
|
|
||
| rule 0 => 1 /Int 0 | ||
|
|
||
| endmodule |
6 changes: 6 additions & 0 deletions
6
k-distribution/tests/regression-new/checks/invalidConstantExp.k.out
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| [Error] Compiler: Division by zero. | ||
| while executing phase "constant expression folding" on sentence at | ||
| Source(invalidConstantExp.k) | ||
| Location(4,8,4,21) | ||
| Source(invalidConstantExp.k) | ||
| Location(4,13,4,21) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 3 |
3 changes: 3 additions & 0 deletions
3
k-distribution/tests/regression-new/constant-folding/1.test.out
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| <k> | ||
| . | ||
| </k> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 11 |
3 changes: 3 additions & 0 deletions
3
k-distribution/tests/regression-new/constant-folding/2.test.out
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| <k> | ||
| . | ||
| </k> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 5 |
3 changes: 3 additions & 0 deletions
3
k-distribution/tests/regression-new/constant-folding/3.test.out
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| <k> | ||
| 5 ~> . | ||
| </k> |
7 changes: 7 additions & 0 deletions
7
k-distribution/tests/regression-new/constant-folding/Makefile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| DEF=test | ||
| EXT=test | ||
| TESTDIR=. | ||
| KOMPILE_BACKEND=llvm | ||
| KOMPILE_FLAGS=--syntax-module TEST | ||
|
|
||
| include ../../../include/kframework/ktest.mak |
15 changes: 15 additions & 0 deletions
15
k-distribution/tests/regression-new/constant-folding/test.k
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| module TEST | ||
| imports INT | ||
| imports STRING | ||
| imports ID | ||
|
|
||
| syntax Int ::= "foo" | "bar" | ||
|
|
||
| syntax Id ::= "main" [token] | ||
|
|
||
| rule foo => 1 +Int 2 [macro] | ||
| rule foo => .K | ||
|
|
||
| rule bar => 1 +Int 2 *Int lengthString(Id2String(main) +String substrString("foo", 0, 1)) [macro] | ||
| rule bar => .K | ||
| endmodule |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.