| 6264 | } |
| 6265 | |
| 6266 | void genCode(CppiaCompiler *compiler, const JitVal &inDest, ExprType destType) HXCPP_OVERRIDE |
| 6267 | { |
| 6268 | ExprType switchType = condition->getType(); |
| 6269 | JitTemp test( compiler, switchType ); |
| 6270 | |
| 6271 | condition->genCode(compiler, test, switchType); |
| 6272 | |
| 6273 | std::vector<JumpId> doneJumps; |
| 6274 | |
| 6275 | for(int i=0;i<caseCount;i++) |
| 6276 | { |
| 6277 | JumpId nextCase = 0; |
| 6278 | Case &c = cases[i]; |
| 6279 | std::vector<JumpId> onMatch; |
| 6280 | for(int j=0;j<c.conditions.size();j++) |
| 6281 | { |
| 6282 | bool last = j==c.conditions.size()-1; |
| 6283 | if (switchType==etInt) |
| 6284 | { |
| 6285 | c.conditions[j]->genCode(compiler, sJitTemp1, switchType); |
| 6286 | if (last) |
| 6287 | nextCase = compiler->compare(cmpI_NOT_EQUAL,test, sJitTemp1.as(jtInt) ); |
| 6288 | else |
| 6289 | onMatch.push_back(compiler->compare(cmpI_EQUAL,test, sJitTemp1.as(jtInt))); |
| 6290 | } |
| 6291 | else if (switchType==etFloat) |
| 6292 | { |
| 6293 | c.conditions[j]->genCode(compiler, sJitTemp1, switchType); |
| 6294 | if (last) |
| 6295 | nextCase = compiler->fcompare(cmpD_NOT_EQUAL,test, sJitTemp1.as(jtFloat),0,false ); |
| 6296 | else |
| 6297 | onMatch.push_back(compiler->fcompare(cmpD_EQUAL,test, sJitTemp1.as(jtFloat),0,false)); |
| 6298 | } |
| 6299 | else if (switchType==etString) |
| 6300 | { |
| 6301 | JitTemp cond(compiler, etString); |
| 6302 | c.conditions[j]->genCode(compiler, cond, etString); |
| 6303 | if (last) |
| 6304 | nextCase = compiler->scompare(cmpP_NOT_EQUAL,test, cond); |
| 6305 | else |
| 6306 | onMatch.push_back(compiler->scompare(cmpP_EQUAL,test, cond)); |
| 6307 | } |
| 6308 | else if (switchType==etObject) |
| 6309 | { |
| 6310 | c.conditions[j]->genCode(compiler, sJitTemp1, switchType); |
| 6311 | compiler->callNative( (void *)sameObject, test, sJitArg1.as(jtPointer) ); |
| 6312 | |
| 6313 | if (last) |
| 6314 | nextCase = compiler->compare(cmpI_EQUAL, sJitReturnReg.as(jtInt), (int) 0); |
| 6315 | else |
| 6316 | onMatch.push_back(compiler->compare(cmpI_NOT_EQUAL, sJitReturnReg.as(jtInt), (int) 0) ); |
| 6317 | } |
| 6318 | else |
| 6319 | { |
| 6320 | CPPIALOG("Missing switch type\n"); |
| 6321 | CppiaTrap(); |
| 6322 | } |
| 6323 | } |