@@ -479,7 +479,7 @@ cgConst (B32 x) = pure $ JsForeign (T.pack $ show x ++ "|0" ) []
479479cgConst (B64 x) =
480480 do
481481 setUsedITBig
482− pure $ JsForeign "new jsbn.BigInteger(%0)" [JsStr $ show x]
482+ pure $ JsForeign "new jsbn.BigInteger(%0).and(new jsbn.BigInteger(%1))" [JsStr $ show x, JsStr $ show 0xFFFFFFFFFFFFFFFF]
483483cgConst x | isTypeConst x = pure $ JsInt 0
484484cgConst x = error $ "Constant " ++ show x ++ " not compilable yet"
485485
@@ -501,14 +501,14 @@ cgOp (LPlus (ATInt ITBig)) [l, r] =
501501cgOp (LPlus (ATInt (ITFixed IT64))) [l, r] =
502502 do
503503 setUsedITBig
504− pure $ JsMethod (JsMethod l "add" [r]) "and" [JsStr $ show 0xFFFFFFFFFFFFFFFF]
504+ pure $ JsForeign "%0.add(%1).and(new jsbn.BigInteger(%2))" [l,r, JsStr $ show 0xFFFFFFFFFFFFFFFF]
505505cgOp (LLSHR (ITFixed IT8)) [l, r] = pure $ JsForeign "new Uint8Array([ %0[0] >> %1[0] ])" [l,r]
506506cgOp (LLSHR (ITFixed IT16)) [l, r] = pure $ JsForeign "new Uint16Array([ %0[0] >> %1[0] ])" [l,r]
507507cgOp (LLSHR (ITFixed IT32)) [l, r] = pure $ JsForeign "%0 >> %1|0" [l,r]
508508cgOp (LLSHR (ITFixed IT64)) [l, r] =
509509 do
510510 setUsedITBig
511− pure $ JsMethod (JsMethod l "shiftLeft" [r]) "and" [JsStr $ show 0xFFFFFFFFFFFFFFFF]
511+ pure $ JsForeign "%0.shiftRight(%1)" [l,r]
512512cgOp (LMinus ATFloat) [l, r] = pure $ JsBinOp "-" l r
513513cgOp (LMinus (ATInt ITNative)) [l, r] = pure $ JsForeign "%0-%1|0" [l,r]
514514cgOp (LMinus (ATInt ITBig)) [l, r] =
@@ -580,7 +580,7 @@ cgOp (LTrunc (ITFixed IT32) (ITFixed IT8)) [x] = pure $ JsForeign "new Uint8Arra
580580cgOp (LTrunc (ITFixed IT64) (ITFixed IT8)) [x] =
581581 do
582582 setUsedITBig
583− pure $ JsForeign "new Uint8Array([ %0.intValue() ])" [x]
583+ pure $ JsForeign "new Uint8Array([ %0.and(new jsbn.BigInteger(%1)).intValue() ])" [x, JsStr $ show 0xFF]
584584cgOp (LSExt ITNative ITBig) [x] =
585585 do
586586 setUsedITBig
@@ -621,7 +621,7 @@ cgOp LReadStr [_] =
621621 pure $ JsForeign (readStrTemplate $ conf s) []
622622cgOp LStrConcat [l,r] = pure $ JsBinOp "+" l r
623623cgOp LStrCons [l,r] = pure $ JsForeign "%0+%1" [l,r]
624−cgOp LStrSubstr [offset,len,str] = pure $ JsMethod str "substr" [offset, len]
624+cgOp LStrSubstr [offset,len,str] = pure $ JsForeign "%0.substr(Math.max(0,%1), Math.max(0, %2))" [str, offset, len] -- JsMethod str "substr" [offset, len]
625625cgOp (LSRem (ATInt ITNative)) [l,r] = pure $ JsBinOp "%" l r
626626cgOp (LSRem (ATInt ITBig)) [l,r] =
627627 do