X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fnasal%2Fcode.c;h=02829f711bf889ee1d722bd8910565ecaf63f7c3;hb=a0bdec284624820feb0a96a06c0c38e2f07d5e4e;hp=d24dcc47ddce5927a33da176479a4bf6b6d79502;hpb=1786692406214447db12b9d5af5364582af23d3b;p=simgear.git diff --git a/simgear/nasal/code.c b/simgear/nasal/code.c index d24dcc47..02829f71 100644 --- a/simgear/nasal/code.c +++ b/simgear/nasal/code.c @@ -102,8 +102,6 @@ static void initContext(struct Context* c) for(i=0; ifStack[i].args = naNil(); - c->argPool = naNewVector(c); - // Note we can't use naNewVector() for this; it requires that // temps exist first. c->temps = naObj(T_VEC, naGC_get(&(c->pools[T_VEC]))); @@ -138,7 +136,6 @@ void naGarbageCollect() for(i=0; i < c->opTop; i++) naGC_mark(c->opStack[i]); - naGC_mark(c->argPool); naGC_mark(c->temps); naGC_mark(c->save); @@ -358,8 +355,12 @@ static void run1(struct Context* ctx, struct Frame* f, naRef code) PUSH(ctx, evalAndOr(ctx, op, a, b)); break; case OP_CAT: - a = stringify(ctx, POP(ctx)); b = stringify(ctx, POP(ctx)); + // stringify can call the GC, so don't take stuff of the stack! + if(ctx->opTop <= 1) ERR(ctx, "BUG: stack underflow"); + a = stringify(ctx, ctx->opStack[ctx->opTop-1]); + b = stringify(ctx, ctx->opStack[ctx->opTop-2]); c = naStr_concat(naNewString(ctx), b, a); + ctx->opTop -= 2; PUSH(ctx, c); break; case OP_NEG: @@ -453,6 +454,7 @@ static void run1(struct Context* ctx, struct Frame* f, naRef code) break; case OP_MCALL: c = POP(ctx); b = POP(ctx); a = POP(ctx); // a,b,c = obj, func, args + naVec_append(ctx->temps, a); setupFuncall(ctx, b, c); naHash_set(ctx->fStack[ctx->fTop-1].locals, ctx->meRef, a); break; @@ -461,7 +463,6 @@ static void run1(struct Context* ctx, struct Frame* f, naRef code) ctx->opTop = f->bp; // restore the correct stack frame! ctx->fTop--; ctx->fStack[ctx->fTop].args.ref.ptr.vec->size = 0; - naVec_append(ctx->argPool, ctx->fStack[ctx->fTop].args); PUSH(ctx, a); break; case OP_LINE: @@ -479,10 +480,6 @@ static void run1(struct Context* ctx, struct Frame* f, naRef code) case OP_BREAK: // restore stack state (FOLLOW WITH JMP!) ctx->opTop = ctx->markStack[--ctx->markTop]; break; - case OP_NEWARGS: // push a new function arg vector - PUSH(ctx, (naVec_size(ctx->argPool) ? - naVec_removelast(ctx->argPool) : naNewVector(ctx))); - break; default: ERR(ctx, "BUG: bad opcode"); } @@ -531,6 +528,7 @@ static naRef run(naContext ctx) { // Return early if an error occurred. It will be visible to the // caller via naGetError(). + ctx->error = 0; if(setjmp(ctx->jumpHandle)) return naNil();