on master help sign in
javascript: unlock primitives
c47bd86raichoo
src/IRTS/CodegenJavaScript.hs+381−385
@@ -81,7 +81,6 @@ data JS = JSRaw String
81 | JSPreOp String JS
81 | JSPreOp String JS
82 | JSPostOp String JS
82 | JSPostOp String JS
83 | JSProj JS String
83 | JSProj JS String
84− | JSVar LVar
85 | JSNull
84 | JSNull
86 | JSThis
85 | JSThis
87 | JSTrue
86 | JSTrue
@@ -171,9 +170,6 @@ compileJS (JSProj obj field)
171 | otherwise =
170 | otherwise =
172 compileJS obj ++ '.' : field
171 compileJS obj ++ '.' : field
173
172
174−{-compileJS (JSVar var) =-}
175− {-translateVariableName var-}
176−
177compileJS JSNull =
173compileJS JSNull =
178 "null"
174 "null"
179
175
@@ -705,430 +701,430 @@ jsOP reg op args = JSAssign (translateReg reg) jsOP'
705 | (LSGe ATFloat) <- op
701 | (LSGe ATFloat) <- op
706 , (lhs:rhs:_) <- args = translateBinaryOp ">=" lhs rhs
702 , (lhs:rhs:_) <- args = translateBinaryOp ">=" lhs rhs
707
703
708− {-| (LPlus (ATInt ITChar)) <- op-}
704+ | (LPlus (ATInt ITChar)) <- op
709− {-, (lhs:rhs:_) <- args =-}
705+ , (lhs:rhs:_) <- args =
710− {-jsCall "__IDRRT__fromCharCode" [-}
706+ jsCall "__IDRRT__fromCharCode" [
711− {-JSBinOp "+" (-}
707+ JSBinOp "+" (
712− {-jsCall "__IDRRT__charCode" [JSVar lhs]-}
708+ jsCall "__IDRRT__charCode" [translateReg lhs]
713− {-) (-}
709+ ) (
714− {-jsCall "__IDRRT__charCode" [JSVar rhs]-}
710+ jsCall "__IDRRT__charCode" [translateReg rhs]
715− {-)-}
711+ )
716− {-]-}
712+ ]
717−
713+
718− {-| (LTrunc (ITFixed IT16) (ITFixed IT8)) <- op-}
714+ | (LTrunc (ITFixed IT16) (ITFixed IT8)) <- op
719− {-, (arg:_) <- args =-}
715+ , (arg:_) <- args =
720− {-jsPackUBits8 (-}
716+ jsPackUBits8 (
721− {-JSBinOp "&" (jsUnPackBits $ JSVar arg) (JSNum (JSInt 0xFF))-}
717+ JSBinOp "&" (jsUnPackBits $ translateReg arg) (JSNum (JSInt 0xFF))
722− {-)-}
718+ )
723−
719+
724− {-| (LTrunc (ITFixed IT32) (ITFixed IT16)) <- op-}
720+ | (LTrunc (ITFixed IT32) (ITFixed IT16)) <- op
725− {-, (arg:_) <- args =-}
721+ , (arg:_) <- args =
726− {-jsPackUBits16 (-}
722+ jsPackUBits16 (
727− {-JSBinOp "&" (jsUnPackBits $ JSVar arg) (JSNum (JSInt 0xFFFF))-}
723+ JSBinOp "&" (jsUnPackBits $ translateReg arg) (JSNum (JSInt 0xFFFF))
728− {-)-}
724+ )
729−
725+
730− {-| (LTrunc (ITFixed IT64) (ITFixed IT32)) <- op-}
726+ | (LTrunc (ITFixed IT64) (ITFixed IT32)) <- op
731− {-, (arg:_) <- args =-}
727+ , (arg:_) <- args =
732− {-jsPackUBits32 (-}
728+ jsPackUBits32 (
733− {-jsMeth (jsMeth (JSVar arg) "and" [-}
729+ jsMeth (jsMeth (translateReg arg) "and" [
734− {-jsBigInt (JSString $ show 0xFFFFFFFF)-}
730+ jsBigInt (JSString $ show 0xFFFFFFFF)
735− {-]) "intValue" []-}
731+ ]) "intValue" []
736− {-)-}
732+ )
737−
733+
738− {-| (LTrunc ITBig (ITFixed IT64)) <- op-}
734+ | (LTrunc ITBig (ITFixed IT64)) <- op
739− {-, (arg:_) <- args =-}
735+ , (arg:_) <- args =
740− {-jsMeth (JSVar arg) "and" [-}
736+ jsMeth (translateReg arg) "and" [
741− {-jsBigInt (JSString $ show 0xFFFFFFFFFFFFFFFF)-}
737+ jsBigInt (JSString $ show 0xFFFFFFFFFFFFFFFF)
742− {-]-}
738+ ]
743−
739+
744− {-| (LLSHR (ITFixed IT8)) <- op-}
740+ | (LLSHR (ITFixed IT8)) <- op
745− {-, (lhs:rhs:_) <- args =-}
741+ , (lhs:rhs:_) <- args =
746− {-jsPackUBits8 (-}
742+ jsPackUBits8 (
747− {-JSBinOp ">>" (jsUnPackBits $ JSVar lhs) (jsUnPackBits $ JSVar rhs)-}
743+ JSBinOp ">>" (jsUnPackBits $ translateReg lhs) (jsUnPackBits $ translateReg rhs)
748− {-)-}
744+ )
749−
745+
750− {-| (LLSHR (ITFixed IT16)) <- op-}
746+ | (LLSHR (ITFixed IT16)) <- op
751− {-, (lhs:rhs:_) <- args =-}
747+ , (lhs:rhs:_) <- args =
752− {-jsPackUBits16 (-}
748+ jsPackUBits16 (
753− {-JSBinOp ">>" (jsUnPackBits $ JSVar lhs) (jsUnPackBits $ JSVar rhs)-}
749+ JSBinOp ">>" (jsUnPackBits $ translateReg lhs) (jsUnPackBits $ translateReg rhs)
754− {-)-}
750+ )
755−
751+
756− {-| (LLSHR (ITFixed IT32)) <- op-}
752+ | (LLSHR (ITFixed IT32)) <- op
757− {-, (lhs:rhs:_) <- args =-}
753+ , (lhs:rhs:_) <- args =
758− {-jsPackUBits32 (-}
754+ jsPackUBits32 (
759− {-JSBinOp ">>" (jsUnPackBits $ JSVar lhs) (jsUnPackBits $ JSVar rhs)-}
755+ JSBinOp ">>" (jsUnPackBits $ translateReg lhs) (jsUnPackBits $ translateReg rhs)
760− {-)-}
756+ )
761
757
762 | (LLSHR (ITFixed IT64)) <- op
758 | (LLSHR (ITFixed IT64)) <- op
763 , (lhs:rhs:_) <- args =
759 , (lhs:rhs:_) <- args =
764 jsMeth (translateReg lhs) "shiftRight" [translateReg rhs]
760 jsMeth (translateReg lhs) "shiftRight" [translateReg rhs]
765
761
766− {-| (LSHL (ITFixed IT8)) <- op-}
762+ | (LSHL (ITFixed IT8)) <- op
767− {-, (lhs:rhs:_) <- args =-}
763+ , (lhs:rhs:_) <- args =
768− {-jsPackUBits8 (-}
764+ jsPackUBits8 (
769− {-JSBinOp "<<" (jsUnPackBits $ JSVar lhs) (jsUnPackBits $ JSVar rhs)-}
765+ JSBinOp "<<" (jsUnPackBits $ translateReg lhs) (jsUnPackBits $ translateReg rhs)
770− {-)-}
766+ )
771−
767+
772− {-| (LSHL (ITFixed IT16)) <- op-}
768+ | (LSHL (ITFixed IT16)) <- op
773− {-, (lhs:rhs:_) <- args =-}
769+ , (lhs:rhs:_) <- args =
774− {-jsPackUBits16 (-}
770+ jsPackUBits16 (
775− {-JSBinOp "<<" (jsUnPackBits $ JSVar lhs) (jsUnPackBits $ JSVar rhs)-}
771+ JSBinOp "<<" (jsUnPackBits $ translateReg lhs) (jsUnPackBits $ translateReg rhs)
776− {-)-}
772+ )
777−
773+
778− {-| (LSHL (ITFixed IT32)) <- op-}
774+ | (LSHL (ITFixed IT32)) <- op
779− {-, (lhs:rhs:_) <- args =-}
775+ , (lhs:rhs:_) <- args =
780− {-jsPackUBits32 (-}
776+ jsPackUBits32 (
781− {-JSBinOp "<<" (jsUnPackBits $ JSVar lhs) (jsUnPackBits $ JSVar rhs)-}
777+ JSBinOp "<<" (jsUnPackBits $ translateReg lhs) (jsUnPackBits $ translateReg rhs)
782− {-)-}
778+ )
783−
779+
784− {-| (LSHL (ITFixed IT64)) <- op-}
780+ | (LSHL (ITFixed IT64)) <- op
785− {-, (lhs:rhs:_) <- args =-}
781+ , (lhs:rhs:_) <- args =
786− {-jsMeth (jsMeth (JSVar lhs) "shiftLeft" [JSVar rhs]) "and" [-}
782+ jsMeth (jsMeth (translateReg lhs) "shiftLeft" [translateReg rhs]) "and" [
787− {-jsBigInt (JSString $ show 0xFFFFFFFFFFFFFFFF)-}
783+ jsBigInt (JSString $ show 0xFFFFFFFFFFFFFFFF)
788− {-]-}
784+ ]
789−
785+
790− {-| (LAnd (ITFixed IT8)) <- op-}
786+ | (LAnd (ITFixed IT8)) <- op
791− {-, (lhs:rhs:_) <- args =-}
787+ , (lhs:rhs:_) <- args =
792− {-jsPackUBits8 (-}
788+ jsPackUBits8 (
793− {-JSBinOp "&" (jsUnPackBits (JSVar lhs)) (jsUnPackBits (JSVar rhs))-}
789+ JSBinOp "&" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
794− {-)-}
790+ )
795−
791+
796− {-| (LAnd (ITFixed IT16)) <- op-}
792+ | (LAnd (ITFixed IT16)) <- op
797− {-, (lhs:rhs:_) <- args =-}
793+ , (lhs:rhs:_) <- args =
798− {-jsPackUBits16 (-}
794+ jsPackUBits16 (
799− {-JSBinOp "&" (jsUnPackBits (JSVar lhs)) (jsUnPackBits (JSVar rhs))-}
795+ JSBinOp "&" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
800− {-)-}
796+ )
801−
797+
802− {-| (LAnd (ITFixed IT32)) <- op-}
798+ | (LAnd (ITFixed IT32)) <- op
803− {-, (lhs:rhs:_) <- args =-}
799+ , (lhs:rhs:_) <- args =
804− {-jsPackUBits32 (-}
800+ jsPackUBits32 (
805− {-JSBinOp "&" (jsUnPackBits (JSVar lhs)) (jsUnPackBits (JSVar rhs))-}
801+ JSBinOp "&" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
806− {-)-}
802+ )
807
803
808 | (LAnd (ITFixed IT64)) <- op
804 | (LAnd (ITFixed IT64)) <- op
809 , (lhs:rhs:_) <- args =
805 , (lhs:rhs:_) <- args =
810 jsMeth (translateReg lhs) "and" [translateReg rhs]
806 jsMeth (translateReg lhs) "and" [translateReg rhs]
811
807
812− {-| (LOr (ITFixed IT8)) <- op-}
808+ | (LOr (ITFixed IT8)) <- op
813− {-, (lhs:rhs:_) <- args =-}
809+ , (lhs:rhs:_) <- args =
814− {-jsPackUBits8 (-}
810+ jsPackUBits8 (
815− {-JSBinOp "|" (jsUnPackBits (JSVar lhs)) (jsUnPackBits (JSVar rhs))-}
811+ JSBinOp "|" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
816− {-)-}
812+ )
817
813
818− {-| (LOr (ITFixed IT16)) <- op-}
814+ | (LOr (ITFixed IT16)) <- op
819− {-, (lhs:rhs:_) <- args =-}
815+ , (lhs:rhs:_) <- args =
820− {-jsPackUBits16 (-}
816+ jsPackUBits16 (
821− {-JSBinOp "|" (jsUnPackBits (JSVar lhs)) (jsUnPackBits (JSVar rhs))-}
817+ JSBinOp "|" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
822− {-)-}
818+ )
823
819
824− {-| (LOr (ITFixed IT32)) <- op-}
820+ | (LOr (ITFixed IT32)) <- op
825− {-, (lhs:rhs:_) <- args =-}
821+ , (lhs:rhs:_) <- args =
826− {-jsPackUBits32 (-}
822+ jsPackUBits32 (
827− {-JSBinOp "|" (jsUnPackBits (JSVar lhs)) (jsUnPackBits (JSVar rhs))-}
823+ JSBinOp "|" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
828− {-)-}
824+ )
829
825
830 | (LOr (ITFixed IT64)) <- op
826 | (LOr (ITFixed IT64)) <- op
831 , (lhs:rhs:_) <- args =
827 , (lhs:rhs:_) <- args =
832 jsMeth (translateReg lhs) "or" [translateReg rhs]
828 jsMeth (translateReg lhs) "or" [translateReg rhs]
833
829
834− {-| (LXOr (ITFixed IT8)) <- op-}
830+ | (LXOr (ITFixed IT8)) <- op
835− {-, (lhs:rhs:_) <- args =-}
831+ , (lhs:rhs:_) <- args =
836− {-jsPackUBits8 (-}
832+ jsPackUBits8 (
837− {-JSBinOp "^" (jsUnPackBits (JSVar lhs)) (jsUnPackBits (JSVar rhs))-}
833+ JSBinOp "^" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
838− {-)-}
834+ )
839
835
840− {-| (LXOr (ITFixed IT16)) <- op-}
836+ | (LXOr (ITFixed IT16)) <- op
841− {-, (lhs:rhs:_) <- args =-}
837+ , (lhs:rhs:_) <- args =
842− {-jsPackUBits16 (-}
838+ jsPackUBits16 (
843− {-JSBinOp "^" (jsUnPackBits (JSVar lhs)) (jsUnPackBits (JSVar rhs))-}
839+ JSBinOp "^" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
844− {-)-}
840+ )
845
841
846− {-| (LXOr (ITFixed IT32)) <- op-}
842+ | (LXOr (ITFixed IT32)) <- op
847− {-, (lhs:rhs:_) <- args =-}
843+ , (lhs:rhs:_) <- args =
848− {-jsPackUBits32 (-}
844+ jsPackUBits32 (
849− {-JSBinOp "^" (jsUnPackBits (JSVar lhs)) (jsUnPackBits (JSVar rhs))-}
845+ JSBinOp "^" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
850− {-)-}
846+ )
851
847
852 | (LXOr (ITFixed IT64)) <- op
848 | (LXOr (ITFixed IT64)) <- op
853 , (lhs:rhs:_) <- args =
849 , (lhs:rhs:_) <- args =
854 jsMeth (translateReg lhs) "xor" [translateReg rhs]
850 jsMeth (translateReg lhs) "xor" [translateReg rhs]
855
851
856− {-| (LPlus (ATInt (ITFixed IT8))) <- op-}
852+ | (LPlus (ATInt (ITFixed IT8))) <- op
857− {-, (lhs:rhs:_) <- args =-}
853+ , (lhs:rhs:_) <- args =
858− {-jsPackUBits8 (-}
854+ jsPackUBits8 (
859− {-JSBinOp "+" (jsUnPackBits (JSVar lhs)) (jsUnPackBits (JSVar rhs))-}
855+ JSBinOp "+" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
860− {-)-}
856+ )
861−
857+
862− {-| (LPlus (ATInt (ITFixed IT16))) <- op-}
858+ | (LPlus (ATInt (ITFixed IT16))) <- op
863− {-, (lhs:rhs:_) <- args =-}
859+ , (lhs:rhs:_) <- args =
864− {-jsPackUBits16 (-}
860+ jsPackUBits16 (
865− {-JSBinOp "+" (jsUnPackBits (JSVar lhs)) (jsUnPackBits (JSVar rhs))-}
861+ JSBinOp "+" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
866− {-)-}
862+ )
867−
863+
868− {-| (LPlus (ATInt (ITFixed IT32))) <- op-}
864+ | (LPlus (ATInt (ITFixed IT32))) <- op
869− {-, (lhs:rhs:_) <- args =-}
865+ , (lhs:rhs:_) <- args =
870− {-jsPackUBits32 (-}
866+ jsPackUBits32 (
871− {-JSBinOp "+" (jsUnPackBits (JSVar lhs)) (jsUnPackBits (JSVar rhs))-}
867+ JSBinOp "+" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
872− {-)-}
868+ )
873−
869+
874− {-| (LPlus (ATInt (ITFixed IT64))) <- op-}
870+ | (LPlus (ATInt (ITFixed IT64))) <- op
875− {-, (lhs:rhs:_) <- args =-}
871+ , (lhs:rhs:_) <- args =
876− {-jsMeth (jsMeth (JSVar lhs) "add" [JSVar rhs]) "and" [-}
872+ jsMeth (jsMeth (translateReg lhs) "add" [translateReg rhs]) "and" [
877− {-jsBigInt (JSString $ show 0xFFFFFFFFFFFFFFFF)-}
873+ jsBigInt (JSString $ show 0xFFFFFFFFFFFFFFFF)
878− {-]-}
874+ ]
879−
875+
880− {-| (LMinus (ATInt (ITFixed IT8))) <- op-}
876+ | (LMinus (ATInt (ITFixed IT8))) <- op
881− {-, (lhs:rhs:_) <- args =-}
877+ , (lhs:rhs:_) <- args =
882− {-jsPackUBits8 (-}
878+ jsPackUBits8 (
883− {-JSBinOp "-" (jsUnPackBits (JSVar lhs)) (jsUnPackBits (JSVar rhs))-}
879+ JSBinOp "-" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
884− {-)-}
880+ )
885−
881+
886− {-| (LMinus (ATInt (ITFixed IT16))) <- op-}
882+ | (LMinus (ATInt (ITFixed IT16))) <- op
887− {-, (lhs:rhs:_) <- args =-}
883+ , (lhs:rhs:_) <- args =
888− {-jsPackUBits16 (-}
884+ jsPackUBits16 (
889− {-JSBinOp "-" (jsUnPackBits (JSVar lhs)) (jsUnPackBits (JSVar rhs))-}
885+ JSBinOp "-" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
890− {-)-}
886+ )
891−
887+
892− {-| (LMinus (ATInt (ITFixed IT32))) <- op-}
888+ | (LMinus (ATInt (ITFixed IT32))) <- op
893− {-, (lhs:rhs:_) <- args =-}
889+ , (lhs:rhs:_) <- args =
894− {-jsPackUBits32 (-}
890+ jsPackUBits32 (
895− {-JSBinOp "-" (jsUnPackBits (JSVar lhs)) (jsUnPackBits (JSVar rhs))-}
891+ JSBinOp "-" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
896− {-)-}
892+ )
897−
893+
898− {-| (LMinus (ATInt (ITFixed IT64))) <- op-}
894+ | (LMinus (ATInt (ITFixed IT64))) <- op
899− {-, (lhs:rhs:_) <- args =-}
895+ , (lhs:rhs:_) <- args =
900− {-jsMeth (jsMeth (JSVar lhs) "subtract" [JSVar rhs]) "and" [-}
896+ jsMeth (jsMeth (translateReg lhs) "subtract" [translateReg rhs]) "and" [
901− {-jsBigInt (JSString $ show 0xFFFFFFFFFFFFFFFF)-}
897+ jsBigInt (JSString $ show 0xFFFFFFFFFFFFFFFF)
902− {-]-}
898+ ]
903−
899+
904− {-| (LTimes (ATInt (ITFixed IT8))) <- op-}
900+ | (LTimes (ATInt (ITFixed IT8))) <- op
905− {-, (lhs:rhs:_) <- args =-}
901+ , (lhs:rhs:_) <- args =
906− {-jsPackUBits8 (-}
902+ jsPackUBits8 (
907− {-JSBinOp "*" (jsUnPackBits (JSVar lhs)) (jsUnPackBits (JSVar rhs))-}
903+ JSBinOp "*" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
908− {-)-}
904+ )
909−
905+
910− {-| (LTimes (ATInt (ITFixed IT16))) <- op-}
906+ | (LTimes (ATInt (ITFixed IT16))) <- op
911− {-, (lhs:rhs:_) <- args =-}
907+ , (lhs:rhs:_) <- args =
912− {-jsPackUBits16 (-}
908+ jsPackUBits16 (
913− {-JSBinOp "*" (jsUnPackBits (JSVar lhs)) (jsUnPackBits (JSVar rhs))-}
909+ JSBinOp "*" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
914− {-)-}
910+ )
915−
911+
916− {-| (LTimes (ATInt (ITFixed IT32))) <- op-}
912+ | (LTimes (ATInt (ITFixed IT32))) <- op
917− {-, (lhs:rhs:_) <- args =-}
913+ , (lhs:rhs:_) <- args =
918− {-jsPackUBits32 (-}
914+ jsPackUBits32 (
919− {-JSBinOp "*" (jsUnPackBits (JSVar lhs)) (jsUnPackBits (JSVar rhs))-}
915+ JSBinOp "*" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
920− {-)-}
916+ )
921−
917+
922− {-| (LTimes (ATInt (ITFixed IT64))) <- op-}
918+ | (LTimes (ATInt (ITFixed IT64))) <- op
923− {-, (lhs:rhs:_) <- args =-}
919+ , (lhs:rhs:_) <- args =
924− {-jsMeth (jsMeth (JSVar lhs) "multiply" [JSVar rhs]) "and" [-}
920+ jsMeth (jsMeth (translateReg lhs) "multiply" [translateReg rhs]) "and" [
925− {-jsBigInt (JSString $ show 0xFFFFFFFFFFFFFFFF)-}
921+ jsBigInt (JSString $ show 0xFFFFFFFFFFFFFFFF)
926− {-]-}
922+ ]
927−
923+
928− {-| (LEq (ATInt (ITFixed IT8))) <- op-}
924+ | (LEq (ATInt (ITFixed IT8))) <- op
929− {-, (lhs:rhs:_) <- args =-}
925+ , (lhs:rhs:_) <- args =
930− {-jsPackUBits8 (-}
926+ jsPackUBits8 (
931− {-JSBinOp "==" (jsUnPackBits (JSVar lhs)) (jsUnPackBits (JSVar rhs))-}
927+ JSBinOp "==" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
932− {-)-}
928+ )
933−
929+
934− {-| (LEq (ATInt (ITFixed IT16))) <- op-}
930+ | (LEq (ATInt (ITFixed IT16))) <- op
935− {-, (lhs:rhs:_) <- args =-}
931+ , (lhs:rhs:_) <- args =
936− {-jsPackUBits16 (-}
932+ jsPackUBits16 (
937− {-JSBinOp "==" (jsUnPackBits (JSVar lhs)) (jsUnPackBits (JSVar rhs))-}
933+ JSBinOp "==" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
938− {-)-}
934+ )
939−
935+
940− {-| (LEq (ATInt (ITFixed IT32))) <- op-}
936+ | (LEq (ATInt (ITFixed IT32))) <- op
941− {-, (lhs:rhs:_) <- args =-}
937+ , (lhs:rhs:_) <- args =
942− {-jsPackUBits32 (-}
938+ jsPackUBits32 (
943− {-JSBinOp "==" (jsUnPackBits (JSVar lhs)) (jsUnPackBits (JSVar rhs))-}
939+ JSBinOp "==" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
944− {-)-}
940+ )
945−
941+
946− {-| (LEq (ATInt (ITFixed IT64))) <- op-}
942+ | (LEq (ATInt (ITFixed IT64))) <- op
947− {-, (lhs:rhs:_) <- args =-}
943+ , (lhs:rhs:_) <- args =
948− {-jsMeth (jsMeth (JSVar lhs) "equals" [JSVar rhs]) "and" [-}
944+ jsMeth (jsMeth (translateReg lhs) "equals" [translateReg rhs]) "and" [
949− {-jsBigInt (JSString $ show 0xFFFFFFFFFFFFFFFF)-}
945+ jsBigInt (JSString $ show 0xFFFFFFFFFFFFFFFF)
950− {-]-}
946+ ]
951−
947+
952− {-| (LLt (ITFixed IT8)) <- op-}
948+ | (LLt (ITFixed IT8)) <- op
953− {-, (lhs:rhs:_) <- args =-}
949+ , (lhs:rhs:_) <- args =
954− {-jsPackUBits8 (-}
950+ jsPackUBits8 (
955− {-JSBinOp "<" (jsUnPackBits (JSVar lhs)) (jsUnPackBits (JSVar rhs))-}
951+ JSBinOp "<" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
956− {-)-}
952+ )
957−
953+
958− {-| (LLt (ITFixed IT16)) <- op-}
954+ | (LLt (ITFixed IT16)) <- op
959− {-, (lhs:rhs:_) <- args =-}
955+ , (lhs:rhs:_) <- args =
960− {-jsPackUBits16 (-}
956+ jsPackUBits16 (
961− {-JSBinOp "<" (jsUnPackBits (JSVar lhs)) (jsUnPackBits (JSVar rhs))-}
957+ JSBinOp "<" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
962− {-)-}
958+ )
963−
959+
964− {-| (LLt (ITFixed IT32)) <- op-}
960+ | (LLt (ITFixed IT32)) <- op
965− {-, (lhs:rhs:_) <- args =-}
961+ , (lhs:rhs:_) <- args =
966− {-jsPackUBits32 (-}
962+ jsPackUBits32 (
967− {-JSBinOp "<" (jsUnPackBits (JSVar lhs)) (jsUnPackBits (JSVar rhs))-}
963+ JSBinOp "<" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
968− {-)-}
964+ )
969
965
970 | (LLt (ITFixed IT64)) <- op
966 | (LLt (ITFixed IT64)) <- op
971 , (lhs:rhs:_) <- args = invokeMeth lhs "lesser" [rhs]
967 , (lhs:rhs:_) <- args = invokeMeth lhs "lesser" [rhs]
972
968
973− {-| (LLe (ITFixed IT8)) <- op-}
969+ | (LLe (ITFixed IT8)) <- op
974− {-, (lhs:rhs:_) <- args =-}
970+ , (lhs:rhs:_) <- args =
975− {-jsPackUBits8 (-}
971+ jsPackUBits8 (
976− {-JSBinOp "<=" (jsUnPackBits (JSVar lhs)) (jsUnPackBits (JSVar rhs))-}
972+ JSBinOp "<=" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
977− {-)-}
973+ )
978
974
979− {-| (LLe (ITFixed IT16)) <- op-}
975+ | (LLe (ITFixed IT16)) <- op
980− {-, (lhs:rhs:_) <- args =-}
976+ , (lhs:rhs:_) <- args =
981− {-jsPackUBits16 (-}
977+ jsPackUBits16 (
982− {-JSBinOp "<=" (jsUnPackBits (JSVar lhs)) (jsUnPackBits (JSVar rhs))-}
978+ JSBinOp "<=" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
983− {-)-}
979+ )
984
980
985− {-| (LLe (ITFixed IT32)) <- op-}
981+ | (LLe (ITFixed IT32)) <- op
986− {-, (lhs:rhs:_) <- args =-}
982+ , (lhs:rhs:_) <- args =
987− {-jsPackUBits32 (-}
983+ jsPackUBits32 (
988− {-JSBinOp "<=" (jsUnPackBits (JSVar lhs)) (jsUnPackBits (JSVar rhs))-}
984+ JSBinOp "<=" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
989− {-)-}
985+ )
990
986
991 | (LLe (ITFixed IT64)) <- op
987 | (LLe (ITFixed IT64)) <- op
992 , (lhs:rhs:_) <- args = invokeMeth lhs "lesserOrEquals" [rhs]
988 , (lhs:rhs:_) <- args = invokeMeth lhs "lesserOrEquals" [rhs]
993
989
994− {-| (LGt (ITFixed IT8)) <- op-}
990+ | (LGt (ITFixed IT8)) <- op
995− {-, (lhs:rhs:_) <- args =-}
991+ , (lhs:rhs:_) <- args =
996− {-jsPackUBits8 (-}
992+ jsPackUBits8 (
997− {-JSBinOp ">" (jsUnPackBits (JSVar lhs)) (jsUnPackBits (JSVar rhs))-}
993+ JSBinOp ">" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
998− {-)-}
994+ )
999−
995+
1000− {-| (LGt (ITFixed IT16)) <- op-}
996+ | (LGt (ITFixed IT16)) <- op
1001− {-, (lhs:rhs:_) <- args =-}
997+ , (lhs:rhs:_) <- args =
1002− {-jsPackUBits16 (-}
998+ jsPackUBits16 (
1003− {-JSBinOp ">" (jsUnPackBits (JSVar lhs)) (jsUnPackBits (JSVar rhs))-}
999+ JSBinOp ">" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
1004− {-)-}
1000+ )
1005− {-| (LGt (ITFixed IT32)) <- op-}
1001+ | (LGt (ITFixed IT32)) <- op
1006− {-, (lhs:rhs:_) <- args =-}
1002+ , (lhs:rhs:_) <- args =
1007− {-jsPackUBits32 (-}
1003+ jsPackUBits32 (
1008− {-JSBinOp ">" (jsUnPackBits (JSVar lhs)) (jsUnPackBits (JSVar rhs))-}
1004+ JSBinOp ">" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
1009− {-)-}
1005+ )
1010
1006
1011 | (LGt (ITFixed IT64)) <- op
1007 | (LGt (ITFixed IT64)) <- op
1012 , (lhs:rhs:_) <- args = invokeMeth lhs "greater" [rhs]
1008 , (lhs:rhs:_) <- args = invokeMeth lhs "greater" [rhs]
1013
1009
1014− {-| (LGe (ITFixed IT8)) <- op-}
1010+ | (LGe (ITFixed IT8)) <- op
1015− {-, (lhs:rhs:_) <- args =-}
1011+ , (lhs:rhs:_) <- args =
1016− {-jsPackUBits8 (-}
1012+ jsPackUBits8 (
1017− {-JSBinOp ">=" (jsUnPackBits (JSVar lhs)) (jsUnPackBits (JSVar rhs))-}
1013+ JSBinOp ">=" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
1018− {-)-}
1014+ )
1019−
1015+
1020− {-| (LGe (ITFixed IT16)) <- op-}
1016+ | (LGe (ITFixed IT16)) <- op
1021− {-, (lhs:rhs:_) <- args =-}
1017+ , (lhs:rhs:_) <- args =
1022− {-jsPackUBits16 (-}
1018+ jsPackUBits16 (
1023− {-JSBinOp ">=" (jsUnPackBits (JSVar lhs)) (jsUnPackBits (JSVar rhs))-}
1019+ JSBinOp ">=" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
1024− {-)-}
1020+ )
1025− {-| (LGe (ITFixed IT32)) <- op-}
1021+ | (LGe (ITFixed IT32)) <- op
1026− {-, (lhs:rhs:_) <- args =-}
1022+ , (lhs:rhs:_) <- args =
1027− {-jsPackUBits32 (-}
1023+ jsPackUBits32 (
1028− {-JSBinOp ">=" (jsUnPackBits (JSVar lhs)) (jsUnPackBits (JSVar rhs))-}
1024+ JSBinOp ">=" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
1029− {-)-}
1025+ )
1030
1026
1031 | (LGe (ITFixed IT64)) <- op
1027 | (LGe (ITFixed IT64)) <- op
1032 , (lhs:rhs:_) <- args = invokeMeth lhs "greaterOrEquals" [rhs]
1028 , (lhs:rhs:_) <- args = invokeMeth lhs "greaterOrEquals" [rhs]
1033
1029
1034− {-| (LUDiv (ITFixed IT8)) <- op-}
1030+ | (LUDiv (ITFixed IT8)) <- op
1035− {-, (lhs:rhs:_) <- args =-}
1031+ , (lhs:rhs:_) <- args =
1036− {-jsPackUBits8 (-}
1032+ jsPackUBits8 (
1037− {-JSBinOp "/" (jsUnPackBits (JSVar lhs)) (jsUnPackBits (JSVar rhs))-}
1033+ JSBinOp "/" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
1038− {-)-}
1034+ )
1039−
1035+
1040− {-| (LUDiv (ITFixed IT16)) <- op-}
1036+ | (LUDiv (ITFixed IT16)) <- op
1041− {-, (lhs:rhs:_) <- args =-}
1037+ , (lhs:rhs:_) <- args =
1042− {-jsPackUBits16 (-}
1038+ jsPackUBits16 (
1043− {-JSBinOp "/" (jsUnPackBits (JSVar lhs)) (jsUnPackBits (JSVar rhs))-}
1039+ JSBinOp "/" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
1044− {-)-}
1040+ )
1045−
1041+
1046− {-| (LUDiv (ITFixed IT32)) <- op-}
1042+ | (LUDiv (ITFixed IT32)) <- op
1047− {-, (lhs:rhs:_) <- args =-}
1043+ , (lhs:rhs:_) <- args =
1048− {-jsPackUBits32 (-}
1044+ jsPackUBits32 (
1049− {-JSBinOp "/" (jsUnPackBits (JSVar lhs)) (jsUnPackBits (JSVar rhs))-}
1045+ JSBinOp "/" (jsUnPackBits (translateReg lhs)) (jsUnPackBits (translateReg rhs))
1050− {-)-}
1046+ )
1051−
1047+
1052− {-| (LUDiv (ITFixed IT64)) <- op-}
1048+ | (LUDiv (ITFixed IT64)) <- op
1053− {-, (lhs:rhs:_) <- args = invokeMeth lhs "divide" [rhs]-}
1049+ , (lhs:rhs:_) <- args = invokeMeth lhs "divide" [rhs]
1054−
1050+
1055− {-| (LSDiv (ATInt (ITFixed IT8))) <- op-}
1051+ | (LSDiv (ATInt (ITFixed IT8))) <- op
1056− {-, (lhs:rhs:_) <- args =-}
1052+ , (lhs:rhs:_) <- args =
1057− {-jsPackSBits8 (-}
1053+ jsPackSBits8 (
1058− {-JSBinOp "/" (-}
1054+ JSBinOp "/" (
1059− {-jsUnPackBits $ jsPackSBits8 $ jsUnPackBits (JSVar lhs)-}
1055+ jsUnPackBits $ jsPackSBits8 $ jsUnPackBits (translateReg lhs)
1060− {-) (-}
1056+ ) (
1061− {-jsUnPackBits $ jsPackSBits8 $ jsUnPackBits (JSVar rhs)-}
1057+ jsUnPackBits $ jsPackSBits8 $ jsUnPackBits (translateReg rhs)
1062− {-)-}
1058+ )
1063− {-)-}
1059+ )
1064−
1060+
1065− {-| (LSDiv (ATInt (ITFixed IT16))) <- op-}
1061+ | (LSDiv (ATInt (ITFixed IT16))) <- op
1066− {-, (lhs:rhs:_) <- args =-}
1062+ , (lhs:rhs:_) <- args =
1067− {-jsPackSBits16 (-}
1063+ jsPackSBits16 (
1068− {-JSBinOp "/" (-}
1064+ JSBinOp "/" (
1069− {-jsUnPackBits $ jsPackSBits16 $ jsUnPackBits (JSVar lhs)-}
1065+ jsUnPackBits $ jsPackSBits16 $ jsUnPackBits (translateReg lhs)
1070− {-) (-}
1066+ ) (
1071− {-jsUnPackBits $ jsPackSBits16 $ jsUnPackBits (JSVar rhs)-}
1067+ jsUnPackBits $ jsPackSBits16 $ jsUnPackBits (translateReg rhs)
1072− {-)-}
1068+ )
1073− {-)-}
1069+ )
1074−
1070+
1075− {-| (LSDiv (ATInt (ITFixed IT32))) <- op-}
1071+ | (LSDiv (ATInt (ITFixed IT32))) <- op
1076− {-, (lhs:rhs:_) <- args =-}
1072+ , (lhs:rhs:_) <- args =
1077− {-jsPackSBits32 (-}
1073+ jsPackSBits32 (
1078− {-JSBinOp "/" (-}
1074+ JSBinOp "/" (
1079− {-jsUnPackBits $ jsPackSBits32 $ jsUnPackBits (JSVar lhs)-}
1075+ jsUnPackBits $ jsPackSBits32 $ jsUnPackBits (translateReg lhs)
1080− {-) (-}
1076+ ) (
1081− {-jsUnPackBits $ jsPackSBits32 $ jsUnPackBits (JSVar rhs)-}
1077+ jsUnPackBits $ jsPackSBits32 $ jsUnPackBits (translateReg rhs)
1082− {-)-}
1078+ )
1083− {-)-}
1079+ )
1084
1080
1085 | (LSDiv (ATInt (ITFixed IT64))) <- op
1081 | (LSDiv (ATInt (ITFixed IT64))) <- op
1086 , (lhs:rhs:_) <- args = invokeMeth lhs "divide" [rhs]
1082 , (lhs:rhs:_) <- args = invokeMeth lhs "divide" [rhs]
1087
1083
1088− {-| (LSRem (ATInt (ITFixed IT8))) <- op-}
1084+ | (LSRem (ATInt (ITFixed IT8))) <- op
1089− {-, (lhs:rhs:_) <- args =-}
1085+ , (lhs:rhs:_) <- args =
1090− {-jsPackSBits8 (-}
1086+ jsPackSBits8 (
1091− {-JSBinOp "%" (-}
1087+ JSBinOp "%" (
1092− {-jsUnPackBits $ jsPackSBits8 $ jsUnPackBits (JSVar lhs)-}
1088+ jsUnPackBits $ jsPackSBits8 $ jsUnPackBits (translateReg lhs)
1093− {-) (-}
1089+ ) (
1094− {-jsUnPackBits $ jsPackSBits8 $ jsUnPackBits (JSVar rhs)-}
1090+ jsUnPackBits $ jsPackSBits8 $ jsUnPackBits (translateReg rhs)
1095− {-)-}
1091+ )
1096− {-)-}
1092+ )
1097−
1093+
1098− {-| (LSRem (ATInt (ITFixed IT16))) <- op-}
1094+ | (LSRem (ATInt (ITFixed IT16))) <- op
1099− {-, (lhs:rhs:_) <- args =-}
1095+ , (lhs:rhs:_) <- args =
1100− {-jsPackSBits16 (-}
1096+ jsPackSBits16 (
1101− {-JSBinOp "%" (-}
1097+ JSBinOp "%" (
1102− {-jsUnPackBits $ jsPackSBits16 $ jsUnPackBits (JSVar lhs)-}
1098+ jsUnPackBits $ jsPackSBits16 $ jsUnPackBits (translateReg lhs)
1103− {-) (-}
1099+ ) (
1104− {-jsUnPackBits $ jsPackSBits16 $ jsUnPackBits (JSVar rhs)-}
1100+ jsUnPackBits $ jsPackSBits16 $ jsUnPackBits (translateReg rhs)
1105− {-)-}
1101+ )
1106− {-)-}
1102+ )
1107−
1103+
1108− {-| (LSRem (ATInt (ITFixed IT32))) <- op-}
1104+ | (LSRem (ATInt (ITFixed IT32))) <- op
1109− {-, (lhs:rhs:_) <- args =-}
1105+ , (lhs:rhs:_) <- args =
1110− {-jsPackSBits32 (-}
1106+ jsPackSBits32 (
1111− {-JSBinOp "%" (-}
1107+ JSBinOp "%" (
1112− {-jsUnPackBits $ jsPackSBits32 $ jsUnPackBits (JSVar lhs)-}
1108+ jsUnPackBits $ jsPackSBits32 $ jsUnPackBits (translateReg lhs)
1113− {-) (-}
1109+ ) (
1114− {-jsUnPackBits $ jsPackSBits32 $ jsUnPackBits (JSVar rhs)-}
1110+ jsUnPackBits $ jsPackSBits32 $ jsUnPackBits (translateReg rhs)
1115− {-)-}
1111+ )
1116− {-)-}
1112+ )
1117
1113
1118 | (LSRem (ATInt (ITFixed IT64))) <- op
1114 | (LSRem (ATInt (ITFixed IT64))) <- op
1119 , (lhs:rhs:_) <- args = invokeMeth lhs "mod" [rhs]
1115 , (lhs:rhs:_) <- args = invokeMeth lhs "mod" [rhs]
1120
1116
1121− {-| (LCompl (ITFixed IT8)) <- op-}
1117+ | (LCompl (ITFixed IT8)) <- op
1122− {-, (arg:_) <- args =-}
1118+ , (arg:_) <- args =
1123− {-jsPackSBits8 $ JSPreOp "~" $ jsUnPackBits (JSVar arg)-}
1119+ jsPackSBits8 $ JSPreOp "~" $ jsUnPackBits (translateReg arg)
1124
1120
1125− {-| (LCompl (ITFixed IT16)) <- op-}
1121+ | (LCompl (ITFixed IT16)) <- op
1126− {-, (arg:_) <- args =-}
1122+ , (arg:_) <- args =
1127− {-jsPackSBits16 $ JSPreOp "~" $ jsUnPackBits (JSVar arg)-}
1123+ jsPackSBits16 $ JSPreOp "~" $ jsUnPackBits (translateReg arg)
1128
1124
1129− {-| (LCompl (ITFixed IT32)) <- op-}
1125+ | (LCompl (ITFixed IT32)) <- op
1130− {-, (arg:_) <- args =-}
1126+ , (arg:_) <- args =
1131− {-jsPackSBits32 $ JSPreOp "~" $ jsUnPackBits (JSVar arg)-}
1127+ jsPackSBits32 $ JSPreOp "~" $ jsUnPackBits (translateReg arg)
1132
1128
1133 | (LCompl (ITFixed IT64)) <- op
1129 | (LCompl (ITFixed IT64)) <- op
1134 , (arg:_) <- args =
1130 , (arg:_) <- args =
@@ -1232,13 +1228,15 @@ jsOP reg op args = JSAssign (translateReg reg) jsOP'
1232 | LStrIndex <- op
1228 | LStrIndex <- op
1233 , (lhs:rhs:_) <- args = JSIndex (translateReg lhs) (translateReg rhs)
1229 , (lhs:rhs:_) <- args = JSIndex (translateReg lhs) (translateReg rhs)
1234 | LStrTail <- op
1230 | LStrTail <- op
1231+ , (arg:_) <- args =
1235− , (arg:_) <- args = let v = translateReg arg in
1232+ let v = translateReg arg in
1236− JSApp (JSProj v "substr") [
1233+ JSApp (JSProj v "substr") [
1237− JSNum (JSInt 1),
1234+ JSNum (JSInt 1),
1238− JSBinOp "-" (JSProj v "length") (JSNum (JSInt 1))
1235+ JSBinOp "-" (JSProj v "length") (JSNum (JSInt 1))
1239− ]
1236+ ]
1237+
1240− {-| LSystemInfo <- op-}
1238+ | LSystemInfo <- op
1241− {-, (arg:_) <- args = jsCall "__IDRRT__systemInfo" [JSVar arg]-}
1239+ , (arg:_) <- args = jsCall "__IDRRT__systemInfo" [translateReg arg]
1242 | LNullPtr <- op
1240 | LNullPtr <- op
1243 , (_) <- args = JSNull
1241 , (_) <- args = JSNull
1244 | otherwise = JSError $ "Not implemented: " ++ show op
1242 | otherwise = JSError $ "Not implemented: " ++ show op
@@ -1258,8 +1256,6 @@ jsOP reg op args = JSAssign (translateReg reg) jsOP'
1258 jsCall :: String -> [JS] -> JS
1256 jsCall :: String -> [JS] -> JS
1259 jsCall fun args = JSApp (JSIdent fun) args
1257 jsCall fun args = JSApp (JSIdent fun) args
1260
1258
1261−
1262−
1263jsRESERVE :: Int -> JS
1259jsRESERVE :: Int -> JS
1264jsRESERVE n = JSApp (JSIdent "i$RESERVE") [JSIdent "vm", JSNum $ JSInt n]
1260jsRESERVE n = JSApp (JSIdent "i$RESERVE") [JSIdent "vm", JSNum $ JSInt n]
1265
1261