forked from Mirrors/openclonk
Remove pointer to start of variables from function context
It pointed always to Pars + Func->GetParCount(). The only users were VARN_CONTEXT, which can be replaced with PARN_CONTEXT that way, and FOREACH_NEXT, where the parser can do the math and simply give a number relative to the current stack position, like regular variable usages do.liquid_container
parent
45003d55fb
commit
168ac8bb40
|
@ -333,7 +333,7 @@ C4AulDebug::ProcessLineResult C4AulDebug::ProcessLine(const StdStrBuf &Line)
|
|||
}
|
||||
else if ((varIndex = pCtx->Func->VarNamed.GetItemNr(szData)) != -1)
|
||||
{
|
||||
val = &pCtx->Vars[varIndex];
|
||||
val = &pCtx->Pars[pCtx->Func->GetParCount() + varIndex];
|
||||
}
|
||||
}
|
||||
const char* typeName = val ? GetC4VName(val->GetType()) : "any";
|
||||
|
|
|
@ -56,24 +56,23 @@ StdStrBuf C4AulScriptContext::ReturnDump(StdStrBuf Dump)
|
|||
Dump.AppendChar('(');
|
||||
int iNullPars = 0;
|
||||
for (int i = 0; i < Func->GetParCount(); i++)
|
||||
if (Pars + i < Vars)
|
||||
{
|
||||
if (!Pars[i])
|
||||
iNullPars++;
|
||||
else
|
||||
{
|
||||
if (!Pars[i])
|
||||
iNullPars++;
|
||||
else
|
||||
if (i > iNullPars)
|
||||
Dump.AppendChar(',');
|
||||
// Insert missing null parameters
|
||||
while (iNullPars > 0)
|
||||
{
|
||||
if (i > iNullPars)
|
||||
Dump.AppendChar(',');
|
||||
// Insert missing null parameters
|
||||
while (iNullPars > 0)
|
||||
{
|
||||
Dump.Append("0,");
|
||||
iNullPars--;
|
||||
}
|
||||
// Insert parameter
|
||||
Dump.Append(Pars[i].GetDataString());
|
||||
Dump.Append("0,");
|
||||
iNullPars--;
|
||||
}
|
||||
// Insert parameter
|
||||
Dump.Append(Pars[i].GetDataString());
|
||||
}
|
||||
}
|
||||
Dump.AppendChar(')');
|
||||
}
|
||||
else
|
||||
|
@ -162,7 +161,6 @@ C4Value C4AulExec::Exec(C4AulScriptFunc *pSFunc, C4PropList * p, C4Value *pnPars
|
|||
ctx.Obj = p;
|
||||
ctx.Return = NULL;
|
||||
ctx.Pars = pPars;
|
||||
ctx.Vars = pCurVal + 1;
|
||||
ctx.Func = pSFunc;
|
||||
ctx.CPos = NULL;
|
||||
PushContext(ctx);
|
||||
|
@ -247,14 +245,10 @@ C4Value C4AulExec::Exec(C4AulBCC *pCPos)
|
|||
case AB_ERR:
|
||||
throw C4AulExecError("syntax error: see above for details");
|
||||
|
||||
case AB_PARN_CONTEXT:
|
||||
case AB_DUP_CONTEXT:
|
||||
PushValue(AulExec.GetContext(AulExec.GetContextDepth()-2)->Pars[pCPos->Par.i]);
|
||||
break;
|
||||
|
||||
case AB_VARN_CONTEXT:
|
||||
PushValue(AulExec.GetContext(AulExec.GetContextDepth()-2)->Vars[pCPos->Par.i]);
|
||||
break;
|
||||
|
||||
case AB_LOCALN:
|
||||
if (!pCurCtx->Obj)
|
||||
throw C4AulExecError("can't access local variables without this");
|
||||
|
@ -733,7 +727,7 @@ C4Value C4AulExec::Exec(C4AulBCC *pCPos)
|
|||
if (pCurVal->_getInt() >= pArray->GetSize())
|
||||
break;
|
||||
// Get next
|
||||
pCurCtx->Vars[pCPos->Par.i] = pArray->GetItem(iItem);
|
||||
pCurVal[pCPos->Par.i] = pArray->GetItem(iItem);
|
||||
// Save position
|
||||
pCurVal->SetInt(iItem + 1);
|
||||
// Jump over next instruction
|
||||
|
@ -837,7 +831,6 @@ C4AulBCC *C4AulExec::Call(C4AulFunc *pFunc, C4Value *pReturn, C4Value *pPars, C4
|
|||
throw C4AulExecError("using removed object");
|
||||
ctx.Return = pReturn;
|
||||
ctx.Pars = pPars;
|
||||
ctx.Vars = pCurVal + 1;
|
||||
ctx.Func = pSFunc;
|
||||
ctx.CPos = NULL;
|
||||
PushContext(ctx);
|
||||
|
|
|
@ -43,7 +43,6 @@ struct C4AulScriptContext
|
|||
C4PropList *Obj;
|
||||
C4Value *Return;
|
||||
C4Value *Pars;
|
||||
C4Value *Vars;
|
||||
C4AulScriptFunc *Func;
|
||||
C4AulBCC *CPos;
|
||||
C4TimeMilliseconds tTime; // initialized only by profiler if active
|
||||
|
@ -185,7 +184,7 @@ private:
|
|||
int LocalValueStackSize() const
|
||||
{
|
||||
return ContextStackSize()
|
||||
? pCurVal - pCurCtx->Vars - pCurCtx->Func->VarNamed.iSize + 1
|
||||
? pCurVal - pCurCtx->Pars - pCurCtx->Func->GetParCount() - pCurCtx->Func->VarNamed.iSize + 1
|
||||
: pCurVal - Values + 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -637,9 +637,6 @@ static const char * GetTTName(C4AulBCCType e)
|
|||
case AB_THIS: return "THIS";
|
||||
case AB_FUNC: return "FUNC"; // function
|
||||
|
||||
case AB_PARN_CONTEXT: return "AB_PARN_CONTEXT";
|
||||
case AB_VARN_CONTEXT: return "AB_VARN_CONTEXT";
|
||||
|
||||
// prefix
|
||||
case AB_Inc: return "Inc"; // ++
|
||||
case AB_Dec: return "Dec"; // --
|
||||
|
@ -678,6 +675,7 @@ static const char * GetTTName(C4AulBCCType e)
|
|||
case AB_NIL: return "NIL"; // constant: nil
|
||||
case AB_NEW_ARRAY: return "NEW_ARRAY"; // semi-constant: array
|
||||
case AB_DUP: return "DUP"; // duplicate value from stack
|
||||
case AB_DUP_CONTEXT: return "AB_DUP_CONTEXT"; // duplicate value from stack of parent function
|
||||
case AB_NEW_PROPLIST: return "NEW_PROPLIST"; // create a new proplist
|
||||
case AB_POP_TO: return "POP_TO"; // initialization of named var
|
||||
case AB_JUMP: return "JUMP"; // jump
|
||||
|
@ -820,11 +818,10 @@ int C4AulParse::GetStackValue(C4AulBCCType eType, intptr_t X)
|
|||
case AB_CARRAY:
|
||||
case AB_CFUNCTION:
|
||||
case AB_NIL:
|
||||
case AB_PARN_CONTEXT:
|
||||
case AB_VARN_CONTEXT:
|
||||
case AB_LOCALN:
|
||||
case AB_GLOBALN:
|
||||
case AB_DUP:
|
||||
case AB_DUP_CONTEXT:
|
||||
case AB_THIS:
|
||||
return 1;
|
||||
|
||||
|
@ -2103,7 +2100,7 @@ void C4AulParse::Parse_ForEach()
|
|||
// push initial position (0)
|
||||
AddBCC(AB_INT);
|
||||
// get array element
|
||||
int iStart = AddBCC(AB_FOREACH_NEXT, iVarID);
|
||||
int iStart = AddBCC(AB_FOREACH_NEXT, 1 + iVarID - (iStack + Fn->VarNamed.iSize));
|
||||
// jump out (FOREACH_NEXT will jump over this if
|
||||
// we're not at the end of the array yet)
|
||||
int iCond = AddBCC(AB_JUMP);
|
||||
|
@ -2159,12 +2156,12 @@ void C4AulParse::Parse_Expression(int iParentPrio)
|
|||
}
|
||||
else if (ContextToExecIn && (ndx = ContextToExecIn->Func->ParNamed.GetItemNr(Idtf)) != -1)
|
||||
{
|
||||
AddBCC(AB_PARN_CONTEXT, ndx);
|
||||
AddBCC(AB_DUP_CONTEXT, ndx);
|
||||
Shift();
|
||||
}
|
||||
else if (ContextToExecIn && (ndx = ContextToExecIn->Func->VarNamed.GetItemNr(Idtf)) != -1)
|
||||
{
|
||||
AddBCC(AB_VARN_CONTEXT, ndx);
|
||||
AddBCC(AB_DUP_CONTEXT, ContextToExecIn->Func->GetParCount() + ndx);
|
||||
Shift();
|
||||
}
|
||||
// check for variable (local)
|
||||
|
|
|
@ -30,6 +30,7 @@ enum C4AulBCCType
|
|||
AB_ARRAY_SLICE, // array slicing
|
||||
AB_ARRAY_SLICE_SET,
|
||||
AB_DUP, // duplicate value from stack
|
||||
AB_DUP_CONTEXT, // duplicate value from stack of parent function
|
||||
AB_STACK_SET, // copy top of stack to stack
|
||||
AB_POP_TO, // pop top of stack to stack
|
||||
AB_LOCALN, // a property of this
|
||||
|
@ -40,9 +41,6 @@ enum C4AulBCCType
|
|||
AB_THIS, // this()
|
||||
AB_FUNC, // function
|
||||
|
||||
AB_PARN_CONTEXT,
|
||||
AB_VARN_CONTEXT,
|
||||
|
||||
// prefix
|
||||
AB_Inc, // ++
|
||||
AB_Dec, // --
|
||||
|
|
Loading…
Reference in New Issue