Parse/GC interaction fixed.

Remove the OP_NEWARGS "optimization" (it wasn't).
This commit is contained in:
andy 2003-12-22 19:27:51 +00:00
parent 6a19bbee7d
commit 5aac63d9f5
4 changed files with 6 additions and 14 deletions

View File

@ -102,8 +102,6 @@ static void initContext(struct Context* c)
for(i=0; i<MAX_RECURSION; i++) for(i=0; i<MAX_RECURSION; i++)
c->fStack[i].args = naNil(); c->fStack[i].args = naNil();
c->argPool = naNewVector(c);
// Note we can't use naNewVector() for this; it requires that // Note we can't use naNewVector() for this; it requires that
// temps exist first. // temps exist first.
c->temps = naObj(T_VEC, naGC_get(&(c->pools[T_VEC]))); c->temps = naObj(T_VEC, naGC_get(&(c->pools[T_VEC])));
@ -138,7 +136,6 @@ void naGarbageCollect()
for(i=0; i < c->opTop; i++) for(i=0; i < c->opTop; i++)
naGC_mark(c->opStack[i]); naGC_mark(c->opStack[i]);
naGC_mark(c->argPool);
naGC_mark(c->temps); naGC_mark(c->temps);
naGC_mark(c->save); naGC_mark(c->save);
@ -465,7 +462,6 @@ static void run1(struct Context* ctx, struct Frame* f, naRef code)
ctx->opTop = f->bp; // restore the correct stack frame! ctx->opTop = f->bp; // restore the correct stack frame!
ctx->fTop--; ctx->fTop--;
ctx->fStack[ctx->fTop].args.ref.ptr.vec->size = 0; ctx->fStack[ctx->fTop].args.ref.ptr.vec->size = 0;
naVec_append(ctx->argPool, ctx->fStack[ctx->fTop].args);
PUSH(ctx, a); PUSH(ctx, a);
break; break;
case OP_LINE: case OP_LINE:
@ -483,10 +479,6 @@ static void run1(struct Context* ctx, struct Frame* f, naRef code)
case OP_BREAK: // restore stack state (FOLLOW WITH JMP!) case OP_BREAK: // restore stack state (FOLLOW WITH JMP!)
ctx->opTop = ctx->markStack[--ctx->markTop]; ctx->opTop = ctx->markStack[--ctx->markTop];
break; break;
case OP_NEWARGS: // push a new function arg vector
PUSH(ctx, (naVec_size(ctx->argPool) ?
naVec_removelast(ctx->argPool) : naNewVector(ctx)));
break;
default: default:
ERR(ctx, "BUG: bad opcode"); ERR(ctx, "BUG: bad opcode");
} }

View File

@ -16,7 +16,7 @@ enum {
OP_PUSHCONST, OP_PUSHONE, OP_PUSHZERO, OP_PUSHNIL, OP_POP, OP_PUSHCONST, OP_PUSHONE, OP_PUSHZERO, OP_PUSHNIL, OP_POP,
OP_DUP, OP_XCHG, OP_INSERT, OP_EXTRACT, OP_MEMBER, OP_SETMEMBER, OP_DUP, OP_XCHG, OP_INSERT, OP_EXTRACT, OP_MEMBER, OP_SETMEMBER,
OP_LOCAL, OP_SETLOCAL, OP_NEWVEC, OP_VAPPEND, OP_NEWHASH, OP_HAPPEND, OP_LOCAL, OP_SETLOCAL, OP_NEWVEC, OP_VAPPEND, OP_NEWHASH, OP_HAPPEND,
OP_LINE, OP_MARK, OP_UNMARK, OP_BREAK, OP_NEWARGS OP_LINE, OP_MARK, OP_UNMARK, OP_BREAK
}; };
struct Frame { struct Frame {
@ -41,10 +41,6 @@ struct Context {
int markTop; int markTop;
int done; int done;
// Vector of arguments vectors. A LIFO cache, basically, to avoid
// thrashing the GC just for function call arguments.
naRef argPool;
// Constants // Constants
naRef meRef; naRef meRef;
naRef argRef; naRef argRef;

View File

@ -163,7 +163,7 @@ static void genFuncall(struct Parser* p, struct Token* t)
} else { } else {
genExpr(p, LEFT(t)); genExpr(p, LEFT(t));
} }
emit(p, OP_NEWARGS); emit(p, OP_NEWVEC);
if(RIGHT(t)) genList(p, RIGHT(t)); if(RIGHT(t)) genList(p, RIGHT(t));
emit(p, op); emit(p, op);
} }

View File

@ -489,6 +489,9 @@ naRef naParseCode(struct Context* c, naRef srcFile, int firstLine,
struct Token* t; struct Token* t;
struct Parser p; struct Parser p;
// Protect from garbage collection
naVec_append(c->temps, srcFile);
// Catch parser errors here. // Catch parser errors here.
*errLine = 0; *errLine = 0;
if(setjmp(p.jumpHandle)) { if(setjmp(p.jumpHandle)) {
@ -520,6 +523,7 @@ naRef naParseCode(struct Context* c, naRef srcFile, int firstLine,
// Clean up our mess // Clean up our mess
naParseDestroy(&p); naParseDestroy(&p);
naVec_append(c->temps, codeObj);
return codeObj; return codeObj;
} }