- record all line numbers during function generation. This is useful for error reporting and eventually debugging.
- throw a useful exception when a VM abort occurs, the simple enum was incapable of reporting anything more than the barest minimum, which at least for array index out of bounds errors was insufficient. The current exception mechanism is still insufficient. It really has to report a proper crash location and print a stack trace to the maximum extent possible. Instead it just prints a message and happily goes on. This is not a good solution.
This commit is contained in:
parent
967f6c0269
commit
1e01e6e4df
10 changed files with 159 additions and 78 deletions
|
|
@ -75,12 +75,38 @@ VMFunctionBuilder::~VMFunctionBuilder()
|
|||
|
||||
//==========================================================================
|
||||
//
|
||||
// VMFunctionBuilder :: MakeFunction
|
||||
// VMFunctionBuilder :: BeginStatement
|
||||
//
|
||||
// Creates a new VMScriptFunction out of the data passed to this class.
|
||||
// Records the start of a new statement.
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
void VMFunctionBuilder::BeginStatement(FxExpression *stmt)
|
||||
{
|
||||
// pop empty statement records.
|
||||
while (LineNumbers.Size() > 0 && LineNumbers.Last().InstructionIndex == Code.Size()) LineNumbers.Pop();
|
||||
// only add a new entry if the line number differs.
|
||||
if (LineNumbers.Size() == 0 || stmt->ScriptPosition.ScriptLine != LineNumbers.Last().LineNumber)
|
||||
{
|
||||
StatementInfo si = { (uint16_t)Code.Size(), (uint16_t)stmt->ScriptPosition.ScriptLine };
|
||||
LineNumbers.Push(si);
|
||||
}
|
||||
StatementStack.Push(stmt);
|
||||
}
|
||||
|
||||
void VMFunctionBuilder::EndStatement()
|
||||
{
|
||||
// pop empty statement records.
|
||||
while (LineNumbers.Size() > 0 && LineNumbers.Last().InstructionIndex == Code.Size()) LineNumbers.Pop();
|
||||
StatementStack.Pop();
|
||||
// Re-enter the previous statement.
|
||||
if (StatementStack.Size() > 0)
|
||||
{
|
||||
StatementInfo si = { (uint16_t)Code.Size(), (uint16_t)StatementStack.Last()->ScriptPosition.ScriptLine };
|
||||
LineNumbers.Push(si);
|
||||
}
|
||||
}
|
||||
|
||||
void VMFunctionBuilder::MakeFunction(VMScriptFunction *func)
|
||||
{
|
||||
func->Alloc(Code.Size(), IntConstantList.Size(), FloatConstantList.Size(), StringConstantList.Size(), AddressConstantList.Size());
|
||||
|
|
@ -880,7 +906,10 @@ void FFunctionBuildList::Build()
|
|||
// Emit code
|
||||
try
|
||||
{
|
||||
sfunc->SourceFileName = item.Code->ScriptPosition.FileName; // remember the file name for printing error messages if something goes wrong in the VM.
|
||||
buildit.BeginStatement(item.Code);
|
||||
item.Code->Emit(&buildit);
|
||||
buildit.EndStatement();
|
||||
buildit.MakeFunction(sfunc);
|
||||
sfunc->NumArgs = 0;
|
||||
// NumArgs for the VMFunction must be the amount of stack elements, which can differ from the amount of logical function arguments if vectors are in the list.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue