diff options
author | Mike Pall <mike> | 2010-02-13 04:51:56 +0100 |
---|---|---|
committer | Mike Pall <mike> | 2010-02-13 04:51:56 +0100 |
commit | c93138b59e8f28b3d412cd7ec0c6631fd27e3e1b (patch) | |
tree | 8c0ffe2086ab0b032ed8e9f92ae6fb9d4d040d66 /src/lj_parse.c | |
parent | 4f8d7be8ea8a103f4d9046188d6005740b74f3d4 (diff) | |
download | luajit-c93138b59e8f28b3d412cd7ec0c6631fd27e3e1b.tar.gz luajit-c93138b59e8f28b3d412cd7ec0c6631fd27e3e1b.tar.bz2 luajit-c93138b59e8f28b3d412cd7ec0c6631fd27e3e1b.zip |
Major redesign of function call handling.
Drop call gates. Use function headers, dispatched like bytecodes.
Emit BC_FUNCF/BC_FUNCV bytecode at PC 0 for all Lua functions.
C functions and ASM fast functions get extra bytecodes.
Modify internal calling convention: new base in BASE (formerly in RA).
Can now use better C function wrapper semantics (dynamic on/off).
Prerequisite for call hooks with zero-overhead if disabled.
Prerequisite for compiling recursive calls.
Prerequisite for efficient 32/64 bit prototype guards.
Diffstat (limited to 'src/lj_parse.c')
-rw-r--r-- | src/lj_parse.c | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/src/lj_parse.c b/src/lj_parse.c index acc25519..3bef225a 100644 --- a/src/lj_parse.c +++ b/src/lj_parse.c | |||
@@ -1036,7 +1036,10 @@ static void fs_fixup_bc(FuncState *fs, GCproto *pt, BCIns *bc, BCLine *lineinfo) | |||
1036 | setmref(pt->lineinfo, lineinfo); | 1036 | setmref(pt->lineinfo, lineinfo); |
1037 | pt->sizebc = n; | 1037 | pt->sizebc = n; |
1038 | bc[n] = ~0u; /* Close potentially uninitialized gap between bc and kgc. */ | 1038 | bc[n] = ~0u; /* Close potentially uninitialized gap between bc and kgc. */ |
1039 | for (i = 0; i < n; i++) { | 1039 | bc[0] = BCINS_AD((fs->flags & PROTO_IS_VARARG) ? BC_FUNCV : BC_FUNCF, |
1040 | fs->framesize, 0); | ||
1041 | lineinfo[0] = fs->linedefined; | ||
1042 | for (i = 1; i < n; i++) { | ||
1040 | bc[i] = base[i].ins; | 1043 | bc[i] = base[i].ins; |
1041 | lineinfo[i] = base[i].line; | 1044 | lineinfo[i] = base[i].line; |
1042 | } | 1045 | } |
@@ -1181,7 +1184,6 @@ static GCproto *fs_finish(LexState *ls, BCLine line) | |||
1181 | pt->flags = fs->flags; | 1184 | pt->flags = fs->flags; |
1182 | pt->numparams = fs->numparams; | 1185 | pt->numparams = fs->numparams; |
1183 | pt->framesize = fs->framesize; | 1186 | pt->framesize = fs->framesize; |
1184 | pt->linedefined = fs->linedefined; | ||
1185 | pt->lastlinedefined = line; | 1187 | pt->lastlinedefined = line; |
1186 | 1188 | ||
1187 | fs_fixup_bc(fs, pt, (BCIns *)((char *)pt + sizeof(GCproto)), | 1189 | fs_fixup_bc(fs, pt, (BCIns *)((char *)pt + sizeof(GCproto)), |
@@ -1416,29 +1418,30 @@ static void parse_chunk(LexState *ls); | |||
1416 | /* Parse body of a function. */ | 1418 | /* Parse body of a function. */ |
1417 | static void parse_body(LexState *ls, ExpDesc *e, int needself, BCLine line) | 1419 | static void parse_body(LexState *ls, ExpDesc *e, int needself, BCLine line) |
1418 | { | 1420 | { |
1419 | FuncState cfs, *fs = ls->fs; | 1421 | FuncState fs, *pfs = ls->fs; |
1420 | BCReg kidx; | 1422 | BCReg kidx; |
1421 | BCLine lastline; | 1423 | BCLine lastline; |
1422 | GCproto *pt; | 1424 | GCproto *pt; |
1423 | ptrdiff_t oldbase = fs->bcbase - ls->bcstack; | 1425 | ptrdiff_t oldbase = pfs->bcbase - ls->bcstack; |
1424 | fs_init(ls, &cfs); | 1426 | fs_init(ls, &fs); |
1425 | cfs.linedefined = line; | 1427 | fs.linedefined = line; |
1426 | cfs.numparams = (uint8_t)parse_params(ls, needself); | 1428 | fs.numparams = (uint8_t)parse_params(ls, needself); |
1427 | cfs.bcbase = fs->bcbase + fs->pc; | 1429 | fs.bcbase = pfs->bcbase + pfs->pc; |
1428 | cfs.bclim = fs->bclim - fs->pc; | 1430 | fs.bclim = pfs->bclim - pfs->pc; |
1431 | bcemit_AD(&fs, BC_FUNCF, 0, 0); /* Placeholder. */ | ||
1429 | parse_chunk(ls); | 1432 | parse_chunk(ls); |
1430 | lastline = ls->linenumber; | 1433 | lastline = ls->linenumber; |
1431 | lex_match(ls, TK_end, TK_function, line); | 1434 | lex_match(ls, TK_end, TK_function, line); |
1432 | pt = fs_finish(ls, lastline); | 1435 | pt = fs_finish(ls, lastline); |
1433 | fs->bcbase = ls->bcstack + oldbase; /* May have been reallocated. */ | 1436 | pfs->bcbase = ls->bcstack + oldbase; /* May have been reallocated. */ |
1434 | fs->bclim = (BCPos)(ls->sizebcstack - oldbase); | 1437 | pfs->bclim = (BCPos)(ls->sizebcstack - oldbase); |
1435 | /* Store new prototype in the constant array of the parent. */ | 1438 | /* Store new prototype in the constant array of the parent. */ |
1436 | kidx = const_gc(fs, obj2gco(pt), LJ_TPROTO); | 1439 | kidx = const_gc(pfs, obj2gco(pt), LJ_TPROTO); |
1437 | expr_init(e, VRELOCABLE, bcemit_AD(fs, BC_FNEW, 0, kidx)); | 1440 | expr_init(e, VRELOCABLE, bcemit_AD(pfs, BC_FNEW, 0, kidx)); |
1438 | if (!(fs->flags & PROTO_HAS_FNEW)) { | 1441 | if (!(pfs->flags & PROTO_HAS_FNEW)) { |
1439 | if (fs->flags & PROTO_HAS_RETURN) | 1442 | if (pfs->flags & PROTO_HAS_RETURN) |
1440 | fs->flags |= PROTO_FIXUP_RETURN; | 1443 | pfs->flags |= PROTO_FIXUP_RETURN; |
1441 | fs->flags |= PROTO_HAS_FNEW; | 1444 | pfs->flags |= PROTO_HAS_FNEW; |
1442 | } | 1445 | } |
1443 | } | 1446 | } |
1444 | 1447 | ||
@@ -2227,6 +2230,7 @@ GCproto *lj_parse(LexState *ls) | |||
2227 | fs.bcbase = NULL; | 2230 | fs.bcbase = NULL; |
2228 | fs.bclim = 0; | 2231 | fs.bclim = 0; |
2229 | fs.flags |= PROTO_IS_VARARG; /* Main chunk is always a vararg func. */ | 2232 | fs.flags |= PROTO_IS_VARARG; /* Main chunk is always a vararg func. */ |
2233 | bcemit_AD(&fs, BC_FUNCV, 0, 0); /* Placeholder. */ | ||
2230 | lj_lex_next(ls); /* Read-ahead first token. */ | 2234 | lj_lex_next(ls); /* Read-ahead first token. */ |
2231 | parse_chunk(ls); | 2235 | parse_chunk(ls); |
2232 | if (ls->token != TK_eof) | 2236 | if (ls->token != TK_eof) |