From a40f40f230e6312ae432f06e7f73aa5945d8fa49 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sun, 18 Jul 2021 23:10:18 -0400 Subject: New JVM compiler can now compile JVM interfaces. --- lux-jvm/source/luxc/lang/translation/jvm.lux | 58 +++++++++++----------- lux-jvm/source/luxc/lang/translation/jvm/case.lux | 12 ++--- .../luxc/lang/translation/jvm/extension/common.lux | 22 ++++---- .../luxc/lang/translation/jvm/extension/host.lux | 20 +++++--- .../source/luxc/lang/translation/jvm/function.lux | 11 ++-- .../source/luxc/lang/translation/jvm/program.lux | 3 +- .../source/luxc/lang/translation/jvm/runtime.lux | 39 ++++++++------- .../source/luxc/lang/translation/jvm/structure.lux | 3 +- 8 files changed, 89 insertions(+), 79 deletions(-) (limited to 'lux-jvm/source/luxc/lang/translation') diff --git a/lux-jvm/source/luxc/lang/translation/jvm.lux b/lux-jvm/source/luxc/lang/translation/jvm.lux index 0f6ba6744..425a259aa 100644 --- a/lux-jvm/source/luxc/lang/translation/jvm.lux +++ b/lux-jvm/source/luxc/lang/translation/jvm.lux @@ -122,7 +122,7 @@ ..value_field ..$Value) (def.method #jvm.Public ($_ jvm.++M jvm.staticM jvm.strictM) "" - (type.method [(list) type.void (list)]) + (type.method [(list) (list) type.void (list)]) (|>> valueI (inst.PUTSTATIC (type.class bytecode_name (list)) ..value_field ..$Value) inst.RETURN))))] @@ -155,35 +155,37 @@ value definition]))) (def: #export host - (IO Host) + (IO [java/lang/ClassLoader Host]) (io (let [library (loader.new_library []) loader (loader.memory library)] - (: Host - (implementation - (def: (evaluate! context valueI) - (\ try.monad map product.left - (..evaluate! library loader context valueI))) - - (def: execute! - (..execute! library loader)) - - (def: define! - (..define! library loader)) - - (def: (ingest context bytecode) - [(..class_name context) bytecode]) - - (def: (re_learn context custom [_ bytecode]) - (io.run - (loader.store (maybe.default (..class_name context) custom) bytecode library))) - - (def: (re_load context custom [_ bytecode]) - (io.run - (do (try.with io.monad) - [#let [class_name (maybe.default (..class_name context) custom)] - _ (loader.store class_name bytecode library) - class (loader.load class_name loader)] - (\ io.monad wrap (..class_value class_name class)))))))))) + [loader + (: Host + (implementation + (def: (evaluate! context valueI) + (\ try.monad map product.left + (..evaluate! library loader context valueI))) + + (def: execute! + (..execute! library loader)) + + (def: define! + (..define! library loader)) + + (def: (ingest context bytecode) + [(..class_name context) bytecode]) + + (def: (re_learn context custom [_ bytecode]) + (io.run + (loader.store (maybe.default (..class_name context) custom) bytecode library))) + + (def: (re_load context custom [directive_name bytecode]) + (io.run + (do (try.with io.monad) + [#let [class_name (maybe.default (..class_name context) + custom)] + _ (loader.store class_name bytecode library) + class (loader.load class_name loader)] + (\ io.monad wrap (..class_value class_name class)))))))]))) (def: #export $Variant (type.array ..$Value)) diff --git a/lux-jvm/source/luxc/lang/translation/jvm/case.lux b/lux-jvm/source/luxc/lang/translation/jvm/case.lux index 65e5dba62..b7b1d6b0f 100644 --- a/lux-jvm/source/luxc/lang/translation/jvm/case.lux +++ b/lux-jvm/source/luxc/lang/translation/jvm/case.lux @@ -53,7 +53,7 @@ (def: pushI Inst - (_.INVOKESTATIC //.$Runtime "pm_push" (type.method [(list runtime.$Stack //.$Value) runtime.$Stack (list)]))) + (_.INVOKESTATIC //.$Runtime "pm_push" (type.method [(list) (list runtime.$Stack //.$Value) runtime.$Stack (list)]))) (def: popI (|>> (_.int +1) @@ -80,7 +80,7 @@ lefts [(leftsI lefts) - (_.INVOKESTATIC //.$Runtime "tuple_left" (type.method [(list //.$Tuple runtime.$Index) //.$Value (list)]))])] + (_.INVOKESTATIC //.$Runtime "tuple_left" (type.method [(list) (list //.$Tuple runtime.$Index) //.$Value (list)]))])] (|>> (_.CHECKCAST //.$Tuple) indexI accessI))) @@ -89,7 +89,7 @@ (-> Nat Inst) (|>> (_.CHECKCAST //.$Tuple) (leftsI lefts) - (_.INVOKESTATIC //.$Runtime "tuple_right" (type.method [(list //.$Tuple runtime.$Index) //.$Value (list)])))) + (_.INVOKESTATIC //.$Runtime "tuple_right" (type.method [(list) (list //.$Tuple runtime.$Index) //.$Value (list)])))) (def: (path' stack_depth @else @end phase archive path) (-> Nat Label Label Phase Archive Path (Operation Inst)) @@ -144,7 +144,7 @@ ([#synthesis.I64_Fork (_.unwrap type.long) _.DUP2 _.POP2 (|>> .int _.long) _.LCMP _.IFNE] [#synthesis.F64_Fork (_.unwrap type.double) _.DUP2 _.POP2 _.double _.DCMPL _.IFNE] [#synthesis.Text_Fork (|>) _.DUP _.POP _.string - (_.INVOKEVIRTUAL (type.class "java.lang.Object" (list)) "equals" (type.method [(list //.$Value) type.boolean (list)])) + (_.INVOKEVIRTUAL (type.class "java.lang.Object" (list)) "equals" (type.method [(list) (list //.$Value) type.boolean (list)])) _.IFEQ]) (#synthesis.Then bodyS) @@ -162,7 +162,7 @@ (_.CHECKCAST //.$Variant) (structure.tagI lefts ) (structure.flagI ) - (_.INVOKESTATIC //.$Runtime "pm_variant" (type.method [(list //.$Variant runtime.$Tag runtime.$Flag) runtime.$Value (list)])) + (_.INVOKESTATIC //.$Runtime "pm_variant" (type.method [(list) (list //.$Variant runtime.$Tag runtime.$Flag) runtime.$Value (list)])) _.DUP (_.IFNULL @fail) (_.GOTO @success) @@ -220,7 +220,7 @@ (wrap (|>> pathI (_.label @else) _.POP - (_.INVOKESTATIC //.$Runtime "pm_fail" (type.method [(list) type.void (list)])) + (_.INVOKESTATIC //.$Runtime "pm_fail" (type.method [(list) (list) type.void (list)])) _.NULL (_.GOTO @end))))) diff --git a/lux-jvm/source/luxc/lang/translation/jvm/extension/common.lux b/lux-jvm/source/luxc/lang/translation/jvm/extension/common.lux index d79362d79..70175b636 100644 --- a/lux-jvm/source/luxc/lang/translation/jvm/extension/common.lux +++ b/lux-jvm/source/luxc/lang/translation/jvm/extension/common.lux @@ -216,20 +216,20 @@ [i64::f64 (_.unwrap type.long) (<| (_.wrap type.double) _.L2D)] [i64::char (_.unwrap type.long) - ((|>> _.L2I _.I2C (_.INVOKESTATIC (type.class "java.lang.Character" (list)) "toString" (type.method [(list type.char) $String (list)]))))] + ((|>> _.L2I _.I2C (_.INVOKESTATIC (type.class "java.lang.Character" (list)) "toString" (type.method [(list) (list type.char) $String (list)]))))] [f64::i64 (_.unwrap type.double) (<| (_.wrap type.long) _.D2L)] [f64::encode (_.unwrap type.double) - (_.INVOKESTATIC (type.class "java.lang.Double" (list)) "toString" (type.method [(list type.double) $String (list)]))] + (_.INVOKESTATIC (type.class "java.lang.Double" (list)) "toString" (type.method [(list) (list type.double) $String (list)]))] [f64::decode ..check_stringI - (_.INVOKESTATIC ///.$Runtime "decode_frac" (type.method [(list $String) ///.$Variant (list)]))] + (_.INVOKESTATIC ///.$Runtime "decode_frac" (type.method [(list) (list $String) ///.$Variant (list)]))] ) (def: (text::size inputI) (Unary Inst) (|>> inputI ..check_stringI - (_.INVOKEVIRTUAL $String "length" (type.method [(list) type.int (list)])) + (_.INVOKEVIRTUAL $String "length" (type.method [(list) (list) type.int (list)])) lux_intI)) (template [ ] @@ -240,13 +240,13 @@ ))] [text::= (<|) (<|) - (_.INVOKEVIRTUAL $Object "equals" (type.method [(list $Object) type.boolean (list)])) + (_.INVOKEVIRTUAL $Object "equals" (type.method [(list) (list $Object) type.boolean (list)])) (_.wrap type.boolean)] [text::< ..check_stringI ..check_stringI - (_.INVOKEVIRTUAL $String "compareTo" (type.method [(list $String) type.int (list)])) + (_.INVOKEVIRTUAL $String "compareTo" (type.method [(list) (list $String) type.int (list)])) (predicateI _.IFLT)] [text::char ..check_stringI jvm_intI - (_.INVOKEVIRTUAL $String "charAt" (type.method [(list type.int) type.char (list)])) + (_.INVOKEVIRTUAL $String "charAt" (type.method [(list) (list type.int) type.char (list)])) lux_intI] ) @@ -254,7 +254,7 @@ (Binary Inst) (|>> leftI ..check_stringI rightI ..check_stringI - (_.INVOKEVIRTUAL $String "concat" (type.method [(list $String) $String (list)])))) + (_.INVOKEVIRTUAL $String "concat" (type.method [(list) (list $String) $String (list)])))) (def: (text::clip [offsetI lengthI subjectI]) (Trinary Inst) @@ -263,9 +263,9 @@ _.DUP lengthI jvm_intI _.IADD - (_.INVOKEVIRTUAL $String "substring" (type.method [(list type.int type.int) $String (list)])))) + (_.INVOKEVIRTUAL $String "substring" (type.method [(list) (list type.int type.int) $String (list)])))) -(def: index_method (type.method [(list $String type.int) type.int (list)])) +(def: index_method (type.method [(list) (list $String type.int) type.int (list)])) (def: (text::index [startI partI textI]) (Trinary Inst) (<| _.with_label (function (_ @not_found)) @@ -285,7 +285,7 @@ runtime.noneI (_.label @end)))) -(def: string_method (type.method [(list $String) type.void (list)])) +(def: string_method (type.method [(list) (list $String) type.void (list)])) (def: (io::log messageI) (Unary Inst) (let [$PrintStream (type.class "java.io.PrintStream" (list))] diff --git a/lux-jvm/source/luxc/lang/translation/jvm/extension/host.lux b/lux-jvm/source/luxc/lang/translation/jvm/extension/host.lux index 441a415ee..a9727fc9a 100644 --- a/lux-jvm/source/luxc/lang/translation/jvm/extension/host.lux +++ b/lux-jvm/source/luxc/lang/translation/jvm/extension/host.lux @@ -536,7 +536,7 @@ (do phase.monad [] (wrap (|>> (_.string class) - (_.INVOKESTATIC $Class "forName" (type.method [(list (type.class "java.lang.String" (list))) $Class (list)]))))) + (_.INVOKESTATIC $Class "forName" (type.method [(list) (list (type.class "java.lang.String" (list))) $Class (list)]))))) _ (phase.throw extension.invalid_syntax [extension_name %synthesis inputs]))) @@ -725,7 +725,7 @@ (do {@ phase.monad} [inputsTI (monad.map @ (generate_input generate archive) inputsTS)] (wrap (|>> (_.fuse (list@map product.right inputsTI)) - (_.INVOKESTATIC class method (type.method [(list@map product.left inputsTI) outputT (list)])) + (_.INVOKESTATIC class method (type.method [(list) (list@map product.left inputsTI) outputT (list)])) (prepare_output outputT)))))])) (template [ ] @@ -741,7 +741,8 @@ (_.CHECKCAST class) (_.fuse (list@map product.right inputsTI)) ( class method - (type.method [(list@map product.left inputsTI) + (type.method [(list) + (list@map product.left inputsTI) outputT (list)])) (prepare_output outputT)))))]))] @@ -761,7 +762,7 @@ (wrap (|>> (_.NEW class) _.DUP (_.fuse (list@map product.right inputsTI)) - (_.INVOKESPECIAL class "" (type.method [(list@map product.left inputsTI) type.void (list)]))))))])) + (_.INVOKESPECIAL class "" (type.method [(list) (list@map product.left inputsTI) type.void (list)]))))))])) (def: member Bundle @@ -919,7 +920,8 @@ (def: (anonymous_init_method env) (-> (Environment Synthesis) (Type Method)) - (type.method [(list.repeat (list.size env) $Object) + (type.method [(list) + (list.repeat (list.size env) $Object) type.void (list)])) @@ -936,7 +938,7 @@ (_def.method #$.Public $.noneM "" (anonymous_init_method env) (|>> (_.ALOAD 0) ((_.fuse (list@map product.right inputsTI))) - (_.INVOKESPECIAL super_class "" (type.method [(list@map product.left inputsTI) type.void (list)])) + (_.INVOKESPECIAL super_class "" (type.method [(list) (list@map product.left inputsTI) type.void (list)])) store_capturedI _.RETURN)))) @@ -986,7 +988,8 @@ (.tuple (<>.some ..class)) (.tuple (<>.some ..input)) (.tuple (<>.some ..overriden_method_definition))) - (function (_ extension_name generate archive [super_class super_interfaces + (function (_ extension_name generate archive [super_class + super_interfaces inputsTS overriden_methods]) (do {@ phase.monad} @@ -1040,7 +1043,8 @@ ($_ $.++M $.finalM $.strictM) $.finalM) name - (type.method [(list@map product.right arguments) + (type.method [(list) + (list@map product.right arguments) returnT exceptionsT]) (|>> bodyG (returnI returnT))))))) diff --git a/lux-jvm/source/luxc/lang/translation/jvm/function.lux b/lux-jvm/source/luxc/lang/translation/jvm/function.lux index 394b0b7b5..9e0f9f225 100644 --- a/lux-jvm/source/luxc/lang/translation/jvm/function.lux +++ b/lux-jvm/source/luxc/lang/translation/jvm/function.lux @@ -57,15 +57,16 @@ (def: (init_method env arity) (-> (Environment Synthesis) Arity (Type Method)) (if (poly_arg? arity) - (type.method [(list.concat (list (captured_args env) + (type.method [(list) + (list.concat (list (captured_args env) (list type.int) (list.repeat (dec arity) //.$Value))) type.void (list)]) - (type.method [(captured_args env) type.void (list)]))) + (type.method [(list) (captured_args env) type.void (list)]))) (def: (implementation_method arity) - (type.method [(list.repeat arity //.$Value) //.$Value (list)])) + (type.method [(list) (list.repeat arity //.$Value) //.$Value (list)])) (def: get_amount_of_partialsI Inst @@ -122,7 +123,7 @@ (def: (reset_method return) (-> (Type Class) (Type Method)) - (type.method [(list) return (list)])) + (type.method [(list) (list) return (list)])) (def: (with_reset class arity env) (-> (Type Class) Arity (Environment Synthesis) Def) @@ -156,7 +157,7 @@ _.ARETURN))) (def: function_init_method - (type.method [(list type.int) type.void (list)])) + (type.method [(list) (list type.int) type.void (list)])) (def: (function_init arity env_size) (-> Arity Nat Inst) diff --git a/lux-jvm/source/luxc/lang/translation/jvm/program.lux b/lux-jvm/source/luxc/lang/translation/jvm/program.lux index 1ebdf33f0..9cd8eeb82 100644 --- a/lux-jvm/source/luxc/lang/translation/jvm/program.lux +++ b/lux-jvm/source/luxc/lang/translation/jvm/program.lux @@ -73,7 +73,8 @@ run_ioI (|>> ($i.CHECKCAST jvm.$Function) $i.NULL ($i.INVOKEVIRTUAL jvm.$Function runtime.apply_method (runtime.apply_signature 1))) - main_type ($t.method [(list ($t.array ($t.class "java.lang.String" (list)))) + main_type ($t.method [(list) + (list ($t.array ($t.class "java.lang.String" (list)))) $t.void (list)]) class (artifact_name context)] diff --git a/lux-jvm/source/luxc/lang/translation/jvm/runtime.lux b/lux-jvm/source/luxc/lang/translation/jvm/runtime.lux index e0426f363..cccdf42bf 100644 --- a/lux-jvm/source/luxc/lang/translation/jvm/runtime.lux +++ b/lux-jvm/source/luxc/lang/translation/jvm/runtime.lux @@ -48,22 +48,22 @@ (def: $Throwable (type.class "java.lang.Throwable" (list))) (def: nullary_init_methodT - (type.method [(list) type.void (list)])) + (type.method [(list) (list) type.void (list)])) (def: throw_methodT - (type.method [(list) type.void (list)])) + (type.method [(list) (list) type.void (list)])) (def: #export logI Inst (let [PrintStream (type.class "java.io.PrintStream" (list)) outI (_.GETSTATIC (type.class "java.lang.System" (list)) "out" PrintStream) printI (function (_ method) - (_.INVOKEVIRTUAL PrintStream method (type.method [(list $Value) type.void (list)])))] + (_.INVOKEVIRTUAL PrintStream method (type.method [(list) (list $Value) type.void (list)])))] (|>> outI (_.string "LOG: ") (printI "print") outI _.SWAP (printI "println")))) (def: variant_method - (type.method [(list $Tag $Flag $Value) //.$Variant (list)])) + (type.method [(list) (list $Tag $Flag $Value) //.$Variant (list)])) (def: #export variantI Inst @@ -115,7 +115,7 @@ (def: #export (apply_signature arity) (-> Arity (Type Method)) - (type.method [(list.repeat arity $Value) $Value (list)])) + (type.method [(list) (list.repeat arity $Value) $Value (list)])) (def: adt_methods Def @@ -123,7 +123,7 @@ store_flagI (|>> _.DUP _.ICONST_1 (_.ALOAD 1) _.AASTORE) store_valueI (|>> _.DUP _.ICONST_2 (_.ALOAD 2) _.AASTORE)] (|>> ($d.method #$.Public $.staticM "variant_make" - (type.method [(list $Tag $Flag $Value) //.$Variant (list)]) + (type.method [(list) (list $Tag $Flag $Value) //.$Variant (list)]) (|>> _.ICONST_3 (_.ANEWARRAY $Value) store_tagI @@ -133,10 +133,10 @@ (def: frac_methods Def - (|>> ($d.method #$.Public $.staticM "decode_frac" (type.method [(list $Text) //.$Variant (list)]) + (|>> ($d.method #$.Public $.staticM "decode_frac" (type.method [(list) (list $Text) //.$Variant (list)]) (tryI (|>> (_.ALOAD 0) - (_.INVOKESTATIC (type.class "java.lang.Double" (list)) "parseDouble" (type.method [(list $Text) type.double (list)])) + (_.INVOKESTATIC (type.class "java.lang.Double" (list)) "parseDouble" (type.method [(list) (list $Text) type.double (list)])) (_.wrap type.double)))) )) @@ -146,7 +146,7 @@ (|>> (_.NEW IllegalStateException) _.DUP (_.string message) - (_.INVOKESPECIAL IllegalStateException "" (type.method [(list $Text) type.void (list)]))))) + (_.INVOKESPECIAL IllegalStateException "" (type.method [(list) (list $Text) type.void (list)]))))) (def: pm_methods Def @@ -175,7 +175,7 @@ ($d.method #$.Public $.staticM "apply_fail" throw_methodT (|>> (illegal_state_exception "Error while applying function.") _.ATHROW)) - ($d.method #$.Public $.staticM "pm_push" (type.method [(list $Stack $Value) $Stack (list)]) + ($d.method #$.Public $.staticM "pm_push" (type.method [(list) (list $Stack $Value) $Stack (list)]) (|>> _.ICONST_2 (_.ANEWARRAY $Value) _.DUP @@ -187,7 +187,7 @@ (_.ALOAD 1) _.AASTORE _.ARETURN)) - ($d.method #$.Public $.staticM "pm_variant" (type.method [(list //.$Variant $Tag $Flag) $Value (list)]) + ($d.method #$.Public $.staticM "pm_variant" (type.method [(list) (list //.$Variant $Tag $Flag) $Value (list)]) (<| _.with_label (function (_ @loop)) _.with_label (function (_ @perfect_match!)) _.with_label (function (_ @tags_match!)) @@ -247,7 +247,7 @@ ## _.POP2 not_found _.ARETURN))) - ($d.method #$.Public $.staticM "tuple_left" (type.method [(list //.$Tuple $Index) $Value (list)]) + ($d.method #$.Public $.staticM "tuple_left" (type.method [(list) (list //.$Tuple $Index) $Value (list)]) (<| _.with_label (function (_ @loop)) _.with_label (function (_ @recursive)) (let [left_accessI (|>> (_.ALOAD 0) left_indexI _.AALOAD)]) @@ -258,7 +258,7 @@ (_.label @recursive) ## Recursive (recurI @loop)))) - ($d.method #$.Public $.staticM "tuple_right" (type.method [(list //.$Tuple $Index) $Value (list)]) + ($d.method #$.Public $.staticM "tuple_right" (type.method [(list) (list //.$Tuple $Index) $Value (list)]) (<| _.with_label (function (_ @loop)) _.with_label (function (_ @not_tail)) _.with_label (function (_ @slice)) @@ -272,7 +272,8 @@ right_indexI tuple_sizeI (_.INVOKESTATIC (type.class "java.util.Arrays" (list)) "copyOfRange" - (type.method [(list //.$Tuple $Index $Index) + (type.method [(list) + (list //.$Tuple $Index $Index) //.$Tuple (list)])))]) (|>> (_.label @loop) @@ -291,7 +292,7 @@ ))) ))) -(def: #export try (type.method [(list //.$Function) //.$Variant (list)])) +(def: #export try (type.method [(list) (list //.$Function) //.$Variant (list)])) (def: io_methods Def @@ -306,7 +307,7 @@ _.POP _.SWAP (_.boolean true) - (_.INVOKESPECIAL PrintWriter "" (type.method [(list (type.class "java.io.Writer" (list)) type.boolean) type.void (list)])) + (_.INVOKESPECIAL PrintWriter "" (type.method [(list) (list (type.class "java.io.Writer" (list)) type.boolean) type.void (list)])) )] (|>> ($d.method #$.Public $.staticM "try" ..try (<| _.with_label (function (_ @from)) @@ -324,8 +325,8 @@ string_writerI ## TW _.DUP2 ## TWTW print_writerI ## TWTP - (_.INVOKEVIRTUAL $Throwable "printStackTrace" (type.method [(list (type.class "java.io.PrintWriter" (list))) type.void (list)])) ## TW - (_.INVOKEVIRTUAL StringWriter "toString" (type.method [(list) $Text (list)])) ## TS + (_.INVOKEVIRTUAL $Throwable "printStackTrace" (type.method [(list) (list (type.class "java.io.PrintWriter" (list))) type.void (list)])) ## TW + (_.INVOKEVIRTUAL StringWriter "toString" (type.method [(list) (list) $Text (list)])) ## TS _.SWAP _.POP leftI _.ARETURN))) ))) @@ -375,7 +376,7 @@ function_class (..reflection //.$Function) bytecode ($d.abstract #$.V1_6 #$.Public $.noneC function_class (list) $Object (list) (|>> ($d.field #$.Public $.finalF partials_field type.int) - ($d.method #$.Public $.noneM "" (type.method [(list type.int) type.void (list)]) + ($d.method #$.Public $.noneM "" (type.method [(list) (list type.int) type.void (list)]) (|>> (_.ALOAD 0) (_.INVOKESPECIAL $Object "" nullary_init_methodT) (_.ALOAD 0) diff --git a/lux-jvm/source/luxc/lang/translation/jvm/structure.lux b/lux-jvm/source/luxc/lang/translation/jvm/structure.lux index 16b320b6d..a9666958b 100644 --- a/lux-jvm/source/luxc/lang/translation/jvm/structure.lux +++ b/lux-jvm/source/luxc/lang/translation/jvm/structure.lux @@ -114,6 +114,7 @@ memberI (_.INVOKESTATIC //.$Runtime "variant_make" - (type.method [(list //runtime.$Tag //runtime.$Flag //runtime.$Value) + (type.method [(list) + (list //runtime.$Tag //runtime.$Flag //runtime.$Value) //.$Variant (list)])))))) -- cgit v1.2.3