Changeset 35

Show
Ignore:
Timestamp:
02/08/06 23:59:49 (3 years ago)
Author:
jvargas
Message:

orOpAdd, orOpSub, orOpMul, orOpDiv now include full support for tuples

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/orca/op.c

    r32 r35  
    4343            return; 
    4444        } 
     45        else if( b->type == OT_TUPLE ) 
     46        { 
     47            int tmp, i; 
     48            OValue *res; 
     49 
     50            res = b;  
     51 
     52            for( i = 0; i < res->argc; i++ ) 
     53            { 
     54                tmp = a->integer + b->tuple[i]; 
     55                res->tuple[i] = tmp < 0 ? 0 : tmp > 255 ? 255 : tmp; // should it be a macro? 
     56            }    
     57 
     58            orResultCopy( *res ); 
     59            return; 
     60        } 
    4561        a = b; 
    4662    } 
     
    5773            return; 
    5874        } 
     75        else if( b->type == OT_TUPLE ) 
     76        { 
     77            int tmp, i; 
     78            OValue *res; 
     79 
     80            res = b;  
     81 
     82            for( i = 0; i < res->argc; i++ ) 
     83            { 
     84                tmp = (int) a->num.decimal + b->tuple[i]; 
     85                res->tuple[i] = tmp < 0 ? 0 : tmp > 255 ? 255 : tmp; 
     86            }    
     87 
     88            orResultCopy( *res ); 
     89            return; 
     90        } 
    5991        a = b; 
    6092    } 
     
    6395        if( b->type == OT_TUPLE ) 
    6496        { 
    65             uint32_t tmp, i; 
     97            int tmp, i; 
    6698            OValue* res; 
    6799             
    68             res = orRESULT; 
    69             orSetTF( res, OT_TUPLE ); 
     100            res = a; 
    70101             
    71102            res->argc = a->argc > b->argc ? a->argc : b->argc; 
    72             for( i = 0; i < OR_TUPLE_MAX; i++ ) 
     103            for( i = 0; i < res->argc; i++ ) 
    73104            { 
    74105                tmp = a->tuple[i] + b->tuple[i]; 
    75106                res->tuple[i] = tmp > 255 ? 255 : tmp; 
    76107            } 
    77              
    78108            return; 
    79109        } 
    80110        else if( b->type == OT_INTEGER ) 
    81111        { 
    82             uint32_t tmp, i; 
    83             OValue *res, t; 
    84  
    85             memSet(&t, 0, sizeof(OValue)); 
    86             orSetTF( &t, OT_TUPLE ); 
    87              
    88             t.argc = a->argc; 
    89             for( i = 0; i < t.argc; i++ ) 
     112            int tmp, i; 
     113            OValue *res; 
     114 
     115            res = a; 
     116 
     117            for( i = 0; i < res->argc; i++ ) 
    90118            { 
    91119                tmp = a->tuple[i] + b->integer; 
    92                 t.tuple[i] = tmp > 255 ? 255 : tmp; 
     120                res->tuple[i] = tmp < 0 ? 0 : tmp > 255 ? 255 : tmp; 
    93121            }             
    94  
    95             res = orRESULT; 
    96             memCpy(res, &t, sizeof(OValue)); 
    97             return; 
    98         } 
    99 #if 0 
     122            return; 
     123        } 
    100124        else if( b->type == OT_DECIMAL) 
    101125        { 
    102             orResult( OT_TUPLE, b->integer ); 
    103             return; 
    104         } 
    105 #endif 
     126            int tmp, i; 
     127            OValue *res; 
     128 
     129            res = a; 
     130 
     131            for( i = 0; i < res->argc; i++ ) 
     132            { 
     133                tmp = a->tuple[i] + (int) b->num.decimal; 
     134                res->tuple[i] = tmp < 0 ? 0 : tmp > 255 ? 255 : tmp; 
     135            }             
     136            return; 
     137        } 
    106138        a = b; 
    107139    } 
     
    146178            return; 
    147179        } 
     180 
    148181        a = b; 
    149182    } 
     
    158191        { 
    159192            orResultDECIMAL( a->num.decimal - b->num.decimal ); 
     193            return; 
     194        } 
     195        a = b; 
     196    } 
     197    else if( a->type == OT_TUPLE ) 
     198    { 
     199        if( b->type == OT_TUPLE ) 
     200        { 
     201            int tmp, i; 
     202            OValue* res; 
     203             
     204            res = a; 
     205             
     206            res->argc = a->argc > b->argc ? a->argc : b->argc; 
     207            for( i = 0; i < res->argc; i++ ) 
     208            { 
     209                tmp = a->tuple[i] - b->tuple[i]; 
     210                res->tuple[i] = tmp < 0 ? 0 : tmp; 
     211            } 
     212            return; 
     213        } 
     214        else if( b->type == OT_INTEGER ) 
     215        { 
     216            int tmp, i; 
     217            OValue *res; 
     218 
     219            res = a; 
     220 
     221            for( i = 0; i < res->argc; i++ ) 
     222            { 
     223                tmp = a->tuple[i] - b->integer; 
     224                res->tuple[i] = tmp < 0 ? 0 : tmp > 255 ? 255 : tmp; 
     225            }             
     226            return; 
     227        } 
     228        else if( b->type == OT_DECIMAL) 
     229        { 
     230            int tmp, i; 
     231            OValue *res; 
     232 
     233            res = a; 
     234 
     235            for( i = 0; i < res->argc; i++ ) 
     236            { 
     237                tmp = a->tuple[i] - (int) b->num.decimal; 
     238                res->tuple[i] = tmp < 0 ? 0 : tmp > 255 ? 255 : tmp; 
     239            }             
    160240            return; 
    161241        } 
     
    216296            return; 
    217297        } 
     298        else if( b->type == OT_TUPLE ) 
     299        { 
     300            int tmp, i; 
     301            OValue *res; 
     302 
     303            res = b;  
     304 
     305            for( i = 0; i < res->argc; i++ ) 
     306            { 
     307                tmp = a->integer * b->tuple[i]; 
     308                res->tuple[i] = tmp < 0 ? 0 : tmp > 255 ? 255 : tmp; 
     309            }    
     310 
     311            orResultCopy( *res ); 
     312            return; 
     313        } 
    218314        a = b; 
    219315    } 
     
    228324        { 
    229325            orResultDECIMAL( a->num.decimal * b->num.decimal ); 
     326            return; 
     327        } 
     328        else if( b->type == OT_TUPLE ) 
     329        { 
     330            int tmp, i; 
     331            OValue *res; 
     332 
     333            res = b;  
     334 
     335            for( i = 0; i < res->argc; i++ ) 
     336            { 
     337                tmp = a->num.decimal * b->tuple[i]; 
     338                res->tuple[i] = tmp < 0 ? 0 : tmp > 255 ? 255 : tmp; 
     339            }    
     340 
     341            orResultCopy( *res ); 
     342            return; 
     343        } 
     344        a = b; 
     345    } 
     346    else if( a->type == OT_TUPLE ) 
     347    { 
     348        if( b->type == OT_TUPLE ) 
     349        { 
     350            int tmp, i; 
     351            OValue* res; 
     352             
     353            res = a; 
     354             
     355            res->argc = a->argc > b->argc ? a->argc : b->argc; 
     356            for( i = 0; i < res->argc; i++ ) 
     357            { 
     358                tmp = a->tuple[i] * b->tuple[i]; 
     359                res->tuple[i] = tmp > 255 ? 255 : tmp; 
     360            } 
     361            return; 
     362        } 
     363        else if( b->type == OT_INTEGER ) 
     364        { 
     365            int tmp, i; 
     366            OValue *res; 
     367 
     368            res = a; 
     369 
     370            for( i = 0; i < res->argc; i++ ) 
     371            { 
     372                tmp = a->tuple[i] * b->integer; 
     373                res->tuple[i] = tmp < 0 ? 0 : tmp > 255 ? 255 : tmp; 
     374            }             
     375            return; 
     376        } 
     377        else if( b->type == OT_DECIMAL) 
     378        { 
     379            int tmp, i; 
     380            OValue *res; 
     381 
     382            res = a; 
     383 
     384            for( i = 0; i < res->argc; i++ ) 
     385            { 
     386                tmp = a->tuple[i] * b->num.decimal; 
     387                res->tuple[i] = tmp < 0 ? 0 : tmp > 255 ? 255 : tmp; 
     388            }             
    230389            return; 
    231390        } 
     
    271430                goto div0; 
    272431            orResultDECIMAL( a->num.decimal / b->num.decimal ); 
     432            return; 
     433        } 
     434        a = b; 
     435    } 
     436    else if( a->type == OT_TUPLE ) 
     437    { 
     438        if( b->type == OT_TUPLE ) 
     439        { 
     440            int tmp, i; 
     441            OValue* res; 
     442             
     443            res = a; 
     444             
     445            res->argc = a->argc > b->argc ? a->argc : b->argc; 
     446            for( i = 0; i < res->argc; i++ ) 
     447            { 
     448                if ( b->tuple[i] == 0) 
     449                    goto div0; 
     450                tmp = a->tuple[i] / b->tuple[i]; 
     451                res->tuple[i] = tmp > 255 ? 255 : tmp; 
     452            } 
     453            return; 
     454        } 
     455        else if( b->type == OT_INTEGER ) 
     456        { 
     457            int tmp, i; 
     458            OValue *res; 
     459 
     460            res = a; 
     461 
     462            for( i = 0; i < res->argc; i++ ) 
     463            { 
     464                if (b->integer == 0) 
     465                    goto div0; 
     466                tmp = a->tuple[i] / b->integer; 
     467                res->tuple[i] = tmp < 0 ? 0 : tmp > 255 ? 255 : tmp; 
     468            }             
     469            return; 
     470        } 
     471        else if( b->type == OT_DECIMAL) 
     472        { 
     473            int tmp, i; 
     474            OValue *res; 
     475 
     476            res = a; 
     477 
     478            for( i = 0; i < res->argc; i++ ) 
     479            { 
     480                if (b->num.decimal == 0) 
     481                    goto div0; 
     482                tmp = a->tuple[i] / b->num.decimal; 
     483                res->tuple[i] = tmp < 0 ? 0 : tmp > 255 ? 255 : tmp; 
     484            }             
    273485            return; 
    274486        }