on master help sign in
Merge branch 'master' of github.com:edwinb/Idris-dev
commit3ebab66b65941a6a2a160189e577e180d550c9ef authorEdwin Brady <ecb10@st-andrews.ac.uk> dateThu 7 Nov 2013, 18:51 (13 years ago) parent9836a07db0c021
16 files changed+143−106
CONTRIBUTORS+1 idris.cabal+2−1 java/executable_pom.xml−66 lib/Builtins.idr+3 src/IRTS/CodegenC.hs+1 src/IRTS/CodegenJava.hs+7−38 src/IRTS/CodegenJavaScript.hs+3 src/IRTS/Java/JTypes.hs+1 src/IRTS/Java/Pom.hs+89 src/IRTS/Lang.hs+1 src/Idris/Primitives.hs+3−1 test/test033/expected+1 test/test033/run+5 test/test033/test033.c+10 test/test033/test033.h+6 test/test033/test033.idr+10
CONTRIBUTORS+1
@@ -2,6 +2,7 @@ Thanks to the following for their help and contributions:
22
33Ozgur Akgun
44Ahmad Salim Al-Sibahi
5+Edward Chadwick Amsden
56Nicola Botta
67Edwin Brady
78David Raymond Christiansen
idris.cabal+2−1
@@ -57,7 +57,6 @@ Data-files: jsrts/Runtime-browser.js
5757 rts/idris_rts.h
5858 rts/idris_stdfgn.h
5959 rts/libtest.c
60− java/*.xml
6160
6261Extra-source-files:
6362 Makefile
@@ -359,6 +358,7 @@ Executable idris
359358 , IRTS.Java.ASTBuilding
360359 , IRTS.Java.JTypes
361360 , IRTS.Java.Mangling
361+ , IRTS.Java.Pom
362362 , IRTS.LParser
363363 , IRTS.Lang
364364 , IRTS.Simplified
@@ -401,6 +401,7 @@ Executable idris
401401 , vector
402402 , vector-binary-instances
403403 , network
404+ , xml
404405
405406 Extensions: MultiParamTypeClasses
406407 , FunctionalDependencies
java/executable_pom.xmldeleted−66
@@ -1,66 +0,0 @@
1−<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2− xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3− <modelVersion>4.0.0</modelVersion>
4− <groupId>org.idris-lang</groupId>
5− <artifactId>$ARTIFACT-NAME$</artifactId>
6− <packaging>jar</packaging>
7− <version>1.0</version>
8− <name>$ARTIFACT-NAME$</name>
9−
10− <properties>
11− <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
12− <skipTests>true</skipTests>
13− </properties>
14− <dependencies>
15− <dependency>
16− <groupId>org.idris-lang</groupId>
17− <artifactId>idris</artifactId>
18− <version>0.9.10-alpha-2</version>
19− </dependency>
20−$DEPENDENCIES$
21− </dependencies>
22−
23−
24− <build>
25− <finalName>$ARTIFACT-NAME$</finalName>
26− <plugins>
27− <plugin>
28− <groupId>org.apache.maven.plugins</groupId>
29− <artifactId>maven-compiler-plugin</artifactId>
30− <version>3.0</version>
31− <configuration>
32− <source>1.7</source>
33− <target>1.7</target>
34− </configuration>
35− </plugin>
36− <plugin>
37− <groupId>org.apache.maven.plugins</groupId>
38− <artifactId>maven-surefire-plugin</artifactId>
39− <version>2.14</version>
40− <configuration>
41− <skipTests>${skipTests}</skipTests>
42− </configuration>
43− </plugin>
44− <plugin>
45− <groupId>org.apache.maven.plugins</groupId>
46− <artifactId>maven-shade-plugin</artifactId>
47− <version>2.1</version>
48− <executions>
49− <execution>
50− <phase>package</phase>
51− <goals>
52− <goal>shade</goal>
53− </goals>
54− <configuration>
55− <transformers>
56− <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
57− <mainClass>$MAIN-CLASS$</mainClass>
58− </transformer>
59− </transformers>
60− </configuration>
61− </execution>
62− </executions>
63− </plugin>
64− </plugins>
65− </build>
66−</project>
lib/Builtins.idr+3
@@ -369,5 +369,8 @@ strIndex = prim__strIndex
369369reverse : String -> String
370370reverse = prim__strRev
371371
372+null : Ptr
373+null = prim__null
374+
372375}
373376
src/IRTS/CodegenC.hs+1
@@ -446,6 +446,7 @@ doOp v LStdErr [] = v ++ "MKPTR(vm, stderr)"
446446doOp v LFork [x] = v ++ "MKPTR(vm, vmThread(vm, " ++ cname (MN 0 "EVAL") ++ ", " ++ creg x ++ "))"
447447doOp v LPar [x] = v ++ creg x -- "MKPTR(vm, vmThread(vm, " ++ cname (MN 0 "EVAL") ++ ", " ++ creg x ++ "))"
448448doOp v LVMPtr [] = v ++ "MKPTR(vm, vm)"
449+doOp v LNullPtr [] = v ++ "MKPTR(vm, NULL)"
449450doOp v (LChInt ITNative) args = v ++ creg (last args)
450451doOp v (LChInt ITChar) args = doOp v (LChInt ITNative) args
451452doOp v (LIntCh ITNative) args = v ++ creg (last args)
src/IRTS/CodegenJava.hs+7−38
@@ -2,14 +2,13 @@
22module IRTS.CodegenJava (codegenJava) where
33
44import Core.TT hiding (mkApp)
5−import IRTS.BCImp
65import IRTS.CodegenCommon
76import IRTS.Java.ASTBuilding
87import IRTS.Java.JTypes
98import IRTS.Java.Mangling
9+import IRTS.Java.Pom (pomString)
1010import IRTS.Lang
1111import IRTS.Simplified
12−import Paths_idris
1312import Util.System
1413
1514import Control.Applicative hiding (Const)
@@ -18,10 +17,7 @@ import Control.Monad
1817import Control.Monad.Error
1918import qualified Control.Monad.Trans as T
2019import Control.Monad.Trans.State
21−import Data.Int
22−import Data.List (foldl', intercalate, isPrefixOf,
23− isSuffixOf)
24−import Data.Maybe (fromJust)
20+import Data.List (foldl', isSuffixOf)
2521import qualified Data.Text as T
2622import qualified Data.Text.IO as TIO
2723import qualified Data.Vector.Unboxed as V
@@ -104,20 +100,11 @@ generatePom :: FilePath -> -- tgt dir
104100 FilePath -> -- output target
105101 [String] -> -- libs
106102 IO ()
107−generatePom tgtDir out libs = do
108− execPom <- getExecutablePom
109− execPomTemplate <- TIO.readFile execPom
110− let (Ident clsName) = either error id (mkClassName out)
111− let execPom = T.replace (T.pack "$MAIN-CLASS$")
112− (T.pack clsName)
113− (T.replace (T.pack "$ARTIFACT-NAME$")
114− (T.pack $ takeBaseName out)
115− (T.replace (T.pack "$DEPENDENCIES$")
116− (mkPomDependencies libs)
117− execPomTemplate
118− )
119− )
120− TIO.writeFile (pomFileName tgtDir) execPom
103+generatePom tgtDir out libs = writeFile (pomFileName tgtDir) execPom
104+ where
105+ (Ident clsName) = either error id (mkClassName out)
106+ execPom = pomString clsName (takeBaseName out) libs
107+
121108
122109invokeMvn :: FilePath -> String -> IO ()
123110invokeMvn tgtDir command = do
@@ -179,24 +166,6 @@ jarHeader =
179166 ++ "exec \"$java\" $java_args -jar $MYSELF \"$@\""
180167 ++ "exit 1\n"
181168
182−mkPomDependencies :: [String] -> T.Text
183−mkPomDependencies deps =
184− T.concat $ map (T.concat . map (T.append (T.pack " ")) . mkDependency . T.pack) deps
185− where
186− mkDependency s =
187− case T.splitOn (T.pack ":") s of
188− [g, a, v] ->
189− [ T.pack $ "<dependency>\n"
190− , T.append (T.pack " ") $ mkGroupId g
191− , T.append (T.pack " ") $ mkArtifactId a
192− , T.append (T.pack " ") $ mkVersion v
193− , T.pack $ "</dependency>\n"
194− ]
195− _ -> []
196− mkGroupId g = T.append (T.pack $ "<groupId>") (T.append g $ T.pack "</groupId>\n")
197− mkArtifactId a = T.append (T.pack $ "<artifactId>") (T.append a $ T.pack "</artifactId>\n")
198− mkVersion v = T.append (T.pack $ "<version>") (T.append v $ T.pack "</version>\n")
199−
200169-----------------------------------------------------------------------
201170-- Code generation environment
202171
src/IRTS/CodegenJavaScript.hs+3
@@ -991,6 +991,9 @@ translateExpression (SOp op vars)
991991 | LStrTail <- op
992992 , (arg:_) <- vars = let v = translateVariableName arg in
993993 JSRaw $ v ++ ".substr(1," ++ v ++ ".length-1)"
994+ | LNullPtr <- op
995+ , (_) <- vars = JSNull
996+
994997 where
995998 translateBinaryOp :: String -> LVar -> LVar -> JS
996999 translateBinaryOp f lhs rhs = JSOp f (JSVar lhs) (JSVar rhs)
src/IRTS/Java/JTypes.hs+1
@@ -293,6 +293,7 @@ sourceTypes (LStdErr) = []
293293sourceTypes (LFork) = [objectType]
294294sourceTypes (LPar) = [objectType]
295295sourceTypes (LVMPtr) = []
296+sourceTypes (LNullPtr) = [objectType]
296297sourceTypes (LNoOp) = repeat objectType
297298
298299
src/IRTS/Java/Pom.hsnew file+89
@@ -0,0 +1,89 @@
1+module IRTS.Java.Pom (pomString) where
2+
3+import Data.List (unfoldr)
4+import Text.XML.Light
5+
6+uattr :: String -> String -> Attr
7+uattr k v = Attr (QName k Nothing Nothing) v
8+
9+-- from http://stackoverflow.com/a/4978733/283260
10+splitOn :: Eq a => a -> [a] -> [[a]]
11+splitOn chr = unfoldr sep where
12+ sep [] = Nothing
13+ sep l = Just . fmap (drop 1) . break (==chr) $ l
14+
15+parseToDep :: String -> Element
16+parseToDep tuple =
17+ case splitOn ':' tuple of
18+ [g, a, v] -> dependency g a v
19+ _ -> blank_element
20+
21+dependency :: String -> String -> String -> Element
22+dependency g a v = unode "dependency" (groupArtifactVersion g a v)
23+
24+groupArtifactVersion :: String -> String -> String -> [Element]
25+groupArtifactVersion g a v = [
26+ unode "groupId" g,
27+ unode "artifactId" a,
28+ unode "version" v
29+ ]
30+
31+pomString :: String -> String -> [String] -> String
32+pomString c a d = ppElement $ pom c a d
33+
34+pom :: String -> String -> [String] -> Element
35+pom clsName artifactName dependencies = unode "project" ([
36+ uattr "xmlns" "http://maven.apache.org/POM/4.0.0",
37+ uattr "xmlns:xsi" "http://www.w3.org/2001/XMLSchema-instance",
38+ uattr "xsi:schemaLocation" "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
39+ ],
40+ [
41+ unode "modelVersion" "4.0.0",
42+ unode "groupId" "org.idris-lang",
43+ unode "artifactId" artifactName,
44+ unode "packaging" "jar",
45+ unode "version" "1.0",
46+ unode "name" artifactName,
47+ unode "properties" [
48+ unode "project.build.sourceEncoding" "UTF-8",
49+ unode "skipTest" "true"
50+ ],
51+ unode "dependencies" (
52+ dependency "org.idris-lang" "idris" "0.9.10-alpha-2" :
53+ map parseToDep dependencies
54+ ),
55+ unode "build" [
56+ unode "finalName" artifactName,
57+ unode "plugins" [
58+ unode "plugin" (
59+ unode "configuration" [
60+ unode "source" "1.7",
61+ unode "target" "1.7"
62+ ] : groupArtifactVersion "org.apache.maven.plugins" "maven-compiler-plugin" "3.0"
63+ ),
64+ unode "plugin" (
65+ unode "configuration" (
66+ unode "skipTests" "${skipTests}"
67+ ) : groupArtifactVersion "org.apache.maven.plugins" "maven-surefile-plugin" "2.14"
68+ ),
69+ unode "plugin" (
70+ unode "executions" [
71+ unode "execution" [
72+ unode "phase" "package",
73+ unode "goals" (
74+ unode "goal" "shade"
75+ ),
76+ unode "configuration" (
77+ unode "transformers" (
78+ unode "transformer" (
79+ uattr "implementation" "org.apache.maven.plugins.shade.resource.ManifestResourceTransformer",
80+ unode "mainClass" clsName
81+ )
82+ )
83+ )
84+ ]
85+ ] : groupArtifactVersion "org.apache.maven.plugins" "maven-shade-plugin" "2.1"
86+ )
87+ ]
88+ ]
89+ ])
src/IRTS/Lang.hs+1
@@ -54,6 +54,7 @@ data PrimFn = LPlus ArithTy | LMinus ArithTy | LTimes ArithTy
5454 | LPar -- evaluate argument anywhere, possibly on another
5555 -- core or another machine. 'id' is a valid implementation
5656 | LVMPtr
57+ | LNullPtr
5758 | LNoOp
5859 deriving (Show, Eq)
5960
src/Idris/Primitives.hs+3−1
@@ -169,7 +169,9 @@ primitives =
169169 (0, LVMPtr) total,
170170 -- Streams
171171 Prim (UN "prim__stdin") (ty [] PtrType) 0 (p_cantreduce)
172− (0, LStdIn) partial
172+ (0, LStdIn) partial,
173+ Prim (UN "prim__null") (ty [] PtrType) 0 (p_cantreduce)
174+ (0, LNullPtr) total
173175 ] ++ concatMap intOps [ITFixed IT8, ITFixed IT16, ITFixed IT32, ITFixed IT64, ITBig, ITNative, ITChar]
174176 ++ concatMap vecOps vecTypes
175177 ++ vecBitcasts vecTypes
test/test033/expectednew file+1
@@ -0,0 +1 @@
1+0
test/test033/runnew file+5
@@ -0,0 +1,5 @@
1+#!/bin/bash
2+gcc -c test033.c
3+idris -o test033 test033.idr
4+./test033
5+rm -f *.ibc *.o test033
test/test033/test033.cnew file+10
@@ -0,0 +1,10 @@
1+#include "test033.h"
2+#include <stddef.h>
3+
4+int testNull(void* p) {
5+ if(p == NULL) {
6+ return 0;
7+ }
8+ return 1;
9+}
10+
test/test033/test033.hnew file+6
@@ -0,0 +1,6 @@
1+#ifndef __TEST033_H__
2+#define __TEST033_H__
3+
4+int testNull(void*);
5+
6+#endif
test/test033/test033.idrnew file+10
@@ -0,0 +1,10 @@
1+module Main
2+
3+%include C "test033.h"
4+%link C "test033.o"
5+
6+testNull : Ptr -> IO Int
7+testNull p = mkForeign (FFun "testNull" [FPtr] FInt) p
8+
9+main : IO ()
10+main = testNull null >>= (putStrLn . show)