on master help sign in
Merge branch 'JavaBuffers' into JavaBackendFixes

Conflicts: src/IRTS/CodegenJava.hs

commit822690a8625affe8b1fda86e53d47d029f5d1034 authorJan Bessai <Jan.Bessai@tu-dortmund.de> dateMon 14 Apr 2014, 12:51 (13 years ago) parent7c2c0103c58bbf
3 files changed+41−2
src/IRTS/CodegenJava.hs+4−1 src/IRTS/Java/JTypes.hs+31−1 src/IRTS/Java/Pom.hs+6
src/IRTS/CodegenJava.hs+4−1
@@ -312,6 +312,7 @@ mkCompilationUnit globalInit defs hdrs out = do
312312 , ImportDecl True idrisPrelude True
313313 , ImportDecl False bigInteger False
314314 , ImportDecl False runtimeException False
315+ , ImportDecl False byteBuffer False
315316 ] ++ otherHdrs
316317 )
317318 <$> mkTypeDecl clsName globalInit defs
@@ -320,6 +321,7 @@ mkCompilationUnit globalInit defs hdrs out = do
320321 idrisPrelude = J.Name $ map Ident ["org", "idris", "rts", "Prelude"]
321322 bigInteger = J.Name $ map Ident ["java", "math", "BigInteger"]
322323 runtimeException = J.Name $ map Ident ["java", "lang", "RuntimeException"]
324+ byteBuffer = J.Name $ map Ident ["java", "nio", "ByteBuffer"]
323325 otherHdrs = map ( (\ name -> ImportDecl False name False)
324326 . J.Name
325327 . map (Ident . T.unpack)
@@ -707,6 +709,7 @@ mkConstant c@(AType x) = ClassLit (Just $ box (constType c))
707709mkConstant c@(StrType ) = ClassLit (Just $ stringType)
708710mkConstant c@(PtrType ) = ClassLit (Just $ objectType)
709711mkConstant c@(ManagedPtrType) = ClassLit (Just $ objectType)
712+mkConstant c@(BufferType) = ClassLit (Just $ bufferType)
710713mkConstant c@(VoidType ) = ClassLit (Just $ voidType)
711714mkConstant c@(Forgot ) = ClassLit (Just $ objectType)
712715
@@ -744,7 +747,7 @@ mkForeign pp (LANG_JAVA callType) resTy text params
744747
745748mkPrimitiveFunction :: PrimFn -> [LVar] -> CodeGeneration Exp
746749mkPrimitiveFunction op args =
747− (\ args -> (primFnType ~> opName op) args)
750+ (\ args -> (primFnType ~> opName op) (endiannessArguments op ++ args))
748751 <$> sequence (zipWith (\ a t -> (Just t) <>@! a) args (sourceTypes op))
749752
750753mkThread :: LVar -> CodeGeneration Exp
src/IRTS/Java/JTypes.hs+31−1
@@ -33,6 +33,9 @@ doubleType = PrimType DoubleT
3333array :: J.Type -> J.Type
3434array t = RefType . ArrayType $ t
3535
36+addressType :: J.Type
37+addressType = longType
38+
3639-----------------------------------------------------------------------
3740-- Boxed types
3841
@@ -48,6 +51,10 @@ stringType :: J.Type
4851stringType =
4952 RefType . ClassRefType $ ClassType [(Ident "String", [])]
5053
54+bufferType :: J.Type
55+bufferType =
56+ RefType . ClassRefType $ ClassType [(Ident "ByteBuffer", [])]
57+
5158threadType :: J.Type
5259threadType =
5360 RefType . ClassRefType $ ClassType [(Ident "Thread", [])]
@@ -132,6 +139,9 @@ runtimeExceptionType :: J.Type
132139runtimeExceptionType =
133140 RefType . ClassRefType $ ClassType [(Ident "RuntimeException", [])]
134141
142+-----------------------------------------------------------------------
143+-- Integer types
144+
135145nativeTyToJType :: NativeTy -> J.Type
136146nativeTyToJType IT8 = byteType
137147nativeTyToJType IT16 = shortType
@@ -219,6 +229,7 @@ opName x
219229 | (LFloatInt to) <- x = "LFloatInt" ++ (suffixFor to)
220230 | (LStrInt to) <- x = "LStrInt" ++ (suffixFor to)
221231 | (LChInt to) <- x = "LChInt" ++ (suffixFor to)
232+ | (LPeek to _) <- x = "LPeek" ++ (suffixFor to)
222233 | otherwise = takeWhile ((/=) ' ') $ show x
223234 where
224235 suffixFor (ITFixed nt) = show nt
@@ -291,10 +302,29 @@ sourceTypes (LStrRev) = [stringType]
291302sourceTypes (LStdIn) = []
292303sourceTypes (LStdOut) = []
293304sourceTypes (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]
294310sourceTypes (LFork) = [objectType]
295311sourceTypes (LPar) = [objectType]
296312sourceTypes (LVMPtr) = []
297313sourceTypes (LNullPtr) = [objectType]
298314sourceTypes (LNoOp) = repeat objectType
299315
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
33import Data.List (unfoldr)
44import Text.XML.Light
55
6+-----------------------------------------------------------------------
7+-- String <-> XML processing
8+
69uattr :: String -> String -> Attr
710uattr k v = Attr (QName k Nothing Nothing) v
811
@@ -31,6 +34,9 @@ groupArtifactVersion g a v = [
3134pomString :: String -> String -> [String] -> String
3235pomString c a d = ppElement $ pom c a d
3336
37+-----------------------------------------------------------------------
38+-- The pom template for idris projects
39+
3440pom :: String -> String -> [String] -> Element
3541pom clsName artifactName dependencies = unode "project" ([
3642 uattr "xmlns" "http://maven.apache.org/POM/4.0.0",