on master help sign in
Merge branch 'JavaBuffers' into JavaBackendFixes
822690aJan Bessai
src/IRTS/CodegenJava.hs+4−1
@@ -312,6 +312,7 @@ mkCompilationUnit globalInit defs hdrs out = do
312 , ImportDecl True idrisPrelude True
312 , ImportDecl True idrisPrelude True
313 , ImportDecl False bigInteger False
313 , ImportDecl False bigInteger False
314 , ImportDecl False runtimeException False
314 , ImportDecl False runtimeException False
315+ , ImportDecl False byteBuffer False
315 ] ++ otherHdrs
316 ] ++ otherHdrs
316 )
317 )
317 <$> mkTypeDecl clsName globalInit defs
318 <$> mkTypeDecl clsName globalInit defs
@@ -320,6 +321,7 @@ mkCompilationUnit globalInit defs hdrs out = do
320 idrisPrelude = J.Name $ map Ident ["org", "idris", "rts", "Prelude"]
321 idrisPrelude = J.Name $ map Ident ["org", "idris", "rts", "Prelude"]
321 bigInteger = J.Name $ map Ident ["java", "math", "BigInteger"]
322 bigInteger = J.Name $ map Ident ["java", "math", "BigInteger"]
322 runtimeException = J.Name $ map Ident ["java", "lang", "RuntimeException"]
323 runtimeException = J.Name $ map Ident ["java", "lang", "RuntimeException"]
324+ byteBuffer = J.Name $ map Ident ["java", "nio", "ByteBuffer"]
323 otherHdrs = map ( (\ name -> ImportDecl False name False)
325 otherHdrs = map ( (\ name -> ImportDecl False name False)
324 . J.Name
326 . J.Name
325 . map (Ident . T.unpack)
327 . map (Ident . T.unpack)
@@ -707,6 +709,7 @@ mkConstant c@(AType x) = ClassLit (Just $ box (constType c))
707mkConstant c@(StrType ) = ClassLit (Just $ stringType)
709mkConstant c@(StrType ) = ClassLit (Just $ stringType)
708mkConstant c@(PtrType ) = ClassLit (Just $ objectType)
710mkConstant c@(PtrType ) = ClassLit (Just $ objectType)
709mkConstant c@(ManagedPtrType) = ClassLit (Just $ objectType)
711mkConstant c@(ManagedPtrType) = ClassLit (Just $ objectType)
712+mkConstant c@(BufferType) = ClassLit (Just $ bufferType)
710mkConstant c@(VoidType ) = ClassLit (Just $ voidType)
713mkConstant c@(VoidType ) = ClassLit (Just $ voidType)
711mkConstant c@(Forgot ) = ClassLit (Just $ objectType)
714mkConstant c@(Forgot ) = ClassLit (Just $ objectType)
712
715
@@ -744,7 +747,7 @@ mkForeign pp (LANG_JAVA callType) resTy text params
744
747
745mkPrimitiveFunction :: PrimFn -> [LVar] -> CodeGeneration Exp
748mkPrimitiveFunction :: PrimFn -> [LVar] -> CodeGeneration Exp
746mkPrimitiveFunction op args =
749mkPrimitiveFunction op args =
747− (\ args -> (primFnType ~> opName op) args)
750+ (\ args -> (primFnType ~> opName op) (endiannessArguments op ++ args))
748 <$> sequence (zipWith (\ a t -> (Just t) <>@! a) args (sourceTypes op))
751 <$> sequence (zipWith (\ a t -> (Just t) <>@! a) args (sourceTypes op))
749
752
750mkThread :: LVar -> CodeGeneration Exp
753mkThread :: LVar -> CodeGeneration Exp
src/IRTS/Java/JTypes.hs+31−1
@@ -33,6 +33,9 @@ doubleType = PrimType DoubleT
33array :: J.Type -> J.Type
33array :: J.Type -> J.Type
34array t = RefType . ArrayType $ t
34array t = RefType . ArrayType $ t
35
35
36+addressType :: J.Type
37+addressType = longType
38+
36-----------------------------------------------------------------------
39-----------------------------------------------------------------------
37-- Boxed types
40-- Boxed types
38
41
@@ -48,6 +51,10 @@ stringType :: J.Type
48stringType =
51stringType =
49 RefType . ClassRefType $ ClassType [(Ident "String", [])]
52 RefType . ClassRefType $ ClassType [(Ident "String", [])]
50
53
54+bufferType :: J.Type
55+bufferType =
56+ RefType . ClassRefType $ ClassType [(Ident "ByteBuffer", [])]
57+
51threadType :: J.Type
58threadType :: J.Type
52threadType =
59threadType =
53 RefType . ClassRefType $ ClassType [(Ident "Thread", [])]
60 RefType . ClassRefType $ ClassType [(Ident "Thread", [])]
@@ -132,6 +139,9 @@ runtimeExceptionType :: J.Type
132runtimeExceptionType =
139runtimeExceptionType =
133 RefType . ClassRefType $ ClassType [(Ident "RuntimeException", [])]
140 RefType . ClassRefType $ ClassType [(Ident "RuntimeException", [])]
134
141
142+-----------------------------------------------------------------------
143+-- Integer types
144+
135nativeTyToJType :: NativeTy -> J.Type
145nativeTyToJType :: NativeTy -> J.Type
136nativeTyToJType IT8 = byteType
146nativeTyToJType IT8 = byteType
137nativeTyToJType IT16 = shortType
147nativeTyToJType IT16 = shortType
@@ -219,6 +229,7 @@ opName x
219 | (LFloatInt to) <- x = "LFloatInt" ++ (suffixFor to)
229 | (LFloatInt to) <- x = "LFloatInt" ++ (suffixFor to)
220 | (LStrInt to) <- x = "LStrInt" ++ (suffixFor to)
230 | (LStrInt to) <- x = "LStrInt" ++ (suffixFor to)
221 | (LChInt to) <- x = "LChInt" ++ (suffixFor to)
231 | (LChInt to) <- x = "LChInt" ++ (suffixFor to)
232+ | (LPeek to _) <- x = "LPeek" ++ (suffixFor to)
222 | otherwise = takeWhile ((/=) ' ') $ show x
233 | otherwise = takeWhile ((/=) ' ') $ show x
223 where
234 where
224 suffixFor (ITFixed nt) = show nt
235 suffixFor (ITFixed nt) = show nt
@@ -291,10 +302,29 @@ sourceTypes (LStrRev) = [stringType]
291sourceTypes (LStdIn) = []
302sourceTypes (LStdIn) = []
292sourceTypes (LStdOut) = []
303sourceTypes (LStdOut) = []
293sourceTypes (LStdErr) = []
304sourceTypes (LStdErr) = []
305+sourceTypes (LAllocate) = [addressType]
306+sourceTypes (LAppendBuffer) =
307+ [bufferType, addressType, addressType, addressType, addressType, bufferType]
308+sourceTypes (LAppend nt _) = [bufferType, intTyToJType nt, addressType]
309+sourceTypes (LPeek _ _) = [bufferType, addressType]
294sourceTypes (LFork) = [objectType]
310sourceTypes (LFork) = [objectType]
295sourceTypes (LPar) = [objectType]
311sourceTypes (LPar) = [objectType]
296sourceTypes (LVMPtr) = []
312sourceTypes (LVMPtr) = []
297sourceTypes (LNullPtr) = [objectType]
313sourceTypes (LNullPtr) = [objectType]
298sourceTypes (LNoOp) = repeat objectType
314sourceTypes (LNoOp) = repeat objectType
299
315
300−
316+-----------------------------------------------------------------------
317+-- Endianess markers
318+
319+endiannessConstant :: Endianness -> Exp
320+endiannessConstant c =
321+ ExpName . Name . map Ident $ ["java", "nio", "ByteOrder", endiannessConstant' c]
322+ where
323+ endiannessConstant' BE = "BIG_ENDIAN"
324+ endiannessConstant' LE = "LITTLE_ENDIAN"
325+ endiannessConstant' (IRTS.Lang.Native) = endiannessConstant' BE
326+
327+endiannessArguments :: PrimFn -> [Exp]
328+endiannessArguments (LAppend _ end) = [endiannessConstant end]
329+endiannessArguments (LPeek _ end) = [endiannessConstant end]
330+endiannessArguments _ = []
src/IRTS/Java/Pom.hs+6
@@ -3,6 +3,9 @@ module IRTS.Java.Pom (pomString) where
3import Data.List (unfoldr)
3import Data.List (unfoldr)
4import Text.XML.Light
4import Text.XML.Light
5
5
6+-----------------------------------------------------------------------
7+-- String <-> XML processing
8+
6uattr :: String -> String -> Attr
9uattr :: String -> String -> Attr
7uattr k v = Attr (QName k Nothing Nothing) v
10uattr k v = Attr (QName k Nothing Nothing) v
8
11
@@ -31,6 +34,9 @@ groupArtifactVersion g a v = [
31pomString :: String -> String -> [String] -> String
34pomString :: String -> String -> [String] -> String
32pomString c a d = ppElement $ pom c a d
35pomString c a d = ppElement $ pom c a d
33
36
37+-----------------------------------------------------------------------
38+-- The pom template for idris projects
39+
34pom :: String -> String -> [String] -> Element
40pom :: String -> String -> [String] -> Element
35pom clsName artifactName dependencies = unode "project" ([
41pom clsName artifactName dependencies = unode "project" ([
36 uattr "xmlns" "http://maven.apache.org/POM/4.0.0",
42 uattr "xmlns" "http://maven.apache.org/POM/4.0.0",