-
Notifications
You must be signed in to change notification settings - Fork 391
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gnovm): support constant evaluation of len and cap on arrays (#3600
) Closes: #3201 This update introduces the ability to evaluate len and cap for arrays at preprocess-time, allowing these values to be treated as constants. While the array itself is not constant, the values of len and cap can be determined during the preprocess. This change eliminates the need for machine.EvalStatic that causes a vm crash. --------- Co-authored-by: Lee ByeongJun <[email protected]> Co-authored-by: Petar Dambovaliev <[email protected]>
- Loading branch information
1 parent
85a8740
commit 479b314
Showing
5 changed files
with
73 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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,20 @@ | ||
package main | ||
|
||
type T1 struct { | ||
x [2]string | ||
} | ||
|
||
type T2 struct { | ||
x *[2]string | ||
} | ||
|
||
func main() { | ||
t1 := T1{x: [2]string{"a", "b"}} | ||
t2 := T2{x: &[2]string{"a", "b"}} | ||
const c1 = len(t1.x) | ||
const c2 = len(t2.x) | ||
println(c1, c2) | ||
} | ||
|
||
// Output: | ||
// 2 2 |
This file contains 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 @@ | ||
package main | ||
|
||
func main() { | ||
s := make([][2]string, 1) // Slice with length 1 | ||
s[0] = [2]string{"a", "b"} // Assign value to s[0] | ||
const r = len(s[0]) | ||
println(r) // Prints: 2 | ||
} | ||
|
||
// Output: | ||
// 2 |