aboutsummaryrefslogtreecommitdiffhomepage
path: root/testdata
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2021-04-20 23:40:16 +0200
committerRon Evans <[email protected]>2021-04-21 07:37:22 +0200
commit768a15c1dd83a462f77a835581357572e3962dbc (patch)
tree15d691556290be170a3ee88ef23a02db90ab48fd /testdata
parentc1c3be1aa7b4fbfeaddb7bf29857efcf77819623 (diff)
downloadtinygo-768a15c1dd83a462f77a835581357572e3962dbc.tar.gz
tinygo-768a15c1dd83a462f77a835581357572e3962dbc.zip
interp: remove map support
The interp package is in many cases able to execute map functions in the runtime directly. This is probably slower than adding special support for them in the interp package and also doesn't cover all cases (most importantly, map keys that contain pointers) but removing this code also removes a large amount of code that needs to be maintained and is susceptible to hard-to-find bugs. As a side effect, this resulted in different output of the testdata/map.go test because the test relied on the existing iteration order of TinyGo maps. I've updated the test to not rely on this test, making the output compatible with what the Go toolchain would output.
Diffstat (limited to 'testdata')
-rw-r--r--testdata/map.go10
-rw-r--r--testdata/map.txt46
2 files changed, 32 insertions, 24 deletions
diff --git a/testdata/map.go b/testdata/map.go
index b93eacac2..558688dc5 100644
--- a/testdata/map.go
+++ b/testdata/map.go
@@ -1,5 +1,7 @@
package main
+import "sort"
+
var testmap1 = map[string]int{"data": 3}
var testmap2 = map[string]int{
"one": 1,
@@ -112,7 +114,13 @@ func main() {
func readMap(m map[string]int, key string) {
println("map length:", len(m))
println("map read:", key, "=", m[key])
- for k, v := range m {
+ keys := make([]string, 0, len(m))
+ for k := range m {
+ keys = append(keys, k)
+ }
+ sort.Strings(keys)
+ for _, k := range keys {
+ v := m[k]
println(" ", k, "=", v)
}
}
diff --git a/testdata/map.txt b/testdata/map.txt
index e6141addc..309881081 100644
--- a/testdata/map.txt
+++ b/testdata/map.txt
@@ -7,45 +7,45 @@ map read: data = 3
data = 3
map length: 12
map read: three = 3
- one = 1
- two = 2
- three = 3
- four = 4
- five = 5
- six = 6
- seven = 7
eight = 8
+ eleven = 11
+ five = 5
+ four = 4
nine = 9
+ one = 1
+ seven = 7
+ six = 6
ten = 10
- eleven = 11
+ three = 3
twelve = 12
+ two = 2
map length: 12
map read: ten = 10
- one = 1
- two = 2
- three = 3
- four = 4
- five = 5
- six = 6
- seven = 7
eight = 8
+ eleven = 11
+ five = 5
+ four = 4
nine = 9
+ one = 1
+ seven = 7
+ six = 6
ten = 10
- eleven = 11
+ three = 3
twelve = 12
+ two = 2
map length: 11
map read: seven = 7
- one = 1
- two = 2
- three = 3
- four = 4
- five = 5
- seven = 7
eight = 8
+ eleven = 11
+ five = 5
+ four = 4
nine = 9
+ one = 1
+ seven = 7
ten = 10
- eleven = 11
+ three = 3
twelve = 12
+ two = 2
lookup with comma-ok: eight 8 true
lookup with comma-ok: nokey 0 false
false true 2