Skip to content

Commit f262d3b

Browse files
committed
#35 support int annotation values, annotation on static methods
1 parent 10e7a48 commit f262d3b

File tree

5 files changed

+23
-11
lines changed

5 files changed

+23
-11
lines changed

idris-jvm-core/src/main/idris/IdrisJvm/Core/Function.idr

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,13 @@ mutual
548548
paramAnns = parseParamAnnotations paramAnnDescs
549549
in exportFun types cname mname sourceCname sourceMname ExportCallInstance parent returns args anns paramAnns
550550

551+
cgExport types cname parent
552+
(ExportFun n (FApp "ExportStaticWithAnn" [FStr mname, FApp "::" annDescs, paramAnnDescs]) returns args)
553+
= let MkJMethodName sourceCname sourceMname = jname n
554+
anns = join $ parseAnnotations <$> annDescs
555+
paramAnns = parseParamAnnotations paramAnnDescs
556+
in exportFun types cname mname sourceCname sourceMname ExportCallStatic parent returns args anns paramAnns
557+
551558
cgExport _ _ _ exportDef = jerror $ "Unsupported export definition: " ++ show exportDef
552559

553560
parseClassAnnotations : List Export -> (List Annotation, List Export)
@@ -843,6 +850,7 @@ mutual
843850

844851
parseAnnotationValue : FDesc -> AnnotationValue
845852
parseAnnotationValue (FApp "AnnString" [FStr value]) = AnnString value
853+
parseAnnotationValue (FApp "AnnInt" [FStr value]) = AnnInt $ cast value
846854
parseAnnotationValue (FApp "AnnEnum" [FStr enum, FStr value]) = AnnEnum (asmRefTyDesc (ClassDesc enum)) value
847855
parseAnnotationValue (FApp "AnnArray" values) = AnnArray (parseAnnArrayElements values)
848856
parseAnnotationValue desc = jerror $ "Invalid or unsupported annotation value: " ++ show desc

idris-jvm-core/src/main/java/IdrisJvm/Core/AnnotationProperty.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package IdrisJvm.Core;
22

3-
class AnnotationProperty {
3+
public class AnnotationProperty {
44
private final String name;
55
private final AnnotationValue value;
66

@@ -17,4 +17,4 @@ public AnnotationValue getValue() {
1717
public String getName() {
1818
return name;
1919
}
20-
}
20+
}

idris-jvm-core/src/main/java/IdrisJvm/Core/AnnotationValue.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import java.util.List;
66

7-
abstract class AnnotationValue {
7+
public abstract class AnnotationValue {
88
private final AnnotationValueType type;
99

1010
private AnnotationValue(final AnnotationValueType type) {
@@ -83,4 +83,4 @@ public List<AnnotationValue> getValues() {
8383
return values;
8484
}
8585
}
86-
}
86+
}

idris-jvm-ffi/src/main/idris/IdrisJvm/FFI.idr

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ data IORef a = MkIORef a
88
AnnotationTypeName : Type
99
AnnotationTypeName = String
1010

11-
data AnnotationValue = AnnInt Int
11+
data AnnotationValue = AnnInt String -- FFI Descriptor can only take String
1212
| AnnString String
1313
| AnnEnum String String
1414
| AnnArray (List AnnotationValue)
@@ -57,7 +57,11 @@ mutual
5757
| ExportInstance String
5858
| ExportDefault -- Export an instance method with idris function name
5959
| Anns (List Annotation)
60+
61+
-- Export a static method with method annotations and parameter annotations
6062
| ExportStaticWithAnn String (List Annotation) (List (List Annotation))
63+
64+
-- Export an instance method with method annotations and parameter annotations
6165
| ExportInstanceWithAnn String (List Annotation) (List (List Annotation))
6266

6367
data JVM_IntTypes : Type -> Type where
@@ -353,5 +357,6 @@ term syntax "<@@>" [anns] = Fun classWith (Anns anns)
353357
term syntax "<@>" [name] [attrs] = Ann name attrs
354358
term syntax "<@..>" [values] = AnnArray values
355359
term syntax "<@s>" [value] = AnnString value
360+
term syntax "<@i>" [value] = AnnInt value -- Descriptor can only take string
356361
term syntax "<@enum>" [ty] [value] = AnnEnum ty value
357362
term syntax [name] "<@:>" [value] = (name, value)

idris-jvm-server/src/main/java/io/github/mmhelloworld/idrisjvm/model/SAltDeserializer.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
package io.github.mmhelloworld.idrisjvm.model;
22

3+
import IdrisJvm.Core.export.Codegen;
4+
import IdrisJvm.IR.export.Const;
5+
import IdrisJvm.IR.export.SAlt;
6+
import IdrisJvm.IR.export.SExp;
37
import com.fasterxml.jackson.core.JsonParser;
4-
import com.fasterxml.jackson.core.JsonProcessingException;
58
import com.fasterxml.jackson.databind.DeserializationContext;
69
import com.fasterxml.jackson.databind.JsonNode;
710
import com.fasterxml.jackson.databind.ObjectMapper;
811
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
9-
import IdrisJvm.IR.export.Const;
10-
import IdrisJvm.Core.export.Codegen;
11-
import IdrisJvm.IR.export.SAlt;
12-
import IdrisJvm.IR.export.SExp;
1312

1413
import java.io.IOException;
1514
import java.util.List;
@@ -31,7 +30,7 @@ public SAltDeserializer(final Class<?> vc) {
3130

3231
@Override
3332
public SAlt deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext)
34-
throws IOException, JsonProcessingException {
33+
throws IOException {
3534
final JsonNode node = jsonParser.getCodec().readTree(jsonParser);
3635
final ObjectMapper mapper = Context.getMapper();
3736

0 commit comments

Comments
 (0)