src/vm/oba_vm.c
static ObjUpvalue* captureUpvalue(ObaVM* vm, Value* local) {
  ObjUpvalue* prev = NULL;
  ObjUpvalue* upvalue = vm->openUpvalues;

  while (upvalue != NULL && upvalue->location > local) {
    prev = upvalue;
    upvalue = upvalue->next;
  }

  if (upvalue != NULL && upvalue->location == local) {
    return upvalue;
  }

  ObjUpvalue* createdUpvalue = newUpvalue(vm, local);
  createdUpvalue->next = upvalue;

  if (prev == NULL) {
    vm->openUpvalues = createdUpvalue;
  } else {
    prev->next = createdUpvalue;
  }

  return createdUpvalue;
}
// Captures the local value in an upvalue.
// If an existing upvalue already closes over the local, it is returned.
// Otherwise a new one is created.
Captures the local value in an upvalue.
If an existing upvalue already closes over the local, it is returned.
Otherwise a new one is created.
Captures the local value in an upvalue . If an existing upvalue already closes over the local it is returned . Otherwise a new one is created .
static ObjUpvalue* captureUpvalue(ObaVM* vm, Value* local) {
  ObjUpvalue* prev = NULL;
  ObjUpvalue* upvalue = vm->openUpvalues;
  while (upvalue != NULL && upvalue->location > local) {
    prev = upvalue;
    upvalue = upvalue->next;
  }
  if (upvalue != NULL && upvalue->location == local) {
    return upvalue;
  }
  ObjUpvalue* createdUpvalue = newUpvalue(vm, local);
  createdUpvalue->next = upvalue;
  if (prev == NULL) {
    vm->openUpvalues = createdUpvalue;
  } else {
    prev->next = createdUpvalue;
  }
  return createdUpvalue;
}
static ObjUpvalue * captureUpvalue ( ObaVM * vm , Value * local ) { ObjUpvalue * prev = NULL ; ObjUpvalue * upvalue = vm -> openUpvalues ; while ( upvalue != NULL && upvalue -> location > local ) { prev = upvalue ; upvalue = upvalue -> next ; } if ( upvalue != NULL && upvalue -> location == local ) { return upvalue ; } ObjUpvalue * createdUpvalue = newUpvalue ( vm , local ) ; createdUpvalue -> next = upvalue ; if ( prev == NULL ) { vm -> openUpvalues = createdUpvalue ; } else { prev -> next = createdUpvalue ; } return createdUpvalue ; }
Captures the local value in an upvalue.
Captures the local value in an upvalue .