| 66 | } |
| 67 | |
| 68 | void CloseUpvalues(char* paramBase, unsigned int depth, unsigned int argument) |
| 69 | { |
| 70 | assert(depth); |
| 71 | // Array of upvalue lists |
| 72 | ExternFuncInfo::Upvalue **externalList = &NULLC::commonLinker->exCloseLists[0]; |
| 73 | for(unsigned i = 0; i < depth; i++) |
| 74 | { |
| 75 | // Current upvalue and previous |
| 76 | ExternFuncInfo::Upvalue *curr = externalList[argument + i]; |
| 77 | // While we have an upvalue that points to address larger than base (so that in recursive function call only last functions upvalues will be closed) |
| 78 | while(curr && ((char*)curr->ptr >= paramBase || (char*)curr->ptr < GC::unmanageableBase)) |
| 79 | { |
| 80 | // Save pointer to next upvalue |
| 81 | ExternFuncInfo::Upvalue *next = curr->next; |
| 82 | // And save the size of target variable |
| 83 | unsigned int size = curr->size; |
| 84 | |
| 85 | // Delete upvalue from list (move global list head to the next element) |
| 86 | externalList[argument] = curr->next; |
| 87 | |
| 88 | // If target value is placed on the heap, we skip copy because it won't die |
| 89 | if((char*)curr->ptr < GC::unmanageableBase || (char*)curr->ptr >= GC::unmanageableTop) |
| 90 | { |
| 91 | curr = next; |
| 92 | continue; |
| 93 | } |
| 94 | |
| 95 | // Copy target variable data to upvalue |
| 96 | memcpy(&curr->next, curr->ptr, size); |
| 97 | curr->ptr = (unsigned int*)&curr->next; |
| 98 | |
| 99 | // Proceed to the next upvalue |
| 100 | curr = next; |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | ExternTypeInfo* GetTypeList() |
| 106 | { |