Skip to content

Commit

Permalink
Build 0.5.1 for JVM
Browse files Browse the repository at this point in the history
  • Loading branch information
mmhelloworld committed Jan 2, 2022
1 parent cde992c commit 1b8fe03
Show file tree
Hide file tree
Showing 43 changed files with 252 additions and 739 deletions.
542 changes: 0 additions & 542 deletions .github/workflows/ci-idris2.yml

This file was deleted.

21 changes: 0 additions & 21 deletions .github/workflows/ci-sphinx.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
run: echo "PREFIX=$IDRIS2_PREFIX" >> $GITHUB_ENV
- name: Download previous version
run: |
wget https://github.com/mmhelloworld/idris-jvm/releases/download/v0.4.0-rc.4/idris2-0.4.0-SNAPSHOT.zip
wget https://github.com/mmhelloworld/idris-jvm/releases/download/v0.4.0/idris2-0.4.0-SNAPSHOT.zip
unzip idris2-0.4.0-SNAPSHOT.zip -d $HOME/bin
echo "::add-path::$HOME/bin/idris2-0.4.0-SNAPSHOT/bin"
- name: Build
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pre-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
run: echo "PREFIX=$IDRIS2_PREFIX" >> $GITHUB_ENV
- name: Download previous version
run: |
wget https://github.com/mmhelloworld/idris-jvm/releases/download/v0.4.0-rc.4/idris2-0.4.0-SNAPSHOT.zip
wget https://github.com/mmhelloworld/idris-jvm/releases/download/v0.4.0/idris2-0.4.0-SNAPSHOT.zip
unzip idris2-0.4.0-SNAPSHOT.zip -d $HOME/bin
echo "::add-path::$HOME/bin/idris2-0.4.0-SNAPSHOT/bin"
- name: Build
Expand All @@ -42,4 +42,4 @@ jobs:
prerelease: true
title: "Development Build"
files: |
idris-jvm-compiler/target/idris2-0.4.0-SNAPSHOT.zip
idris-jvm-compiler/target/idris2-0.5.1-SNAPSHOT.zip
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
run: echo "PREFIX=$IDRIS2_PREFIX" >> $GITHUB_ENV
- name: Download previous version
run: |
wget https://github.com/mmhelloworld/idris-jvm/releases/download/v0.4.0-rc.4/idris2-0.4.0-SNAPSHOT.zip
wget https://github.com/mmhelloworld/idris-jvm/releases/download/v0.4.0/idris2-0.4.0-SNAPSHOT.zip
unzip idris2-0.4.0-SNAPSHOT.zip -d $HOME/bin
echo "::add-path::$HOME/bin/idris2-0.4.0-SNAPSHOT/bin"
- name: Build
Expand All @@ -39,6 +39,6 @@ jobs:
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
prerelease: false
title: "Release 0.4.0"
title: "Release 0.5.1-rc.1"
files: |
idris-jvm-compiler/target/idris2-0.4.0-SNAPSHOT.zip
idris-jvm-compiler/target/idris2-0.5.1-SNAPSHOT.zip
2 changes: 1 addition & 1 deletion idris-jvm-assembler/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.github.mmhelloworld</groupId>
<artifactId>idris-jvm</artifactId>
<version>0.4.0-SNAPSHOT</version>
<version>0.5.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ public void classCodeEnd(String outputDirectory, String outputFile, String mainC

public void interpret(String mainClass) {
Map<String, byte[]> classes = getClassNameAndClassWriters()
.collect(toMap(Entry::getKey, entry -> entry.getValue().toByteArray()));
.collect(toMap(Entry::getKey, entry -> entry.getValue().toByteArray(),
(first, second) -> second));
try {
new InterpreterClassLoader(classes)
.loadClass(mainClass)
Expand Down
2 changes: 1 addition & 1 deletion idris-jvm-compiler/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.github.mmhelloworld</groupId>
<artifactId>idris-jvm</artifactId>
<version>0.4.0-SNAPSHOT</version>
<version>0.5.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
4 changes: 2 additions & 2 deletions idris-jvm-compiler/src/assembly/bin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
</formats>
<fileSets>
<fileSet>
<directory>${env.IDRIS2_PREFIX}/idris2-0.4.0</directory>
<outputDirectory>lib/idris2-0.4.0</outputDirectory>
<directory>${env.IDRIS2_PREFIX}/idris2-0.5.1</directory>
<outputDirectory>lib/idris2-0.5.1</outputDirectory>
</fileSet>
<fileSet>
<directory>${project.build.directory}/assembly</directory>
Expand Down
2 changes: 1 addition & 1 deletion idris-jvm-runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.github.mmhelloworld</groupId>
<artifactId>idris-jvm</artifactId>
<version>0.4.0-SNAPSHOT</version>
<version>0.5.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ public int seekLine() {

public void handleException(Exception e) {
this.exception = e;
Runtime.setException(exception);
Runtime.setErrorNumber(getErrorNumber(e));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static int createDirectory(String pathString) {
java.nio.file.Files.createDirectory(Paths.createPath(pathString));
return 0;
} catch (Exception exception) {
Runtime.setErrorNumber(ChannelIo.getErrorNumber(exception));
handleException(exception);
return -1;
}
}
Expand Down Expand Up @@ -51,40 +51,48 @@ public static boolean deleteIfExists(Path path) {
}

public static void delete(String pathString) {
Runtime.setErrorNumber(0);
try {
Files.delete(Paths.createPath(pathString));
} catch (IOException exception) {
Runtime.setErrorNumber(ChannelIo.getErrorNumber(exception));
handleException(exception);
}
}

public static Object openDirectory(String name) {
Runtime.setErrorNumber(0);
Path path = Paths.createPath(name);
try {
DirectoryStream<Path> stream = newDirectoryStream(path);
return new Directory(path, stream, stream.iterator());
} catch (Exception exception) {
Runtime.setErrorNumber(ChannelIo.getErrorNumber(exception));
handleException(exception);
return null;
}
}

public static void closeDirectory(Object directory) {
Runtime.setErrorNumber(0);
try {
if (directory != null) {
((Directory) directory).getStream().close();
}
} catch (IOException exception) {
Runtime.setErrorNumber(ChannelIo.getErrorNumber(exception));
handleException(exception);
}
}

private static void handleException(Exception exception) {
Runtime.setException(exception);
Runtime.setErrorNumber(ChannelIo.getErrorNumber(exception));
}

public static Object getNextDirectoryEntry(Object directory) {
Runtime.setErrorNumber(0);
Iterator<Path> iterator = ((Directory) directory).getIterator();
if (iterator.hasNext()) {
return iterator.next().getFileName().toString();
} else {
Runtime.setErrorNumber(2);
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static IdrisSocket create(int socketFamily, int socketType, int protocolN
return null;
}
} catch (Exception exception) {
Runtime.setErrorNumber(getErrorNumber(exception));
handleException(exception);
return null;
}
}
Expand Down Expand Up @@ -346,7 +346,7 @@ private long withExceptionHandling(LongSupplierE<? extends Exception> action, lo
}
}

private void handleException(Exception e) {
private static void handleException(Exception e) {
Runtime.setException(e);
Runtime.setErrorNumber(getErrorNumber(e));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ public static int getPid() {
return Integer.parseInt(ManagementFactory.getRuntimeMXBean().getName().split("@")[0]);
}

public static int getAvailableProcessors() {
return java.lang.Runtime.getRuntime().availableProcessors();
}

public static <T> T crash(String message) {
throw new RuntimeException(message);
}
Expand All @@ -86,13 +90,20 @@ static void setException(Exception exception) {
}

static void setErrorNumber(int errorNumber) {
if (errorNumber == 0) {
setException(null);
}
ERROR_NUMBER.set(errorNumber);
}

public static int getEagain() {
return EAGAIN;
}

public static String getErrorMessage(int errorNumber) {
return "Error code: " + errorNumber;
}

public static void free(Object object) {
}

Expand Down
2 changes: 1 addition & 1 deletion idris-jvm-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.github.mmhelloworld</groupId>
<artifactId>idris-jvm</artifactId>
<version>0.4.0-SNAPSHOT</version>
<version>0.5.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
4 changes: 4 additions & 0 deletions libs/base/System/Errno.idr
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
module System.Errno

import System.FFI

%default total

%foreign "C:idris2_getErrno, libidris2_support, idris_support.h"
jvm' runtimeClass "getErrorNumber" "java/lang/Object" "int"
prim__getErrno : PrimIO Int

%foreign "C:idris2_strerror, libidris2_support, idris_support.h"
"node:lambda:errno=>'Error code: '+errno"
jvm' runtimeClass "getErrorMessage" "int" "String"
prim__strerror : Int -> PrimIO String

||| Fetch libc `errno` global variable.
Expand Down
25 changes: 12 additions & 13 deletions libs/base/System/FFI.idr
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ setField : {s : _} -> Struct s fs -> (n : String) ->
{auto fieldok : FieldType n ty fs} -> ty -> IO ()
setField s n val = primIO (prim__setField s n fieldok val)

public export
runtimeClass : String
runtimeClass = "io/github/mmhelloworld/idrisjvm/runtime/Runtime"

public export
jvm' : String -> String -> String -> String -> String
jvm' className methodName arguments ret = "jvm:" ++ methodName ++ "(" ++ arguments ++ " " ++ ret ++ ")," ++ className

public export
jvm : String -> String -> String
jvm className methodName = "jvm:" ++ methodName ++ "," ++ className

%foreign "C:idris2_malloc, libidris2_support, idris_memory.h"
"jvm:malloc(int java/lang/Object),io/github/mmhelloworld/idrisjvm/runtime/IdrisSystem"
prim__malloc : (size : Int) -> PrimIO AnyPtr
Expand All @@ -52,16 +64,3 @@ malloc size = primIO $ prim__malloc size
export
free : HasIO io => AnyPtr -> io ()
free ptr = primIO $ prim__free ptr

public export
jvm' : String -> String -> String -> String -> String
jvm' className methodName arguments ret = "jvm:" ++ methodName ++ "(" ++
arguments ++ " " ++ ret ++ ")," ++ className

public export
jvm : String -> String -> String
jvm className methodName = "jvm:" ++ methodName ++ "," ++ className

public export
runtimeClass : String
runtimeClass = "io/github/mmhelloworld/idrisjvm/runtime/Runtime"
4 changes: 2 additions & 2 deletions libs/base/System/File/Buffer.idr
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import Data.Buffer

%foreign support "idris2_readBufferData"
"node:lambda:(f,b,l,m) => require('fs').readSync(f.fd,b,l,m)"
"jvm:readFromFile(java/nio/channels/ReadableByteChannel io/github/mmhelloworld/idris2/runtime/IdrisBuffer int int int),io/github/mmhelloworld/idris2/runtime/IdrisBuffer"
"jvm:readFromFile(java/nio/channels/ReadableByteChannel io/github/mmhelloworld/idrisjvm/runtime/IdrisBuffer int int int),io/github/mmhelloworld/idrisjvm/runtime/IdrisBuffer"
prim__readBufferData : FilePtr -> Buffer -> (offset : Int) -> (maxbytes : Int) -> PrimIO Int

%foreign support "idris2_writeBufferData"
"node:lambda:(f,b,l,m) => require('fs').writeSync(f.fd,b,l,m)"
"jvm:writeToFile(java/nio/channels/WritableByteChannel io/github/mmhelloworld/idris2/runtime/IdrisBuffer int int int),io/github/mmhelloworld/idris2/runtime/IdrisBuffer"
"jvm:writeToFile(java/nio/channels/WritableByteChannel io/github/mmhelloworld/idrisjvm/runtime/IdrisBuffer int int int),io/github/mmhelloworld/idrisjvm/runtime/IdrisBuffer"
prim__writeBufferData : FilePtr -> Buffer -> (offset : Int) -> (maxbytes : Int) -> PrimIO Int

export
Expand Down
6 changes: 6 additions & 0 deletions libs/base/System/File/Error.idr
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@ import System.Errno

import System.File.Support
import public System.File.Types
import System.FFI

%default total

fileClass : String
fileClass = "io/github/mmhelloworld/idrisjvm/runtime/ChannelIo"

%foreign support "idris2_fileError"
"node:lambda:x=>(x===1?1:0)"
jvm' fileClass "getErrorNumber" fileClass "int"
prim__error : FilePtr -> PrimIO Int

%foreign support "idris2_fileErrno"
"node:support:fileErrno,support_system_file"
jvm' runtimeClass "getErrorNumber" "java/lang/Object" "int"
prim__fileErrno : PrimIO Int

public export
Expand Down
6 changes: 6 additions & 0 deletions libs/base/System/File/Handle.idr
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@ import public System.File.Error
import public System.File.Mode
import System.File.Support
import public System.File.Types
import System.FFI

%default total

fileClass : String
fileClass = "io/github/mmhelloworld/idrisjvm/runtime/ChannelIo"

%foreign support "idris2_openFile"
"node:support:openFile,support_system_file"
jvm' fileClass "open" "String String" fileClass
prim__open : String -> String -> PrimIO FilePtr

%foreign support "idris2_closeFile"
"node:lambda:(fp) => require('fs').closeSync(fp.fd)"
jvm' fileClass "close" fileClass "void"
prim__close : FilePtr -> PrimIO ()

export
Expand Down
9 changes: 9 additions & 0 deletions libs/base/System/File/Meta.idr
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,33 @@ module System.File.Meta
import System.File.Handle
import System.File.Support
import public System.File.Types
import System.FFI

%default total

fileClass : String
fileClass = "io/github/mmhelloworld/idrisjvm/runtime/ChannelIo"

%foreign support "idris2_fileSize"
"node:lambda:fp=>require('fs').fstatSync(fp.fd).size"
jvm' fileClass "size" fileClass "int"
prim__fileSize : FilePtr -> PrimIO Int

%foreign support "idris2_fileSize"
jvm' fileClass "size" fileClass "int"
prim__fPoll : FilePtr -> PrimIO Int

%foreign support "idris2_fileAccessTime"
jvm' fileClass "getAccessTime" fileClass "int"
prim__fileAccessTime : FilePtr -> PrimIO Int

%foreign support "idris2_fileModifiedTime"
"node:lambda:fp=>require('fs').fstatSync(fp.fd).mtimeMs / 1000"
jvm' fileClass "getModifiedTime" fileClass "int"
prim__fileModifiedTime : FilePtr -> PrimIO Int

%foreign support "idris2_fileStatusTime"
jvm' fileClass "getStatusTime" fileClass "int"
prim__fileStatusTime : FilePtr -> PrimIO Int

%foreign support "idris2_fileIsTTY"
Expand Down
Loading

0 comments on commit 1b8fe03

Please sign in to comment.