mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-12 06:38:45 +01:00
Upvalue -> ObjUpvalue.
This is consistent with ObjModule which also is an Obj even though it isn't first class in the language.
This commit is contained in:
@ -123,7 +123,7 @@ void wrenBindMethod(WrenVM* vm, ObjClass* classObj, int symbol, Method method)
|
||||
ObjClosure* wrenNewClosure(WrenVM* vm, ObjFn* fn)
|
||||
{
|
||||
ObjClosure* closure = ALLOCATE_FLEX(vm, ObjClosure,
|
||||
Upvalue*, fn->numUpvalues);
|
||||
ObjUpvalue*, fn->numUpvalues);
|
||||
initObj(vm, &closure->obj, OBJ_CLOSURE, vm->fnClass);
|
||||
|
||||
closure->fn = fn;
|
||||
@ -791,9 +791,9 @@ uint32_t wrenStringFind(ObjString* haystack, ObjString* needle)
|
||||
return UINT32_MAX;
|
||||
}
|
||||
|
||||
Upvalue* wrenNewUpvalue(WrenVM* vm, Value* value)
|
||||
ObjUpvalue* wrenNewUpvalue(WrenVM* vm, Value* value)
|
||||
{
|
||||
Upvalue* upvalue = ALLOCATE(vm, Upvalue);
|
||||
ObjUpvalue* upvalue = ALLOCATE(vm, ObjUpvalue);
|
||||
|
||||
// Upvalues are never used as first-class objects, so don't need a class.
|
||||
initObj(vm, &upvalue->obj, OBJ_UPVALUE, NULL);
|
||||
@ -841,7 +841,7 @@ static void markClosure(WrenVM* vm, ObjClosure* closure)
|
||||
|
||||
// Keep track of how much memory is still in use.
|
||||
vm->bytesAllocated += sizeof(ObjClosure);
|
||||
vm->bytesAllocated += sizeof(Upvalue*) * closure->fn->numUpvalues;
|
||||
vm->bytesAllocated += sizeof(ObjUpvalue*) * closure->fn->numUpvalues;
|
||||
}
|
||||
|
||||
static void markFiber(WrenVM* vm, ObjFiber* fiber)
|
||||
@ -859,7 +859,7 @@ static void markFiber(WrenVM* vm, ObjFiber* fiber)
|
||||
}
|
||||
|
||||
// Open upvalues.
|
||||
Upvalue* upvalue = fiber->openUpvalues;
|
||||
ObjUpvalue* upvalue = fiber->openUpvalues;
|
||||
while (upvalue != NULL)
|
||||
{
|
||||
wrenMarkObj(vm, (Obj*)upvalue);
|
||||
@ -964,13 +964,13 @@ static void markString(WrenVM* vm, ObjString* string)
|
||||
vm->bytesAllocated += sizeof(ObjString) + string->length + 1;
|
||||
}
|
||||
|
||||
static void markUpvalue(WrenVM* vm, Upvalue* upvalue)
|
||||
static void markUpvalue(WrenVM* vm, ObjUpvalue* upvalue)
|
||||
{
|
||||
// Mark the closed-over object (in case it is closed).
|
||||
wrenMarkValue(vm, upvalue->closed);
|
||||
|
||||
// Keep track of how much memory is still in use.
|
||||
vm->bytesAllocated += sizeof(Upvalue);
|
||||
vm->bytesAllocated += sizeof(ObjUpvalue);
|
||||
}
|
||||
|
||||
void wrenMarkObj(WrenVM* vm, Obj* obj)
|
||||
@ -1005,7 +1005,7 @@ void wrenMarkObj(WrenVM* vm, Obj* obj)
|
||||
case OBJ_MODULE: markModule( vm, (ObjModule*) obj); break;
|
||||
case OBJ_RANGE: markRange( vm, (ObjRange*) obj); break;
|
||||
case OBJ_STRING: markString( vm, (ObjString*) obj); break;
|
||||
case OBJ_UPVALUE: markUpvalue( vm, (Upvalue*) obj); break;
|
||||
case OBJ_UPVALUE: markUpvalue( vm, (ObjUpvalue*) obj); break;
|
||||
}
|
||||
|
||||
#if WREN_DEBUG_TRACE_MEMORY
|
||||
|
||||
@ -187,7 +187,7 @@ typedef struct sUpvalue
|
||||
// Open upvalues are stored in a linked list by the fiber. This points to the
|
||||
// next upvalue in that list.
|
||||
struct sUpvalue* next;
|
||||
} Upvalue;
|
||||
} ObjUpvalue;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@ -216,7 +216,7 @@ typedef struct sObjFiber
|
||||
// Pointer to the first node in the linked list of open upvalues that are
|
||||
// pointing to values still on the stack. The head of the list will be the
|
||||
// upvalue closest to the top of the stack, and then the list works downwards.
|
||||
Upvalue* openUpvalues;
|
||||
ObjUpvalue* openUpvalues;
|
||||
|
||||
// The fiber that ran this one. If this fiber is yielded, control will resume
|
||||
// to this one. May be `NULL`.
|
||||
@ -323,7 +323,7 @@ typedef struct
|
||||
ObjFn* fn;
|
||||
|
||||
// The upvalues this function has closed over.
|
||||
Upvalue* upvalues[FLEXIBLE_ARRAY];
|
||||
ObjUpvalue* upvalues[FLEXIBLE_ARRAY];
|
||||
} ObjClosure;
|
||||
|
||||
typedef enum
|
||||
@ -691,7 +691,7 @@ Value wrenStringCodePointAt(WrenVM* vm, ObjString* string, uint32_t index);
|
||||
uint32_t wrenStringFind(ObjString* haystack, ObjString* needle);
|
||||
|
||||
// Creates a new open upvalue pointing to [value] on the stack.
|
||||
Upvalue* wrenNewUpvalue(WrenVM* vm, Value* value);
|
||||
ObjUpvalue* wrenNewUpvalue(WrenVM* vm, Value* value);
|
||||
|
||||
// Mark [value] as reachable and still in use. This should only be called
|
||||
// during the sweep phase of a garbage collection.
|
||||
|
||||
@ -217,7 +217,7 @@ void* wrenReallocate(WrenVM* vm, void* memory, size_t oldSize, size_t newSize)
|
||||
// ensure that multiple closures closing over the same variable actually see
|
||||
// the same variable.) Otherwise, it will create a new open upvalue and add it
|
||||
// the fiber's list of upvalues.
|
||||
static Upvalue* captureUpvalue(WrenVM* vm, ObjFiber* fiber, Value* local)
|
||||
static ObjUpvalue* captureUpvalue(WrenVM* vm, ObjFiber* fiber, Value* local)
|
||||
{
|
||||
// If there are no open upvalues at all, we must need a new one.
|
||||
if (fiber->openUpvalues == NULL)
|
||||
@ -226,8 +226,8 @@ static Upvalue* captureUpvalue(WrenVM* vm, ObjFiber* fiber, Value* local)
|
||||
return fiber->openUpvalues;
|
||||
}
|
||||
|
||||
Upvalue* prevUpvalue = NULL;
|
||||
Upvalue* upvalue = fiber->openUpvalues;
|
||||
ObjUpvalue* prevUpvalue = NULL;
|
||||
ObjUpvalue* upvalue = fiber->openUpvalues;
|
||||
|
||||
// Walk towards the bottom of the stack until we find a previously existing
|
||||
// upvalue or pass where it should be.
|
||||
@ -243,7 +243,7 @@ static Upvalue* captureUpvalue(WrenVM* vm, ObjFiber* fiber, Value* local)
|
||||
// We've walked past this local on the stack, so there must not be an
|
||||
// upvalue for it already. Make a new one and link it in in the right
|
||||
// place to keep the list sorted.
|
||||
Upvalue* createdUpvalue = wrenNewUpvalue(vm, local);
|
||||
ObjUpvalue* createdUpvalue = wrenNewUpvalue(vm, local);
|
||||
if (prevUpvalue == NULL)
|
||||
{
|
||||
// The new one is the first one in the list.
|
||||
@ -260,7 +260,7 @@ static Upvalue* captureUpvalue(WrenVM* vm, ObjFiber* fiber, Value* local)
|
||||
|
||||
static void closeUpvalue(ObjFiber* fiber)
|
||||
{
|
||||
Upvalue* upvalue = fiber->openUpvalues;
|
||||
ObjUpvalue* upvalue = fiber->openUpvalues;
|
||||
|
||||
// Move the value into the upvalue itself and point the upvalue to it.
|
||||
upvalue->closed = *upvalue->value;
|
||||
@ -922,14 +922,14 @@ static bool runInterpreter(WrenVM* vm)
|
||||
|
||||
CASE_CODE(LOAD_UPVALUE):
|
||||
{
|
||||
Upvalue** upvalues = ((ObjClosure*)frame->fn)->upvalues;
|
||||
ObjUpvalue** upvalues = ((ObjClosure*)frame->fn)->upvalues;
|
||||
PUSH(*upvalues[READ_BYTE()]->value);
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
CASE_CODE(STORE_UPVALUE):
|
||||
{
|
||||
Upvalue** upvalues = ((ObjClosure*)frame->fn)->upvalues;
|
||||
ObjUpvalue** upvalues = ((ObjClosure*)frame->fn)->upvalues;
|
||||
*upvalues[READ_BYTE()]->value = PEEK();
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user