on master help sign in
Merge pull request #400 from JanBessai/JavaRTSOnMavenCentral

Remove Java RTS build in favor of the version hosted on Maven Central

commit1d3486f92d5cadf0455b0af40bc11620e1654299 authorEdwin Brady <edwin.brady@gmail.com> dateFri 19 Jul 2013, 02:11 (13 years ago) parent3b15bf75d5c613
10 files changed+19−1870
.travis.yml+2−2 Setup.hs+15−54 config.mk−2 idris.cabal−5 java/pom_template.xml−39 java/src/main/java/org/idris/rts/Closure.java−26 java/src/main/java/org/idris/rts/ForeignPrimitives.java−255 java/src/main/java/org/idris/rts/IdrisObject.java−19 java/src/main/java/org/idris/rts/PrimFn.java−1464 src/IRTS/CodegenJava.hs+2−4
.travis.yml+2−2
@@ -10,8 +10,8 @@ before_script:
1010 - tar -xf edwinb/Idris-dev/dist/idris*.tar.gz
1111 - cd idris*
1212script:
13− - cabal configure -f Java
14− - cabal install -f Java
13+ - cabal configure
14+ - cabal install
1515 - make test
1616 - make test_java
1717
Setup.hs+15−54
@@ -21,12 +21,6 @@ import qualified Data.Text.IO as TIO
2121-- After Idris is built, we need to check and install the prelude and other libs
2222
2323make verbosity = P.runProgramInvocation verbosity . P.simpleProgramInvocation "make"
24−mvn verbosity = P.runProgramInvocation verbosity . P.simpleProgramInvocation
25−#ifdef mingw32_HOST_OS
26− "mvn.bat"
27−#else
28− "mvn"
29−#endif
3024
3125#ifdef mingw32_HOST_OS
3226-- make on mingw32 exepects unix style separators
@@ -45,13 +39,9 @@ cleanStdLib verbosity
4539 make verbosity [ "-C", "effects", "clean", "IDRIS=idris" ]
4640 make verbosity [ "-C", "javascript", "clean", "IDRIS=idris" ]
4741
48−cleanJavaLib verbosity
49− = do dirty <- doesDirectoryExist ("java" </> "target")
50− when dirty $ mvn verbosity [ "-f", "java/pom.xml", "clean" ]
51− pomExists <- doesFileExist ("java" </> "pom.xml")
52− when pomExists $ removeFile ("java" </> "pom.xml")
53− execPomExists <- doesFileExist ("java" </> "executable_pom.xml")
54− when pomExists $ removeFile ("java" </> "executable_pom.xml")
42+cleanJavaPom verbosity
43+ = do execPomExists <- doesFileExist ("java" </> "executable_pom.xml")
44+ when execPomExists $ removeFile ("java" </> "executable_pom.xml")
5545
5646cleanLLVMLib verbosity = make verbosity ["-C", "llvm", "clean"]
5747
@@ -88,17 +78,8 @@ installLLVMLib verbosity pkg local copy =
8878 let idir = datadir $ L.absoluteInstallDirs pkg local copy in
8979 make verbosity ["-C", "llvm", "install", "TARGET=" ++ idir </> "llvm"]
9080
91−installJavaLib pkg local verbosity copy version = do
92− let rtsFile = "idris-" ++ display version ++ ".jar"
93− putStrLn $ "Installing java libraries"
94− mvn verbosity [ "install:install-file"
95− , "-Dfile=" ++ ("java" </> "target" </> rtsFile)
96− , "-DgroupId=org.idris-lang"
97− , "-DartifactId=idris"
98− , "-Dversion=" ++ display version
99− , "-Dpackaging=jar"
100− , "-DgeneratePom=True"
101− ]
81+installJavaPom pkg local verbosity copy version = do
82+ putStrLn $ "Installing java pom template"
10283 let dir = datadir $ L.absoluteInstallDirs pkg local copy
10384 copyFile ("java" </> "executable_pom.xml") (dir </> "executable_pom.xml")
10485
@@ -135,14 +116,6 @@ checkStdLib local withoutEffects verbosity
135116 , "IDRIS=" ++ icmd
136117 ]
137118
138−checkJavaLib verbosity = mvn verbosity [ "-f", "java" </> "pom.xml", "package" ]
139−
140−javaFlag flags =
141− case lookup (FlagName "java") (S.configConfigurationsFlags flags) of
142− Just True -> True
143− Just False -> False
144− Nothing -> False
145−
146119llvmFlag flags =
147120 case lookup (FlagName "LLVM") (S.configConfigurationsFlags flags) of
148121 Just True -> True
@@ -156,9 +129,7 @@ noEffectsFlag flags =
156129 Nothing -> False
157130
158131preparePoms version
159− = do pomTemplate <- TIO.readFile ("java" </> "pom_template.xml")
160− TIO.writeFile ("java" </> "pom.xml") (insertVersion pomTemplate)
161− execPomTemplate <- TIO.readFile ("java" </> "executable_pom_template.xml")
132+ = do execPomTemplate <- TIO.readFile ("java" </> "executable_pom_template.xml")
162133 TIO.writeFile ("java" </> "executable_pom.xml") (insertVersion execPomTemplate)
163134 where
164135 insertVersion template =
@@ -173,41 +144,31 @@ main = do
173144 let withoutEffects = noEffectsFlag $ configFlags lbi
174145 installStdLib pkg lbi withoutEffects verb
175146 (S.fromFlag $ S.copyDest flags)
176− when (llvmFlag $ configFlags lbi)
177− (installLLVMLib verb pkg lbi (S.fromFlag $ S.copyDest flags))
178− when (javaFlag $ configFlags lbi)
179− (installJavaLib pkg
180− lbi
181− verb
147+ installJavaPom pkg lbi verb
182148 (S.fromFlag $ S.copyDest flags)
183149 (pkgVersion . package $ localPkgDescr lbi)
184− )
185− , postInst = \ _ flags pkg lbi -> do
150+ when (llvmFlag $ configFlags lbi)
151+ (installLLVMLib verb pkg lbi (S.fromFlag $ S.copyDest flags))
152+ , postInst = \ _ flags pkg lbi -> do
186153 let verb = (S.fromFlag $ S.installVerbosity flags)
187154 let withoutEffects = noEffectsFlag $ configFlags lbi
188155 installStdLib pkg lbi withoutEffects verb
189156 NoCopyDest
190− when (llvmFlag $ configFlags lbi)
191− (installLLVMLib verb pkg lbi NoCopyDest)
192− when (javaFlag $ configFlags lbi)
193− (installJavaLib pkg
194− lbi
195− verb
157+ installJavaPom pkg lbi verb
196158 NoCopyDest
197159 (pkgVersion . package $ localPkgDescr lbi)
198− )
160+ when (llvmFlag $ configFlags lbi)
161+ (installLLVMLib verb pkg lbi NoCopyDest)
199162 , postConf = \ _ flags _ lbi -> do
200163 removeLibIdris lbi (S.fromFlag $ S.configVerbosity flags)
201− when (javaFlag $ configFlags lbi)
202− (preparePoms . pkgVersion . package $ localPkgDescr lbi)
164+ preparePoms . pkgVersion . package $ localPkgDescr lbi
203165 , postClean = \ _ flags _ _ -> do
204166 let verb = S.fromFlag $ S.cleanVerbosity flags
205167 cleanStdLib verb
206168 cleanLLVMLib verb
207− cleanJavaLib verb
169+ cleanJavaPom verb
208170 , postBuild = \ _ flags _ lbi -> do
209171 let verb = S.fromFlag $ S.buildVerbosity flags
210172 let withoutEffects = noEffectsFlag $ configFlags lbi
211173 checkStdLib lbi withoutEffects verb
212− when (javaFlag $ configFlags lbi) (checkJavaLib verb)
213174 }
config.mk−2
@@ -2,8 +2,6 @@ GMP_INCLUDE_DIR :=
22CC :=gcc
33CABAL :=cabal
44#CABALFLAGS :=
5−## Enable Java RTS:
6−#CABALFLAGS :=-f Java
75## Disable building of Effects
86#CABALFLAGS :=-f NoEffects
97
idris.cabal−5
@@ -72,7 +72,6 @@ Extra-source-files: lib/Makefile lib/*.idr lib/Prelude/*.idr
7272 rts/*.c rts/*.h rts/Makefile
7373 llvm/*.c llvm/Makefile
7474 js/*.js
75− java/src/main/java/org/idris/rts/*.java
7675 java/*.xml
7776
7877 Makefile
@@ -234,10 +233,6 @@ source-repository head
234233 type: git
235234 location: git://github.com/edwinb/Idris-dev.git
236235
237−Flag Java
238− Description: Build the Java RTS
239− Default: False
240−
241236Flag NoEffects
242237 Description: Do not build the effects package
243238 Default: False
java/pom_template.xmldeleted−39
@@ -1,39 +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/xsd/maven-4.0.0.xsd">
3− <modelVersion>4.0.0</modelVersion>
4−
5− <groupId>org.idris-lang</groupId>
6− <artifactId>idris</artifactId>
7− <version>$RTS-VERSION$</version>
8− <packaging>jar</packaging>
9−
10− <name>Runtime System for the Idris Java Backend</name>
11− <url>http://www.irdis-lang.org</url>
12−
13− <properties>
14− <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15− <skipTests>true</skipTests>
16− </properties>
17−
18− <build>
19− <plugins>
20− <plugin>
21− <groupId>org.apache.maven.plugins</groupId>
22− <artifactId>maven-compiler-plugin</artifactId>
23− <version>3.0</version>
24− <configuration>
25− <source>1.7</source>
26− <target>1.7</target>
27− </configuration>
28− </plugin>
29− <plugin>
30− <groupId>org.apache.maven.plugins</groupId>
31− <artifactId>maven-surefire-plugin</artifactId>
32− <version>2.14</version>
33− <configuration>
34− <skipTests>${skipTests}</skipTests>
35− </configuration>
36− </plugin>
37− </plugins>
38− </build>
39−</project>
java/src/main/java/org/idris/rts/Closure.javadeleted−26
@@ -1,26 +0,0 @@
1−package org.idris.rts;
2−
3−import java.util.concurrent.Callable;
4−
5−public abstract class Closure implements Callable<Object>, Runnable {
6− @Override
7− public abstract Object call();
8−
9− public static Object unwrapTailCall(Object o) {
10− while (o instanceof Closure) {
11− o = ((Closure)o).call();
12− }
13− return o;
14− }
15−
16− @Override
17− public void run() {
18− unwrapTailCall(call());
19− }
20−
21− public Thread fork() {
22− Thread childProcess = new Thread(this);
23− childProcess.start();
24− return childProcess;
25− }
26−}
java/src/main/java/org/idris/rts/ForeignPrimitives.javadeleted−255
@@ -1,255 +0,0 @@
1−package org.idris.rts;
2−
3−import java.lang.reflect.InvocationTargetException;
4−import java.util.Arrays;
5−import java.util.List;
6−import java.util.Map;
7−import java.util.HashMap;
8−import java.util.Set;
9−import java.util.HashSet;
10−import java.io.Closeable;
11−import java.io.File;
12−import java.io.IOException;
13−import java.io.PrintStream;
14−import java.io.InputStream;
15−import java.nio.ByteBuffer;
16−import java.nio.file.Files;
17−import java.nio.file.OpenOption;
18−import java.nio.file.StandardOpenOption;
19−import java.nio.channels.Channels;
20−import java.nio.channels.SeekableByteChannel;
21−import java.nio.channels.ReadableByteChannel;
22−import java.util.concurrent.BlockingQueue;
23−import java.util.concurrent.LinkedBlockingQueue;
24−import java.util.concurrent.Semaphore;
25−
26−@SuppressWarnings("unchecked")
27−public class ForeignPrimitives {
28−
29− private static final Map<Thread, List<String>> args = new HashMap<>();
30− private static final Semaphore messageMutex = new Semaphore(1);
31− private static final Map<Thread, BlockingQueue<Object>> messages = new HashMap<>();
32− private static final Set<Object> feofFiles = new HashSet<>();
33−
34− public static synchronized void idris_initArgs(Thread t, String[] args) {
35− ForeignPrimitives.args.put(t, Arrays.asList(args));
36− }
37−
38− public static synchronized int idris_numArgs(Object thread) {
39− List<String> argsForThread = ForeignPrimitives.args.get((Thread) thread);
40− return (argsForThread == null ? 0 : argsForThread.size());
41− }
42−
43− public static synchronized String idris_getArg(Object thread, int num) {
44− List<String> argsForThread = ForeignPrimitives.args.get((Thread) thread);
45− return (argsForThread == null ? null : argsForThread.get(num));
46− }
47−
48− public static String getenv(String x) {
49− return System.getenv(x);
50− }
51−
52− public static void exit(int exitCode) {
53− System.exit(exitCode);
54− }
55−
56− public static void usleep(int microsecs) {
57− try {
58− Thread.sleep(microsecs / 1000, microsecs % 1000);
59− } catch (InterruptedException ex) {
60− }
61− }
62−
63− public static void idris_sendMessage(Object from, Object dest, Object message) throws InterruptedException {
64− messageMutex.acquire();
65− BlockingQueue<Object> messagesForTarget = messages.get((Thread) dest);
66− if (messagesForTarget == null) {
67− messagesForTarget = new LinkedBlockingQueue<>();
68− messages.put((Thread) dest, messagesForTarget);
69− }
70− messagesForTarget.put(message);
71− messageMutex.release();
72− }
73−
74− public static int idris_checkMessage(Object dest) throws InterruptedException {
75− messageMutex.acquire();
76− BlockingQueue<Object> messagesForTarget = messages.get((Thread) dest);
77− messageMutex.release();
78− return (messagesForTarget == null ? 0 : messagesForTarget.size());
79− }
80−
81− public static Object idris_recvMessage(Object dest) throws InterruptedException {
82− messageMutex.acquire();
83− BlockingQueue<Object> messagesForTarget = messages.get((Thread) dest);
84− if (messagesForTarget == null) {
85− messagesForTarget = new LinkedBlockingQueue();
86− messages.put((Thread) dest, messagesForTarget);
87− }
88− messageMutex.release();
89− return messagesForTarget.take();
90− }
91−
92− public static void putStr(String str) {
93− System.out.print(str);
94− }
95−
96− public static void putchar(char c) {
97− System.out.print(c);
98− }
99−
100− public static int getchar() {
101− try {
102− return (char) System.in.read();
103− } catch (IOException ex) {
104− return -1;
105− }
106− }
107−
108− public static SeekableByteChannel fileOpen(String name, String privs) {
109− try {
110− OpenOption[] options;
111− switch (privs) {
112− case "r":
113− options = new StandardOpenOption[]{StandardOpenOption.READ};
114− break;
115− case "r+":
116− options = new StandardOpenOption[]{StandardOpenOption.READ,
117− StandardOpenOption.WRITE};
118− break;
119− case "w":
120− options = new StandardOpenOption[]{StandardOpenOption.WRITE,
121− StandardOpenOption.CREATE};
122− break;
123− case "w+":
124− options = new StandardOpenOption[]{StandardOpenOption.READ,
125− StandardOpenOption.WRITE,
126− StandardOpenOption.CREATE};
127− break;
128− case "a":
129− options = new StandardOpenOption[]{StandardOpenOption.WRITE,
130− StandardOpenOption.CREATE,
131− StandardOpenOption.APPEND};
132− break;
133− case "a+":
134− options = new StandardOpenOption[]{StandardOpenOption.READ,
135− StandardOpenOption.WRITE,
136− StandardOpenOption.CREATE,
137− StandardOpenOption.APPEND};
138− break;
139− default:
140− options = new StandardOpenOption[]{};
141− break;
142− }
143− return Files.newByteChannel(new File(name).toPath(), options);
144− } catch (IOException ex) {
145− return null;
146− }
147− }
148−
149− public static synchronized void fileClose(Object file) throws IOException {
150− ((Closeable) file).close();
151− feofFiles.remove(file);
152− }
153−
154− public static void fputStr(Object file, String string) throws IOException {
155− if (file instanceof PrintStream) {
156− ((PrintStream) file).print(string);
157− } else if (file instanceof SeekableByteChannel) {
158− ((SeekableByteChannel) file).write(ByteBuffer.wrap(string.getBytes()));
159− }
160− }
161−
162− public static synchronized String idris_readStr(Object file) throws IOException {
163− ReadableByteChannel channel = file instanceof InputStream
164− ? Channels.newChannel((InputStream) file)
165− : (ReadableByteChannel) file;
166− ByteBuffer buf = ByteBuffer.allocate(1);
167− StringBuilder resultBuilder = new StringBuilder("");
168− String delimiter = System.getProperty("line.separator");
169− int read = 0;
170− do {
171− buf.rewind();
172− read = channel.read(buf);
173− if (read > 0) {
174− resultBuilder.append(new String(buf.array()));
175− if (resultBuilder.lastIndexOf(delimiter) > -1) {
176− return resultBuilder.toString();
177− }
178− }
179− if (read < 0) {
180− feofFiles.add(file);
181− }
182− } while (read >= 0);
183− return resultBuilder.toString();
184− }
185−
186− public static int fileEOF(Object file) {
187− return (feofFiles.contains(file) ? 1 : 0);
188− }
189−
190− public static int isNull(Object o) {
191− return (o == null ? 1 : 0);
192− }
193−
194− public static Object malloc(int size) {
195− return ByteBuffer.allocate(size);
196− }
197−
198− public static void idris_memset(Object buf, int offset, Object c, int size) {
199− ByteBuffer buffer = (ByteBuffer)buf;
200− buffer.rewind();
201− buffer.position(offset);
202− byte init[] = new byte[size];
203− Arrays.fill(init, (Byte)c);
204− buffer.put(init, offset, size);
205− buffer.rewind();
206− }
207−
208− public static void free(Object buf) {
209− buf = null;
210− }
211−
212− public static byte idris_peek(Object buf, int offset) {
213− ByteBuffer buffer = (ByteBuffer)buf;
214− return buffer.get(offset);
215− }
216−
217− public static void idris_poke(Object buf, int offset, Object data) {
218− ByteBuffer buffer = (ByteBuffer)buf;
219− buffer.put(offset, (Byte)data);
220− }
221−
222− public static void idris_memmove(Object dstBuf, Object srcBuf, int dstOffset, int srcOffset, int size) {
223− ByteBuffer dst = (ByteBuffer)dstBuf;
224− ByteBuffer src = (ByteBuffer)srcBuf;
225− byte [] srcData = new byte[size];
226− src.rewind();
227− src.position(srcOffset);
228− src.get(srcData, 0, size);
229− src.rewind();
230− dst.rewind();
231− dst.position(dstOffset);
232− dst.put(srcData, 0, size);
233− dst.rewind();
234− }
235−
236− public final static Object idris_K(final Object result, final Object drop) {
237− return result;
238− }
239−
240− public final static Object idris_flipK(final Object drop, final Object result) {
241− return result;
242− }
243−
244− public final static Object[] idris_assignStack(final Object[] context, final int start, final Object... vars) {
245− int i = start;
246− for (Object var : vars) {
247− context[i] = var;
248− }
249− return context;
250− }
251−
252− public final static Object idris_throwException(RuntimeException ex) {
253− throw ex;
254− }
255−}
java/src/main/java/org/idris/rts/IdrisObject.javadeleted−19
@@ -1,19 +0,0 @@
1−package org.idris.rts;
2−
3−public class IdrisObject {
4− private final int constructorId;
5− private final Object data[];
6−
7− public IdrisObject(final int constructorId, final Object ... data) {
8− this.constructorId = constructorId;
9− this.data = data;
10− }
11−
12− public int getConstructorId() {
13− return constructorId;
14− }
15−
16− public Object[] getData() {
17− return data;
18− }
19−}
java/src/main/java/org/idris/rts/PrimFn.javadeleted−1464
@@ -1,1464 +0,0 @@
1−/*
2− */
3−package org.idris.rts;
4−
5−import java.io.IOException;
6−import java.io.InputStream;
7−import java.io.OutputStream;
8−import java.math.BigInteger;
9−
10−public class PrimFn {
11− public static byte LPlus(byte x, byte y) {
12− return (byte)(x + y);
13− }
14− public static char LPlus(char x, char y) {
15− return (char)(x + y);
16− }
17− public static short LPlus(short x, short y) {
18− return (short)(x + y);
19− }
20− public static int LPlus(int x, int y) {
21− return x + y;
22− }
23− public static long LPlus(long x, long y) {
24− return x + y;
25− }
26− public static double LPlus(double x, double y) {
27− return x + y;
28− }
29− public static BigInteger LPlus(BigInteger x, BigInteger y) {
30− return x.add(y);
31− }
32− public static byte[] LPlus(byte[] x, byte[] y) {
33− byte[] res = x.clone();
34− for (int i = 0; i < res.length; ++i) {
35− res[i] += y[i];
36− }
37− return res;
38− }
39− public static short[] LPlus(short[] x, short[] y) {
40− short[] res = x.clone();
41− for (int i = 0; i < res.length; ++i) {
42− res[i] += y[i];
43− }
44− return res;
45− }
46− public static int[] LPlus(int[] x, int[] y) {
47− int[] res = x.clone();
48− for (int i = 0; i < res.length; ++i) {
49− res[i] += y[i];
50− }
51− return res;
52− }
53− public static long[] LPlus(long[] x, long[] y) {
54− long[] res = x.clone();
55− for (int i = 0; i < res.length; ++i) {
56− res[i] += y[i];
57− }
58− return res;
59− }
60−
61− public static byte LMinus(byte x, byte y) {
62− return (byte)(x - y);
63− }
64− public static char LMinus(char x, char y) {
65− return (char)(x - y);
66− }
67− public static short LMinus(short x, short y) {
68− return (short)(x - y);
69− }
70− public static int LMinus(int x, int y) {
71− return x - y;
72− }
73− public static long LMinus(long x, long y) {
74− return x - y;
75− }
76− public static double LMinus(double x, double y) {
77− return x - y;
78− }
79− public static BigInteger LMinus(BigInteger x, BigInteger y) {
80− return x.subtract(y);
81− }
82− public static byte[] LMinus(byte[] x, byte[] y) {
83− byte[] res = x.clone();
84− for (int i = 0; i < res.length; ++i) {
85− res[i] -= y[i];
86− }
87− return res;
88− }
89− public static short[] LMinus(short[] x, short[] y) {
90− short[] res = x.clone();
91− for (int i = 0; i < res.length; ++i) {
92− res[i] -= y[i];
93− }
94− return res;
95− }
96− public static int[] LMinus(int[] x, int[] y) {
97− int[] res = x.clone();
98− for (int i = 0; i < res.length; ++i) {
99− res[i] -= y[i];
100− }
101− return res;
102− }
103− public static long[] LMinus(long[] x, long[] y) {
104− long[] res = x.clone();
105− for (int i = 0; i < res.length; ++i) {
106− res[i] -= y[i];
107− }
108− return res;
109− }
110−
111− public static byte LTimes(byte x, byte y) {
112− return (byte)(x * y);
113− }
114− public static char LTimes(char x, char y) {
115− return (char)(x * y);
116− }
117− public static short LTimes(short x, short y) {
118− return (short)(x * y);
119− }
120− public static int LTimes(int x, int y) {
121− return x * y;
122− }
123− public static long LTimes(long x, long y) {
124− return x * y;
125− }
126− public static double LTimes(double x, double y) {
127− return x * y;
128− }
129− public static BigInteger LTimes(BigInteger x, BigInteger y) {
130− return x.multiply(y);
131− }
132− public static byte[] LTimes(byte[] x, byte[] y) {
133− byte[] res = x.clone();
134− for (int i = 0; i < res.length; ++i) {
135− res[i] *= y[i];
136− }
137− return res;
138− }
139− public static short[] LTimes(short[] x, short[] y) {
140− short[] res = x.clone();
141− for (int i = 0; i < res.length; ++i) {
142− res[i] *= y[i];
143− }
144− return res;
145− }
146− public static int[] LTimes(int[] x, int[] y) {
147− int[] res = x.clone();
148− for (int i = 0; i < res.length; ++i) {
149− res[i] *= y[i];
150− }
151− return res;
152− }
153− public static long[] LTimes(long[] x, long[] y) {
154− long[] res = x.clone();
155− for (int i = 0; i < res.length; ++i) {
156− res[i] *= y[i];
157− }
158− return res;
159− }
160−
161− public static byte LUDiv(byte x, byte y) {
162− return (byte)(((short)x) / ((short)y));
163− }
164− public static char LUDiv(char x, char y) {
165− return (char)(((long)x) / ((long)y));
166− }
167− public static short LUDiv(short x, short y) {
168− return (short)(((int)x) / ((int)y));
169− }
170− public static int LUDiv(int x, int y) {
171− return (int)(((long)x) / ((long)y));
172− }
173− public static long LUDiv(long x, long y) {
174− return BigInteger.valueOf(x).divide(BigInteger.valueOf(y)).longValue();
175− }
176− public static byte[] LUDiv(byte[] x, byte[] y) {
177− byte[] res = x.clone();
178− for (int i = 0; i < res.length; ++i) {
179− res[i] = (byte)(((short)res[i]) / ((short)y[i]));
180− }
181− return res;
182− }
183− public static short[] LUDiv(short[] x, short[] y) {
184− short[] res = x.clone();
185− for (int i = 0; i < res.length; ++i) {
186− res[i] = (short)(((int)res[i]) / ((int)y[i]));
187− }
188− return res;
189− }
190− public static int[] LUDiv(int[] x, int[] y) {
191− int[] res = x.clone();
192− for (int i = 0; i < res.length; ++i) {
193− res[i] = (int)(((long)res[i]) / ((long)y[i]));
194− }
195− return res;
196− }
197− public static long[] LUDiv(long[] x, long[] y) {
198− long[] res = x.clone();
199− for (int i = 0; i < res.length; ++i) {
200− res[i] = BigInteger.valueOf(res[i]).divide(BigInteger.valueOf(y[i])).longValue();
201− }
202− return res;
203− }
204−
205− public static byte LSDiv(byte x, byte y) {
206− return (byte)(x / y);
207− }
208− public static char LSDiv(char x, char y) {
209− return (char)(x / y);
210− }
211− public static short LSDiv(short x, short y) {
212− return (short)(x / y);
213− }
214− public static int LSDiv(int x, int y) {
215− return x / y;
216− }
217− public static long LSDiv(long x, long y) {
218− return x / y;
219− }
220− public static double LSDiv(double x, double y) {
221− return x / y;
222− }
223− public static BigInteger LSDiv(BigInteger x, BigInteger y) {
224− return x.divide(y);
225− }
226− public static byte[] LSDiv(byte[] x, byte[] y) {
227− byte[] res = x.clone();
228− for (int i = 0; i < res.length; ++i) {
229− res[i] /= y[i];
230− }
231− return res;
232− }
233− public static short[] LSDiv(short[] x, short[] y) {
234− short[] res = x.clone();
235− for (int i = 0; i < res.length; ++i) {
236− res[i] /= y[i];
237− }
238− return res;
239− }
240− public static int[] LSDiv(int[] x, int[] y) {
241− int[] res = x.clone();
242− for (int i = 0; i < res.length; ++i) {
243− res[i] /= y[i];
244− }
245− return res;
246− }
247− public static long[] LSDiv(long[] x, long[] y) {
248− long[] res = x.clone();
249− for (int i = 0; i < res.length; ++i) {
250− res[i] /= y[i];
251− }
252− return res;
253− }
254−
255− public static byte LURem(byte x, byte y) {
256− return (byte)(((short)x) % ((short)y));
257− }
258− public static char LURem(char x, char y) {
259− return (char)(((long)x) % ((long)y));
260− }
261− public static short LURem(short x, short y) {
262− return (short)(((int)x) % ((int)y));
263− }
264− public static int LURem(int x, int y) {
265− return (int)(((long)x) % ((long)y));
266− }
267− public static long LURem(long x, long y) {
268− return BigInteger.valueOf(x).divide(BigInteger.valueOf(y)).longValue();
269− }
270− public static byte[] LURem(byte[] x, byte[] y) {
271− byte[] res = x.clone();
272− for (int i = 0; i < res.length; ++i) {
273− res[i] = (byte)(((short)res[i]) % ((short)y[i]));
274− }
275− return res;
276− }
277− public static short[] LURem(short[] x, short[] y) {
278− short[] res = x.clone();
279− for (int i = 0; i < res.length; ++i) {
280− res[i] = (short)(((int)res[i]) % ((int)y[i]));
281− }
282− return res;
283− }
284− public static int[] LURem(int[] x, int[] y) {
285− int[] res = x.clone();
286− for (int i = 0; i < res.length; ++i) {
287− res[i] = (int)(((long)res[i]) % ((long)y[i]));
288− }
289− return res;
290− }
291− public static long[] LURem(long[] x, long[] y) {
292− long[] res = x.clone();
293− for (int i = 0; i < res.length; ++i) {
294− res[i] = BigInteger.valueOf(res[i]).divide(BigInteger.valueOf(y[i])).longValue();
295− }
296− return res;
297− }
298−
299− public static byte LSRem(byte x, byte y) {
300− return (byte)(x % y);
301− }
302− public static char LSRem(char x, char y) {
303− return (char)(x % y);
304− }
305− public static short LSRem(short x, short y) {
306− return (short)(x % y);
307− }
308− public static int LSRem(int x, int y) {
309− return x % y;
310− }
311− public static long LSRem(long x, long y) {
312− return x % y;
313− }
314− public static double LSRem(double x, double y) {
315− return x % y;
316− }
317− public static BigInteger LSRem(BigInteger x, BigInteger y) {
318− return x.remainder(y);
319− }
320− public static byte[] LSRem(byte[] x, byte[] y) {
321− byte[] res = x.clone();
322− for (int i = 0; i < res.length; ++i) {
323− res[i] %= y[i];
324− }
325− return res;
326− }
327− public static short[] LSRem(short[] x, short[] y) {
328− short[] res = x.clone();
329− for (int i = 0; i < res.length; ++i) {
330− res[i] %= y[i];
331− }
332− return res;
333− }
334− public static int[] LSRem(int[] x, int[] y) {
335− int[] res = x.clone();
336− for (int i = 0; i < res.length; ++i) {
337− res[i] %= y[i];
338− }
339− return res;
340− }
341− public static long[] LSRem(long[] x, long[] y) {
342− long[] res = x.clone();
343− for (int i = 0; i < res.length; ++i) {
344− res[i] %= y[i];
345− }
346− return res;
347− }
348−
349−
350− public static byte LAnd(byte x, byte y) {
351− return (byte)(x & y);
352− }
353− public static char LAnd(char x, char y) {
354− return (char)(x & y);
355− }
356− public static short LAnd(short x, short y) {
357− return (short)(x & y);
358− }
359− public static int LAnd(int x, int y) {
360− return x & y;
361− }
362− public static long LAnd(long x, long y) {
363− return x & y;
364− }
365− public static BigInteger LAnd(BigInteger x, BigInteger y) {
366− return x.and(y);
367− }
368− public static byte[] LAnd(byte[] x, byte[] y) {
369− byte[] res = x.clone();
370− for (int i = 0; i < res.length; ++i) {
371− res[i] &= y[i];
372− }
373− return res;
374− }
375− public static short[] LAnd(short[] x, short[] y) {
376− short[] res = x.clone();
377− for (int i = 0; i < res.length; ++i) {
378− res[i] &= y[i];
379− }
380− return res;
381− }
382− public static int[] LAnd(int[] x, int[] y) {
383− int[] res = x.clone();
384− for (int i = 0; i < res.length; ++i) {
385− res[i] &= y[i];
386− }
387− return res;
388− }
389− public static long[] LAnd(long[] x, long[] y) {
390− long[] res = x.clone();
391− for (int i = 0; i < res.length; ++i) {
392− res[i] &= y[i];
393− }
394− return res;
395− }
396−
397− public static byte LOr(byte x, byte y) {
398− return (byte)(x | y);
399− }
400− public static char LOr(char x, char y) {
401− return (char)(x | y);
402− }
403− public static short LOr(short x, short y) {
404− return (short)(x | y);
405− }
406− public static int LOr(int x, int y) {
407− return x | y;
408− }
409− public static long LOr(long x, long y) {
410− return x | y;
411− }
412− public static BigInteger LOr(BigInteger x, BigInteger y) {
413− return x.or(y);
414− }
415− public static byte[] LOr(byte[] x, byte[] y) {
416− byte[] res = x.clone();
417− for (int i = 0; i < res.length; ++i) {
418− res[i] |= y[i];
419− }
420− return res;
421− }
422− public static short[] LOr(short[] x, short[] y) {
423− short[] res = x.clone();
424− for (int i = 0; i < res.length; ++i) {
425− res[i] |= y[i];
426− }
427− return res;
428− }
429− public static int[] LOr(int[] x, int[] y) {
430− int[] res = x.clone();
431− for (int i = 0; i < res.length; ++i) {
432− res[i] |= y[i];
433− }
434− return res;
435− }
436− public static long[] LOr(long[] x, long[] y) {
437− long[] res = x.clone();
438− for (int i = 0; i < res.length; ++i) {
439− res[i] |= y[i];
440− }
441− return res;
442− }
443−
444− public static byte LXOr(byte x, byte y) {
445− return (byte)(x ^ y);
446− }
447− public static char LXOr(char x, char y) {
448− return (char)(x ^ y);
449− }
450− public static short LXOr(short x, short y) {
451− return (short)(x ^ y);
452− }
453− public static int LXOr(int x, int y) {
454− return x ^ y;
455− }
456− public static long LXOr(long x, long y) {
457− return x ^ y;
458− }
459− public static BigInteger LXOr(BigInteger x, BigInteger y) {
460− return x.xor(y);
461− }
462− public static byte[] LXOr(byte[] x, byte[] y) {
463− byte[] res = x.clone();
464− for (int i = 0; i < res.length; ++i) {
465− res[i] ^= y[i];
466− }
467− return res;
468− }
469− public static short[] LXOr(short[] x, short[] y) {
470− short[] res = x.clone();
471− for (int i = 0; i < res.length; ++i) {
472− res[i] ^= y[i];
473− }
474− return res;
475− }
476− public static int[] LXOr(int[] x, int[] y) {
477− int[] res = x.clone();
478− for (int i = 0; i < res.length; ++i) {
479− res[i] ^= y[i];
480− }
481− return res;
482− }
483− public static long[] LXOr(long[] x, long[] y) {
484− long[] res = x.clone();
485− for (int i = 0; i < res.length; ++i) {
486− res[i] ^= y[i];
487− }
488− return res;
489− }
490−
491− public static byte LCompl(byte x) {
492− return (byte)~x;
493− }
494− public static char LCompl(char x) {
495− return (char)~x;
496− }
497− public static short LCompl(short x) {
498− return (short)(~x);
499− }
500− public static int LCompl(int x) {
501− return ~x;
502− }
503− public static long LCompl(long x) {
504− return ~x;
505− }
506− public static BigInteger LCompl(BigInteger x) {
507− return x.not();
508− }
509− public static byte[] LCompl(byte[] x) {
510− byte[] res = new byte[x.length];
511− for (int i = 0; i < res.length; ++i) {
512− res[i] = (byte)~(x[i]);
513− }
514− return res;
515− }
516− public static short[] LCompl(short[] x) {
517− short[] res = new short[x.length];
518− for (int i = 0; i < res.length; ++i) {
519− res[i] = (short)~(x[i]);
520− }
521− return res;
522− }
523− public static int[] LCompl(int[] x) {
524− int[] res = new int[x.length];
525− for (int i = 0; i < res.length; ++i) {
526− res[i] = (int)~(x[i]);
527− }
528− return res;
529− }
530− public static long[] LCompl(long[] x) {
531− long[] res = new long[x.length];
532− for (int i = 0; i < res.length; ++i) {
533− res[i] = (long)~(x[i]);
534− }
535− return res;
536− }
537−
538− public static byte LSHL(byte x, byte y) {
539− return (byte)(x << y);
540− }
541− public static char LSHL(char x, char y) {
542− return (char)(x << y);
543− }
544− public static short LSHL(short x, short y) {
545− return (short)(x << y);
546− }
547− public static int LSHL(int x, int y) {
548− return x << y;
549− }
550− public static long LSHL(long x, long y) {
551− return x << y;
552− }
553− public static BigInteger LSHL(BigInteger x, BigInteger y) {
554− return x.shiftLeft(y.intValue());
555− }
556− public static byte[] LSHL(byte[] x, byte[] y) {
557− byte[] res = x.clone();
558− for (int i = 0; i < res.length; ++i) {
559− res[i] <<= y[i];
560− }
561− return res;
562− }
563− public static short[] LSHL(short[] x, short[] y) {
564− short[] res = x.clone();
565− for (int i = 0; i < res.length; ++i) {
566− res[i] <<= y[i];
567− }
568− return res;
569− }
570− public static int[] LSHL(int[] x, int[] y) {
571− int[] res = x.clone();
572− for (int i = 0; i < res.length; ++i) {
573− res[i] <<= y[i];
574− }
575− return res;
576− }
577− public static long[] LSHL(long[] x, long[] y) {
578− long[] res = x.clone();
579− for (int i = 0; i < res.length; ++i) {
580− res[i] <<= y[i];
581− }
582− return res;
583− }
584−
585− public static byte LLSHR(byte x, byte y) {
586− return (byte)(x >>> y);
587− }
588− public static char LLSHR(char x, char y) {
589− return (char)(x >>> y);
590− }
591− public static short LLSHR(short x, short y) {
592− return (short)(x >>> y);
593− }
594− public static int LLSHR(int x, int y) {
595− return x >>> y;
596− }
597− public static long LLSHR(long x, long y) {
598− return x >>> y;
599− }
600− public static byte[] LLSHR(byte[] x, byte[] y) {
601− byte[] res = x.clone();
602− for (int i = 0; i < res.length; ++i) {
603− res[i] >>>= y[i];
604− }
605− return res;
606− }
607− public static short[] LLSHR(short[] x, short[] y) {
608− short[] res = x.clone();
609− for (int i = 0; i < res.length; ++i) {
610− res[i] >>>= y[i];
611− }
612− return res;
613− }
614− public static int[] LLSHR(int[] x, int[] y) {
615− int[] res = x.clone();
616− for (int i = 0; i < res.length; ++i) {
617− res[i] >>>= y[i];
618− }
619− return res;
620− }
621− public static long[] LLSHR(long[] x, long[] y) {
622− long[] res = x.clone();
623− for (int i = 0; i < res.length; ++i) {
624− res[i] >>>= y[i];
625− }
626− return res;
627− }
628−
629− public static byte LASHR(byte x, byte y) {
630− return (byte)(x >> y);
631− }
632− public static char LASHR(char x, char y) {
633− return (char)(x >> y);
634− }
635− public static short LASHR(short x, short y) {
636− return (short)(x >> y);
637− }
638− public static int LASHR(int x, int y) {
639− return x >> y;
640− }
641− public static long LASHR(long x, long y) {
642− return x >> y;
643− }
644− public static BigInteger LASHR(BigInteger x, BigInteger y) {
645− return x.shiftRight(y.intValue());
646− }
647− public static byte[] LASHR(byte[] x, byte[] y) {
648− byte[] res = x.clone();
649− for (int i = 0; i < res.length; ++i) {
650− res[i] >>= y[i];
651− }
652− return res;
653− }
654− public static short[] LASHR(short[] x, short[] y) {
655− short[] res = x.clone();
656− for (int i = 0; i < res.length; ++i) {
657− res[i] >>= y[i];
658− }
659− return res;
660− }
661− public static int[] LASHR(int[] x, int[] y) {
662− int[] res = x.clone();
663− for (int i = 0; i < res.length; ++i) {
664− res[i] >>= y[i];
665− }
666− return res;
667− }
668− public static long[] LASHR(long[] x, long[] y) {
669− long[] res = x.clone();
670− for (int i = 0; i < res.length; ++i) {
671− res[i] >>= y[i];
672− }
673− return res;
674− }
675−
676− public static int LEq(byte x, byte y) {
677− return (x == y ? 1 : 0);
678− }
679− public static int LEq(char x, char y) {
680− return (x == y ? 1 : 0);
681− }
682− public static int LEq(short x, short y) {
683− return (x == y ? 1 : 0);
684− }
685− public static int LEq(int x, int y) {
686− return (x == y ? 1 : 0);
687− }
688− public static int LEq(long x, long y) {
689− return (x == y ? 1 : 0);
690− }
691− public static int LEq(double x, double y) {
692− return (x == y ? 1 : 0);
693− }
694− public static int LEq(BigInteger x, BigInteger y) {
695− return (x.equals(y) ? 1 : 0);
696− }
697− public static byte[] LEq(byte[] x, byte[] y) {
698− byte[] res = new byte[x.length];
699− for (int i = 0; i < x.length; ++i) {
700− res[i] = (byte)(x[i] == y[i] ? -1 : 0);
701− }
702− return res;
703− }
704− public static short[] LEq(short[] x, short[] y) {
705− short[] res = new short[x.length];
706− for (int i = 0; i < x.length; ++i) {
707− res[i] = (short)(x[i] == y[i] ? -1 : 0);
708− }
709− return res;
710− }
711− public static int[] LEq(int[] x, int[] y) {
712− int[] res = new int[x.length];
713− for (int i = 0; i < x.length; ++i) {
714− res[i] = (x[i] == y[i] ? -1 : 0);
715− }
716− return res;
717− }
718− public static long[] LEq(long[] x, long[] y) {
719− long[] res = new long[x.length];
720− for (int i = 0; i < x.length; ++i) {
721− res[i] = (x[i] == y[i] ? -1 : 0);
722− }
723− return res;
724− }
725−
726− public static int LLt(byte x, byte y) {
727− return (x < y ? 1 : 0);
728− }
729− public static int LLt(char x, char y) {
730− return (x < y ? 1 : 0);
731− }
732− public static int LLt(short x, short y) {
733− return (x < y ? 1 : 0);
734− }
735− public static int LLt(int x, int y) {
736− return (x < y ? 1 : 0);
737− }
738− public static int LLt(long x, long y) {
739− return (x < y ? 1 : 0);
740− }
741− public static double LLt(double x, double y) {
742− return (x < y ? 1 : 0);
743− }
744− public static int LLt(BigInteger x, BigInteger y) {
745− return (x.compareTo(y) < 0 ? 1 : 0);
746− }
747− public static byte[] LLt(byte[] x, byte[] y) {
748− byte[] res = new byte[x.length];
749− for (int i = 0; i < x.length; ++i) {
750− res[i] = (byte)(x[i] < y[i] ? -1 : 0);
751− }
752− return res;
753− }
754− public static short[] LLt(short[] x, short[] y) {
755− short[] res = new short[x.length];
756− for (int i = 0; i < x.length; ++i) {
757− res[i] = (short)(x[i] < y[i] ? -1 : 0);
758− }
759− return res;
760− }
761− public static int[] LLt(int[] x, int[] y) {
762− int[] res = new int[x.length];
763− for (int i = 0; i < x.length; ++i) {
764− res[i] = (x[i] < y[i] ? -1 : 0);
765− }
766− return res;
767− }
768− public static long[] LLt(long[] x, long[] y) {
769− long[] res = new long[x.length];
770− for (int i = 0; i < x.length; ++i) {
771− res[i] = (x[i] < y[i] ? -1 : 0);
772− }
773− return res;
774− }
775−
776− public static int LLe(byte x, byte y) {
777− return (x <= y ? 1 : 0);
778− }
779− public static int LLe(char x, char y) {
780− return (x <= y ? 1 : 0);
781− }
782− public static int LLe(short x, short y) {
783− return (x <= y ? 1 : 0);
784− }
785− public static int LLe(int x, int y) {
786− return (x <= y ? 1 : 0);
787− }
788− public static int LLe(long x, long y) {
789− return (x <= y ? 1 : 0);
790− }
791− public static double LLe(double x, double y) {
792− return (x <= y ? 1 : 0);
793− }
794− public static int LLe(BigInteger x, BigInteger y) {
795− return (x.compareTo(y) <= 0 ? 1 : 0);
796− }
797− public static byte[] LLe(byte[] x, byte[] y) {
798− byte[] res = new byte[x.length];
799− for (int i = 0; i < x.length; ++i) {
800− res[i] = (byte)(x[i] <= y[i] ? -1 : 0);
801− }
802− return res;
803− }
804− public static short[] LLe(short[] x, short[] y) {
805− short[] res = new short[x.length];
806− for (int i = 0; i < x.length; ++i) {
807− res[i] = (short)(x[i] <= y[i] ? -1 : 0);
808− }
809− return res;
810− }
811− public static int[] LLe(int[] x, int[] y) {
812− int[] res = new int[x.length];
813− for (int i = 0; i < x.length; ++i) {
814− res[i] = (x[i] <= y[i] ? -1 : 0);
815− }
816− return res;
817− }
818− public static long[] LLe(long[] x, long[] y) {
819− long[] res = new long[x.length];
820− for (int i = 0; i < x.length; ++i) {
821− res[i] = (x[i] <= y[i] ? -1 : 0);
822− }
823− return res;
824− }
825−
826− public static int LGt(byte x, byte y) {
827− return (x > y ? 1 : 0);
828− }
829− public static int LGt(char x, char y) {
830− return (x > y ? 1 : 0);
831− }
832− public static int LGt(short x, short y) {
833− return (x > y ? 1 : 0);
834− }
835− public static int LGt(int x, int y) {
836− return (x > y ? 1 : 0);
837− }
838− public static int LGt(long x, long y) {
839− return (x > y ? 1 : 0);
840− }
841− public static double LGt(double x, double y) {
842− return (x > y ? 1 : 0);
843− }
844− public static int LGt(BigInteger x, BigInteger y) {
845− return (x.compareTo(y) > 0 ? 1 : 0);
846− }
847− public static byte[] LGt(byte[] x, byte[] y) {
848− byte[] res = new byte[x.length];
849− for (int i = 0; i < x.length; ++i) {
850− res[i] = (byte)(x[i] > y[i] ? -1 : 0);
851− }
852− return res;
853− }
854− public static short[] LGt(short[] x, short[] y) {
855− short[] res = new short[x.length];
856− for (int i = 0; i < x.length; ++i) {
857− res[i] = (short)(x[i] > y[i] ? -1 : 0);
858− }
859− return res;
860− }
861− public static int[] LGt(int[] x, int[] y) {
862− int[] res = new int[x.length];
863− for (int i = 0; i < x.length; ++i) {
864− res[i] = (x[i] > y[i] ? -1 : 0);
865− }
866− return res;
867− }
868− public static long[] LGt(long[] x, long[] y) {
869− long[] res = new long[x.length];
870− for (int i = 0; i < x.length; ++i) {
871− res[i] = (x[i] > y[i] ? -1 : 0);
872− }
873− return res;
874− }
875−
876− public static int LGe(byte x, byte y) {
877− return (x >= y ? 1 : 0);
878− }
879− public static int LGe(char x, char y) {
880− return (x >= y ? 1 : 0);
881− }
882− public static int LGe(short x, short y) {
883− return (x >= y ? 1 : 0);
884− }
885− public static int LGe(int x, int y) {
886− return (x >= y ? 1 : 0);
887− }
888− public static int LGe(long x, long y) {
889− return (x >= y ? 1 : 0);
890− }
891− public static double LGe(double x, double y) {
892− return (x >= y ? 1 : 0);
893− }
894− public static int LGe(BigInteger x, BigInteger y) {
895− return (x.compareTo(y) >= 0 ? 1 : 0);
896− }
897− public static byte[] LGe(byte[] x, byte[] y) {
898− byte[] res = new byte[x.length];
899− for (int i = 0; i < x.length; ++i) {
900− res[i] = (byte)(x[i] >= y[i] ? -1 : 0);
901− }
902− return res;
903− }
904− public static short[] LGe(short[] x, short[] y) {
905− short[] res = new short[x.length];
906− for (int i = 0; i < x.length; ++i) {
907− res[i] = (short)(x[i] >= y[i] ? -1 : 0);
908− }
909− return res;
910− }
911− public static int[] LGe(int[] x, int[] y) {
912− int[] res = new int[x.length];
913− for (int i = 0; i < x.length; ++i) {
914− res[i] = (x[i] >= y[i] ? -1 : 0);
915− }
916− return res;
917− }
918− public static long[] LGe(long[] x, long[] y) {
919− long[] res = new long[x.length];
920− for (int i = 0; i < x.length; ++i) {
921− res[i] = (x[i] >= y[i] ? -1 : 0);
922− }
923− return res;
924− }
925−
926−
927− public static short LSExtIT16(byte x) {
928− return (short)x;
929− }
930− public static int LSExtIT32(byte x) {
931− return (int)x;
932− }
933− public static long LSExtIT64(byte x) {
934− return (long)x;
935− }
936− public static BigInteger LSExtITBig(byte x) {
937− return BigInteger.valueOf(x);
938− }
939− public static short[] LSExtITVec16(byte[] x) {
940− short[] res = new short[x.length];
941− for (int i = 0; i < res.length; ++i) {
942− res[i] = (short)x[i];
943− }
944− return res;
945− }
946− public static int[] LSExtITVec32(byte[] x) {
947− int[] res = new int[x.length];
948− for (int i = 0; i < res.length; ++i) {
949− res[i] = (int)x[i];
950− }
951− return res;
952− }
953− public static long[] LSExtITVec64(byte[] x) {
954− long[] res = new long[x.length];
955− for (int i = 0; i < res.length; ++i) {
956− res[i] = (long)x[i];
957− }
958− return res;
959− }
960−
961− public static short LSExtIT16(char x) {
962− return (short)x;
963− }
964− public static int LSExtIT32(char x) {
965− return (int)x;
966− }
967− public static long LSExtIT64(char x) {
968− return (long)x;
969− }
970− public static BigInteger LSExtITBig(char x) {
971− return BigInteger.valueOf(x);
972− }
973−
974− public static int LSExtIT32(short x) {
975− return (int)x;
976− }
977− public static long LSExtIT64(short x) {
978− return (long)x;
979− }
980− public static BigInteger LSExtITBig(short x) {
981− return BigInteger.valueOf(x);
982− }
983− public static int[] LSExtITVec32(short[] x) {
984− int[] res = new int[x.length];
985− for (int i = 0; i < res.length; ++i) {
986− res[i] = (int)x[i];
987− }
988− return res;
989− }
990− public static long[] LSExtITVec64(short[] x) {
991− long[] res = new long[x.length];
992− for (int i = 0; i < res.length; ++i) {
993− res[i] = (long)x[i];
994− }
995− return res;
996− }
997−
998− public static long LSExtIT64(int x) {
999− return (long)x;
1000− }
1001− public static BigInteger LSExtITBig(int x) {
1002− return BigInteger.valueOf(x);
1003− }
1004− public static long[] LSExtITVec64(int[] x) {
1005− long[] res = new long[x.length];
1006− for (int i = 0; i < res.length; ++i) {
1007− res[i] = (long)x[i];
1008− }
1009− return res;
1010− }
1011− public static BigInteger LSExtITBig(long x) {
1012− return BigInteger.valueOf(x);
1013− }
1014−
1015−
1016− public static short LZExtIT16(byte x) {
1017− return (short)(x < 0 ? x + (2 << 7) : x);
1018− }
1019− public static int LZExtIT32(byte x) {
1020− return (int)(x < 0 ? x + (2 << 7) : x);
1021− }
1022− public static long LZExtIT64(byte x) {
1023− return (long)(x < 0 ? x + (2 << 7) : x);
1024− }
1025− public static BigInteger LZExtITBig(byte x) {
1026− return BigInteger.valueOf(x < 0 ? x + (2 << 7) : x);
1027− }
1028− public static char LZExtITChar(byte x) {
1029− return (char)(x < 0 ? x + (2 << 7) : x);
1030− }
1031− public static short[] LZExtITVec16(byte[] x) {
1032− short[] res = new short[x.length];
1033− for (int i = 0; i < res.length; ++i) {
1034− res[i] = (short)(x[i] < 0 ? x[i] + (2 << 7) : x[i]);
1035− }
1036− return res;
1037− }
1038− public static int[] LZExtITVec32(byte[] x) {
1039− int[] res = new int[x.length];
1040− for (int i = 0; i < res.length; ++i) {
1041− res[i] = (int)(x[i] < 0 ? x[i] + (2 << 7) : x[i]);
1042− }
1043− return res;
1044− }
1045− public static long[] LZExtITVec64(byte[] x) {
1046− long[] res = new long[x.length];
1047− for (int i = 0; i < res.length; ++i) {
1048− res[i] = (long)(x[i] < 0 ? x[i] + (2 << 7) : x[i]);
1049− }
1050− return res;
1051− }
1052−
1053− public static int LZExtIT32(short x) {
1054− return (int)(x < 0 ? x + (2 << 15) : x);
1055− }
1056− public static long LZExtIT64(short x) {
1057− return (long)(x < 0 ? x + (2 << 15) : x);
1058− }
1059− public static BigInteger LZExtITBig(short x) {
1060− return BigInteger.valueOf(x < 0 ? x + (2 << 15) : x);
1061− }
1062− public static char LZExtITChar(short x) {
1063− return (char)(x < 0 ? x + (2 << 15) : x);
1064− }
1065− public static int[] LZExtITVec32(short[] x) {
1066− int[] res = new int[x.length];
1067− for (int i = 0; i < res.length; ++i) {
1068− res[i] = (int)(x[i] < 0 ? x[i] + (2 << 15) : x[i]);
1069− }
1070− return res;
1071− }
1072− public static long[] LZExtITVec64(short[] x) {
1073− long[] res = new long[x.length];
1074− for (int i = 0; i < res.length; ++i) {
1075− res[i] = (long)(x[i] < 0 ? x[i] + (2 << 15) : x[i]);
1076− }
1077− return res;
1078− }
1079−
1080− public static long LZExtIT64(int x) {
1081− return (long)(x < 0 ? ((long)x) + (2l << 31) : x);
1082− }
1083− public static BigInteger LZExtITBig(int x) {
1084− return BigInteger.valueOf(x < 0 ? ((long)x) + (2l << 31) : x);
1085− }
1086− public static char LZExtITChar(int x) {
1087− return (char)(x < 0 ? ((long)x) + (2l << 31) : x);
1088− }
1089− public static long[] LZExtITVec64(int[] x) {
1090− long[] res = new long[x.length];
1091− for (int i = 0; i < res.length; ++i) {
1092− res[i] = (long)(((long)x[i]) < 0 ? x[i] + (2l << 31) : x[i]);
1093− }
1094− return res;
1095− }
1096−
1097− public static BigInteger LZExtITBig(long x) {
1098− return (x < 0 ? BigInteger.valueOf(x).add(BigInteger.valueOf(2).shiftLeft(61)) : BigInteger.valueOf(x));
1099− }
1100− public static char LZExtITChar(long x) {
1101− return (char)((x < 0 ? BigInteger.valueOf(x).add(BigInteger.valueOf(2).shiftLeft(61)) : BigInteger.valueOf(x)).intValue());
1102− }
1103−
1104− public static byte LTruncIT8(short x) {
1105− return (byte)x;
1106− }
1107− public static byte[] LTruncITVec8(short[] x) {
1108− byte[] res = new byte[x.length];
1109− for (int i = 0; i < res.length; ++i) {
1110− res[i] = (byte)x[i];
1111− }
1112− return res;
1113− }
1114− public static char LTruncITChar(short x) {
1115− return (char)x;
1116− }
1117−
1118− public static byte LTruncIT8(int x) {
1119− return (byte)x;
1120− }
1121− public static short LTruncIT16(int x) {
1122− return (short)x;
1123− }
1124− public static byte[] LTruncITVec8(int[] x) {
1125− byte[] res = new byte[x.length];
1126− for (int i = 0; i < res.length; ++i) {
1127− res[i] = (byte)x[i];
1128− }
1129− return res;
1130− }
1131− public static short[] LTruncITVec16(int[] x) {
1132− short[] res = new short[x.length];
1133− for (int i = 0; i < res.length; ++i) {
1134− res[i] = (short)x[i];
1135− }
1136− return res;
1137− }
1138− public static char LTruncITChar(int x) {
1139− return (char)x;
1140− }
1141−
1142− public static byte LTruncIT8(long x) {
1143− return (byte)x;
1144− }
1145− public static short LTruncIT16(long x) {
1146− return (short)x;
1147− }
1148− public static int LTruncIT32(long x) {
1149− return (int)x;
1150− }
1151− public static byte[] LTruncITVec8(long[] x) {
1152− byte[] res = new byte[x.length];
1153− for (int i = 0; i < res.length; ++i) {
1154− res[i] = (byte)x[i];
1155− }
1156− return res;
1157− }
1158− public static short[] LTruncITVec16(long[] x) {
1159− short[] res = new short[x.length];
1160− for (int i = 0; i < res.length; ++i) {
1161− res[i] = (short)x[i];
1162− }
1163− return res;
1164− }
1165− public static int[] LTruncITVec32(long[] x) {
1166− int[] res = new int[x.length];
1167− for (int i = 0; i < res.length; ++i) {
1168− res[i] = (int)x[i];
1169− }
1170− return res;
1171− }
1172− public static char LTruncITChar(long x) {
1173− return (char)x;
1174− }
1175−
1176− public static byte LTruncIT8(BigInteger x) {
1177− return x.byteValue();
1178− }
1179− public static short LTruncIT16(BigInteger x) {
1180− return x.shortValue();
1181− }
1182− public static int LTruncIT32(BigInteger x) {
1183− return x.intValue();
1184− }
1185− public static long LTruncIT64(BigInteger x) {
1186− return x.longValue();
1187− }
1188− public static char LTruncITChar(BigInteger x) {
1189− return (char)x.intValue();
1190− }
1191−
1192− public static byte LTruncIT8(char x) {
1193− return (byte)x;
1194− }
1195− public static short LTruncIT16(char x) {
1196− return (short)x;
1197− }
1198− public static int LTruncIT32(char x) {
1199− return (int)x;
1200− }
1201− public static long LTruncIT64(char x) {
1202− return (int)x;
1203− }
1204− public static BigInteger LTruncITBig(char x) {
1205− return BigInteger.valueOf(x);
1206− }
1207−
1208−
1209− public static double LFExp(double x) {
1210− return Math.exp(x);
1211− }
1212− public static double LFLog(double x) {
1213− return Math.log(x);
1214− }
1215− public static double LFSin(double x) {
1216− return Math.sin(x);
1217− }
1218− public static double LFCos(double x) {
1219− return Math.cos(x);
1220− }
1221− public static double LFTan(double x) {
1222− return Math.tan(x);
1223− }
1224− public static double LFASin(double x) {
1225− return Math.asin(x);
1226− }
1227− public static double LFACos(double x) {
1228− return Math.acos(x);
1229− }
1230− public static double LFATan(double x) {
1231− return Math.atan(x);
1232− }
1233− public static double LFSqrt(double x) {
1234− return Math.sqrt(x);
1235− }
1236− public static double LFFloor(double x) {
1237− return Math.floor(x);
1238− }
1239− public static double LFCeil(double x) {
1240− return Math.ceil(x);
1241− }
1242−
1243− public static byte[] LMkVec(byte ... x) {
1244− return x;
1245− }
1246− public static short[] LMkVec(short ... x) {
1247− return x;
1248− }
1249− public static int[] LMKVec(int ... x) {
1250− return x;
1251− }
1252− public static long[] LMKVec(long ... x) {
1253− return x;
1254− }
1255−
1256− public static byte LIdxVec(byte[] x, int y) {
1257− return x[y];
1258− }
1259− public static short LIdxVec(short[] x, int y) {
1260− return x[y];
1261− }
1262− public static int LIdxVec(int[] x, int y) {
1263− return x[y];
1264− }
1265− public long LIdxVec(long[] x, int y) {
1266− return x[y];
1267− }
1268−
1269− public static byte[] LUpdateVec(byte[] x, int y, byte z) {
1270− x[y] = z;
1271− return x;
1272− }
1273− public static short[] LUpdateVec(short[] x, int y, short z) {
1274− x[y] = z;
1275− return x;
1276− }
1277− public static int[] LUpdateVec(int[] x, int y, int z) {
1278− x[y] = z;
1279− return x;
1280− }
1281− public long[] LUpdateVec(long[] x, int y, long z) {
1282− x[y] = z;
1283− return x;
1284− }
1285−
1286− public static String LStrConcat(String ... args) {
1287− StringBuilder builder = new StringBuilder();
1288− for (String arg : args) {
1289− builder.append(arg);
1290− }
1291− return builder.toString();
1292− }
1293−
1294− public static int LStrLt(String x, String y) {
1295− return (x.compareTo(y) < 0 ? 1 : 0);
1296− }
1297−
1298− public static int LStrEq(String x, String y) {
1299− return (x.equals(y) ? 1 : 0);
1300− }
1301−
1302− public static int LStrLen(String x) {
1303− return x.length();
1304− }
1305−
1306− public static double LIntFloat(byte x) {
1307− return (double)x;
1308− }
1309− public static double LIntFloat(char x) {
1310− return (double)x;
1311− }
1312− public static double LIntFloat(short x) {
1313− return (double)x;
1314− }
1315− public static double LIntFloat(int x) {
1316− return (double)x;
1317− }
1318− public static double LIntFloat(long x) {
1319− return (double)x;
1320− }
1321− public static double LIntFloat(BigInteger x) {
1322− return x.doubleValue();
1323− }
1324−
1325− public static byte LFloatIntIT8(double x) {
1326− return (byte)x;
1327− }
1328− public static short LFloatIntIT16(double x) {
1329− return (short)x;
1330− }
1331− public static int LFloatIntIT32(double x) {
1332− return (int)x;
1333− }
1334− public static long LFloatIntIT64(double x) {
1335− return (long)x;
1336− }
1337− public static BigInteger LFloatIntITBig(double x) {
1338− return BigInteger.valueOf((long)x);
1339− }
1340− public static char LFloatIntITChar(double x) {
1341− return (char)x;
1342− }
1343−
1344− public static String LIntStr(byte x) {
1345− return Byte.toString(x);
1346− }
1347− public static String LIntStr(char x) {
1348− return Character.toString(x);
1349− }
1350− public static String LIntStr(short x) {
1351− return Short.toString(x);
1352− }
1353− public static String LIntStr(int x) {
1354− return Integer.toString(x);
1355− }
1356− public static String LIntStr(long x) {
1357− return Long.toString(x);
1358− }
1359− public static String LIntStr(BigInteger x) {
1360− return x.toString();
1361− }
1362− public static byte LStrIntIT8(String x) {
1363− return Byte.parseByte(x);
1364− }
1365− public static short LStrIntIT16(String x) {
1366− return Short.parseShort(x);
1367− }
1368− public static int LStrIntIT32(String x) {
1369− return Integer.parseInt(x);
1370− }
1371− public static long LStrIntIT64(String x) {
1372− return Long.parseLong(x);
1373− }
1374− public static BigInteger LStrIntITBig(String x) {
1375− return new BigInteger(x);
1376− }
1377− public static char LStrIntITChar(String x) {
1378− return x.charAt(0);
1379− }
1380−
1381− public static String LFloatStr(double x) {
1382− return Double.toString(x);
1383− }
1384− public static double LStrFloat(String x) {
1385− return Double.parseDouble(x);
1386− }
1387−
1388− public static char LIntCh(byte x) {
1389− return (char)x;
1390− }
1391− public static char LIntCh(char x) {
1392− return x;
1393− }
1394− public static char LIntCh(short x) {
1395− return (char)x;
1396− }
1397− public static char LIntCh(int x) {
1398− return (char)x;
1399− }
1400− public static char LIntCh(long x) {
1401− return (char)x;
1402− }
1403− public static char LIntCh(BigInteger x) {
1404− return (char)(x.intValue());
1405− }
1406− public static byte LChIntIT8(char x) {
1407− return (byte)x;
1408− }
1409− public static short LChIntIT16(char x) {
1410− return (short)x;
1411− }
1412− public static int LChIntIT32(char x) {
1413− return (int)x;
1414− }
1415− public static long LChIntIT64(char x) {
1416− return (long)x;
1417− }
1418− public static BigInteger LChIntITBig(char x) {
1419− return BigInteger.valueOf((long)x);
1420− }
1421−
1422− public static void LPrintNum(Object x) {
1423− System.out.print(x);
1424− }
1425− public static void LPrintStr(String x) {
1426− System.out.print(x);
1427− }
1428− public static String LReadStr(Object x) {
1429− try {
1430− return ForeignPrimitives.idris_readStr(x);
1431− } catch (IOException ex) {
1432− throw new RuntimeException(ex);
1433− }
1434− }
1435−
1436− public static char LStrHead(String x) {
1437− return x.charAt(0);
1438− }
1439− public static String LStrTail(String x) {
1440− return x.substring(1);
1441− }
1442− public static String LStrCons(char x, String y) {
1443− return String.format("%c%s", x, y);
1444− }
1445− public static char LStrIndex(String x, int y) {
1446− return x.charAt(y);
1447− }
1448− public static String LStrRev(String x) {
1449− return new StringBuffer(x).reverse().toString();
1450− }
1451−
1452− public static InputStream LStdIn() {
1453− return System.in;
1454− }
1455− public static OutputStream LStdOut() {
1456− return System.out;
1457− }
1458− public static OutputStream LStdErr() {
1459− return System.err;
1460− }
1461− public static Thread LVMPtr() {
1462− return Thread.currentThread();
1463− }
1464−}
src/IRTS/CodegenJava.hs+2−4
@@ -268,8 +268,7 @@ mkCompilationUnit :: [(Name, SExp)] -> [(Name, SDecl)] -> [String] -> FilePath -
268268mkCompilationUnit globalInit defs hdrs out = do
269269 clsName <- mkClassName out
270270 CompilationUnit Nothing ( [ ImportDecl False idrisRts True
271− , ImportDecl True idrisForeign True
272− , ImportDecl False idrisPrimFn False
271+ , ImportDecl True idrisPrelude True
273272 , ImportDecl False bigInteger False
274273 , ImportDecl False runtimeException False
275274 ] ++ otherHdrs
@@ -277,8 +276,7 @@ mkCompilationUnit globalInit defs hdrs out = do
277276 <$> mkTypeDecl clsName globalInit defs
278277 where
279278 idrisRts = J.Name $ map Ident ["org", "idris", "rts"]
280− idrisForeign = J.Name $ map Ident ["org", "idris", "rts", "ForeignPrimitives"]
281− idrisPrimFn = J.Name $ map Ident ["org", "idris", "rts", "PrimFn"]
279+ idrisPrelude = J.Name $ map Ident ["org", "idris", "rts", "Prelude"]
282280 bigInteger = J.Name $ map Ident ["java", "math", "BigInteger"]
283281 runtimeException = J.Name $ map Ident ["java", "lang", "RuntimeException"]
284282 otherHdrs = map ( (\ name -> ImportDecl False name False)