Sign in to follow this  
RCL

assert( tempVariables.GetLength() == 0 ) fails

Recommended Posts

RCL    123
Hi, Assertion tempVariables.GetLength() == 0 fails when Build()ing the following script:
int main()
{
    bstr s = true ? "true" : "false";

    return 0;
}


AngelScript 1.9.0 ( + BubbleSort fix ) Cheers, RCL

Share this post


Link to post
Share on other sites
WitchLord    4677
I've found and fixed the bug. The fix is not quite as simple as I thought, but here it is: Exchange the function asCCompiler::CompileCondition() in as_compiler_expressions.cpp for the below function.


void asCCompiler::CompileCondition(asCScriptNode *expr, asCByteCode *bc, sTypeInfo *type)
{
sTypeInfo ctype, rtype, ltype;

// Compile the conditional expression
asCScriptNode *cexpr = expr->firstChild;
if( cexpr->next )
{
CompileExpression(cexpr, bc, &ctype);
PrepareOperand(&ctype, bc, cexpr);
if( ctype.dataType != asCDataType(ttBool, true, false) )
Error(TXT_EXPR_MUST_BE_BOOL, cexpr);

int afterLabel = nextLabel++;
int elseLabel = nextLabel++;

bc->InstrINT(BC_JMP0, elseLabel);

CompileAssignment(cexpr->next, bc, &ltype);

// Allocate temporary variable and copy the result to that one
sTypeInfo temp;
temp = ltype;
int offset = AllocateVariable(temp.dataType, true);
temp.isTemporary = true;
temp.stackOffset = (short)offset;

CompileConstructor(temp.dataType, offset, bc);
bc->InstrWORD(BC_PSF, offset);

sTypeInfo rtemp;
rtemp = temp;
rtemp.dataType.isReference = true;
rtemp.dataType.isReadOnly = false;

PrepareForAssignment(&rtemp.dataType, &ltype, bc, cexpr->next);
PerformAssignment(&rtemp, bc, cexpr->next);

// Release the old temporary variable
ReleaseTemporaryVariable(ltype, bc);

bc->InstrINT(BC_JMP, afterLabel);
bc->Label((short)elseLabel);

CompileAssignment(cexpr->next->next, bc, &rtype);

// Copy the result to the same temporary variable
CompileConstructor(temp.dataType, offset, bc);
bc->InstrWORD(BC_PSF, offset);

PrepareForAssignment(&rtemp.dataType, &rtype, bc, cexpr->next);
PerformAssignment(&rtemp, bc, cexpr->next);

// Release the old temporary variable
ReleaseTemporaryVariable(rtype, bc);

bc->Label((short)afterLabel);

// Make sure both expressions have the same type
if( ltype.dataType != rtype.dataType )
Error(TXT_BOTH_MUST_BE_SAME, expr);

// Set the temporary variable as output
*type = temp;
}
else
CompileExpression(cexpr, bc, type);
}

Share this post


Link to post
Share on other sites
RCL    123
Quote:
Original post by WitchLord
I've found and fixed the bug.


You are really quick :) I wish everyone fixed his/her bugs like you do.

Thanks, it compiles and works correctly.

Cheers,
RCL

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this