diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-11-04 10:57:02 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-11-04 10:57:02 -0200 |
| commit | 93fd67b7936f0f1fc20645d18eb85a193887c315 (patch) | |
| tree | 11cd249fad6b0253f0de48b94c08ab08671b8544 /lstate.c | |
| parent | 6bb3e40a8d2cdb64a6ac1962d8748dd638a11721 (diff) | |
| download | lua-93fd67b7936f0f1fc20645d18eb85a193887c315.tar.gz lua-93fd67b7936f0f1fc20645d18eb85a193887c315.tar.bz2 lua-93fd67b7936f0f1fc20645d18eb85a193887c315.zip | |
no more 'CallInfo' structure
Diffstat (limited to 'lstate.c')
| -rw-r--r-- | lstate.c | 57 |
1 files changed, 4 insertions, 53 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstate.c,v 2.143 2017/10/31 17:54:35 roberto Exp roberto $ | 2 | ** $Id: lstate.c,v 2.144 2017/11/03 12:12:30 roberto Exp roberto $ |
| 3 | ** Global State | 3 | ** Global State |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -97,51 +97,8 @@ void luaE_setdebt (global_State *g, l_mem debt) { | |||
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | 99 | ||
| 100 | CallInfo *luaE_extendCI (lua_State *L) { | ||
| 101 | CallInfo *ci = luaM_new(L, CallInfo); | ||
| 102 | lua_assert(L->ci->next == NULL); | ||
| 103 | L->ci->next = ci; | ||
| 104 | ci->previous = L->ci; | ||
| 105 | ci->next = NULL; | ||
| 106 | L->nci++; | ||
| 107 | return ci; | ||
| 108 | } | ||
| 109 | |||
| 110 | |||
| 111 | /* | ||
| 112 | ** free all CallInfo structures not in use by a thread | ||
| 113 | */ | ||
| 114 | void luaE_freeCI (lua_State *L) { | ||
| 115 | CallInfo *ci = L->ci; | ||
| 116 | CallInfo *next = ci->next; | ||
| 117 | ci->next = NULL; | ||
| 118 | while ((ci = next) != NULL) { | ||
| 119 | next = ci->next; | ||
| 120 | luaM_free(L, ci); | ||
| 121 | L->nci--; | ||
| 122 | } | ||
| 123 | } | ||
| 124 | |||
| 125 | |||
| 126 | /* | ||
| 127 | ** free half of the CallInfo structures not in use by a thread | ||
| 128 | */ | ||
| 129 | void luaE_shrinkCI (lua_State *L) { | ||
| 130 | CallInfo *ci = L->ci; | ||
| 131 | CallInfo *next2; /* next's next */ | ||
| 132 | /* while there are two nexts */ | ||
| 133 | while (ci->next != NULL && (next2 = ci->next->next) != NULL) { | ||
| 134 | luaM_free(L, ci->next); /* free next */ | ||
| 135 | L->nci--; | ||
| 136 | ci->next = next2; /* remove 'next' from the list */ | ||
| 137 | next2->previous = ci; | ||
| 138 | ci = next2; /* keep next's next */ | ||
| 139 | } | ||
| 140 | } | ||
| 141 | |||
| 142 | |||
| 143 | static void stack_init (lua_State *L1, lua_State *L) { | 100 | static void stack_init (lua_State *L1, lua_State *L) { |
| 144 | int i; CallInfo *ci; | 101 | int i; |
| 145 | /* initialize stack array */ | 102 | /* initialize stack array */ |
| 146 | L1->stack = luaM_newvector(L, BASIC_STACK_SIZE, StackValue); | 103 | L1->stack = luaM_newvector(L, BASIC_STACK_SIZE, StackValue); |
| 147 | L1->stacksize = BASIC_STACK_SIZE; | 104 | L1->stacksize = BASIC_STACK_SIZE; |
| @@ -149,24 +106,19 @@ static void stack_init (lua_State *L1, lua_State *L) { | |||
| 149 | setnilvalue(s2v(L1->stack + i)); /* erase new stack */ | 106 | setnilvalue(s2v(L1->stack + i)); /* erase new stack */ |
| 150 | L1->top = L1->stack; | 107 | L1->top = L1->stack; |
| 151 | L1->stack_last = L1->stack + L1->stacksize - EXTRA_STACK; | 108 | L1->stack_last = L1->stack + L1->stacksize - EXTRA_STACK; |
| 152 | /* initialize first ci */ | 109 | /* initialize first 'function' */ |
| 153 | ci = &L1->base_ci; | 110 | L1->func = L1->stack; |
| 154 | ci->next = ci->previous = NULL; | ||
| 155 | L1->func = ci->func = L1->top; | ||
| 156 | L1->func->stkci.previous = 0; /* end of linked list */ | 111 | L1->func->stkci.previous = 0; /* end of linked list */ |
| 157 | L1->func->stkci.framesize = LUA_MINSTACK + 1; | 112 | L1->func->stkci.framesize = LUA_MINSTACK + 1; |
| 158 | callstatus(L1->func) = 0; | 113 | callstatus(L1->func) = 0; |
| 159 | setnilvalue(s2v(L1->top)); /* 'function' entry for this 'ci' */ | 114 | setnilvalue(s2v(L1->top)); /* 'function' entry for this 'ci' */ |
| 160 | L1->top++; | 115 | L1->top++; |
| 161 | L1->ci = ci; | ||
| 162 | } | 116 | } |
| 163 | 117 | ||
| 164 | 118 | ||
| 165 | static void freestack (lua_State *L) { | 119 | static void freestack (lua_State *L) { |
| 166 | if (L->stack == NULL) | 120 | if (L->stack == NULL) |
| 167 | return; /* stack not completely built yet */ | 121 | return; /* stack not completely built yet */ |
| 168 | L->ci = &L->base_ci; /* free the entire 'ci' list */ | ||
| 169 | luaE_freeCI(L); | ||
| 170 | lua_assert(L->nci == 0); | 122 | lua_assert(L->nci == 0); |
| 171 | luaM_freearray(L, L->stack, L->stacksize); /* free stack array */ | 123 | luaM_freearray(L, L->stack, L->stacksize); /* free stack array */ |
| 172 | } | 124 | } |
| @@ -216,7 +168,6 @@ static void f_luaopen (lua_State *L, void *ud) { | |||
| 216 | static void preinit_thread (lua_State *L, global_State *g) { | 168 | static void preinit_thread (lua_State *L, global_State *g) { |
| 217 | G(L) = g; | 169 | G(L) = g; |
| 218 | L->stack = NULL; | 170 | L->stack = NULL; |
| 219 | L->ci = NULL; | ||
| 220 | L->func = NULL; | 171 | L->func = NULL; |
| 221 | L->nci = 0; | 172 | L->nci = 0; |
| 222 | L->stacksize = 0; | 173 | L->stacksize = 0; |
