@@ -231,7 +231,6 @@ CppiaExpr *convertToFunction(CppiaExpr *inExpr);
231231
232232
233233
234-
235234bool TypeData::isClassOf (Dynamic inInstance)
236235{
237236 if (cppiaClass)
@@ -1261,18 +1260,29 @@ struct CastExpr : public CppiaDynamicExpr
12611260 {
12621261 if (destType==etObject)
12631262 value->genCode (compiler, inDest, destType);
1263+ else if (destType==etString)
1264+ {
1265+ value->genCode (compiler, inDest, etString);
1266+ }
12641267 else
12651268 {
1266- value->genCode (compiler, sJitTemp0 , etObject);
1267- compiler->convert (sJitTemp0 ,etObject, inDest, destType);
1269+ JitTemp o (compiler,jtPointer);
1270+ value->genCode (compiler, o, etObject);
1271+ compiler->convert (o,etObject, inDest, destType);
12681272 }
12691273 }
12701274 else
12711275 {
12721276 value->genCode (compiler, sJitArg0 , etObject);
1277+ JumpId notNull = compiler->compare (cmpP_NOT_ZERO, sJitArg0 .as (jtPointer), (void *)0 );
1278+ compiler->returnNull (inDest, destType);
1279+ JumpId returnedNull = compiler->jump ();
1280+
1281+ compiler->comeFrom (notNull);
12731282 compiler->callNative ( (void *)callDynamicToArrayType, sJitArg0 .as (jtPointer), (int )arrayType );
12741283 compiler->checkException ();
12751284 compiler->convertReturnReg (etObject, inDest, destType);
1285+ compiler->comeFrom (returnedNull);
12761286 }
12771287 }
12781288 #endif
@@ -1758,6 +1768,13 @@ struct CallHaxe : public CppiaExpr
17581768 }
17591769
17601770 #ifdef CPPIA_JIT
1771+ static void SLJIT_CALL tryCallHaxe ( void (SLJIT_CALL *func)(StackContext *), StackContext *ctx )
1772+ {
1773+ TRY_NATIVE
1774+ func (ctx);
1775+ CATCH_NATIVE
1776+ }
1777+
17611778 void genCode (CppiaCompiler *compiler, const JitVal &inDest,ExprType destType)
17621779 {
17631780 int framePos = compiler->getCurrentFrameSize ();
@@ -1798,8 +1815,7 @@ struct CallHaxe : public CppiaExpr
17981815 // Store new frame in context ...
17991816 compiler->add ( sJitCtxFrame , sJitFrame , JitVal (framePos) );
18001817
1801- // Compiled yet
1802- compiler->call ( JitVal ( (void *)(function.execute )), sJitCtx );
1818+ compiler->callNative ( (void *)tryCallHaxe, JitVal ( (void *)(function.execute )), sJitCtx );
18031819
18041820 // TODO - from signature
18051821 bool isBoolReturn = false ;
@@ -2842,7 +2858,7 @@ struct GetFieldByName : public CppiaDynamicExpr
28422858 {
28432859 // TODO - interfaces
28442860 if (object)
2845- object->genCode (compiler, sJitTemp0 , etObject);
2861+ object->genCode (compiler, sJitTemp0 . as (jtPointer) , etObject);
28462862 else if (isStatic)
28472863 {
28482864 compiler->move (sJitTemp0 , (void *)&staticClass.mPtr );
@@ -2851,38 +2867,38 @@ struct GetFieldByName : public CppiaDynamicExpr
28512867 else
28522868 {
28532869 // this...
2854- compiler->move (sJitTemp0 , JitFramePos ( 0 ,etObject) );
2870+ compiler->move (sJitTemp0 , sJitThis );
28552871 }
28562872
28572873 switch (destType)
28582874 {
28592875 case etInt:
2860- compiler->callNative ( (void *)getFieldInt, sJitTemp0 , (void *)&name);
2876+ compiler->callNative ( (void *)getFieldInt, sJitTemp0 . as (jtPointer) , (void *)&name);
28612877 compiler->checkException ();
2862- compiler->move (inDest, sJitTemp0 );
2878+ compiler->move (inDest. as (jtInt), sJitReturnReg . as (jtInt) );
28632879 break ;
28642880 case etFloat:
28652881 if (isMemoryVal (inDest))
28662882 {
2867- compiler->callNative ( (void *)getFieldFloat, sJitTemp0 , (void *)&name, inDest.as (jtFloat) );
2883+ compiler->callNative ( (void *)getFieldFloat, sJitTemp0 . as (jtPointer) , (void *)&name, inDest.as (jtFloat) );
28682884 compiler->checkException ();
28692885 }
28702886 else
28712887 {
28722888 JitTemp floatResult (compiler, jtFloat);
2873- compiler->callNative ( (void *)getFieldFloat, sJitTemp0 , &name, floatResult );
2889+ compiler->callNative ( (void *)getFieldFloat, sJitTemp0 . as (jtPointer) , &name, floatResult );
28742890 compiler->checkException ();
28752891 compiler->move (inDest.as (jtFloat), floatResult);
28762892 }
28772893 break ;
28782894 case etString:
2879- compiler->callNative ( (void *)getFieldString, sJitTemp0 , (void *)&name, inDest );
2895+ compiler->callNative ( (void *)getFieldString, sJitTemp0 . as (jtPointer) , (void *)&name, inDest. as (jtString) );
28802896 compiler->checkException ();
28812897 break ;
28822898 case etObject:
2883- compiler->callNative ( (void *)getFieldObject, sJitTemp0 , (void *)&name);
2899+ compiler->callNative ( (void *)getFieldObject, sJitTemp0 . as (jtPointer) , (void *)&name);
28842900 compiler->checkException ();
2885- compiler->move (inDest.as (jtPointer), sJitTemp0 .as (jtPointer));
2901+ compiler->move (inDest.as (jtPointer), sJitReturnReg .as (jtPointer));
28862902 break ;
28872903 default : ;
28882904 }
@@ -3329,22 +3345,22 @@ struct MemReference : public CppiaExpr
33293345 if (REFMODE==locAbsolute)
33303346 {
33313347 compiler->move ( sJitTemp0 , JitVal ( (void *)pointer ) );
3332- compiler->convert ( sJitTemp0 .star (jtPointer,0 ), getType (),inDest, destType );
3348+ compiler->convert ( sJitTemp0 .star (jtPointer,0 ), getType (),inDest, destType, isBoolInt () );
33333349 }
33343350 else if (REFMODE==locObj)
33353351 {
33363352 object->genCode ( compiler, sJitTemp2 , etObject );
3337- compiler->convert ( sJitTemp2 .star (jtPointer,offset) ,getType (),inDest, destType );
3353+ compiler->convert ( sJitTemp2 .star (jtPointer,offset) ,getType (),inDest, destType, isBoolInt () );
33383354 }
33393355 else if (REFMODE==locThis)
33403356 {
33413357 JitThisPos target (offset, getJitType (getType ()) );
3342- compiler->convert ( target,getType (),inDest, destType );
3358+ compiler->convert ( target,getType (),inDest, destType, isBoolInt () );
33433359 }
33443360 else
33453361 {
33463362 JitFramePos target (offset, getJitType (getType ()));
3347- compiler->convert ( target,getType (),inDest, destType );
3363+ compiler->convert ( target,getType (),inDest, destType, isBoolInt () );
33483364 }
33493365 }
33503366 #endif
@@ -3923,15 +3939,35 @@ struct MemReferenceCrement : public CppiaExpr
39233939 }
39243940 else if (op==coPostInc || op==coPostDec)
39253941 {
3926- compiler->move ( sJitTemp1 .as (jtInt), ioPtr );
3927- compiler->add ( ioPtr, sJitTemp1 .as (jtInt), diff );
3928- compiler->convert ( sJitTemp1 , etInt, inDest, destType );
3942+ if (destType==etInt)
3943+ {
3944+ compiler->move ( sJitTemp0 .as (jtInt), ioPtr );
3945+ compiler->add ( ioPtr, sJitTemp0 .as (jtInt), diff );
3946+ compiler->move ( inDest, sJitTemp0 .as (jtInt) );
3947+ }
3948+ else
3949+ {
3950+ JitTemp result (compiler, jtInt);
3951+ compiler->move ( result, ioPtr );
3952+ compiler->add ( ioPtr, ioPtr, diff );
3953+ compiler->convert ( result, etInt, inDest, destType );
3954+ }
39293955 }
39303956 else
39313957 {
3932- compiler->add ( sJitTemp1 .as (jtInt), ioPtr, diff );
3933- compiler->move ( ioPtr, sJitTemp1 .as (jtInt));
3934- compiler->convert ( sJitTemp1 , etInt, inDest, destType );
3958+ if (destType==etInt)
3959+ {
3960+ compiler->add ( sJitTemp1 .as (jtInt), ioPtr, diff );
3961+ compiler->move ( ioPtr, sJitTemp1 .as (jtInt));
3962+ compiler->move ( inDest, sJitTemp1 .as (jtInt));
3963+ }
3964+ else
3965+ {
3966+ JitTemp result (compiler, jtInt);
3967+ compiler->add ( result, ioPtr, diff );
3968+ compiler->move ( ioPtr, result );
3969+ compiler->convert (result, etInt, inDest, destType);
3970+ }
39353971 }
39363972 break ;
39373973
@@ -5832,17 +5868,20 @@ struct TryExpr : public CppiaVoidExpr
58325868
58335869 void genCode (CppiaCompiler *compiler, const JitVal &inDest, ExprType destType)
58345870 {
5835- compiler->pushCatching ();
5871+ ThrowList thisThrown;
5872+ ThrowList *oldList = compiler->pushCatching (&thisThrown);
58365873 body->genCode (compiler, inDest, destType);
5837- compiler->popCatching ();
58385874
5839- if (compiler->hasThrown ())
5875+ compiler->popCatching (oldList);
5876+
5877+ if (thisThrown.size ()>0 )
58405878 {
58415879 std::vector<JumpId> handledExceptions;
58425880
58435881 JumpId noThrow = compiler->jump ();
58445882
5845- compiler->catchThrown ();
5883+ for (int i=0 ;i<thisThrown.size ();i++)
5884+ compiler->comeFrom (thisThrown[i]);
58465885
58475886 for (int i=0 ;i<catches.size ();i++)
58485887 {
@@ -6973,7 +7012,7 @@ struct OpAdd : public BinOp
69737012 JitTemp temp (compiler,jtFloat);
69747013 left->genCode (compiler,temp,etFloat);
69757014 right->genCode (compiler,sJitTempF0 ,etFloat);
6976- if (destType==etObject)
7015+ if (destType==etObject || destType==etString )
69777016 {
69787017 compiler->add ( sJitTempF0 , temp, sJitTempF0 );
69797018 compiler->convert (sJitTempF0 , etFloat, inDest, destType);
@@ -7164,7 +7203,9 @@ struct OpCompare : public OpCompareBase
71647203
71657204 static int SLJIT_CALL dynamicCompare (hx::Object *o0, hx::Object *o1)
71667205 {
7167- return Dynamic (o0).Compare ( Dynamic (o1) );
7206+ COMPARE compare;
7207+
7208+ return compare.test ( Dynamic (o0), Dynamic (o1) );
71687209 }
71697210
71707211
@@ -7204,15 +7245,14 @@ struct OpCompare : public OpCompareBase
72047245 JitTemp lhs (compiler,jtPointer);
72057246 left->genCode (compiler, lhs, etObject);
72067247 right->genCode (compiler, sJitArg1 , etObject);
7207-
72087248 compiler->callNative ( (void *)dynamicCompare, lhs, sJitArg1 .as (jtPointer) );
7209- return compiler->compare ( (JitCompare)(inReverse ? COMPARE::reverse :COMPARE::compare),
7210- sJitReturnReg , (int ) 0 , inLabel );
7249+ return compiler->compare ( inReverse ? cmpI_EQUAL : cmpI_NOT_EQUAL, sJitReturnReg .as (jtInt), (int ) 0 , inLabel );
72117250 }
72127251
72137252
72147253 default :
7215- printf (" todo - other compares\n " );
7254+ left->genCode (compiler, sJitTemp0 , etObject);
7255+ right->genCode (compiler, sJitTemp0 , etObject);
72167256 }
72177257 return 0 ;
72187258 }
0 commit comments