@@ -11,8 +11,13 @@ import Util.System
11import Control.Applicative
11import Control.Applicative
12import Control.Arrow
12import Control.Arrow
13import Control.Monad
13import Control.Monad
14+import qualified Control.Monad.Trans as T
15+import Control.Monad.Trans.State
14import Data.Char
16import Data.Char
15import Data.Maybe (fromJust)
17import Data.Maybe (fromJust)
18+import Data.List (isPrefixOf, intercalate)
19+import qualified Data.Text as T
20+import qualified Data.Text.IO as TIO
16import Language.Java.Parser
21import Language.Java.Parser
17import Language.Java.Pretty
22import Language.Java.Pretty
18import Language.Java.Syntax hiding (Name)
23import Language.Java.Syntax hiding (Name)
@@ -23,19 +28,83 @@ import System.FilePath
23import System.IO
28import System.IO
24import System.Process
29import System.Process
31+data CodeGenerationEnv = CodeGenerationEnv { globalVariablePositions :: [(Name, Integer)] }
33+type CodeGeneration = StateT (CodeGenerationEnv) (Either String)
26−codegenJava :: [(Name, SDecl)] ->
35+codegenJava :: [(Name, SExp)] -> -- initialization of globals
27 FilePath -> -- output file name
37 FilePath -> -- output file name
28 OutputType ->
38 OutputType ->
30−codegenJava defs out exec =
40+codegenJava globalInit defs out exec = do
31− either (error)
41+ withTempdir (takeBaseName out) $ \ tmpDir -> do
42+ let srcdir = tmpDir </> "src" </> "main" </> "java"
43+ createDirectoryIfMissing True srcdir
44+ let (Ident clsName) =
45+ either error id (evalStateT (mkClassName out) (mkCodeGenEnv globalInit))
46+ let outjava = srcdir </> clsName <.> "java"
47+ let jout = either error
32− (writeFile out . flatIndent . prettyPrint)
48+ (flatIndent . prettyPrint)
33− (mkCompilationUnit defs out)
49+ (evalStateT (mkCompilationUnit globalInit defs out) (mkCodeGenEnv globalInit))
34−
50+ writeFile outjava jout
52+ then copyFile outjava (takeDirectory out </> clsName <.> "java")
54+ execPom <- getExecutablePom
55+ execPomTemplate <- TIO.readFile execPom
56+ let execPom = T.replace (T.pack "$MAIN-CLASS$")
58+ (T.replace (T.pack "$ARTIFACT-NAME$")
59+ (T.pack $ takeBaseName out)
61+ TIO.writeFile (tmpDir </> "pom.xml") execPom
63+ let args = ["-f", (tmpDir </> "pom.xml")]
64+ (exit, _, err) <- readProcessWithExitCode mvnCmd (args ++ ["compile"]) ""
65+ when (exit /= ExitSuccess) $ error ("FAILURE: " ++ mvnCmd ++ " compile\n" ++ err)
69+ map (\ clsFile -> tmpDir </> "target" </> "classes" </> clsFile)
70+ . filter ((".class" ==) . takeExtension)
71+ <$> getDirectoryContents (tmpDir </> "target" </> "classes")
72+ mapM_ (\ clsFile -> copyFile clsFile (takeDirectory out </> takeFileName clsFile))
75+ (exit, _, err) <- readProcessWithExitCode mvnCmd (args ++ ["package"]) ""
76+ when (exit /= ExitSuccess) (error ("FAILURE: " ++ mvnCmd ++ " package\n" ++ err))
77+ copyFile (tmpDir </> "target" </> (takeBaseName out) <.> "jar") out
78+ handle <- openBinaryFile out ReadMode
79+ contents <- TIO.hGetContents handle
81+ handle <- openBinaryFile out WriteMode
82+ TIO.hPutStr handle (T.append (T.pack jarHeader) contents)
85+ perms <- getPermissions out
86+ setPermissions out (setOwnerExecutable True perms)
87+ readProcess mvnCmd (args ++ ["clean"]) ""
88+ removeFile (tmpDir </> "pom.xml")
93+ ++ "MYSELF=`which \"$0\" 2>/dev/null`\n"
94+ ++ "[ $? -gt 0 -a -f \"$0\" ] && MYSELF=\"./$0\"\n"
96+ ++ "if test -n \"$JAVA_HOME\"; then\n"
97+ ++ " java=\"$JAVA_HOME/bin/java\"\n"
99+ ++ "exec \"$java\" $java_args -jar $MYSELF \"$@\""
102+mkCodeGenEnv :: [(Name, SExp)] -> CodeGenerationEnv
103+mkCodeGenEnv globalInit =
104+ CodeGenerationEnv $ zipWith (\ (name, _) pos -> (name, pos)) globalInit [0..]
35−mkCompilationUnit :: [(Name, SDecl)] ->
106+mkCompilationUnit :: [(Name, SExp)] -> [(Name, SDecl)] -> FilePath -> CodeGeneration CompilationUnit
37− Either String CompilationUnit
38−mkCompilationUnit defs out =
107+mkCompilationUnit globalInit defs out =
39 CompilationUnit Nothing [ ImportDecl False idrisRts True
108 CompilationUnit Nothing [ ImportDecl False idrisRts True
40 , ImportDecl True idrisForeign True
109 , ImportDecl True idrisForeign True
41 , ImportDecl False bigInteger False
110 , ImportDecl False bigInteger False
@@ -44,7 +113,7 @@ mkCompilationUnit defs out =
44 , ImportDecl False scanner False
113 , ImportDecl False scanner False
45 , ImportDecl False arrays False
114 , ImportDecl False arrays False
47− mkTypeDecl defs out
116+ mkTypeDecl globalInit defs out
49 idrisRts = J.Name $ map Ident ["org", "idris", "rts"]
118 idrisRts = J.Name $ map Ident ["org", "idris", "rts"]
50 idrisForeign = J.Name $ map Ident ["org", "idris", "rts", "ForeignPrimitives"]
119 idrisForeign = J.Name $ map Ident ["org", "idris", "rts", "ForeignPrimitives"]
@@ -75,10 +144,8 @@ prefixCallNamespacesCase name (SDefaultCase e) = SDefaultCase (prefixCallNamespa
75prefixCallNamespacesDecl :: Ident -> SDecl -> SDecl
144prefixCallNamespacesDecl :: Ident -> SDecl -> SDecl
76prefixCallNamespacesDecl name (SFun fname args i e) = SFun fname args i (prefixCallNamespaces name e)
145prefixCallNamespacesDecl name (SFun fname args i e) = SFun fname args i (prefixCallNamespaces name e)
78−mkTypeDecl :: [(Name, SDecl)] ->
147+mkTypeDecl :: [(Name, SExp)] -> [(Name, SDecl)] -> FilePath -> CodeGeneration [TypeDecl]
80− Either String [TypeDecl]
81−mkTypeDecl defs out =
148+mkTypeDecl globalInit defs out =
82 (\ name body -> [ClassTypeDecl $ ClassDecl [ Public
149 (\ name body -> [ClassTypeDecl $ ClassDecl [ Public
83 , Annotation $ SingleElementAnnotation
150 , Annotation $ SingleElementAnnotation
84 (J.Name [Ident "SuppressWarnings"])
151 (J.Name [Ident "SuppressWarnings"])
@@ -91,18 +158,33 @@ mkTypeDecl defs out =
92 <$> mkClassName out
159 <$> mkClassName out
93 <*> ( mkClassName out
160 <*> ( mkClassName out
94− >>= (\ ident -> mkClassBody (map (second (prefixCallNamespacesDecl ident)) defs))
161+ >>= (\ ident -> mkClassBody globalInit (map (second (prefixCallNamespacesDecl ident)) defs))
97−mkClassName :: FilePath -> Either String Ident
164+mkClassName :: FilePath -> CodeGeneration Ident
98mkClassName path =
165mkClassName path =
99− left (\ err -> "Parser error in \"" ++ path ++ "\": " ++ (show err))
166+ T.lift $ left (\ err -> "Parser error in \"" ++ path ++ "\": " ++ (show err))
100− (parser ident . takeBaseName $ takeFileName path)
167+ (parser ident . takeBaseName $ takeFileName path)
169+mkClassBody :: [(Name, SExp)] -> [(Name, SDecl)] -> CodeGeneration ClassBody
170+mkClassBody globalInit defs =
171+ (\ globals defs -> ClassBody . (globals++) . addMainMethod . mergeInnerClasses $ defs)
172+ <$> mkGlobalContext globalInit
173+ <*> mapM mkDecl defs
175+mkGlobalContext :: [(Name, SExp)] -> CodeGeneration [Decl]
176+mkGlobalContext [] = return []
177+mkGlobalContext initExps =
178+ (\ exps -> [ MemberDecl $ FieldDecl [Private, Static, Final]
180+ [VarDecl (VarId $ Ident "globalContext")
181+ (Just . InitArray $ ArrayInit exps)
185+ <$> mapM (\ (_, exp) -> InitExp <$> mkExp exp) initExps
102−mkClassBody :: [(Name, SDecl)] ->
187+
103− Either String ClassBody
104−mkClassBody defs = (ClassBody . addMainMethod . mergeInnerClasses)
105− <$> mapM mkDecl defs
107addMainMethod :: [Decl] -> [Decl]
189addMainMethod :: [Decl] -> [Decl]
108addMainMethod decls
190addMainMethod decls
@@ -160,17 +242,17 @@ mergeInnerClasses = foldl mergeInner []
160 mergeInner [] decl' = [decl']
242 mergeInner [] decl' = [decl']
163−mkIdentifier :: Name -> Either String Ident
245+mkIdentifier :: Name -> CodeGeneration Ident
164mkIdentifier (NS name _) = mkIdentifier name
246mkIdentifier (NS name _) = mkIdentifier name
165mkIdentifier (MN i name) = (\ (Ident x) -> Ident $ x ++ ('_' : show i))
247mkIdentifier (MN i name) = (\ (Ident x) -> Ident $ x ++ ('_' : show i))
166 <$> mkIdentifier (UN name)
248 <$> mkIdentifier (UN name)
167mkIdentifier (UN name) =
249mkIdentifier (UN name) =
168− left (\ err -> "Parser error in \"" ++ name ++ "\": " ++ (show err))
250+ T.lift $ left (\ err -> "Parser error in \"" ++ name ++ "\": " ++ (show err))
169− ( parser ident
251+ ( parser ident
170− . cleanReserved
252+ . cleanReserved
171− . cleanNonLetter
253+ . cleanNonLetter
172− . cleanStart
254+ . cleanStart
173− $ cleanWs False name)
255+ $ cleanWs False name)
175 cleanStart (x:xs)
257 cleanStart (x:xs)
176 | isNumber x = '_' : (x:xs)
258 | isNumber x = '_' : (x:xs)
@@ -207,6 +289,7 @@ mkIdentifier (UN name) =
209 cleanReserved "param" = "_param"
291 cleanReserved "param" = "_param"
292+ cleanReserved "globalContext" = "_globalContext"
210 cleanReserved "context" = "_context"
293 cleanReserved "context" = "_context"
211 cleanReserved "newcontext" = "_newcontext"
294 cleanReserved "newcontext" = "_newcontext"
@@ -300,10 +383,13 @@ mkIdentifier (UN name) =
300 cleanReserved "fputStr" = "_fputStr"
383 cleanReserved "fputStr" = "_fputStr"
301 cleanReserved "fileEOF" = "_fileEOF"
384 cleanReserved "fileEOF" = "_fileEOF"
302 cleanReserved "isNull" = "_isNull"
385 cleanReserved "isNull" = "_isNull"
386+ cleanReserved "idris_K" = "_idris_K"
387+ cleanReserved "idris_flipK" = "_idris_flipK"
388+ cleanReserved "idris_assignStack" = "_idris_assignStack"
304 cleanReserved x = x
390 cleanReserved x = x
306−mkName :: Name -> Either String J.Name
392+mkName :: Name -> CodeGeneration J.Name
307mkName (NS name nss) = (\ n ns -> J.Name (n:ns))
393mkName (NS name nss) = (\ n ns -> J.Name (n:ns))
308 <$> mkIdentifier name
394 <$> mkIdentifier name
309 <*> mapM (mkIdentifier . UN) nss
395 <*> mapM (mkIdentifier . UN) nss
@@ -330,8 +416,9 @@ idrisTailCallClosureType = ClassType [(Ident "TailCallClosure", [])]
330idrisObjectType :: ClassType
416idrisObjectType :: ClassType
331idrisObjectType = ClassType [(Ident "IdrisObject", [])]
417idrisObjectType = ClassType [(Ident "IdrisObject", [])]
333−contextArray :: Exp
419+contextArray :: LVar -> Exp
334−contextArray = ExpName $ J.Name [Ident "context"]
420+contextArray (Loc _) = ExpName $ J.Name [Ident "context"]
421+contextArray (Glob _) = ExpName $ J.Name [Ident "globalContext"]
336charType :: ClassType
423charType :: ClassType
337charType = ClassType [(Ident "Character", [])]
424charType = ClassType [(Ident "Character", [])]
@@ -369,29 +456,38 @@ runtimeExceptionType = ClassType [(Ident "RuntimeException", [])]
369comparableType :: ClassType
456comparableType :: ClassType
370comparableType = ClassType [(Ident "Comparable", [])]
457comparableType = ClassType [(Ident "Comparable", [])]
372−mkDecl :: (Name, SDecl) ->
459+mkDecl :: (Name, SDecl) -> CodeGeneration Decl
374mkDecl ((NS n (ns:nss)), decl) =
460mkDecl ((NS n (ns:nss)), decl) =
375 (\ name body -> MemberDecl $ MemberClassDecl $ ClassDecl [Public, Static] name [] Nothing [] body)
461 (\ name body -> MemberDecl $ MemberClassDecl $ ClassDecl [Public, Static] name [] Nothing [] body)
376 <$> mkIdentifier (UN ns)
462 <$> mkIdentifier (UN ns)
377− <*> mkClassBody [(NS n nss, decl)]
463+ <*> mkClassBody [] [(NS n nss, decl)]
378mkDecl (_, SFun name params stackSize body) =
464mkDecl (_, SFun name params stackSize body) =
379− (\ name params cont ->
465+ (\ name params paramNames methodBody ->
380 MemberDecl $ MethodDecl [Public, Static]
466 MemberDecl $ MethodDecl [Public, Static]
382 (Just . RefType $ ClassRefType objectType)
468 (Just . RefType $ ClassRefType objectType)
386− (MethodBody . Just $ Block [ BlockStmt . Return . Just . MethodInv $
472+ (MethodBody . Just $ Block
387− PrimaryMethodCall cont [] (Ident "call") []])
473+ [ LocalVars [Final]
475+ [ VarDecl (VarDeclArray . VarId $ Ident "context")
476+ (Just . InitArray . ArrayInit $
478+ ++ replicate stackSize (InitExp . Lit $ Null))
480+ , BlockStmt . Return $ Just methodBody
389 <$> mkIdentifier name
484 <$> mkIdentifier name
390 <*> mapM mkFormalParam params
485 <*> mapM mkFormalParam params
391− <*> mkClosure params stackSize body
486+ <*> mapM (\ p -> (InitExp . ExpName) <$> mkName p) params
394−mkClosure :: [Name] -> Int -> SExp -> Either String Exp
490+mkClosure :: [Name] -> Int -> SExp -> CodeGeneration Exp
395mkClosure params stackSize body =
491mkClosure params stackSize body =
396 (\ paramArray body ->
492 (\ paramArray body ->
397 InstanceCreation []
493 InstanceCreation []
@@ -402,126 +498,55 @@ mkClosure params stackSize body =
402 <$> mkStackInit params stackSize
498 <$> mkStackInit params stackSize
403 <*> mkClosureCall body
499 <*> mkClosureCall body
405−mkFormalParam :: Name -> Either String FormalParam
501+mkFormalParam :: Name -> CodeGeneration FormalParam
406mkFormalParam name =
502mkFormalParam name =
407 (\ name -> FormalParam [Final] (RefType . ClassRefType $ objectType) False (VarId name))
503 (\ name -> FormalParam [Final] (RefType . ClassRefType $ objectType) False (VarId name))
408 <$> mkIdentifier name
504 <$> mkIdentifier name
410−mkClosureCall :: SExp -> Either String Decl
506+mkClosureCall :: SExp -> CodeGeneration Decl
411mkClosureCall body =
507mkClosureCall body =
412 (\ body -> MemberDecl $ MethodDecl [Public] [] (Just . RefType $ ClassRefType objectType) (Ident "call") [] [] body)
508 (\ body -> MemberDecl $ MethodDecl [Public] [] (Just . RefType $ ClassRefType objectType) (Ident "call") [] [] body)
413 <$> mkMethodBody body
509 <$> mkMethodBody body
415−mkMethodBody :: SExp -> Either String MethodBody
511+mkMethodBody :: SExp -> CodeGeneration MethodBody
416mkMethodBody exp =
512mkMethodBody exp =
417 (\ exp -> MethodBody . Just . Block $ [BlockStmt . Return . Just $ exp])
513 (\ exp -> MethodBody . Just . Block $ [BlockStmt . Return . Just $ exp])
418 <$> mkExp exp
514 <$> mkExp exp
420−mkStackInit :: [Name] -> Int -> Either String Exp
516+mkStackInit :: [Name] -> Int -> CodeGeneration Exp
421mkStackInit params stackSize =
517mkStackInit params stackSize =
422 (\ localVars -> ArrayCreateInit objectArrayType 0 . ArrayInit $
518 (\ localVars -> ArrayCreateInit objectArrayType 0 . ArrayInit $
423 (map (InitExp . ExpName) localVars)
519 (map (InitExp . ExpName) localVars)
424 ++ (replicate (stackSize) (InitExp $ Lit Null)))
520 ++ (replicate (stackSize) (InitExp $ Lit Null)))
425 <$> mapM mkName params
521 <$> mapM mkName params
427−mkAnonymousLetBinding :: LVar -> SExp -> SExp -> Either String Exp
523+mkK :: Exp -> Exp -> Exp
428−mkAnonymousLetBinding var oldExp newExp =
524+mkK result drop =
429− (\ bindingMethod newExp ->
525+ MethodInv $ MethodCall (J.Name [Ident "idris_K"]) [ result, drop ]
430− MethodInv $ PrimaryMethodCall
526+
431− ( MethodInv $ PrimaryMethodCall ( InstanceCreation []
527+mkFlipK :: Exp -> Exp -> Exp
432− objectType
528+mkFlipK drop result =
433− []
529+ MethodInv $ MethodCall (J.Name [Ident "idris_flipK"]) [ drop, result ]
434− (Just $ ClassBody [MemberDecl $ bindingMethod])
530+
435− )
531+mkLet :: LVar -> SExp -> SExp -> CodeGeneration Exp
436− []
532+mkLet (Loc pos) oldExp newExp =
437− (Ident "apply")
533+ (\ oldExp newExp ->
445− <$> mkLetBindingMethod var oldExp
449−mkContextParam :: FormalParam
451− FormalParam [Final] (objectArrayType) False (VarId (Ident "context"))
453−mkLetBindingMethod :: LVar -> SExp -> Either String MemberDecl
454−mkLetBindingMethod (Loc i) oldExp =
455− (\ param bindingStack oldCont ->
456− MethodDecl [Final, Public]
458− (Just . RefType $ ClassRefType idrisClosureType)
460− [mkContextParam, param]
462− (MethodBody . Just . Block $
463− bindingStack ++ [BlockStmt . Return $ Just oldCont]
466− <$> mkFormalParam (UN "param")
467− <*> mkBindingStack True i [UN "param"]
468− <*> mkBindingClosure oldExp
470−mkBindingClosure :: SExp -> Either String Exp
471−mkBindingClosure oldExp =
475− [ ExpName $ J.Name [Ident "new_context"] ]
534+ mkFlipK ( Assign ( ArrayLhs $ ArrayIndex (ExpName $ J.Name [Ident "context"])
476− (Just $ ClassBody [oldCall])
535+ (Lit $ Int (toInteger pos)))
478− <$> mkClosureCall oldExp
541+ <$> mkExp oldExp
479−
542+ <*> mkExp newExp
480−
543+mkLet (Glob _) _ _ = T.lift $ Left "Cannot let bind to global variable"
481−mkBindingStack :: Bool -> Int -> [Name] -> Either String [BlockStmt]
482−mkBindingStack checked parentStackStart params =
486− [ VarDecl (VarDeclArray . VarId $ Ident "new_context")
487− (Just . InitExp $ mkContextCopy checked parentStackStart params)
489− : ( map (\ (param, pos) ->
490− BlockStmt . ExpStmt $
491− Assign (ArrayLhs $ ArrayIndex (ExpName $ J.Name [Ident "new_context"])
492− (Lit $ Int (toInteger pos)))
494− (ExpName param)) $ zip paramNames [parentStackStart..]
497− <$> mapM mkName params
499−mkContextCopy :: Bool -> Int -> [Name] -> Exp
500−mkContextCopy True parentStackStart params =
501− MethodInv $ PrimaryMethodCall (ExpName $ J.Name [Ident "context"])
505−mkContextCopy False parentStackStart params =
506− MethodInv $ TypeMethodCall (J.Name [Ident "Arrays"])
509− [ ExpName $ J.Name [Ident "context"]
511− $ TypeMethodCall (J.Name [Ident "Math"])
514− [ FieldAccess $ PrimaryFieldAccess (ExpName $ J.Name [Ident "context"])
516− , Lit . Int $ toInteger (parentStackStart + length params)
520reverseNameSpace :: J.Name -> J.Name
545reverseNameSpace :: J.Name -> J.Name
521reverseNameSpace (J.Name ids) =
546reverseNameSpace (J.Name ids) =
522 J.Name ((tail ids) ++ [head ids])
547 J.Name ((tail ids) ++ [head ids])
524−mkCase :: Bool -> LVar -> [SAlt] -> Either String Exp
549+mkCase :: Bool -> LVar -> [SAlt] -> CodeGeneration Exp
525mkCase checked var ((SConCase parentStackPos consIndex _ params branchExpression):cases) =
550mkCase checked var ((SConCase parentStackPos consIndex _ params branchExpression):cases) =
526 mkConsCase checked
551 mkConsCase checked
@@ -531,11 +556,11 @@ mkCase checked var ((SConCase parentStackPos consIndex _ params branchExpression
531 branchExpression
556 branchExpression
532 (SCase var cases)
557 (SCase var cases)
533mkCase checked var (c@(SConstCase constant branchExpression):cases) =
558mkCase checked var (c@(SConstCase constant branchExpression):cases) =
534− (\ constant branchExpression alternative ->
559+ (\ constant branchExpression alternative var->
535 Cond ( MethodInv $ PrimaryMethodCall (constant)
560 Cond ( MethodInv $ PrimaryMethodCall (constant)
537 (Ident "equals")
562 (Ident "equals")
538− [mkVarAccess Nothing var]
563+ [var]
540 branchExpression
565 branchExpression
541 alternative
566 alternative
@@ -543,10 +568,11 @@ mkCase checked var (c@(SConstCase constant branchExpression):cases) =
543 <$> mkExp (SConst constant)
568 <$> mkExp (SConst constant)
544 <*> mkExp branchExpression
569 <*> mkExp branchExpression
545 <*> mkCase checked var cases
570 <*> mkCase checked var cases
571+ <*> mkVarAccess Nothing var
546mkCase checked var (SDefaultCase exp:cases) = mkExp exp
572mkCase checked var (SDefaultCase exp:cases) = mkExp exp
547mkCase checked _ [] = mkExp (SError "Non-exhaustive pattern")
573mkCase checked _ [] = mkExp (SError "Non-exhaustive pattern")
549−mkConsCase :: Bool -> LVar -> Int -> Int -> [Name] -> SExp -> SExp -> Either String Exp
575+mkConsCase :: Bool -> LVar -> Int -> Int -> [Name] -> SExp -> SExp -> CodeGeneration Exp
550mkConsCase checked
576mkConsCase checked
551 toDeconstruct
577 toDeconstruct
552 parentStackStart
578 parentStackStart
@@ -554,13 +580,13 @@ mkConsCase checked
555 branchExpression
581 branchExpression
556 alternative =
582 alternative =
557− (\ caseBinding alternative->
583+ (\ caseBinding alternative var varCasted->
558− Cond (BinOp (InstanceOf (mkVarAccess Nothing toDeconstruct)
584+ Cond (BinOp (InstanceOf (var)
559 (ClassRefType idrisObjectType)
585 (ClassRefType idrisObjectType)
563− ( MethodInv $ PrimaryMethodCall (mkVarAccess (Just idrisObjectType) toDeconstruct)
589+ ( MethodInv $ PrimaryMethodCall (varCasted)
565 (Ident "getConstructorId")
591 (Ident "getConstructorId")
@@ -574,11 +600,24 @@ mkConsCase checked
575 <$> mkCaseBinding checked toDeconstruct parentStackStart params branchExpression
601 <$> mkCaseBinding checked toDeconstruct parentStackStart params branchExpression
576 <*> mkExp alternative
602 <*> mkExp alternative
577−
603+ <*> mkVarAccess (Nothing) toDeconstruct
578−
604+ <*> mkVarAccess (Just idrisObjectType) toDeconstruct
579−mkCaseBinding :: Bool -> LVar -> Int -> [Name] -> SExp -> Either String Exp
607+mkCaseBinding :: Bool -> LVar -> Int -> [Name] -> SExp -> CodeGeneration Exp
608+mkCaseBinding True var parentStackStart params branchExpression =
609+ (\ branchExpression deconstruction ->
610+ mkFlipK (MethodInv $ MethodCall (J.Name [Ident "idris_assignStack"])
611+ ( (ExpName $ J.Name [Ident "context"])
612+ : (Lit $ Int (toInteger parentStackStart))
617+ <$> mkExp branchExpression
618+ <*> mkCaseBindingDeconstruction var params
580−mkCaseBinding checked var parentStackStart params branchExpression =
619+mkCaseBinding False var parentStackStart params branchExpression =
581− (\ bindingMethod ->
620+ (\ bindingMethod deconstruction ->
582 MethodInv $ PrimaryMethodCall
621 MethodInv $ PrimaryMethodCall
583 ( MethodInv $ PrimaryMethodCall (InstanceCreation []
622 ( MethodInv $ PrimaryMethodCall (InstanceCreation []
584 (ClassType [(Ident "Object", [])])
623 (ClassType [(Ident "Object", [])])
@@ -587,20 +626,21 @@ mkCaseBinding checked var parentStackStart params branchExpression =
589 (Ident "apply")
628 (Ident "apply")
590− ( contextArray
629+ ( contextArray (Loc undefined) : deconstruction )
591− : (mkCaseBindingDeconstruction var params)
595 (Ident "call")
632 (Ident "call")
598− <$> mkCaseBindingMethod checked parentStackStart params branchExpression
635+ <$> mkCaseBindingMethod parentStackStart params branchExpression
599−
636+ <*> mkCaseBindingDeconstruction var params
638+mkCaseBindingDeconstruction :: LVar -> [Name] -> CodeGeneration [Exp]
639+mkCaseBindingDeconstruction var members =
640+ mapM (mkProjection var) ([0..(length members - 1)])
602−mkCaseBindingMethod :: Bool -> Int -> [Name] -> SExp -> Either String MemberDecl
642+mkCaseBindingMethod :: Int -> [Name] -> SExp -> CodeGeneration MemberDecl
603−mkCaseBindingMethod checked parentStackStart params branchExpression =
643+mkCaseBindingMethod parentStackStart params branchExpression =
604 (\ formalParams caseBindingStack branchExpression ->
644 (\ formalParams caseBindingStack branchExpression ->
605 MethodDecl [Final, Public]
645 MethodDecl [Final, Public]
@@ -612,22 +652,74 @@ mkCaseBindingMethod checked parentStackStart params branchExpression =
612 caseBindingStack ++
652 caseBindingStack ++
613 [BlockStmt . Return $ Just branchExpression]))
653 [BlockStmt . Return $ Just branchExpression]))
614 <$> mapM mkFormalParam params
654 <$> mapM mkFormalParam params
615− <*> mkBindingStack checked parentStackStart params
655+ <*> mkBindingStack False parentStackStart params
616 <*> mkBindingClosure branchExpression
656 <*> mkBindingClosure branchExpression
618−mkCaseBindingDeconstruction :: LVar -> [Name] -> [Exp]
658+mkContextParam :: FormalParam
619−mkCaseBindingDeconstruction var members =
659+mkContextParam =
620− map (mkProjection var) ([0..(length members - 1)])
660+ FormalParam [Final] (objectArrayType) False (VarId (Ident "context"))
662+mkBindingClosure :: SExp -> CodeGeneration Exp
663+mkBindingClosure oldExp =
667+ [ ExpName $ J.Name [Ident "new_context"] ]
668+ (Just $ ClassBody [oldCall])
670+ <$> mkClosureCall oldExp
673+mkBindingStack :: Bool -> Int -> [Name] -> CodeGeneration [BlockStmt]
674+mkBindingStack checked parentStackStart params =
678+ [ VarDecl (VarDeclArray . VarId $ Ident "new_context")
679+ (Just . InitExp $ mkContextCopy checked parentStackStart params)
681+ : ( map (\ (param, pos) ->
682+ BlockStmt . ExpStmt $
683+ Assign (ArrayLhs $ ArrayIndex (ExpName $ J.Name [Ident "new_context"])
684+ (Lit $ Int (toInteger pos)))
686+ (ExpName param)) $ zip paramNames [parentStackStart..]
689+ <$> mapM mkName params
691+mkContextCopy :: Bool -> Int -> [Name] -> Exp
692+mkContextCopy True parentStackStart params =
693+ MethodInv $ PrimaryMethodCall (ExpName $ J.Name [Ident "context"])
697+mkContextCopy False parentStackStart params =
698+ MethodInv $ TypeMethodCall (J.Name [Ident "Arrays"])
701+ [ ExpName $ J.Name [Ident "context"]
703+ $ TypeMethodCall (J.Name [Ident "Math"])
706+ [ FieldAccess $ PrimaryFieldAccess (ExpName $ J.Name [Ident "context"])
708+ , Lit . Int $ toInteger (parentStackStart + length params)
622−mkProjection :: LVar -> Int -> Exp
712+mkProjection :: LVar -> Int -> CodeGeneration Exp
623mkProjection var memberNr =
713mkProjection var memberNr =
624− ArrayAccess $ ArrayIndex ( MethodInv $ PrimaryMethodCall
714+ (\ var -> ArrayAccess $ ArrayIndex ( MethodInv $ PrimaryMethodCall
625− (mkVarAccess (Just idrisObjectType) var)
715+ (var)
627− (Ident "getData")
717+ (Ident "getData")
630− (Lit $ Int (toInteger memberNr))
720+ (Lit $ Int (toInteger memberNr))
722+ <$> mkVarAccess (Just idrisObjectType) var
632type ClassName = String
724type ClassName = String
@@ -642,22 +734,22 @@ mkClass :: ClassType -> Exp
642mkClass classType =
734mkClass classType =
643 ClassLit . Just . RefType .ClassRefType $ classType
735 ClassLit . Just . RefType .ClassRefType $ classType
645−mkBinOpExp :: ClassType -> Op -> [LVar] -> Exp
737+mkBinOpExp :: ClassType -> Op -> [LVar] -> CodeGeneration Exp
646−mkBinOpExp castTo op (var:vars) =
738+mkBinOpExp castTo op (var:vars) = do
739+ start <- mkVarAccess (Just castTo) var
740+ foldM (\ exp var -> BinOp exp op <$> mkVarAccess (Just castTo) var) start vars
742+mkBinOpExpTrans :: (Exp -> Exp) -> (Exp -> Exp) -> ClassType -> Op -> [LVar] -> CodeGeneration Exp
743+mkBinOpExpTrans opTransformation resultTransformation castTo op (var:vars) = do
744+ start <- (mkVarAccess (Just castTo) var)
745+ foldM (\ exp var -> resultTransformation
746+ . BinOp (opTransformation exp) op
647− foldl (\ exp -> BinOp exp op . mkVarAccess (Just castTo))
748+ <$> mkVarAccess (Just castTo) var)
648− (mkVarAccess (Just castTo) var)
749+ start
651−mkBinOpExpTrans :: (Exp -> Exp) -> (Exp -> Exp) -> ClassType -> Op -> [LVar] -> Exp
652−mkBinOpExpTrans opTransformation resultTransformation castTo op (var:vars) =
653− foldl (\ exp -> resultTransformation
654− . BinOp (opTransformation exp) op
656− . mkVarAccess (Just castTo))
657− (mkVarAccess (Just castTo) var)
660−mkBinOpExpConv :: String -> PrimType -> ClassType -> Op -> [LVar] -> Exp
752+mkBinOpExpConv :: String -> PrimType -> ClassType -> Op -> [LVar] -> CodeGeneration Exp
661mkBinOpExpConv fromMethodName toType fromType@(ClassType [(cls@(Ident _), [])]) op args =
753mkBinOpExpConv fromMethodName toType fromType@(ClassType [(cls@(Ident _), [])]) op args =
662 mkBinOpExpTrans (\ exp -> MethodInv $ TypeMethodCall (J.Name [cls])
754 mkBinOpExpTrans (\ exp -> MethodInv $ TypeMethodCall (J.Name [cls])
@@ -673,59 +765,70 @@ mkBinOpExpConv fromMethodName toType fromType@(ClassType [(cls@(Ident _), [])])
676−mkLogicalBinOpExp :: ClassType -> Op -> [LVar] -> Exp
768+mkLogicalBinOpExp :: ClassType -> Op -> [LVar] -> CodeGeneration Exp
677−mkLogicalBinOpExp castTo op (var:vars) =
769+mkLogicalBinOpExp castTo op (var:vars) = do
770+ start <- mkVarAccess (Just castTo) var
678− foldl (\ exp -> mkBoolToNumber castTo . BinOp exp op . mkVarAccess (Just castTo))
771+ foldM (\ exp var -> mkBoolToNumber castTo . BinOp exp op <$> mkVarAccess (Just castTo) var)
679− (mkVarAccess (Just castTo) var)
772+ start
682−mkMethodOpChain1 :: (Exp -> Exp) -> ClassType -> String -> [LVar] -> Exp
775+mkMethodOpChain1 :: (Exp -> Exp) -> ClassType -> String -> [LVar] -> CodeGeneration Exp
683mkMethodOpChain1 = mkMethodOpChain id
776mkMethodOpChain1 = mkMethodOpChain id
685−mkMethodOpChain :: (Exp -> Exp) -> (Exp -> Exp) -> ClassType -> String -> [LVar] -> Exp
778+mkMethodOpChain :: (Exp -> Exp) -> (Exp -> Exp) -> ClassType -> String -> [LVar] -> CodeGeneration Exp
686−mkMethodOpChain initialTransformation resultTransformation castTo method (arg:args) =
779+mkMethodOpChain initialTransformation resultTransformation castTo method (arg:args) = do
780+ start <- initialTransformation <$> mkVarAccess (Just $ castTo) arg
687− foldl (\ exp arg' ->
781+ foldM (\ exp arg' ->
688− resultTransformation . MethodInv $ PrimaryMethodCall exp
782+ resultTransformation
690− (Ident method)
784+ . PrimaryMethodCall exp [] (Ident method)
691− [mkVarAccess (Just $ castTo) arg']
786+ <$> mkVarAccess (Just $ castTo) arg'
693− (initialTransformation (mkVarAccess (Just $ castTo) arg))
788+ start
696mkBoolToNumber :: ClassType -> Exp -> Exp
791mkBoolToNumber :: ClassType -> Exp -> Exp
697mkBoolToNumber (ClassType [(Ident name, [])]) boolExp =
792mkBoolToNumber (ClassType [(Ident name, [])]) boolExp =
698 Cond boolExp (mkPrimitive name (Int 1)) (mkPrimitive name (Int 0))
793 Cond boolExp (mkPrimitive name (Int 1)) (mkPrimitive name (Int 0))
700−mkZeroExt :: String -> Int -> ClassType -> ClassType -> LVar -> Exp
795+mkZeroExt :: String -> Int -> ClassType -> ClassType -> LVar -> CodeGeneration Exp
701−mkZeroExt toMethod bits fromType toType@(ClassType [(toTypeName, [])]) var =
796+mkZeroExt toMethod bits fromType toType@(ClassType [(toTypeName, [])]) var = do
702− MethodInv $ TypeMethodCall (J.Name [toTypeName])
798+ MethodInv $ TypeMethodCall (J.Name [toTypeName])
704− (Ident "valueOf")
800+ (Ident "valueOf")
705− [ Cond ( BinOp (mkVarAccess (Just $ fromType) var)
801+ [ Cond ( BinOp (var)
707− (Lit $ Int 0)
803+ (Lit $ Int 0)
709− ( BinOp (Lit $ Int (2^bits))
805+ ( BinOp (Lit $ Int (2^bits))
711− (mkSignedExt' toMethod fromType var)
807+ (sext)
812+ <$> mkVarAccess (Just $ fromType) var
713− (mkSignedExt' toMethod fromType var)
813+ <*> mkSignedExt' toMethod fromType var
716−mkSignedExt :: String -> ClassType -> ClassType -> LVar -> Exp
815+mkSignedExt :: String -> ClassType -> ClassType -> LVar -> CodeGeneration Exp
717mkSignedExt toMethod fromType (ClassType [(toTypeName, [])]) var =
816mkSignedExt toMethod fromType (ClassType [(toTypeName, [])]) var =
718− MethodInv $ TypeMethodCall (J.Name [toTypeName])
817+ (\ sext -> MethodInv $ TypeMethodCall (J.Name [toTypeName])
720− (Ident "valueOf")
819+ (Ident "valueOf")
721− [ mkSignedExt' toMethod fromType var ]
822+ <$> mkSignedExt' toMethod fromType var
723−mkSignedExt' :: String -> ClassType -> LVar -> Exp
824+mkSignedExt' :: String -> ClassType -> LVar -> CodeGeneration Exp
724mkSignedExt' toMethod fromType var =
825mkSignedExt' toMethod fromType var =
826+ (\ var -> MethodInv $ PrimaryMethodCall (var)
725− MethodInv $ PrimaryMethodCall (mkVarAccess (Just $ fromType) var)
831+ <$> mkVarAccess (Just $ fromType) var
730data SPartialOrder
833data SPartialOrder
@@ -747,26 +850,39 @@ mkPartialOrder SGe x =
747 (BinOp (Lit $ Int 0) Equal x)
850 (BinOp (Lit $ Int 0) Equal x)
748mkPartialOrder SGt x = (BinOp (Lit $ Int 1) Equal x)
851mkPartialOrder SGt x = (BinOp (Lit $ Int 1) Equal x)
853+varPos :: LVar -> CodeGeneration Integer
854+varPos (Loc i) = return (toInteger i)
855+varPos (Glob name) = do
856+ positions <- globalVariablePositions <$> get
857+ case lookup name positions of
858+ (Just pos) -> return pos
859+ Nothing -> T.lift . Left $ "Invalid global variable id: " ++ show name
750−mkVarAccess :: Maybe ClassType -> LVar -> Exp
861+mkVarAccess :: Maybe ClassType -> LVar -> CodeGeneration Exp
751−mkVarAccess Nothing (Loc i) =
862+mkVarAccess Nothing var =
752− ArrayAccess $ ArrayIndex contextArray (Lit $ Int (toInteger i))
863+ (\ pos -> ArrayAccess $ ArrayIndex (contextArray var) (Lit $ Int pos))
753mkVarAccess (Just castTo) var =
865mkVarAccess (Just castTo) var =
754− Cast (RefType . ClassRefType $ castTo) (mkVarAccess Nothing var)
866+ Cast (RefType . ClassRefType $ castTo) <$> (mkVarAccess Nothing var)
756−mkPrimitiveCast :: ClassType -> ClassType -> LVar -> Exp
868+mkPrimitiveCast :: ClassType -> ClassType -> LVar -> CodeGeneration Exp
757mkPrimitiveCast fromType (ClassType [(toType, [])]) var =
869mkPrimitiveCast fromType (ClassType [(toType, [])]) var =
758− MethodInv $ TypeMethodCall (J.Name [toType])
871+ MethodInv $ TypeMethodCall (J.Name [toType])
761− [mkVarAccess (Just fromType) var]
763−mkToString :: ClassType -> LVar -> Exp
764−mkToString castTo var =
765− MethodInv $ PrimaryMethodCall (mkVarAccess (Just castTo) var)
876+ <$> mkVarAccess (Just fromType) var
878+mkToString :: ClassType -> LVar -> CodeGeneration Exp
879+mkToString castTo var =
880+ (\ var -> MethodInv $ PrimaryMethodCall (var)
885+ <$> mkVarAccess (Just castTo) var
770data Std = In | Out | Err
886data Std = In | Out | Err
772instance Show Std where
888instance Show Std where
@@ -784,49 +900,57 @@ mkSystemOutPrint value =
784 (Ident "print")
900 (Ident "print")
787−mkMathFun :: String -> LVar -> Exp
903+mkMathFun :: String -> LVar -> CodeGeneration Exp
788mkMathFun funName var =
904mkMathFun funName var =
789− MethodInv $ TypeMethodCall (J.Name [Ident "Double"])
905+ (\ var -> MethodInv $ TypeMethodCall (J.Name [Ident "Double"])
791− (Ident "valueOf")
907+ (Ident "valueOf")
792− [ MethodInv $ TypeMethodCall (J.Name [Ident "Math"])
908+ [ MethodInv $ TypeMethodCall (J.Name [Ident "Math"])
794− (Ident funName)
910+ (Ident funName)
795− [mkVarAccess (Just doubleType) var]
914+ <$> mkVarAccess (Just doubleType) var
798−mkStringAtIndex :: LVar -> Exp -> Exp
916+mkStringAtIndex :: LVar -> Exp -> CodeGeneration Exp
799mkStringAtIndex var indexExp =
917mkStringAtIndex var indexExp =
800− MethodInv $ TypeMethodCall (J.Name [Ident "Integer"])
918+ (\ var -> MethodInv $ TypeMethodCall (J.Name [Ident "Integer"])
802− (Ident "valueOf")
920+ (Ident "valueOf")
921+ [ MethodInv $ PrimaryMethodCall (var)
803− [ MethodInv $ PrimaryMethodCall (mkVarAccess (Just stringType) var)
927+ <$> mkVarAccess (Just stringType) var
809mkForeignType :: FType -> Maybe ClassType
929mkForeignType :: FType -> Maybe ClassType
810−mkForeignType FInt = return $ integerType
930+mkForeignType FInt = return integerType
811−mkForeignType FChar = return $ integerType
931+mkForeignType FChar = return integerType
812−mkForeignType FString = return $ stringType
932+mkForeignType FString = return stringType
813−mkForeignType FPtr = return $ objectType
933+mkForeignType FPtr = return objectType
814−mkForeignType FDouble = return $ doubleType
934+mkForeignType FDouble = return doubleType
815−mkForeignType FAny = return $ objectType
935+mkForeignType FAny = return objectType
816mkForeignType FUnit = Nothing
936mkForeignType FUnit = Nothing
818−mkForeignVarAccess :: FType -> LVar -> Exp
938+mkForeignVarAccess :: FType -> LVar -> CodeGeneration Exp
819mkForeignVarAccess FInt var =
939mkForeignVarAccess FInt var =
940+ (\ var -> MethodInv $ PrimaryMethodCall (var)
820− MethodInv $ PrimaryMethodCall (mkVarAccess (Just integerType) var)
945+ <$> mkVarAccess (Just integerType) var
824−mkForeignVarAccess FChar var = Cast (PrimType CharT) (mkForeignVarAccess FInt var)
946+mkForeignVarAccess FChar var = Cast (PrimType CharT) <$> mkForeignVarAccess FInt var
825mkForeignVarAccess FDouble var =
947mkForeignVarAccess FDouble var =
948+ (\ var -> MethodInv $ PrimaryMethodCall (var)
950+ (Ident "doubleValue")
826− MethodInv $ PrimaryMethodCall (mkVarAccess (Just doubleType) var)
953+ <$> mkVarAccess (Just doubleType) var
828− (Ident "doubleValue")
830mkForeignVarAccess otherType var = mkVarAccess (mkForeignType otherType) var
954mkForeignVarAccess otherType var = mkVarAccess (mkForeignType otherType) var
832mkFromForeignType :: FType -> Exp -> Exp
956mkFromForeignType :: FType -> Exp -> Exp
@@ -843,7 +967,7 @@ mkFromForeignType FDouble from =
844mkFromForeignType _ from = from
968mkFromForeignType _ from = from
846−mkForeignInvoke :: FType -> String -> [(FType, LVar)] -> Either String Exp
970+mkForeignInvoke :: FType -> String -> [(FType, LVar)] -> CodeGeneration Exp
847mkForeignInvoke fType method args =
971mkForeignInvoke fType method args =
848 (\ foreignInvokeMeth ->
972 (\ foreignInvokeMeth ->
849 MethodInv $ PrimaryMethodCall (InstanceCreation []
973 MethodInv $ PrimaryMethodCall (InstanceCreation []
@@ -858,7 +982,7 @@ mkForeignInvoke fType method args =
858 <$> mkForeignInvokeMethod fType method args
982 <$> mkForeignInvokeMethod fType method args
861−mkForeignInvokeMethod :: FType -> String -> [(FType, LVar)] -> Either String MemberDecl
985+mkForeignInvokeMethod :: FType -> String -> [(FType, LVar)] -> CodeGeneration MemberDecl
862mkForeignInvokeMethod fType method args =
986mkForeignInvokeMethod fType method args =
863 (\ tryBlock ->
987 (\ tryBlock ->
864 MethodDecl [Public, Final]
988 MethodDecl [Public, Final]
@@ -867,111 +991,124 @@ mkForeignInvokeMethod fType method args =
867 (Ident "foreignInvoke")
991 (Ident "foreignInvoke")
870− (MethodBody . Just $ Block [ BlockStmt $
994+ (MethodBody . Just $ Block
871− Try tryBlock
996+ $ Try tryBlock
872− [ Catch (FormalParam []
997+ [ Catch (FormalParam []
873− (RefType $ ClassRefType exceptionType)
998+ (RefType $ ClassRefType exceptionType)
875− (VarId $ Ident "ex")
1000+ (VarId $ Ident "ex")
877− (Block [ BlockStmt . Throw $
1002+ (Block [ BlockStmt
878− InstanceCreation []
1004+ $ InstanceCreation []
879− runtimeExceptionType
1005+ runtimeExceptionType
880− [ExpName $ J.Name [Ident "ex"]]
1006+ [ExpName $ J.Name [Ident "ex"]]
881− Nothing
1007+ Nothing
885− Nothing
1011+ Nothing
889 <$> mkForeignInvokeTryBlock fType method args
1015 <$> mkForeignInvokeTryBlock fType method args
892−mkForeignInvokeTryBlock :: FType -> String -> [(FType, LVar)] -> Either String Block
1018+mkForeignInvokeTryBlock :: FType -> String -> [(FType, LVar)] -> CodeGeneration Block
893mkForeignInvokeTryBlock FUnit method args =
1019mkForeignInvokeTryBlock FUnit method args =
894− (\ method -> Block [ BlockStmt . ExpStmt . MethodInv $
1020+ (\ method args -> Block [ BlockStmt . ExpStmt . MethodInv $ MethodCall method args
896− (map (uncurry mkForeignVarAccess) args)
897− , BlockStmt $ Return (Just $ Lit Null)
1021+ , BlockStmt $ Return (Just $ Lit Null)
900− <$> ( left (\ err -> "Error parsing name \"" ++ method ++ "\" :" ++ (show err))
1024+ <$> ( T.lift $ left (\ err -> "Error parsing name \"" ++ method ++ "\" :" ++ (show err))
901− (parser name method)
1025+ (parser name method)
1027+ <*> mapM (uncurry mkForeignVarAccess) args
903mkForeignInvokeTryBlock fType method args =
1028mkForeignInvokeTryBlock fType method args =
904− (\ method -> Block [ BlockStmt . Return
1029+ (\ method args -> Block [ BlockStmt . Return
906 . mkFromForeignType fType
1031 . mkFromForeignType fType
907− . MethodInv $
1032+ . MethodInv
908− MethodCall method
1033+ $ MethodCall method args
909− (map (uncurry mkForeignVarAccess) args)
912− <$> ( left (\ err -> "Error parsing name \"" ++ method ++ "\" :" ++ (show err))
1036+ <$> ( T.lift $ left (\ err -> "Error parsing name \"" ++ method ++ "\" :" ++ (show err))
913− (parser name method)
1037+ (parser name method)
1039+ <*> mapM (uncurry mkForeignVarAccess) args
916−mkMethodClosure :: Name -> [LVar] -> Either String Exp
1041+mkMethodClosure :: Name -> [LVar] -> CodeGeneration Exp
917mkMethodClosure name args =
1042mkMethodClosure name args =
918 (\ name args ->
1043 (\ name args ->
919 InstanceCreation []
1044 InstanceCreation []
920 idrisClosureType
1045 idrisClosureType
921 [ (ExpName $ J.Name [Ident "context"]) ]
1046 [ (ExpName $ J.Name [Ident "context"]) ]
922− ( Just $ ClassBody
1048+ $ ClassBody
923− [ MemberDecl $
1049+ [ MemberDecl
924− MethodDecl [Public, Final]
1050+ $ MethodDecl [Public, Final]
926− (Just . RefType $ ClassRefType objectType)
1052+ (Just . RefType $ ClassRefType objectType)
927− (Ident "call")
1053+ (Ident "call")
930− ( MethodBody . Just $
1056+ ( MethodBody
931− Block [ BlockStmt . Return . Just . MethodInv $
1058+ $ Block [ BlockStmt
932− MethodCall (reverseNameSpace name)
1062+ $ MethodCall (reverseNameSpace name)
939 <$> mkName name
1069 <$> mkName name
940 <*> mapM (mkExp . SV) args
1070 <*> mapM (mkExp . SV) args
942−mkThread :: LVar -> Either String Exp
1072+mkThread :: LVar -> CodeGeneration Exp
943mkThread arg =
1073mkThread arg =
944− (\ eval -> MethodInv $
1075+ MethodInv
945− PrimaryMethodCall (InstanceCreation []
1076+ $ PrimaryMethodCall (InstanceCreation []
946− (ClassType [(Ident "Thread", [])])
1077+ (ClassType [(Ident "Thread", [])])
947− [ eval ]
1078+ [ eval ]
948− ( Just $ ClassBody
1080+ $ ClassBody [ MemberDecl
949− [ MemberDecl $ MethodDecl
950− [Public, Final]
1081+ $ MethodDecl [Public, Final]
952− (Just . RefType $ ClassRefType objectType)
1083+ (Just . RefType $ ClassRefType objectType)
953− (Ident "_start")
1084+ (Ident "_start")
956− ( MethodBody . Just $ Block
1087+ ( MethodBody
1089+ $ Block [ BlockStmt
957− [ BlockStmt . ExpStmt . MethodInv $ MethodCall
1091+ . MethodInv
958− (J.Name [Ident "start"])
1092+ $ MethodCall (J.Name [Ident "start"])
960− , BlockStmt . Return . Just $ This
1094+ , BlockStmt
967− (Ident "_start")
1104+ (Ident "_start")
970 <$> mkThreadBinding arg
1107 <$> mkThreadBinding arg
972−mkThreadBinding :: LVar -> Either String Exp
1109+mkThreadBinding :: LVar -> CodeGeneration Exp
973mkThreadBinding var =
1110mkThreadBinding var =
974− (\ bindingMethod ->
1111+ (\ bindingMethod var ->
975 MethodInv $ PrimaryMethodCall ( InstanceCreation []
1112 MethodInv $ PrimaryMethodCall ( InstanceCreation []
976 objectType
1113 objectType
@@ -979,12 +1116,13 @@ mkThreadBinding var =
981 (Ident "apply")
1118 (Ident "apply")
982− [ mkVarAccess Nothing var ]
1119+ [ var ]
984 <$> mkThreadBindingMethod
1121 <$> mkThreadBindingMethod
1122+ <*> mkVarAccess Nothing var
987−mkThreadBindingMethod :: Either String MemberDecl
1125+mkThreadBindingMethod :: CodeGeneration MemberDecl
988mkThreadBindingMethod =
1126mkThreadBindingMethod =
989 (\ compute ->
1127 (\ compute ->
990 MethodDecl [Final, Public]
1128 MethodDecl [Final, Public]
@@ -1011,9 +1149,8 @@ mkThreadBindingStack =
1014−mkExp :: SExp -> Either String Exp
1152+mkExp :: SExp -> CodeGeneration Exp
1016− return $ mkVarAccess Nothing var
1153+mkExp (SV var) = mkVarAccess Nothing var
1017mkExp (SApp False name args) =
1154mkExp (SApp False name args) =
1018 (\ methClosure ->
1155 (\ methClosure ->
1019 MethodInv $ PrimaryMethodCall ( InstanceCreation []
1156 MethodInv $ PrimaryMethodCall ( InstanceCreation []
@@ -1036,12 +1173,14 @@ mkExp (SApp True name args) =
1037 <$> mkMethodClosure name args
1174 <$> mkMethodClosure name args
1038mkExp (SLet var new old) =
1175mkExp (SLet var new old) =
1039− mkAnonymousLetBinding var old new
1176+ mkLet var old new
1040−mkExp (SUpdate (Loc i) exp) =
1177+mkExp (SUpdate var exp) =
1041− (\ rhs -> Assign (ArrayLhs $ ArrayIndex (contextArray) (Lit $ Int (toInteger i)))
1178+ (\ rhs varPos -> Assign (ArrayLhs $ ArrayIndex (contextArray var) (Lit $ Int varPos))
1044 <$> mkExp exp
1182 <$> mkExp exp
1045mkExp (SCon conId name args) =
1184mkExp (SCon conId name args) =
1046 (\ args -> InstanceCreation []
1185 (\ args -> InstanceCreation []
1047 idrisObjectType
1186 idrisObjectType
@@ -1050,7 +1189,7 @@ mkExp (SCon conId name args) =
1050 <$> mapM (mkExp .SV) args
1189 <$> mapM (mkExp .SV) args
1051mkExp (SCase var alts) = mkCase False var alts
1190mkExp (SCase var alts) = mkCase False var alts
1052mkExp (SChkCase var alts) = mkCase True var alts
1191mkExp (SChkCase var alts) = mkCase True var alts
1053−mkExp (SProj var i) = return $ mkProjection var i
1192+mkExp (SProj var i) = mkProjection var i
1054mkExp (SConst (I x)) = return $ mkPrimitive "Integer" (Int (toInteger x))
1193mkExp (SConst (I x)) = return $ mkPrimitive "Integer" (Int (toInteger x))
1055mkExp (SConst (BI x)) =
1194mkExp (SConst (BI x)) =
1056 return $ InstanceCreation []
1195 return $ InstanceCreation []
@@ -1077,226 +1216,235 @@ mkExp (SConst (PtrType)) = return $ mkClass objectType
1077mkExp (SConst (VoidType)) = return $ mkClass voidType
1216mkExp (SConst (VoidType)) = return $ mkClass voidType
1078mkExp (SConst (Forgot)) = return $ mkClass objectType
1217mkExp (SConst (Forgot)) = return $ mkClass objectType
1079mkExp (SForeign _ fType meth args) = mkForeignInvoke fType meth args
1218mkExp (SForeign _ fType meth args) = mkForeignInvoke fType meth args
1080−mkExp (SOp LPlus args) = return $ mkBinOpExp integerType Add args
1219+mkExp (SOp LPlus args) = mkBinOpExp integerType Add args
1081−mkExp (SOp LMinus args) = return $ mkBinOpExp integerType Sub args
1220+mkExp (SOp LMinus args) = mkBinOpExp integerType Sub args
1082−mkExp (SOp LTimes args) = return $ mkBinOpExp integerType Mult args
1221+mkExp (SOp LTimes args) = mkBinOpExp integerType Mult args
1083−mkExp (SOp LDiv args) = return $ mkBinOpExp integerType Div args
1222+mkExp (SOp LDiv args) = mkBinOpExp integerType Div args
1084−mkExp (SOp LMod args) = return $ mkBinOpExp integerType Rem args
1223+mkExp (SOp LMod args) = mkBinOpExp integerType Rem args
1085−mkExp (SOp LAnd args) = return $ mkBinOpExp integerType And args
1224+mkExp (SOp LAnd args) = mkBinOpExp integerType And args
1086−mkExp (SOp LOr args) = return $ mkBinOpExp integerType Or args
1225+mkExp (SOp LOr args) = mkBinOpExp integerType Or args
1087−mkExp (SOp LXOr args) = return $ mkBinOpExp integerType Xor args
1226+mkExp (SOp LXOr args) = mkBinOpExp integerType Xor args
1088mkExp (SOp LCompl [var]) =
1227mkExp (SOp LCompl [var]) =
1089− return $ PreBitCompl (mkVarAccess (Just $ integerType) var)
1228+ PreBitCompl <$> mkVarAccess (Just $ integerType) var
1090−mkExp (SOp LSHL args) = return $ mkBinOpExp integerType LShift args
1229+mkExp (SOp LSHL args) = mkBinOpExp integerType LShift args
1091−mkExp (SOp LSHR args) = return $ mkBinOpExp integerType RShift args
1230+mkExp (SOp LSHR args) = mkBinOpExp integerType RShift args
1092mkExp (SOp LEq args) =
1231mkExp (SOp LEq args) =
1093− return $ mkMethodOpChain1 (mkBoolToNumber integerType) objectType "equals" args
1232+ mkMethodOpChain1 (mkBoolToNumber integerType) objectType "equals" args
1094−mkExp (SOp LLt args) = return $ mkLogicalBinOpExp integerType LThan args
1233+mkExp (SOp LLt args) = mkLogicalBinOpExp integerType LThan args
1095−mkExp (SOp LLe args) = return $ mkLogicalBinOpExp integerType LThanE args
1234+mkExp (SOp LLe args) = mkLogicalBinOpExp integerType LThanE args
1096−mkExp (SOp LGt args) = return $ mkLogicalBinOpExp integerType GThan args
1235+mkExp (SOp LGt args) = mkLogicalBinOpExp integerType GThan args
1097−mkExp (SOp LGe args) = return $ mkLogicalBinOpExp integerType GThanE args
1236+mkExp (SOp LGe args) = mkLogicalBinOpExp integerType GThanE args
1098−mkExp (SOp LFPlus args) = return $ mkBinOpExp doubleType Add args
1237+mkExp (SOp LFPlus args) = mkBinOpExp doubleType Add args
1099−mkExp (SOp LFMinus args) = return $ mkBinOpExp doubleType Sub args
1238+mkExp (SOp LFMinus args) = mkBinOpExp doubleType Sub args
1100−mkExp (SOp LFTimes args) = return $ mkBinOpExp doubleType Mult args
1239+mkExp (SOp LFTimes args) = mkBinOpExp doubleType Mult args
1101−mkExp (SOp LFDiv args) = return $ mkBinOpExp doubleType Div args
1240+mkExp (SOp LFDiv args) = mkBinOpExp doubleType Div args
1102mkExp (SOp LFEq args) =
1241mkExp (SOp LFEq args) =
1103− return $ mkMethodOpChain1 (mkBoolToNumber doubleType) doubleType "equals" args
1242+ mkMethodOpChain1 (mkBoolToNumber doubleType) doubleType "equals" args
1104−mkExp (SOp LFLt args) = return $ mkLogicalBinOpExp integerType LThan args
1243+mkExp (SOp LFLt args) = mkLogicalBinOpExp integerType LThan args
1105−mkExp (SOp LFLe args) = return $ mkLogicalBinOpExp integerType LThanE args
1244+mkExp (SOp LFLe args) = mkLogicalBinOpExp integerType LThanE args
1106−mkExp (SOp LFGt args) = return $ mkLogicalBinOpExp integerType GThan args
1245+mkExp (SOp LFGt args) = mkLogicalBinOpExp integerType GThan args
1107−mkExp (SOp LFGe args) = return $ mkLogicalBinOpExp integerType GThanE args
1246+mkExp (SOp LFGe args) = mkLogicalBinOpExp integerType GThanE args
1108−mkExp (SOp LBPlus args) = return $ mkMethodOpChain1 id bigIntegerType "add" args
1247+mkExp (SOp LBPlus args) = mkMethodOpChain1 id bigIntegerType "add" args
1109−mkExp (SOp LBMinus args) = return $ mkMethodOpChain1 id bigIntegerType "subtract" args
1248+mkExp (SOp LBMinus args) = mkMethodOpChain1 id bigIntegerType "subtract" args
1110−mkExp (SOp LBTimes args) = return $ mkMethodOpChain1 id bigIntegerType "multiply" args
1249+mkExp (SOp LBTimes args) = mkMethodOpChain1 id bigIntegerType "multiply" args
1111−mkExp (SOp LBDiv args) = return $ mkMethodOpChain1 id bigIntegerType "divide" args
1250+mkExp (SOp LBDiv args) = mkMethodOpChain1 id bigIntegerType "divide" args
1112−mkExp (SOp LBMod args) = return $ mkMethodOpChain1 id bigIntegerType "mod" args
1251+mkExp (SOp LBMod args) = mkMethodOpChain1 id bigIntegerType "mod" args
1113mkExp (SOp LBEq args) =
1252mkExp (SOp LBEq args) =
1114− return $ mkMethodOpChain1 (mkBoolToNumber bigIntegerType) bigIntegerType "equals" args
1253+ mkMethodOpChain1 (mkBoolToNumber bigIntegerType) bigIntegerType "equals" args
1115mkExp (SOp LBLt args) =
1254mkExp (SOp LBLt args) =
1116− return $ mkMethodOpChain1 ( mkBoolToNumber bigIntegerType
1255+ mkMethodOpChain1 ( mkBoolToNumber bigIntegerType
1117− . mkPartialOrder SLt
1256+ . mkPartialOrder SLt
1119− bigIntegerType
1258+ bigIntegerType
1120− "compare"
1259+ "compare"
1122mkExp (SOp LBLe args) =
1261mkExp (SOp LBLe args) =
1123− return $ mkMethodOpChain1 ( mkBoolToNumber bigIntegerType
1262+ mkMethodOpChain1 ( mkBoolToNumber bigIntegerType
1124− . mkPartialOrder SLe
1263+ . mkPartialOrder SLe
1126− bigIntegerType
1265+ bigIntegerType
1127− "compare"
1266+ "compare"
1129mkExp (SOp LBGt args) =
1268mkExp (SOp LBGt args) =
1130− return $ mkMethodOpChain1 ( mkBoolToNumber bigIntegerType
1269+ mkMethodOpChain1 ( mkBoolToNumber bigIntegerType
1131− . mkPartialOrder SGt
1270+ . mkPartialOrder SGt
1133− bigIntegerType
1272+ bigIntegerType
1134− "compare"
1273+ "compare"
1136mkExp (SOp LBGe args) =
1275mkExp (SOp LBGe args) =
1137− return $ mkMethodOpChain1 ( mkBoolToNumber bigIntegerType
1276+ mkMethodOpChain1 ( mkBoolToNumber bigIntegerType
1138− . mkPartialOrder SGe
1277+ . mkPartialOrder SGe
1140− bigIntegerType
1279+ bigIntegerType
1141− "compare"
1280+ "compare"
1143mkExp (SOp LStrConcat args) =
1282mkExp (SOp LStrConcat args) =
1144− return $ mkMethodOpChain (\ exp ->
1145− InstanceCreation []
1283+ mkMethodOpChain (\ exp -> InstanceCreation []
1146− (ClassType [(Ident "StringBuilder", [])])
1284+ (ClassType [(Ident "StringBuilder", [])])
1148− Nothing
1286+ Nothing
1150− (\ exp -> MethodInv $ PrimaryMethodCall exp [] (Ident "toString") [])
1288+ (\ exp -> MethodInv $ PrimaryMethodCall exp [] (Ident "toString") [])
1151− stringType
1289+ stringType
1152− "append"
1290+ "append"
1154mkExp (SOp LStrLt args@[_, _]) =
1292mkExp (SOp LStrLt args@[_, _]) =
1155− return $ mkMethodOpChain1 ( mkBoolToNumber integerType
1293+ mkMethodOpChain1 ( mkBoolToNumber integerType
1156− . mkPartialOrder SLt
1294+ . mkPartialOrder SLt
1158− stringType
1296+ stringType
1159− "compare"
1297+ "compare"
1161mkExp (SOp LStrEq args@[_, _]) =
1299mkExp (SOp LStrEq args@[_, _]) =
1162− return $ mkMethodOpChain1 ( mkBoolToNumber integerType)
1300+ mkMethodOpChain1 ( mkBoolToNumber integerType)
1163− stringType
1301+ stringType
1164− "equals"
1302+ "equals"
1166mkExp (SOp LStrLen [arg]) =
1304mkExp (SOp LStrLen [arg]) =
1305+ (\ var -> MethodInv $ PrimaryMethodCall var [] (Ident "length") [])
1167− return . MethodInv $ PrimaryMethodCall (mkVarAccess (Just stringType) arg) [] (Ident "length") []
1306+ <$> mkVarAccess (Just stringType) arg
1168mkExp (SOp LIntFloat [arg]) =
1307mkExp (SOp LIntFloat [arg]) =
1169− return $ mkPrimitiveCast integerType doubleType arg
1308+ mkPrimitiveCast integerType doubleType arg
1170mkExp (SOp LFloatInt [arg]) =
1309mkExp (SOp LFloatInt [arg]) =
1171− return $ mkPrimitiveCast doubleType integerType arg
1310+ mkPrimitiveCast doubleType integerType arg
1172mkExp (SOp LIntStr [arg]) =
1311mkExp (SOp LIntStr [arg]) =
1173− return $ mkToString integerType arg
1312+ mkToString integerType arg
1174mkExp (SOp LStrInt [arg]) =
1313mkExp (SOp LStrInt [arg]) =
1175− return $ mkPrimitiveCast stringType integerType arg
1314+ mkPrimitiveCast stringType integerType arg
1176mkExp (SOp LFloatStr [arg]) =
1315mkExp (SOp LFloatStr [arg]) =
1177− return $ mkToString doubleType arg
1316+ mkToString doubleType arg
1178mkExp (SOp LStrFloat [arg]) =
1317mkExp (SOp LStrFloat [arg]) =
1179− return $ mkPrimitiveCast doubleType stringType arg
1318+ mkPrimitiveCast doubleType stringType arg
1180mkExp (SOp LIntBig [arg]) =
1319mkExp (SOp LIntBig [arg]) =
1181− return $ mkPrimitiveCast integerType bigIntegerType arg
1320+ mkPrimitiveCast integerType bigIntegerType arg
1182mkExp (SOp LBigInt [arg]) =
1321mkExp (SOp LBigInt [arg]) =
1183− return $ mkPrimitiveCast bigIntegerType integerType arg
1322+ mkPrimitiveCast bigIntegerType integerType arg
1184mkExp (SOp LStrBig [arg]) =
1323mkExp (SOp LStrBig [arg]) =
1324+ (\ var -> InstanceCreation [] bigIntegerType [var] Nothing)
1185− return $ InstanceCreation [] bigIntegerType [mkVarAccess (Just stringType) arg] Nothing
1325+ <$> mkVarAccess (Just stringType) arg
1186mkExp (SOp LBigStr [arg]) =
1326mkExp (SOp LBigStr [arg]) =
1187− return $ mkToString bigIntegerType arg
1327+ mkToString bigIntegerType arg
1188mkExp (SOp LChInt [arg]) =
1328mkExp (SOp LChInt [arg]) =
1189− return $ mkVarAccess (Just integerType) arg
1329+ mkVarAccess (Just integerType) arg
1190mkExp (SOp LIntCh [arg]) =
1330mkExp (SOp LIntCh [arg]) =
1191− return $ mkVarAccess (Just integerType) arg
1331+ mkVarAccess (Just integerType) arg
1192mkExp (SOp LPrintNum [arg]) =
1332mkExp (SOp LPrintNum [arg]) =
1193− return $ mkSystemOutPrint (mkVarAccess Nothing arg)
1333+ mkSystemOutPrint <$> (mkVarAccess Nothing arg)
1194mkExp (SOp LPrintStr [arg]) =
1334mkExp (SOp LPrintStr [arg]) =
1195− return $ mkSystemOutPrint (mkVarAccess (Just stringType) arg)
1335+ mkSystemOutPrint <$> (mkVarAccess (Just stringType) arg)
1196mkExp (SOp LReadStr [arg]) = mkExp (SForeign LANG_C FString "idris_readStr" [(FPtr, arg)])
1336mkExp (SOp LReadStr [arg]) = mkExp (SForeign LANG_C FString "idris_readStr" [(FPtr, arg)])
1197−mkExp (SOp LB8Lt args) = return $ mkLogicalBinOpExp byteType LThan args
1337+mkExp (SOp LB8Lt args) = mkLogicalBinOpExp byteType LThan args
1198−mkExp (SOp LB8Lte args) = return $ mkLogicalBinOpExp byteType LThanE args
1338+mkExp (SOp LB8Lte args) = mkLogicalBinOpExp byteType LThanE args
1199mkExp (SOp LB8Eq args) =
1339mkExp (SOp LB8Eq args) =
1200− return $ mkMethodOpChain1 (mkBoolToNumber byteType) byteType "equals" args
1340+ mkMethodOpChain1 (mkBoolToNumber byteType) byteType "equals" args
1201−mkExp (SOp LB8Gt args) = return $ mkLogicalBinOpExp byteType GThan args
1341+mkExp (SOp LB8Gt args) = mkLogicalBinOpExp byteType GThan args
1202−mkExp (SOp LB8Gte args) = return $ mkLogicalBinOpExp byteType GThanE args
1342+mkExp (SOp LB8Gte args) = mkLogicalBinOpExp byteType GThanE args
1203−mkExp (SOp LB8Plus args) = return $ mkBinOpExp byteType Add args
1343+mkExp (SOp LB8Plus args) = mkBinOpExp byteType Add args
1204−mkExp (SOp LB8Minus args) = return $ mkBinOpExp byteType Sub args
1344+mkExp (SOp LB8Minus args) = mkBinOpExp byteType Sub args
1205−mkExp (SOp LB8Times args) = return $ mkBinOpExp byteType Mult args
1345+mkExp (SOp LB8Times args) = mkBinOpExp byteType Mult args
1206−mkExp (SOp LB8UDiv args) = return $ mkBinOpExpConv "shortValue" ShortT byteType Div args
1346+mkExp (SOp LB8UDiv args) = mkBinOpExpConv "shortValue" ShortT byteType Div args
1207−mkExp (SOp LB8SDiv args) = return $ mkBinOpExp byteType Div args
1347+mkExp (SOp LB8SDiv args) = mkBinOpExp byteType Div args
1208−mkExp (SOp LB8URem args) = return $ mkBinOpExpConv "shortValue" ShortT byteType Rem args
1348+mkExp (SOp LB8URem args) = mkBinOpExpConv "shortValue" ShortT byteType Rem args
1209−mkExp (SOp LB8SRem args) = return $ mkBinOpExp byteType Rem args
1349+mkExp (SOp LB8SRem args) = mkBinOpExp byteType Rem args
1210−mkExp (SOp LB8Shl args) = return $ mkBinOpExp byteType LShift args
1350+mkExp (SOp LB8Shl args) = mkBinOpExp byteType LShift args
1211−mkExp (SOp LB8LShr args) = return $ mkBinOpExp byteType RRShift args
1351+mkExp (SOp LB8LShr args) = mkBinOpExp byteType RRShift args
1212−mkExp (SOp LB8AShr args) = return $ mkBinOpExp byteType RShift args
1352+mkExp (SOp LB8AShr args) = mkBinOpExp byteType RShift args
1213−mkExp (SOp LB8And args) = return $ mkBinOpExp byteType And args
1353+mkExp (SOp LB8And args) = mkBinOpExp byteType And args
1214−mkExp (SOp LB8Or args) = return $ mkBinOpExp byteType Or args
1354+mkExp (SOp LB8Or args) = mkBinOpExp byteType Or args
1215−mkExp (SOp LB8Xor args) = return $ mkBinOpExp byteType Xor args
1355+mkExp (SOp LB8Xor args) = mkBinOpExp byteType Xor args
1216mkExp (SOp LB8Compl [var]) =
1356mkExp (SOp LB8Compl [var]) =
1217− return $ PreBitCompl (mkVarAccess (Just $ byteType) var)
1357+ PreBitCompl <$> mkVarAccess (Just $ byteType) var
1218−mkExp (SOp LB8Z16 [var]) = return $ mkZeroExt "shortValue" 8 byteType shortType var
1358+mkExp (SOp LB8Z16 [var]) = mkZeroExt "shortValue" 8 byteType shortType var
1219−mkExp (SOp LB8Z32 [var]) = return $ mkZeroExt "intValue" 8 byteType integerType var
1359+mkExp (SOp LB8Z32 [var]) = mkZeroExt "intValue" 8 byteType integerType var
1220−mkExp (SOp LB8Z64 [var]) = return $ mkZeroExt "longValue" 8 byteType longType var
1360+mkExp (SOp LB8Z64 [var]) = mkZeroExt "longValue" 8 byteType longType var
1221−mkExp (SOp LB8S16 [var]) = return $ mkSignedExt "shortValue" byteType shortType var
1361+mkExp (SOp LB8S16 [var]) = mkSignedExt "shortValue" byteType shortType var
1222−mkExp (SOp LB8S32 [var]) = return $ mkSignedExt "intValue" byteType integerType var
1362+mkExp (SOp LB8S32 [var]) = mkSignedExt "intValue" byteType integerType var
1223−mkExp (SOp LB8S64 [var]) = return $ mkSignedExt "longValue" byteType longType var
1363+mkExp (SOp LB8S64 [var]) = mkSignedExt "longValue" byteType longType var
1224−mkExp (SOp LB16Lt args) = return $ mkLogicalBinOpExp shortType LThan args
1364+mkExp (SOp LB16Lt args) = mkLogicalBinOpExp shortType LThan args
1225−mkExp (SOp LB16Lte args) = return $ mkLogicalBinOpExp shortType LThanE args
1365+mkExp (SOp LB16Lte args) = mkLogicalBinOpExp shortType LThanE args
1226mkExp (SOp LB16Eq args) =
1366mkExp (SOp LB16Eq args) =
1227− return $ mkMethodOpChain1 (mkBoolToNumber shortType) shortType "equals" args
1367+ mkMethodOpChain1 (mkBoolToNumber shortType) shortType "equals" args
1228−mkExp (SOp LB16Gt args) = return $ mkLogicalBinOpExp shortType GThan args
1368+mkExp (SOp LB16Gt args) = mkLogicalBinOpExp shortType GThan args
1229−mkExp (SOp LB16Gte args) = return $ mkLogicalBinOpExp shortType GThanE args
1369+mkExp (SOp LB16Gte args) = mkLogicalBinOpExp shortType GThanE args
1230−mkExp (SOp LB16Plus args) = return $ mkBinOpExp shortType Add args
1370+mkExp (SOp LB16Plus args) = mkBinOpExp shortType Add args
1231−mkExp (SOp LB16Minus args) = return $ mkBinOpExp shortType Sub args
1371+mkExp (SOp LB16Minus args) = mkBinOpExp shortType Sub args
1232−mkExp (SOp LB16Times args) = return $ mkBinOpExp shortType Mult args
1372+mkExp (SOp LB16Times args) = mkBinOpExp shortType Mult args
1233−mkExp (SOp LB16UDiv args) = return $ mkBinOpExpConv "intValue" IntT shortType Div args
1373+mkExp (SOp LB16UDiv args) = mkBinOpExpConv "intValue" IntT shortType Div args
1234−mkExp (SOp LB16SDiv args) = return $ mkBinOpExp shortType Div args
1374+mkExp (SOp LB16SDiv args) = mkBinOpExp shortType Div args
1235−mkExp (SOp LB16URem args) = return $ mkBinOpExpConv "intValue" IntT shortType Rem args
1375+mkExp (SOp LB16URem args) = mkBinOpExpConv "intValue" IntT shortType Rem args
1236−mkExp (SOp LB16SRem args) = return $ mkBinOpExp shortType Rem args
1376+mkExp (SOp LB16SRem args) = mkBinOpExp shortType Rem args
1237−mkExp (SOp LB16Shl args) = return $ mkBinOpExp shortType LShift args
1377+mkExp (SOp LB16Shl args) = mkBinOpExp shortType LShift args
1238−mkExp (SOp LB16LShr args) = return $ mkBinOpExp shortType RRShift args
1378+mkExp (SOp LB16LShr args) = mkBinOpExp shortType RRShift args
1239−mkExp (SOp LB16AShr args) = return $ mkBinOpExp shortType RShift args
1379+mkExp (SOp LB16AShr args) = mkBinOpExp shortType RShift args
1240−mkExp (SOp LB16And args) = return $ mkBinOpExp shortType And args
1380+mkExp (SOp LB16And args) = mkBinOpExp shortType And args
1241−mkExp (SOp LB16Or args) = return $ mkBinOpExp shortType Or args
1381+mkExp (SOp LB16Or args) = mkBinOpExp shortType Or args
1242−mkExp (SOp LB16Xor args) = return $ mkBinOpExp shortType Xor args
1382+mkExp (SOp LB16Xor args) = mkBinOpExp shortType Xor args
1243mkExp (SOp LB16Compl [var]) =
1383mkExp (SOp LB16Compl [var]) =
1244− return $ PreBitCompl (mkVarAccess (Just $ shortType) var)
1384+ PreBitCompl <$> mkVarAccess (Just $ shortType) var
1245−mkExp (SOp LB16Z32 [var]) = return $ mkZeroExt "intValue" 16 shortType integerType var
1385+mkExp (SOp LB16Z32 [var]) = mkZeroExt "intValue" 16 shortType integerType var
1246−mkExp (SOp LB16Z64 [var]) = return $ mkZeroExt "longValue" 16 shortType longType var
1386+mkExp (SOp LB16Z64 [var]) = mkZeroExt "longValue" 16 shortType longType var
1247−mkExp (SOp LB16S32 [var]) = return $ mkSignedExt "intValue" shortType integerType var
1387+mkExp (SOp LB16S32 [var]) = mkSignedExt "intValue" shortType integerType var
1248−mkExp (SOp LB16S64 [var]) = return $ mkSignedExt "longValue" shortType longType var
1388+mkExp (SOp LB16S64 [var]) = mkSignedExt "longValue" shortType longType var
1249mkExp (SOp LB16T8 [var]) =
1389mkExp (SOp LB16T8 [var]) =
1250− return . MethodInv $
1390+ (\ var -> MethodInv $
1251− TypeMethodCall (J.Name [Ident "Byte"])
1391+ TypeMethodCall (J.Name [Ident "Byte"])
1253− (Ident "valueOf")
1393+ (Ident "valueOf")
1395+ $ PrimaryMethodCall var [] (Ident "byteValue") [] ]
1254− [ MethodInv $ PrimaryMethodCall (mkVarAccess (Just $ shortType) var) [] (Ident "byteValue") [] ]
1397+ <$> mkVarAccess (Just $ shortType) var
1255−mkExp (SOp LB32Lt args) = return $ mkLogicalBinOpExp integerType LThan args
1398+mkExp (SOp LB32Lt args) = mkLogicalBinOpExp integerType LThan args
1256−mkExp (SOp LB32Lte args) = return $ mkLogicalBinOpExp integerType LThanE args
1399+mkExp (SOp LB32Lte args) = mkLogicalBinOpExp integerType LThanE args
1257mkExp (SOp LB32Eq args) =
1400mkExp (SOp LB32Eq args) =
1258− return $ mkMethodOpChain1 (mkBoolToNumber integerType) integerType "equals" args
1401+ mkMethodOpChain1 (mkBoolToNumber integerType) integerType "equals" args
1259−mkExp (SOp LB32Gt args) = return $ mkLogicalBinOpExp integerType GThan args
1402+mkExp (SOp LB32Gt args) = mkLogicalBinOpExp integerType GThan args
1260−mkExp (SOp LB32Gte args) = return $ mkLogicalBinOpExp integerType GThanE args
1403+mkExp (SOp LB32Gte args) = mkLogicalBinOpExp integerType GThanE args
1261−mkExp (SOp LB32Plus args) = return $ mkBinOpExp integerType Add args
1404+mkExp (SOp LB32Plus args) = mkBinOpExp integerType Add args
1262−mkExp (SOp LB32Minus args) = return $ mkBinOpExp integerType Sub args
1405+mkExp (SOp LB32Minus args) = mkBinOpExp integerType Sub args
1263−mkExp (SOp LB32Times args) = return $ mkBinOpExp integerType Mult args
1406+mkExp (SOp LB32Times args) = mkBinOpExp integerType Mult args
1264−mkExp (SOp LB32UDiv args) = return $ mkBinOpExpConv "longValue" LongT integerType Div args
1407+mkExp (SOp LB32UDiv args) = mkBinOpExpConv "longValue" LongT integerType Div args
1265−mkExp (SOp LB32SDiv args) = return $ mkBinOpExp integerType Div args
1408+mkExp (SOp LB32SDiv args) = mkBinOpExp integerType Div args
1266−mkExp (SOp LB32URem args) = return $ mkBinOpExpConv "longValue" LongT integerType Rem args
1409+mkExp (SOp LB32URem args) = mkBinOpExpConv "longValue" LongT integerType Rem args
1267−mkExp (SOp LB32SRem args) = return $ mkBinOpExp integerType Rem args
1410+mkExp (SOp LB32SRem args) = mkBinOpExp integerType Rem args
1268−mkExp (SOp LB32Shl args) = return $ mkBinOpExp integerType LShift args
1411+mkExp (SOp LB32Shl args) = mkBinOpExp integerType LShift args
1269−mkExp (SOp LB32LShr args) = return $ mkBinOpExp integerType RRShift args
1412+mkExp (SOp LB32LShr args) = mkBinOpExp integerType RRShift args
1270−mkExp (SOp LB32AShr args) = return $ mkBinOpExp integerType RShift args
1413+mkExp (SOp LB32AShr args) = mkBinOpExp integerType RShift args
1271−mkExp (SOp LB32And args) = return $ mkBinOpExp integerType And args
1414+mkExp (SOp LB32And args) = mkBinOpExp integerType And args
1272−mkExp (SOp LB32Or args) = return $ mkBinOpExp integerType Or args
1415+mkExp (SOp LB32Or args) = mkBinOpExp integerType Or args
1273−mkExp (SOp LB32Xor args) = return $ mkBinOpExp integerType Xor args
1416+mkExp (SOp LB32Xor args) = mkBinOpExp integerType Xor args
1274mkExp (SOp LB32Compl [var]) =
1417mkExp (SOp LB32Compl [var]) =
1275− return $ PreBitCompl (mkVarAccess (Just $ integerType) var)
1418+ PreBitCompl <$> mkVarAccess (Just $ integerType) var
1276−mkExp (SOp LB32Z64 [var]) = return $ mkZeroExt "longValue" 32 integerType longType var
1419+mkExp (SOp LB32Z64 [var]) = mkZeroExt "longValue" 32 integerType longType var
1277−mkExp (SOp LB32S64 [var]) = return $ mkSignedExt "longValue" integerType longType var
1420+mkExp (SOp LB32S64 [var]) = mkSignedExt "longValue" integerType longType var
1278mkExp (SOp LB32T8 [var]) =
1421mkExp (SOp LB32T8 [var]) =
1279− return . MethodInv $
1422+ (\ var -> MethodInv
1280− TypeMethodCall (J.Name [Ident "Byte"])
1423+ $ TypeMethodCall (J.Name [Ident "Byte"])
1282− (Ident "valueOf")
1425+ (Ident "valueOf")
1426+ [ MethodInv $ PrimaryMethodCall var [] (Ident "byteValue") [] ]
1283− [ MethodInv $ PrimaryMethodCall (mkVarAccess (Just $ integerType) var) [] (Ident "byteValue") [] ]
1428+ <$> mkVarAccess (Just $ integerType) var
1284mkExp (SOp LB32T16 [var]) =
1429mkExp (SOp LB32T16 [var]) =
1285− return . MethodInv $
1430+ (\ var -> MethodInv
1286− TypeMethodCall (J.Name [Ident "Short"])
1431+ $ TypeMethodCall (J.Name [Ident "Short"])
1288− (Ident "valueOf")
1433+ (Ident "valueOf")
1434+ [ MethodInv $ PrimaryMethodCall var [] (Ident "shortValue") [] ]
1289− [ MethodInv $ PrimaryMethodCall (mkVarAccess (Just $ integerType) var) [] (Ident "shortValue") [] ]
1436+ <$> mkVarAccess (Just $ integerType) var
1290−mkExp (SOp LB64Lt args) = return $ mkLogicalBinOpExp longType LThan args
1437+mkExp (SOp LB64Lt args) = mkLogicalBinOpExp longType LThan args
1291−mkExp (SOp LB64Lte args) = return $ mkLogicalBinOpExp longType LThanE args
1438+mkExp (SOp LB64Lte args) = mkLogicalBinOpExp longType LThanE args
1292mkExp (SOp LB64Eq args) =
1439mkExp (SOp LB64Eq args) =
1293− return $ mkMethodOpChain1 (mkBoolToNumber longType) longType "equals" args
1440+ mkMethodOpChain1 (mkBoolToNumber longType) longType "equals" args
1294−mkExp (SOp LB64Gt args) = return $ mkLogicalBinOpExp longType GThan args
1441+mkExp (SOp LB64Gt args) = mkLogicalBinOpExp longType GThan args
1295−mkExp (SOp LB64Gte args) = return $ mkLogicalBinOpExp longType GThanE args
1442+mkExp (SOp LB64Gte args) = mkLogicalBinOpExp longType GThanE args
1296−mkExp (SOp LB64Plus args) = return $ mkBinOpExp longType Add args
1443+mkExp (SOp LB64Plus args) = mkBinOpExp longType Add args
1297−mkExp (SOp LB64Minus args) = return $ mkBinOpExp longType Sub args
1444+mkExp (SOp LB64Minus args) = mkBinOpExp longType Sub args
1298−mkExp (SOp LB64Times args) = return $ mkBinOpExp longType Mult args
1445+mkExp (SOp LB64Times args) = mkBinOpExp longType Mult args
1299−mkExp (SOp LB64UDiv (arg:args)) =
1446+mkExp (SOp LB64UDiv (arg:args)) = do
1447+ (arg:args) <- mapM (mkVarAccess (Just longType)) (arg:args)
1300 return $ foldl (\ exp arg ->
1448 return $ foldl (\ exp arg ->
1301 MethodInv $ PrimaryMethodCall
1449 MethodInv $ PrimaryMethodCall
1302 ( MethodInv $ PrimaryMethodCall
1450 ( MethodInv $ PrimaryMethodCall
@@ -1310,17 +1458,18 @@ mkExp (SOp LB64UDiv (arg:args)) =
1310 [ MethodInv $ TypeMethodCall (J.Name [Ident "BigInteger"])
1458 [ MethodInv $ TypeMethodCall (J.Name [Ident "BigInteger"])
1312 (Ident "valueOf")
1460 (Ident "valueOf")
1313− [ (mkVarAccess (Just longType) arg) ]
1461+ [ arg ]
1317 (Ident "longValue")
1465 (Ident "longValue")
1320− (mkVarAccess (Just longType) arg)
1468+ arg
1322−mkExp (SOp LB64SDiv args) = return $ mkBinOpExp longType Div args
1470+mkExp (SOp LB64SDiv args) = mkBinOpExp longType Div args
1323−mkExp (SOp LB64URem (arg:args)) =
1471+mkExp (SOp LB64URem (arg:args)) = do
1472+ (arg:args) <- mapM (mkVarAccess (Just longType)) (arg:args)
1324 return $ foldl (\ exp arg ->
1473 return $ foldl (\ exp arg ->
1325 MethodInv $ PrimaryMethodCall
1474 MethodInv $ PrimaryMethodCall
1326 ( MethodInv $ PrimaryMethodCall
1475 ( MethodInv $ PrimaryMethodCall
@@ -1334,69 +1483,79 @@ mkExp (SOp LB64URem (arg:args)) =
1334 [ MethodInv $ TypeMethodCall (J.Name [Ident "BigInteger"])
1483 [ MethodInv $ TypeMethodCall (J.Name [Ident "BigInteger"])
1336 (Ident "valueOf")
1485 (Ident "valueOf")
1337− [ (mkVarAccess (Just longType) arg) ]
1486+ [ arg ]
1341 (Ident "longValue")
1490 (Ident "longValue")
1344− (mkVarAccess (Just longType) arg)
1493+ arg
1346−mkExp (SOp LB64SRem args) = return $ mkBinOpExp longType Rem args
1495+mkExp (SOp LB64SRem args) = mkBinOpExp longType Rem args
1347−mkExp (SOp LB64Shl args) = return $ mkBinOpExp longType LShift args
1496+mkExp (SOp LB64Shl args) = mkBinOpExp longType LShift args
1348−mkExp (SOp LB64LShr args) = return $ mkBinOpExp longType RRShift args
1497+mkExp (SOp LB64LShr args) = mkBinOpExp longType RRShift args
1349−mkExp (SOp LB64AShr args) = return $ mkBinOpExp longType RShift args
1498+mkExp (SOp LB64AShr args) = mkBinOpExp longType RShift args
1350−mkExp (SOp LB64And args) = return $ mkBinOpExp longType And args
1499+mkExp (SOp LB64And args) = mkBinOpExp longType And args
1351−mkExp (SOp LB64Or args) = return $ mkBinOpExp longType Or args
1500+mkExp (SOp LB64Or args) = mkBinOpExp longType Or args
1352−mkExp (SOp LB64Xor args) = return $ mkBinOpExp longType Xor args
1501+mkExp (SOp LB64Xor args) = mkBinOpExp longType Xor args
1353mkExp (SOp LB64Compl [var]) =
1502mkExp (SOp LB64Compl [var]) =
1354− return $ PreBitCompl (mkVarAccess (Just $ longType) var)
1503+ PreBitCompl <$> mkVarAccess (Just $ longType) var
1355mkExp (SOp LB64T8 [var]) =
1504mkExp (SOp LB64T8 [var]) =
1356− return . MethodInv $
1505+ (\ var -> MethodInv
1357− TypeMethodCall (J.Name [Ident "Byte"])
1506+ $ TypeMethodCall (J.Name [Ident "Byte"])
1359− (Ident "valueOf")
1508+ (Ident "valueOf")
1510+ $ PrimaryMethodCall var [] (Ident "byteValue") []
1360− [ MethodInv $ PrimaryMethodCall (mkVarAccess (Just $ longType) var) [] (Ident "byteValue") [] ]
1513+ <$> mkVarAccess (Just $ longType) var
1361mkExp (SOp LB64T16 [var]) =
1514mkExp (SOp LB64T16 [var]) =
1362− return . MethodInv $
1515+ (\ var -> MethodInv
1363− TypeMethodCall (J.Name [Ident "Short"])
1516+ $ TypeMethodCall (J.Name [Ident "Short"])
1365− (Ident "valueOf")
1518+ (Ident "valueOf")
1519+ [ MethodInv $ PrimaryMethodCall var [] (Ident "shortValue") [] ]
1366− [ MethodInv $ PrimaryMethodCall (mkVarAccess (Just $ longType) var) [] (Ident "shortValue") [] ]
1521+ <$> mkVarAccess (Just $ longType) var
1367mkExp (SOp LB64T32 [var]) =
1522mkExp (SOp LB64T32 [var]) =
1368− return . MethodInv $
1523+ (\ var -> MethodInv
1369− TypeMethodCall (J.Name [Ident "Integer"])
1524+ $ TypeMethodCall (J.Name [Ident "Integer"])
1371− (Ident "valueOf")
1526+ (Ident "valueOf")
1527+ [ MethodInv $ PrimaryMethodCall var [] (Ident "intValue") [] ]
1372− [ MethodInv $ PrimaryMethodCall (mkVarAccess (Just $ longType) var) [] (Ident "intValue") [] ]
1529+ <$> mkVarAccess (Just $ longType) var
1373mkExp (SOp LIntB8 [arg]) = mkExp (SOp LB32T8 [arg])
1530mkExp (SOp LIntB8 [arg]) = mkExp (SOp LB32T8 [arg])
1374mkExp (SOp LIntB16 [arg]) = mkExp (SOp LB32T16 [arg])
1531mkExp (SOp LIntB16 [arg]) = mkExp (SOp LB32T16 [arg])
1375mkExp (SOp LIntB32 [arg]) = mkExp (SV arg)
1532mkExp (SOp LIntB32 [arg]) = mkExp (SV arg)
1376mkExp (SOp LIntB64 [arg]) = mkExp (SOp LB32S64 [arg])
1533mkExp (SOp LIntB64 [arg]) = mkExp (SOp LB32S64 [arg])
1377mkExp (SOp LB32Int [arg]) = mkExp (SV arg)
1534mkExp (SOp LB32Int [arg]) = mkExp (SV arg)
1378−mkExp (SOp LFExp [arg]) = return $ mkMathFun "exp" arg
1535+mkExp (SOp LFExp [arg]) = mkMathFun "exp" arg
1379−mkExp (SOp LFLog [arg]) = return $ mkMathFun "log" arg
1536+mkExp (SOp LFLog [arg]) = mkMathFun "log" arg
1380−mkExp (SOp LFSin [arg]) = return $ mkMathFun "sin" arg
1537+mkExp (SOp LFSin [arg]) = mkMathFun "sin" arg
1381−mkExp (SOp LFCos [arg]) = return $ mkMathFun "cos" arg
1538+mkExp (SOp LFCos [arg]) = mkMathFun "cos" arg
1382−mkExp (SOp LFTan [arg]) = return $ mkMathFun "tan" arg
1539+mkExp (SOp LFTan [arg]) = mkMathFun "tan" arg
1383−mkExp (SOp LFASin [arg]) = return $ mkMathFun "asin" arg
1540+mkExp (SOp LFASin [arg]) = mkMathFun "asin" arg
1384−mkExp (SOp LFACos [arg]) = return $ mkMathFun "acos" arg
1541+mkExp (SOp LFACos [arg]) = mkMathFun "acos" arg
1385−mkExp (SOp LFATan [arg]) = return $ mkMathFun "atan" arg
1542+mkExp (SOp LFATan [arg]) = mkMathFun "atan" arg
1386−mkExp (SOp LFSqrt [arg]) = return $ mkMathFun "sqrt" arg
1543+mkExp (SOp LFSqrt [arg]) = mkMathFun "sqrt" arg
1387−mkExp (SOp LFFloor [arg]) = return $ mkMathFun "floor" arg
1544+mkExp (SOp LFFloor [arg]) = mkMathFun "floor" arg
1388−mkExp (SOp LFCeil [arg]) = return $ mkMathFun "ceil" arg
1545+mkExp (SOp LFCeil [arg]) = mkMathFun "ceil" arg
1389−mkExp (SOp LStrHead [arg]) = return $ mkStringAtIndex arg (Lit $ Int 0)
1546+mkExp (SOp LStrHead [arg]) = mkStringAtIndex arg (Lit $ Int 0)
1390mkExp (SOp LStrTail [arg]) =
1547mkExp (SOp LStrTail [arg]) =
1391− return . MethodInv $ PrimaryMethodCall (mkVarAccess (Just stringType) arg)
1548+ (\ var -> MethodInv $ PrimaryMethodCall (var)
1393 (Ident "substring")
1550 (Ident "substring")
1394 [Lit $ Int 1]
1551 [Lit $ Int 1]
1553+ <$> mkVarAccess (Just stringType) arg
1395mkExp (SOp LStrCons [c, cs]) =
1554mkExp (SOp LStrCons [c, cs]) =
1396− return . MethodInv $
1555+ (\ cVar csVar -> MethodInv $
1397 PrimaryMethodCall ( MethodInv $ PrimaryMethodCall (InstanceCreation []
1556 PrimaryMethodCall ( MethodInv $ PrimaryMethodCall (InstanceCreation []
1398 (ClassType [(Ident "StringBuilder", [])])
1557 (ClassType [(Ident "StringBuilder", [])])
1399− [mkVarAccess (Just stringType) cs]
1558+ [csVar]
@@ -1404,7 +1563,7 @@ mkExp (SOp LStrCons [c, cs]) =
1404 [ Lit $ Int 0,
1563 [ Lit $ Int 0,
1405 Cast (PrimType CharT)
1564 Cast (PrimType CharT)
1406 (MethodInv $ PrimaryMethodCall
1565 (MethodInv $ PrimaryMethodCall
1407− (mkVarAccess (Just integerType) c)
1566+ (cVar)
1409 (Ident "intValue")
1568 (Ident "intValue")
@@ -1414,12 +1573,15 @@ mkExp (SOp LStrCons [c, cs]) =
1415 (Ident "toString")
1574 (Ident "toString")
1577+ <$> mkVarAccess (Just integerType) c
1578+ <*> mkVarAccess (Just stringType) cs
1417−mkExp (SOp LStrIndex [str, i]) = return $ mkStringAtIndex str (mkVarAccess (Just integerType) i)
1579+mkExp (SOp LStrIndex [str, i]) = mkVarAccess (Just integerType) i >>= mkStringAtIndex str
1418mkExp (SOp LStrRev [str]) =
1580mkExp (SOp LStrRev [str]) =
1419− return . MethodInv $
1581+ (\ var -> MethodInv $
1420 PrimaryMethodCall ( MethodInv $ PrimaryMethodCall (InstanceCreation []
1582 PrimaryMethodCall ( MethodInv $ PrimaryMethodCall (InstanceCreation []
1421 (ClassType [(Ident "StringBuffer", [])])
1583 (ClassType [(Ident "StringBuffer", [])])
1422− [mkVarAccess (Just stringType) str]
1584+ [var]
@@ -1429,13 +1591,15 @@ mkExp (SOp LStrRev [str]) =
1430 (Ident "toString")
1592 (Ident "toString")
1595+ <$> mkVarAccess (Just stringType) str
1432mkExp (SOp LStdIn []) = return $ mkSystemStd In
1596mkExp (SOp LStdIn []) = return $ mkSystemStd In
1433mkExp (SOp LStdOut []) = return $ mkSystemStd Out
1597mkExp (SOp LStdOut []) = return $ mkSystemStd Out
1434mkExp (SOp LStdErr []) = return $ mkSystemStd Err
1598mkExp (SOp LStdErr []) = return $ mkSystemStd Err
1435mkExp (SOp LFork [arg]) = mkThread arg
1599mkExp (SOp LFork [arg]) = mkThread arg
1436mkExp (SOp LPar [arg]) = mkExp (SV arg)
1600mkExp (SOp LPar [arg]) = mkExp (SV arg)
1437mkExp (SOp LVMPtr []) =
1601mkExp (SOp LVMPtr []) =
1438− return . MethodInv $ TypeMethodCall (J.Name [Ident "Thread"]) [] (Ident "currentThread") []
1602+ return $ MethodInv $ TypeMethodCall (J.Name [Ident "Thread"]) [] (Ident "currentThread") []
1439mkExp (SOp LNoOp args) = mkExp . SV $ last args
1603mkExp (SOp LNoOp args) = mkExp . SV $ last args
1440mkExp (SNothing) = return $ Lit Null
1604mkExp (SNothing) = return $ Lit Null
1441mkExp (SError err) =
1605mkExp (SError err) =