diff options
author | Eduardo Julian | 2019-10-16 20:55:03 -0400 |
---|---|---|
committer | Eduardo Julian | 2019-10-16 20:55:03 -0400 |
commit | de9d57c45da46cdae9e21ff1d9747952e0815b32 (patch) | |
tree | b65b465b097fcd99484aa6baab30b2a7254834dc /stdlib/source/test | |
parent | 3028cc4f45d2d7d66456467de506341800df14d8 (diff) |
Ported JVM function generation to the new JVM bytecode machinery.
Diffstat (limited to 'stdlib/source/test')
-rw-r--r-- | stdlib/source/test/lux.lux | 2 | ||||
-rw-r--r-- | stdlib/source/test/lux/target/jvm.lux | 76 |
2 files changed, 40 insertions, 38 deletions
diff --git a/stdlib/source/test/lux.lux b/stdlib/source/test/lux.lux index 34000d362..85b062009 100644 --- a/stdlib/source/test/lux.lux +++ b/stdlib/source/test/lux.lux @@ -1,10 +1,10 @@ (.with-expansions [<host-modules> (.as-is [runtime (#+)] [primitive (#+)] [structure (#+)] - ## [function (#+)] [reference (#+)] ## [case (#+)] ## [loop (#+)] + [function (#+)] ## [extension (#+)] )] (.module: diff --git a/stdlib/source/test/lux/target/jvm.lux b/stdlib/source/test/lux/target/jvm.lux index 5ffe668fc..a9eb21c22 100644 --- a/stdlib/source/test/lux/target/jvm.lux +++ b/stdlib/source/test/lux/target/jvm.lux @@ -1,5 +1,5 @@ (.module: - [lux #* + [lux (#- Type type) ["." host (#+ import:)] [abstract/monad (#+ do)] [control @@ -42,9 +42,8 @@ ["#." name]] ["#." instruction ["#/." condition (#+ Environment)]] - [type - [category (#+ Value)] - ["#." descriptor (#+ Descriptor)]]]}) + ["#." type (#+ Type) + [category (#+ Value)]]]}) ## (def: (write-class! name bytecode) ## (-> Text Binary (IO Text)) @@ -76,45 +75,49 @@ (import: #long java/lang/Long (#static TYPE (java/lang/Class java/lang/Long))) -(def: descriptor - (Random (Descriptor Value)) +(def: class-name + (Random Text) + (do random.monad + [super-package (random.ascii/lower-alpha 10) + package (random.ascii/lower-alpha 10) + name (random.ascii/upper-alpha 10)] + (wrap (format super-package + /name.external-separator package + /name.external-separator name)))) + +(def: type + (Random (Type Value)) (random.rec - (function (_ descriptor) + (function (_ type) ($_ random.either - (random@wrap /descriptor.boolean) - (random@wrap /descriptor.byte) - (random@wrap /descriptor.short) - (random@wrap /descriptor.int) - (random@wrap /descriptor.long) - (random@wrap /descriptor.float) - (random@wrap /descriptor.double) - (random@wrap /descriptor.char) - (random@map (|>> (text.join-with /name.external-separator) /descriptor.class) - (random.list 3 (random.ascii/upper-alpha 10))) - (random@map /descriptor.array descriptor) + (random@wrap /type.boolean) + (random@wrap /type.byte) + (random@wrap /type.short) + (random@wrap /type.int) + (random@wrap /type.long) + (random@wrap /type.float) + (random@wrap /type.double) + (random@wrap /type.char) + (random@map (function (_ name) (/type.class name (list))) ..class-name) + (random@map /type.array type) )))) (def: field - (Random [Text (Descriptor Value)]) + (Random [Text (Type Value)]) ($_ random.and (random.ascii/lower-alpha 10) - ..descriptor + ..type )) -(def: class-name - (Random Text) - (do random.monad - [super-package (random.ascii/lower-alpha 10) - package (random.ascii/lower-alpha 10) - name (random.ascii/upper-alpha 10)] - (wrap (format super-package "." package "." name)))) - (def: (get-method name class) (-> Text (java/lang/Class java/lang/Object) java/lang/reflect/Method) (java/lang/Class::getDeclaredMethod name (host.array (java/lang/Class java/lang/Object) 0) class)) +(def: $Long (/type.class "java.lang.Long" (list))) +(def: $Object (/type.class "java.lang.Object" (list))) + (def: method Test (do random.monad @@ -122,7 +125,7 @@ method-name (random.ascii/upper-alpha 10) expected random.int #let [inputsJT (list) - outputJT (/descriptor.class "java.lang.Object")]] + outputJT $Object]] (_.test "Can compile a method." (let [bytecode (|> (/class.class /version.v6_0 /class.public (/name.internal class-name) @@ -133,13 +136,12 @@ /method.public /method.static) method-name - (/descriptor.method [inputsJT outputJT]) + (/type.method [inputsJT outputJT (list)]) (list) (do /instruction.monad [_ (/instruction.ldc/long (/constant.long expected)) - _ (/instruction.invokestatic "java.lang.Long" "valueOf" - [(list /descriptor.long) - (/descriptor.class "java.lang.Long")])] + _ (/instruction.invokestatic $Long "valueOf" + (/type.method [(list /type.long) $Long (list)]))] /instruction.areturn))) (row.row)) (binaryF.run /class.writer)) @@ -160,15 +162,15 @@ Test (do random.monad [class-name ..class-name - [field0 descriptor0] ..field - [field1 descriptor1] ..field + [field0 type0] ..field + [field1 type1] ..field #let [input (/class.class /version.v6_0 /class.public (/name.internal class-name) (/name.internal "java.lang.Object") (list (/name.internal "java.io.Serializable") (/name.internal "java.lang.Runnable")) - (list (/field.field /field.public field0 descriptor0 (row.row)) - (/field.field /field.public field1 descriptor1 (row.row))) + (list (/field.field /field.public field0 type0 (row.row)) + (/field.field /field.public field1 type1 (row.row))) (list) (row.row)) bytecode (binaryF.run /class.writer input) |