Changeset 820

Show
Ignore:
Timestamp:
06/25/07 23:40:18 (17 months ago)
Author:
volker
Message:

calculate only necessary elements of operands

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/volker_dev/evaluator.c

    r805 r820  
    973973    RESULT *param[10]; 
    974974 
    975     for (i = 0; i < Root->Children; i++) { 
    976   EvalTree(Root->Child[i]); 
    977     } 
    978  
    979975    switch (Root->Token) { 
    980976 
     
    992988  /* prepare parameter list */ 
    993989  argc = Root->Children; 
    994   if (argc > 10) 
     990  if (argc > 10) { 
     991            error("evaluator: more than 10 children (operands) not supported!"); 
    995992      argc = 10; 
     993        } 
    996994  for (i = 0; i < argc; i++) { 
     995            EvalTree(Root->Child[i]); 
    997996      param[i] = Root->Child[i]->Result; 
    998997  } 
     
    10121011  case O_LST:   /* expression list: result is last expression */ 
    10131012      i = Root->Children - 1; 
     1013            EvalTree(Root->Child[i]); 
    10141014      type = Root->Child[i]->Result->type; 
    10151015      number = Root->Child[i]->Result->number; 
     
    10181018 
    10191019  case O_SET:   /* variable assignment */ 
     1020            EvalTree(Root->Child[0]); 
    10201021      CopyResult(&Root->Variable->value, Root->Child[0]->Result); 
    10211022      type = Root->Child[0]->Result->type; 
     
    10251026 
    10261027  case O_CND:   /* conditional expression */ 
     1028            EvalTree(Root->Child[0]); 
    10271029      i = 1 + (R2N(Root->Child[0]->Result) == 0.0); 
     1030            EvalTree(Root->Child[i]); 
    10281031      type = Root->Child[i]->Result->type; 
    10291032      number = Root->Child[i]->Result->number; 
     
    10331036  case O_OR:    /* logical OR */ 
    10341037      type = R_NUMBER; 
     1038            EvalTree(Root->Child[0]); 
     1039            if (R2N(Root->Child[0]->Result) == 0.0) { 
     1040                /* calculate 2nd operator only, if 1st operator is false */ 
     1041                EvalTree(Root->Child[1]); 
     1042            } 
    10351043      number = ((R2N(Root->Child[0]->Result) != 0.0) || (R2N(Root->Child[1]->Result) != 0.0)); 
    10361044      break; 
     
    10381046  case O_AND:   /* logical AND */ 
    10391047      type = R_NUMBER; 
     1048            EvalTree(Root->Child[0]); 
     1049            if (R2N(Root->Child[0]->Result) != 0.0) { 
     1050                /* calculate 2nd operator only, if 1st operator is true */ 
     1051                EvalTree(Root->Child[1]); 
     1052            } 
    10401053      number = ((R2N(Root->Child[0]->Result) != 0.0) && (R2N(Root->Child[1]->Result) != 0.0)); 
    10411054      break; 
     
    10431056  case O_EQ:    /* numeric equal */ 
    10441057      type = R_NUMBER; 
     1058            EvalTree(Root->Child[0]); 
     1059            EvalTree(Root->Child[1]); 
    10451060      number = (R2N(Root->Child[0]->Result) == R2N(Root->Child[1]->Result)); 
    10461061      break; 
     
    10481063  case O_NE:    /* numeric not equal */ 
    10491064      type = R_NUMBER; 
     1065            EvalTree(Root->Child[0]); 
     1066            EvalTree(Root->Child[1]); 
    10501067      number = (R2N(Root->Child[0]->Result) != R2N(Root->Child[1]->Result)); 
    10511068      break; 
     
    10531070  case O_LT:    /* numeric less than */ 
    10541071      type = R_NUMBER; 
     1072            EvalTree(Root->Child[0]); 
     1073            EvalTree(Root->Child[1]); 
    10551074      number = (R2N(Root->Child[0]->Result) < R2N(Root->Child[1]->Result)); 
    10561075      break; 
     
    10581077  case O_LE:    /* numeric less equal */ 
    10591078      type = R_NUMBER; 
     1079            EvalTree(Root->Child[0]); 
     1080            EvalTree(Root->Child[1]); 
    10601081      number = (R2N(Root->Child[0]->Result) <= R2N(Root->Child[1]->Result)); 
    10611082      break; 
     
    10631084  case O_GT:    /* numeric greater than */ 
    10641085      type = R_NUMBER; 
     1086            EvalTree(Root->Child[0]); 
     1087            EvalTree(Root->Child[1]); 
    10651088      number = (R2N(Root->Child[0]->Result) > R2N(Root->Child[1]->Result)); 
    10661089      break; 
     
    10681091  case O_GE:    /* numeric greater equal */ 
    10691092      type = R_NUMBER; 
     1093            EvalTree(Root->Child[0]); 
     1094            EvalTree(Root->Child[1]); 
    10701095      number = (R2N(Root->Child[0]->Result) >= R2N(Root->Child[1]->Result)); 
    10711096      break; 
     
    10731098  case O_ADD:   /* addition */ 
    10741099      type = R_NUMBER; 
     1100            EvalTree(Root->Child[0]); 
     1101            EvalTree(Root->Child[1]); 
    10751102      number = R2N(Root->Child[0]->Result) + R2N(Root->Child[1]->Result); 
    10761103      break; 
     
    10781105  case O_SUB:   /* subtraction */ 
    10791106      type = R_NUMBER; 
     1107            EvalTree(Root->Child[0]); 
     1108            EvalTree(Root->Child[1]); 
    10801109      number = R2N(Root->Child[0]->Result) - R2N(Root->Child[1]->Result); 
    10811110      break; 
     
    10831112  case O_SGN:   /* sign */ 
    10841113      type = R_NUMBER; 
     1114            EvalTree(Root->Child[0]); 
    10851115      number = -R2N(Root->Child[0]->Result); 
    10861116      break; 
     
    10881118  case O_CAT:   /* string concatenation */ 
    10891119      type = R_STRING; 
     1120            EvalTree(Root->Child[0]); 
     1121            EvalTree(Root->Child[1]); 
    10901122      s1 = R2S(Root->Child[0]->Result); 
    10911123      s2 = R2S(Root->Child[1]->Result); 
     
    10981130  case O_MUL:   /* multiplication */ 
    10991131      type = R_NUMBER; 
     1132            EvalTree(Root->Child[0]); 
     1133            EvalTree(Root->Child[1]); 
    11001134      number = R2N(Root->Child[0]->Result) * R2N(Root->Child[1]->Result); 
    11011135      break; 
     
    11031137  case O_DIV:   /* division */ 
    11041138      type = R_NUMBER; 
     1139            EvalTree(Root->Child[0]); 
     1140            EvalTree(Root->Child[1]); 
    11051141      dummy = R2N(Root->Child[1]->Result); 
    11061142      if (dummy == 0) { 
     
    11141150  case O_MOD:   /* modulo */ 
    11151151      type = R_NUMBER; 
     1152            EvalTree(Root->Child[0]); 
     1153            EvalTree(Root->Child[1]); 
    11161154      dummy = R2N(Root->Child[1]->Result); 
    11171155      if (dummy == 0) { 
     
    11251163  case O_POW:   /* x^y */ 
    11261164      type = R_NUMBER; 
     1165            EvalTree(Root->Child[0]); 
     1166            EvalTree(Root->Child[1]); 
    11271167      number = pow(R2N(Root->Child[0]->Result), R2N(Root->Child[1]->Result)); 
    11281168      break; 
     
    11301170  case O_NOT:   /* logical NOT */ 
    11311171      type = R_NUMBER; 
     1172            EvalTree(Root->Child[0]); 
    11321173      number = (R2N(Root->Child[0]->Result) == 0.0); 
    11331174      break;