forked from Mirror/wren
Don't allow fibers as map keys.
I hacked in support for it for a misguided reason (trying to fake "thread-local storage") and ended up not using it for that anyway.
This commit is contained in:
@ -54,13 +54,13 @@ bool validateInt(WrenVM* vm, Value arg, const char* argName)
|
|||||||
|
|
||||||
bool validateKey(WrenVM* vm, Value arg)
|
bool validateKey(WrenVM* vm, Value arg)
|
||||||
{
|
{
|
||||||
if (IS_BOOL(arg) || IS_CLASS(arg) || IS_FIBER(arg) || IS_NULL(arg) ||
|
if (IS_BOOL(arg) || IS_CLASS(arg) || IS_NULL(arg) ||
|
||||||
IS_NUM(arg) || IS_RANGE(arg) || IS_STRING(arg))
|
IS_NUM(arg) || IS_RANGE(arg) || IS_STRING(arg))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
vm->fiber->error = CONST_STRING(vm, "Key must be a value type or fiber.");
|
vm->fiber->error = CONST_STRING(vm, "Key must be a value type.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -155,7 +155,6 @@ ObjFiber* wrenNewFiber(WrenVM* vm, Obj* fn)
|
|||||||
|
|
||||||
ObjFiber* fiber = ALLOCATE(vm, ObjFiber);
|
ObjFiber* fiber = ALLOCATE(vm, ObjFiber);
|
||||||
initObj(vm, &fiber->obj, OBJ_FIBER, vm->fiberClass);
|
initObj(vm, &fiber->obj, OBJ_FIBER, vm->fiberClass);
|
||||||
fiber->id = vm->nextFiberId++;
|
|
||||||
fiber->frames = frames;
|
fiber->frames = frames;
|
||||||
fiber->frameCapacity = INITIAL_CALL_FRAMES;
|
fiber->frameCapacity = INITIAL_CALL_FRAMES;
|
||||||
fiber->stack = stack;
|
fiber->stack = stack;
|
||||||
@ -344,9 +343,6 @@ static uint32_t hashObject(Obj* object)
|
|||||||
// Classes just use their name.
|
// Classes just use their name.
|
||||||
return hashObject((Obj*)((ObjClass*)object)->name);
|
return hashObject((Obj*)((ObjClass*)object)->name);
|
||||||
|
|
||||||
case OBJ_FIBER:
|
|
||||||
return ((ObjFiber*)object)->id;
|
|
||||||
|
|
||||||
case OBJ_RANGE:
|
case OBJ_RANGE:
|
||||||
{
|
{
|
||||||
ObjRange* range = (ObjRange*)object;
|
ObjRange* range = (ObjRange*)object;
|
||||||
|
|||||||
@ -242,10 +242,6 @@ typedef struct sObjFiber
|
|||||||
// error object. Otherwise, it will be null.
|
// error object. Otherwise, it will be null.
|
||||||
Value error;
|
Value error;
|
||||||
|
|
||||||
// A unique-ish numeric ID for the fiber. Lets fibers be used as map keys.
|
|
||||||
// Unique-ish since IDs may overflow and wrap around.
|
|
||||||
uint16_t id;
|
|
||||||
|
|
||||||
// This will be true if the caller that called this fiber did so using "try".
|
// This will be true if the caller that called this fiber did so using "try".
|
||||||
// In that case, if this fiber fails with an error, the error will be given
|
// In that case, if this fiber fails with an error, the error will be given
|
||||||
// to the caller.
|
// to the caller.
|
||||||
|
|||||||
@ -50,11 +50,6 @@ struct WrenVM
|
|||||||
// for the module.
|
// for the module.
|
||||||
ObjMap* modules;
|
ObjMap* modules;
|
||||||
|
|
||||||
// The ID that will be assigned to the next fiber that is allocated. Fibers
|
|
||||||
// are given unique-ish (not completely unique since this can overflow) IDs
|
|
||||||
// so that they can be used as map keys.
|
|
||||||
uint16_t nextFiberId;
|
|
||||||
|
|
||||||
// Memory management data:
|
// Memory management data:
|
||||||
|
|
||||||
// The number of bytes that are known to be currently allocated. Includes all
|
// The number of bytes that are known to be currently allocated. Includes all
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
var result = {}.containsKey([]) // expect runtime error: Key must be a value type or fiber.
|
var result = {}.containsKey([]) // expect runtime error: Key must be a value type.
|
||||||
|
|||||||
@ -8,8 +8,7 @@ var map = {
|
|||||||
1.2: "1 point 2",
|
1.2: "1 point 2",
|
||||||
List: "list class",
|
List: "list class",
|
||||||
"null": "string value",
|
"null": "string value",
|
||||||
(1..3): "1 to 3",
|
(1..3): "1 to 3"
|
||||||
fiber: "fiber"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
System.print(map[null]) // expect: null value
|
System.print(map[null]) // expect: null value
|
||||||
@ -20,9 +19,8 @@ System.print(map[1.2]) // expect: 1 point 2
|
|||||||
System.print(map[List]) // expect: list class
|
System.print(map[List]) // expect: list class
|
||||||
System.print(map["null"]) // expect: string value
|
System.print(map["null"]) // expect: string value
|
||||||
System.print(map[1..3]) // expect: 1 to 3
|
System.print(map[1..3]) // expect: 1 to 3
|
||||||
System.print(map[fiber]) // expect: fiber
|
|
||||||
|
|
||||||
System.print(map.count) // expect: 9
|
System.print(map.count) // expect: 8
|
||||||
|
|
||||||
// Use the same keys (but sometimes different objects) to ensure keys have the
|
// Use the same keys (but sometimes different objects) to ensure keys have the
|
||||||
// right equality semantics.
|
// right equality semantics.
|
||||||
@ -44,4 +42,4 @@ System.print(map[List]) // expect: new list class
|
|||||||
System.print(map["null"]) // expect: new string value
|
System.print(map["null"]) // expect: new string value
|
||||||
System.print(map[1..3]) // expect: new 1 to 3
|
System.print(map[1..3]) // expect: new 1 to 3
|
||||||
|
|
||||||
System.print(map.count) // expect: 9
|
System.print(map.count) // expect: 8
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
var result = {}.remove([]) // expect runtime error: Key must be a value type or fiber.
|
var result = {}.remove([]) // expect runtime error: Key must be a value type.
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
var result = {}[[]] // expect runtime error: Key must be a value type or fiber.
|
var result = {}[[]] // expect runtime error: Key must be a value type.
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
var result = {}[[]] = "value" // expect runtime error: Key must be a value type or fiber.
|
var result = {}[[]] = "value" // expect runtime error: Key must be a value type.
|
||||||
|
|||||||
Reference in New Issue
Block a user