diff options
author | Mike Pall <mike> | 2010-02-08 05:29:47 +0100 |
---|---|---|
committer | Mike Pall <mike> | 2010-02-08 05:29:47 +0100 |
commit | f275a9d7ef1a47c30cbb9c70897914d633dff14c (patch) | |
tree | d0ca90013142a0e3b4ac486c2923057bdfc7f0cf /src | |
parent | 4424027844bdcdb76e90e0994efafeee7ea5cc1f (diff) | |
download | luajit-f275a9d7ef1a47c30cbb9c70897914d633dff14c.tar.gz luajit-f275a9d7ef1a47c30cbb9c70897914d633dff14c.tar.bz2 luajit-f275a9d7ef1a47c30cbb9c70897914d633dff14c.zip |
Redesign of prototype generation, part 4: late creation of prototype.
Diffstat (limited to 'src')
-rw-r--r-- | src/lj_gc.c | 3 | ||||
-rw-r--r-- | src/lj_parse.c | 37 |
2 files changed, 20 insertions, 20 deletions
diff --git a/src/lj_gc.c b/src/lj_gc.c index 5750d0ef..bcef576b 100644 --- a/src/lj_gc.c +++ b/src/lj_gc.c | |||
@@ -251,8 +251,7 @@ static void gc_traverse_proto(global_State *g, GCproto *pt) | |||
251 | } | 251 | } |
252 | #endif | 252 | #endif |
253 | /* GC during prototype creation could cause NULL fields. */ | 253 | /* GC during prototype creation could cause NULL fields. */ |
254 | if (gcref(pt->chunkname)) | 254 | gc_mark_str(proto_chunkname(pt)); |
255 | gc_mark_str(proto_chunkname(pt)); | ||
256 | for (i = -(ptrdiff_t)pt->sizekgc; i < 0; i++) /* Mark collectable consts. */ | 255 | for (i = -(ptrdiff_t)pt->sizekgc; i < 0; i++) /* Mark collectable consts. */ |
257 | gc_markobj(g, proto_kgc(pt, i)); | 256 | gc_markobj(g, proto_kgc(pt, i)); |
258 | for (i = 0; i < (ptrdiff_t)pt->sizeuvname; i++) /* Mark upvalue names. */ | 257 | for (i = 0; i < (ptrdiff_t)pt->sizeuvname; i++) /* Mark upvalue names. */ |
diff --git a/src/lj_parse.c b/src/lj_parse.c index 54ff6974..ec355403 100644 --- a/src/lj_parse.c +++ b/src/lj_parse.c | |||
@@ -100,7 +100,6 @@ typedef struct UVMap { | |||
100 | 100 | ||
101 | /* Per-function state. */ | 101 | /* Per-function state. */ |
102 | typedef struct FuncState { | 102 | typedef struct FuncState { |
103 | GCproto *pt; /* Prototype object to be built. */ | ||
104 | GCtab *kt; /* Hash table for constants. */ | 103 | GCtab *kt; /* Hash table for constants. */ |
105 | LexState *ls; /* Lexer state. */ | 104 | LexState *ls; /* Lexer state. */ |
106 | lua_State *L; /* Lua state. */ | 105 | lua_State *L; /* Lua state. */ |
@@ -1129,12 +1128,26 @@ static GCproto *fs_finish(LexState *ls, BCLine line) | |||
1129 | { | 1128 | { |
1130 | lua_State *L = ls->L; | 1129 | lua_State *L = ls->L; |
1131 | FuncState *fs = ls->fs; | 1130 | FuncState *fs = ls->fs; |
1132 | GCproto *pt = fs->pt; | 1131 | GCproto *pt; |
1133 | 1132 | ||
1134 | /* Apply final fixups. */ | 1133 | /* Apply final fixups. */ |
1135 | var_remove(ls, 0); | 1134 | var_remove(ls, 0); |
1135 | lua_assert(fs->bl == NULL); | ||
1136 | fs_fixup_ret(fs); | 1136 | fs_fixup_ret(fs); |
1137 | 1137 | ||
1138 | /* Allocate prototype and initialize its fields. */ | ||
1139 | pt = lj_func_newproto(L); | ||
1140 | setgcref(pt->chunkname, obj2gco(ls->chunkname)); | ||
1141 | pt->flags = fs->flags; | ||
1142 | pt->numparams = fs->numparams; | ||
1143 | pt->framesize = fs->framesize; | ||
1144 | pt->linedefined = fs->linedefined; | ||
1145 | pt->lastlinedefined = line; | ||
1146 | |||
1147 | /* Anchor prototype since allocation of the arrays may fail. */ | ||
1148 | setprotoV(L, L->top, pt); | ||
1149 | incr_top(L); | ||
1150 | |||
1138 | fs_fixup_k(fs, pt); | 1151 | fs_fixup_k(fs, pt); |
1139 | fs_fixup_uv(fs, pt); | 1152 | fs_fixup_uv(fs, pt); |
1140 | 1153 | ||
@@ -1171,23 +1184,15 @@ static GCproto *fs_finish(LexState *ls, BCLine line) | |||
1171 | pt->sizeuvname = n; | 1184 | pt->sizeuvname = n; |
1172 | } | 1185 | } |
1173 | 1186 | ||
1174 | /* Initialize prototype fields. */ | ||
1175 | setgcref(pt->chunkname, obj2gco(ls->chunkname)); | ||
1176 | pt->flags = fs->flags; | ||
1177 | pt->numparams = fs->numparams; | ||
1178 | pt->framesize = fs->framesize; | ||
1179 | pt->linedefined = fs->linedefined; | ||
1180 | pt->lastlinedefined = line; | ||
1181 | |||
1182 | lj_vmevent_send(L, BC, | 1187 | lj_vmevent_send(L, BC, |
1183 | setprotoV(L, L->top++, pt); | 1188 | setprotoV(L, L->top++, pt); |
1184 | ); | 1189 | ); |
1185 | 1190 | ||
1186 | /* Remove VarInfo and FuncState. Pop const table and prototype. */ | 1191 | L->top--; /* Pop prototype. */ |
1187 | lua_assert(fs->bl == NULL); | 1192 | |
1188 | ls->vtop = fs->vbase; | 1193 | L->top--; /* Pop table of constants. */ |
1194 | ls->vtop = fs->vbase; /* Reset variable stack. */ | ||
1189 | ls->fs = fs->prev; | 1195 | ls->fs = fs->prev; |
1190 | L->top -= 2; | ||
1191 | lua_assert(ls->fs != NULL || ls->token == TK_eof); | 1196 | lua_assert(ls->fs != NULL || ls->token == TK_eof); |
1192 | /* Re-anchor last string token to avoid GC. */ | 1197 | /* Re-anchor last string token to avoid GC. */ |
1193 | if (ls->token == TK_name || ls->token == TK_string) { | 1198 | if (ls->token == TK_name || ls->token == TK_string) { |
@@ -1201,8 +1206,6 @@ static GCproto *fs_finish(LexState *ls, BCLine line) | |||
1201 | static void fs_init(LexState *ls, FuncState *fs) | 1206 | static void fs_init(LexState *ls, FuncState *fs) |
1202 | { | 1207 | { |
1203 | lua_State *L = ls->L; | 1208 | lua_State *L = ls->L; |
1204 | GCproto *pt = lj_func_newproto(L); | ||
1205 | fs->pt = pt; | ||
1206 | fs->prev = ls->fs; ls->fs = fs; /* Append to list. */ | 1209 | fs->prev = ls->fs; ls->fs = fs; /* Append to list. */ |
1207 | fs->ls = ls; | 1210 | fs->ls = ls; |
1208 | fs->vbase = ls->vtop; | 1211 | fs->vbase = ls->vtop; |
@@ -1222,8 +1225,6 @@ static void fs_init(LexState *ls, FuncState *fs) | |||
1222 | /* Anchor table of constants and prototype (to avoid being collected). */ | 1225 | /* Anchor table of constants and prototype (to avoid being collected). */ |
1223 | settabV(L, L->top, fs->kt); | 1226 | settabV(L, L->top, fs->kt); |
1224 | incr_top(L); | 1227 | incr_top(L); |
1225 | setprotoV(L, L->top, pt); | ||
1226 | incr_top(L); | ||
1227 | } | 1228 | } |
1228 | 1229 | ||
1229 | /* -- Expressions --------------------------------------------------------- */ | 1230 | /* -- Expressions --------------------------------------------------------- */ |