Changeset 505 for trunk/thune/math.c

Show
Ignore:
Timestamp:
02/05/08 16:46:07 (10 months ago)
Author:
krobillard
Message:

Math functions no longer drop TOS when a datatype error occurs.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/thune/math.c

    r485 r505  
    244244#define MATH_OPERATION_END \ 
    245245        default: \ 
     246            UR_S_GROW; \ 
    246247            ur_throwErr( UR_ERR_DATATYPE, \ 
    247248                         "Math operator requires int!/decimal!/vec3!" ); \ 
     
    388389 
    389390 
     391static void logicError( UThread* ut, const char* name ) 
     392{ 
     393    ur_throwErr( UR_ERR_DATATYPE, "%s expected int!/logic!/char!", name ); 
     394} 
     395 
     396 
    390397// (number number -- and) 
    391398UR_CALL( uc_and ) 
    392399{ 
    393     UCell* res; 
    394     UR_S_DROP; 
    395     res = UR_TOS; 
     400    UCell* res = ur_s_prev(UR_TOS); 
    396401 
    397402    if( UR_IS_ANY3(tos, UT_INT, UT_LOGIC, UT_CHAR) && 
    398403        UR_IS_ANY3(res, UT_INT, UT_LOGIC, UT_CHAR) ) 
    399404    { 
     405        UR_S_DROP; 
    400406        ur_initType(res, UT_INT); 
    401407        ur_int(res) &= ur_int(tos); 
    402408    } 
     409    else 
     410        logicError(ut,"and");  
    403411} 
    404412 
     
    407415UR_CALL( uc_or ) 
    408416{ 
    409     UCell* res; 
    410     UR_S_DROP; 
    411     res = UR_TOS; 
     417    UCell* res = ur_s_prev(UR_TOS); 
    412418 
    413419    if( UR_IS_ANY3(tos, UT_INT, UT_LOGIC, UT_CHAR) && 
    414420        UR_IS_ANY3(res, UT_INT, UT_LOGIC, UT_CHAR) ) 
    415421    { 
     422        UR_S_DROP; 
    416423        ur_initType(res, UT_INT); 
    417424        ur_int(res) |= ur_int(tos); 
    418425    } 
     426    else 
     427        logicError(ut,"or");  
    419428} 
    420429 
     
    423432UR_CALL( uc_xor ) 
    424433{ 
    425     UCell* res; 
    426     UR_S_DROP; 
    427     res = UR_TOS; 
     434    UCell* res = ur_s_prev(UR_TOS); 
    428435 
    429436    if( UR_IS_ANY3(tos, UT_INT, UT_LOGIC, UT_CHAR) && 
    430437        UR_IS_ANY3(res, UT_INT, UT_LOGIC, UT_CHAR) ) 
    431438    { 
     439        UR_S_DROP; 
    432440        ur_initType(res, UT_INT); 
    433441        ur_int(res) ^= ur_int(tos); 
    434442    } 
     443    else 
     444        logicError(ut,"xor");  
    435445} 
    436446 
     
    479489            break; 
    480490        default: 
    481             ur_throwErr( UR_ERR_DATATYPE, 
    482                         "Invalid type for 'minimum" ); 
     491            UR_S_GROW; 
     492            ur_throwErr( UR_ERR_DATATYPE, "Invalid type for 'minimum" ); 
    483493            break; 
    484494    } 
     
    529539            break; 
    530540        default: 
     541            UR_S_GROW; 
    531542            ur_throwErr( UR_ERR_DATATYPE, "Invalid type for 'maximum" ); 
    532543            break;