Script: Repeat the parser error message when executing a broken function

liquid_container
Günther Brammer 2016-04-29 19:52:13 +02:00
parent 17b18da26c
commit b8f2d0ca87
3 changed files with 13 additions and 7 deletions

View File

@ -1154,7 +1154,7 @@ void C4CodeGen::AddLoopControl(const char * SPos, bool fBreak)
AddBCC(SPos, AB_JUMP);
}
void C4CodeGen::ErrorOut(const char * SPos)
void C4CodeGen::ErrorOut(const char * SPos, C4AulError & e)
{
// make all jumps that don't have their destination yet jump here
for (unsigned int i = 0; i < Fn->Code.size(); i++)
@ -1165,7 +1165,9 @@ void C4CodeGen::ErrorOut(const char * SPos)
pBCC->Par.i = Fn->Code.size() - i;
}
// add an error chunk
AddBCC(SPos, AB_ERR);
const char * msg = e.what();
if (SEqual2(msg, "ERROR: ")) msg += 7;
AddBCC(SPos, AB_ERR, reinterpret_cast<intptr_t>(::Strings.RegString(msg)));
}
const char * C4AulParse::GetTokenName(C4AulTokenType TokenType)
@ -1341,7 +1343,7 @@ void C4AulParse::Parse_Script(C4ScriptHost * scripthost)
if (Fn)
{
codegen.ErrorOut(TokenSPos);
codegen.ErrorOut(TokenSPos, err);
}
}
}

View File

@ -32,7 +32,7 @@ public:
int GetStackValue(C4AulBCCType eType, intptr_t X = 0);
int AddBCC(const char * SPos, C4AulBCCType eType, intptr_t X = 0);
void ErrorOut(const char * SPos);
void ErrorOut(const char * SPos, C4AulError & e);
void RemoveLastBCC();
C4V_Type GetLastRetType(C4AulScriptEngine * Engine, C4V_Type to); // for warning purposes

View File

@ -106,7 +106,7 @@ public:
C4ValueArray * a;
C4AulFunc * f;
} Par; // extra info
C4AulBCC(): bccType(AB_ERR) { }
C4AulBCC(): bccType(AB_EOFN) { }
C4AulBCC(C4AulBCCType bccType, intptr_t X): bccType(bccType), Par{X}
{
IncRef();
@ -122,14 +122,14 @@ public:
}
C4AulBCC(C4AulBCC && from): bccType(from.bccType), Par(from.Par)
{
from.bccType = AB_ERR;
from.bccType = AB_EOFN;
}
C4AulBCC & operator = (C4AulBCC && from)
{
DecRef();
bccType = from.bccType;
Par = from.Par;
from.bccType = AB_ERR;
from.bccType = AB_EOFN;
return *this;
}
~C4AulBCC()
@ -141,6 +141,8 @@ private:
{
switch (bccType)
{
case AB_ERR:
if (Par.s)
case AB_STRING: case AB_CALL: case AB_CALLFS: case AB_LOCALN: case AB_LOCALN_SET: case AB_PROP: case AB_PROP_SET:
Par.s->IncRef();
break;
@ -154,6 +156,8 @@ private:
{
switch (bccType)
{
case AB_ERR:
if (Par.s)
case AB_STRING: case AB_CALL: case AB_CALLFS: case AB_LOCALN: case AB_LOCALN_SET: case AB_PROP: case AB_PROP_SET:
Par.s->DecRef();
break;