Skip to content

Commit

Permalink
Initial support for method and class export to Java #140
Browse files Browse the repository at this point in the history
  • Loading branch information
mmhelloworld committed Jan 31, 2024
1 parent d51a3d3 commit 005c2bc
Show file tree
Hide file tree
Showing 19 changed files with 780 additions and 272 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
env:
IDRIS2_TESTS_CG: jvm
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
PREVIOUS_VERSION: 0.6.0
PREVIOUS_VERSION: 0.6.0.4

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pre-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
env:
IDRIS2_TESTS_CG: jvm
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
PREVIOUS_VERSION: 0.6.0
PREVIOUS_VERSION: 0.6.0.4

jobs:
pre-release:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ on:
env:
IDRIS2_TESTS_CG: jvm
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
PREVIOUS_VERSION: 0.6.0
PREVIOUS_VERSION: 0.6.0.4

jobs:
release:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
Expand Down Expand Up @@ -150,7 +149,7 @@ public void interpret(String mainClass, String outputDirectory) throws IOExcepti
public void writeClass(String className, ClassWriter classWriter, String outputClassFileDir) {
File outFile = new File(outputClassFileDir, className + ".class");
new File(outFile.getParent()).mkdirs();
try (OutputStream out = new FileOutputStream(outFile)) {
try (OutputStream out = newOutputStream(outFile.toPath())) {
out.write(classWriter.toByteArray());
} catch (Exception exception) {
exception.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1297,15 +1297,18 @@ private void handleCreateMethod(MethodVisitor targetMethodVisitor, List<Annotati
for (int index = 0; index < parametersAnnotations.size(); index++) {
int parameterIndex = index;
List<Annotation> parameterAnnotations = parametersAnnotations.get(parameterIndex);
parameterAnnotations.forEach(paramAnnotation -> {
final AnnotationVisitor av =
targetMethodVisitor.visitParameterAnnotation(parameterIndex, paramAnnotation.getName(), true);
paramAnnotation.getProperties().forEach(prop -> visitAnnotationProperty(av, prop.getName(),
prop.getValue()));
av.visitEnd();
});
parameterAnnotations.forEach(paramAnnotation ->
addParameterAnnotation(targetMethodVisitor, parameterIndex, paramAnnotation));
}
}

private void addParameterAnnotation(MethodVisitor targetMethodVisitor, int parameterIndex,
Annotation paramAnnotation) {
AnnotationVisitor av =
targetMethodVisitor.visitParameterAnnotation(parameterIndex, paramAnnotation.getName(), true);
paramAnnotation.getProperties().forEach(prop -> visitAnnotationProperty(av, prop.getName(),
prop.getValue()));
av.visitEnd();
}

private Object toOpcode(String s) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ private static Entry<String, String> getClassAndMemberName(String programName, S
private static String getClassName(String programName, String idrisNamespace) {
if (idrisNamespace.startsWith("io/github/mmhelloworld/idrisjvm")) {
return idrisNamespace;
} else if (idrisNamespace.startsWith("nomangle:")) {
return idrisNamespace.substring("nomangle:".length());
} else {
LinkedList<String> moduleParts =
Stream.of(idrisNamespace.split("/")).collect(toCollection(LinkedList::new));
Expand Down
2 changes: 1 addition & 1 deletion idris2.ipkg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package idris2app

depends = network
depends = network, contrib

sourcedir = "src"

Expand Down
1 change: 1 addition & 0 deletions idris2api.ipkg
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ modules =
Compiler.Jvm.Math,
Compiler.Jvm.Asm,
Compiler.Jvm.Codegen,
Compiler.Jvm.Export,
Compiler.Jvm.ExtPrim,
Compiler.Jvm.FunctionTree,
Compiler.Jvm.Optimizer,
Expand Down
Loading

0 comments on commit 005c2bc

Please sign in to comment.