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

Started by
3 comments, last by WitchLord 19 years, 7 months ago
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
Advertisement
Thanks RCL. I'll look into it. The fix should be quite easy, just a matter of releasing the temporary variables at right location.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

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);}

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

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
Thanks. I try to do my best [wink]

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement