feat: allow fibers as map keys by adding unique fiber IDs and hash support

Add a unique numeric ID to each fiber allocation, enabling fibers to be used as map keys. This includes updating the hash function for OBJ_FIBER to return the fiber's ID, modifying key validation to accept fibers, updating documentation to describe the new capability, and adjusting all relevant test expectations and error messages.
This commit is contained in:
Bob Nystrom
2015-05-03 18:10:31 +00:00
parent 332f570a1a
commit cd1cc07c6f
10 changed files with 60 additions and 20 deletions
+1 -1
View File
@@ -1 +1 @@
var result = {}.containsKey([]) // expect runtime error: Key must be a value type.
var result = {}.containsKey([]) // expect runtime error: Key must be a value type or fiber.
+7 -3
View File
@@ -1,3 +1,5 @@
var fiber = new Fiber {}
var map = {
null: "null value",
true: "true value",
@@ -6,7 +8,8 @@ var map = {
1.2: "1 point 2",
List: "list class",
"null": "string value",
(1..3): "1 to 3"
(1..3): "1 to 3",
fiber: "fiber"
}
IO.print(map[null]) // expect: null value
@@ -17,8 +20,9 @@ IO.print(map[1.2]) // expect: 1 point 2
IO.print(map[List]) // expect: list class
IO.print(map["null"]) // expect: string value
IO.print(map[1..3]) // expect: 1 to 3
IO.print(map[fiber]) // expect: fiber
IO.print(map.count) // expect: 8
IO.print(map.count) // expect: 9
// Use the same keys (but sometimes different objects) to ensure keys have the
// right equality semantics.
@@ -40,4 +44,4 @@ IO.print(map[List]) // expect: new list class
IO.print(map["null"]) // expect: new string value
IO.print(map[1..3]) // expect: new 1 to 3
IO.print(map.count) // expect: 8
IO.print(map.count) // expect: 9
+1 -1
View File
@@ -1 +1 @@
var result = {}.remove([]) // expect runtime error: Key must be a value type.
var result = {}.remove([]) // expect runtime error: Key must be a value type or fiber.
+1 -1
View File
@@ -1 +1 @@
var result = {}[[]] // expect runtime error: Key must be a value type.
var result = {}[[]] // expect runtime error: Key must be a value type or fiber.
@@ -1 +1 @@
var result = {}[[]] = "value" // expect runtime error: Key must be a value type.
var result = {}[[]] = "value" // expect runtime error: Key must be a value type or fiber.