Create PropLists with one bytecode instead of one per property

Günther Brammer 2011-04-09 21:35:16 +02:00
parent 71f42d7d8f
commit a3fab0234e
3 changed files with 27 additions and 54 deletions

View File

@ -32,26 +32,9 @@
#include <string>
#include <vector>
class C4Def;
class C4DefList;
// class predefs
class C4AulError;
class C4AulFunc;
class C4AulScriptFunc;
class C4AulDefFunc;
class C4AulScript;
class C4AulScriptEngine;
class C4AulDebug;
class C4LangStringTable;
struct C4AulContext;
struct C4AulBCC;
// consts
#define C4AUL_MAX_Identifier 100 // max length of function identifiers
#define C4AUL_MAX_Par 10 // max number of parameters
#define C4AUL_MAX_Var 10 // max number of func local vars
// generic C4Aul error class
class C4AulError
@ -170,10 +153,9 @@ enum C4AulBCCType
AB_CPROPLIST, // constant: proplist
AB_CARRAY, // constant: array
AB_NIL, // constant: nil
AB_ARRAY, // semi-constant: array
AB_NEW_ARRAY, // semi-constant: array
AB_DUP, // duplicate value from stack
AB_PROPLIST, // create a new proplist
AB_IPROPLIST, // set a property of a proplist
AB_NEW_PROPLIST, // create a new proplist
AB_IVARN, // initialization of named var
AB_JUMP, // jump
AB_JUMPAND, // jump if zero, else pop the stack

View File

@ -420,7 +420,7 @@ C4Value C4AulExec::Exec(C4AulBCC *pCPos, bool fPassErrors)
PopValue();
break;
}
case AB_ARRAY:
case AB_NEW_ARRAY:
{
// Create array
C4ValueArray *pArray = new C4ValueArray(pCPos->Par.i);
@ -430,31 +430,21 @@ C4Value C4AulExec::Exec(C4AulBCC *pCPos, bool fPassErrors)
(*pArray)[i] = pCurVal[i - pCPos->Par.i + 1];
// Push array
if (pCPos->Par.i > 0)
{
PopValues(pCPos->Par.i - 1);
pCurVal->SetArray(pArray);
}
else
PushArray(pArray);
PopValues(pCPos->Par.i);
PushArray(pArray);
break;
}
case AB_PROPLIST:
case AB_NEW_PROPLIST:
{
PushPropList(C4PropList::New());
break;
}
case AB_IPROPLIST:
{
C4Value *pPropSet = pCurVal - 2, *pKey = pCurVal -1, *pValue = pCurVal;
if (!pPropSet->ConvertTo(C4V_PropList))
throw new C4AulExecError(pCurCtx->Obj, FormatString("internal error: proplist expected, got %s", pPropSet->GetTypeName()).getData());
if (!pKey->ConvertTo(C4V_String))
throw new C4AulExecError(pCurCtx->Obj, FormatString("internal error: string expected, got %s", pPropSet->GetTypeName()).getData());
pPropSet->_getPropList()->SetPropertyByS(pKey->_getStr(), *pValue);
PopValues(2);
C4PropList * pPropList = C4PropList::New();
for (int i = 0; i < pCPos->Par.i; i++)
pPropList->SetPropertyByS(pCurVal[-2 * i - 1]._getStr(), pCurVal[-2 * i]);
PopValues(pCPos->Par.i * 2);
PushPropList(pPropList);
break;
}

View File

@ -825,10 +825,9 @@ static const char * GetTTName(C4AulBCCType e)
case AB_CPROPLIST: return "CPROPLIST"; // constant: proplist
case AB_CARRAY: return "CARRAY"; // constant: array
case AB_NIL: return "NIL"; // constant: nil
case AB_ARRAY: return "ARRAY"; // semi-constant: array
case AB_DUP: return "DUP"; // constant: nil
case AB_PROPLIST: return "PROPLIST"; // semi-constant: array
case AB_IPROPLIST: return "IPROPLIST";
case AB_NEW_ARRAY: return "NEW_ARRAY"; // semi-constant: array
case AB_DUP: return "DUP"; // duplicate value from stack
case AB_NEW_PROPLIST: return "NEW_PROPLIST"; // create a new proplist
case AB_IVARN: return "IVARN"; // initialization of named var
case AB_JUMP: return "JUMP"; // jump
case AB_JUMPAND: return "JUMPAND";
@ -956,7 +955,6 @@ int C4AulParseState::GetStackValue(C4AulBCCType eType, intptr_t X)
case AB_STRING:
case AB_CPROPLIST:
case AB_CARRAY:
case AB_PROPLIST:
case AB_NIL:
case AB_VARN:
case AB_PARN:
@ -1026,12 +1024,14 @@ int C4AulParseState::GetStackValue(C4AulBCCType eType, intptr_t X)
case AB_STACK:
return X;
case AB_ARRAY:
case AB_NEW_ARRAY:
return -X+1;
case AB_NEW_PROPLIST:
return -X * 2 + 1;
case AB_ARRAYA_SET:
case AB_ARRAY_SLICE:
case AB_IPROPLIST:
return -2;
case AB_ARRAY_SLICE_SET:
@ -1910,8 +1910,8 @@ int C4AulParseState::Parse_Params(int iMaxCnt, const char * sWarn, C4AulFunc * p
{
case AB_INT: from = Config.Developer.ExtraWarnings || (a->CPos-1)->Par.i ? C4V_Int : C4V_Any; break;
case AB_STRING: from = C4V_String; break;
case AB_ARRAY: case AB_CARRAY: case AB_ARRAY_SLICE: from = C4V_Array; break;
case AB_PROPLIST: case AB_CPROPLIST: from = C4V_PropList; break;
case AB_NEW_ARRAY: case AB_CARRAY: case AB_ARRAY_SLICE: from = C4V_Array; break;
case AB_NEW_PROPLIST: case AB_CPROPLIST: from = C4V_PropList; break;
case AB_BOOL: from = C4V_Bool; break;
case AB_FUNC:
from = (a->CPos-1)->Par.f->GetRetType(); break;
@ -2016,13 +2016,13 @@ void C4AulParseState::Parse_Array()
}
while (!fDone);
// add terminator
AddBCC(AB_ARRAY, size);
AddBCC(AB_NEW_ARRAY, size);
}
void C4AulParseState::Parse_PropList()
{
AddBCC(AB_PROPLIST);
Shift();
int size = 0;
// insert block in byte code
while (TokenType != ATT_BLCLOSE)
{
@ -2043,12 +2043,13 @@ void C4AulParseState::Parse_PropList()
UnexpectedToken("':' or '='");
Shift();
Parse_Expression();
AddBCC(AB_IPROPLIST);
++size;
if (TokenType == ATT_COMMA)
Shift();
else if (TokenType != ATT_BLCLOSE)
UnexpectedToken("'}' or ','");
}
AddBCC(AB_NEW_PROPLIST, size);
Shift();
}
@ -3133,7 +3134,7 @@ bool C4AulScript::Parse()
case AB_STRING:
fprintf(stderr, "\t\"%s\"\n", pBCC->Par.s->GetCStr()); break;
case AB_DEBUG: case AB_NIL: case AB_RETURN:
case AB_PROPLIST: case AB_IPROPLIST: case AB_PAR:
case AB_PAR:
case AB_ARRAYA: case AB_ARRAY_SLICE: case AB_ERR:
case AB_EOFN: case AB_EOF:
assert(!pBCC->Par.X); fprintf(stderr, "\n"); break;