From 832a9361b632331e82a64c07baa560487ca8abde Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Tue, 29 Dec 2020 00:38:21 -0400 Subject: Moved "lux/data/number" to "lux/math/number". --- .../source/luxc/lang/translation/jvm/runtime.lux | 224 ++++++++++----------- 1 file changed, 112 insertions(+), 112 deletions(-) (limited to 'lux-jvm/source/luxc/lang/translation/jvm/runtime.lux') diff --git a/lux-jvm/source/luxc/lang/translation/jvm/runtime.lux b/lux-jvm/source/luxc/lang/translation/jvm/runtime.lux index e7a37584e..061972df1 100644 --- a/lux-jvm/source/luxc/lang/translation/jvm/runtime.lux +++ b/lux-jvm/source/luxc/lang/translation/jvm/runtime.lux @@ -46,10 +46,10 @@ (def: #export $Stack (type.array $Value)) (def: $Throwable (type.class "java.lang.Throwable" (list))) -(def: nullary-init-methodT +(def: nullary_init_methodT (type.method [(list) type.void (list)])) -(def: throw-methodT +(def: throw_methodT (type.method [(list) type.void (list)])) (def: #export logI @@ -61,12 +61,12 @@ (|>> outI (_.string "LOG: ") (printI "print") outI _.SWAP (printI "println")))) -(def: variant-method +(def: variant_method (type.method [(list $Tag $Flag $Value) //.$Variant (list)])) (def: #export variantI Inst - (_.INVOKESTATIC //.$Runtime "variant_make" variant-method)) + (_.INVOKESTATIC //.$Runtime "variant_make" variant_method)) (def: #export leftI Inst @@ -95,9 +95,9 @@ (def: (tryI unsafeI) (-> Inst Inst) - (<| _.with-label (function (_ @from)) - _.with-label (function (_ @to)) - _.with-label (function (_ @handler)) + (<| _.with_label (function (_ @from)) + _.with_label (function (_ @to)) + _.with_label (function (_ @handler)) (|>> (_.try @from @to @handler (type.class "java.lang.Exception" (list))) (_.label @from) unsafeI @@ -108,29 +108,29 @@ noneI _.ARETURN))) -(def: #export partials-field Text "partials") -(def: #export apply-method Text "apply") -(def: #export num-apply-variants Nat 8) +(def: #export partials_field Text "partials") +(def: #export apply_method Text "apply") +(def: #export num_apply_variants Nat 8) -(def: #export (apply-signature arity) +(def: #export (apply_signature arity) (-> Arity (Type Method)) (type.method [(list.repeat arity $Value) $Value (list)])) -(def: adt-methods +(def: adt_methods Def - (let [store-tagI (|>> _.DUP _.ICONST_0 (_.ILOAD 0) (_.wrap type.int) _.AASTORE) - store-flagI (|>> _.DUP _.ICONST_1 (_.ALOAD 1) _.AASTORE) - store-valueI (|>> _.DUP _.ICONST_2 (_.ALOAD 2) _.AASTORE)] + (let [store_tagI (|>> _.DUP _.ICONST_0 (_.ILOAD 0) (_.wrap type.int) _.AASTORE) + 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)]) (|>> _.ICONST_3 (_.ANEWARRAY $Value) - store-tagI - store-flagI - store-valueI + store_tagI + store_flagI + store_valueI _.ARETURN))))) -(def: frac-methods +(def: frac_methods Def (|>> ($d.method #$.Public $.staticM "decode_frac" (type.method [(list $Text) //.$Variant (list)]) (tryI @@ -139,7 +139,7 @@ (_.wrap type.double)))) )) -(def: (illegal-state-exception message) +(def: (illegal_state_exception message) (-> Text Inst) (let [IllegalStateException (type.class "java.lang.IllegalStateException" (list))] (|>> (_.NEW IllegalStateException) @@ -147,32 +147,32 @@ (_.string message) (_.INVOKESPECIAL IllegalStateException "" (type.method [(list $Text) type.void (list)]))))) -(def: pm-methods +(def: pm_methods Def - (let [tuple-sizeI (|>> (_.ALOAD 0) + (let [tuple_sizeI (|>> (_.ALOAD 0) _.ARRAYLENGTH) - last-rightI (|>> tuple-sizeI + last_rightI (|>> tuple_sizeI _.ICONST_1 _.ISUB) leftsI (_.ILOAD 1) - left-indexI leftsI - sub-leftsI (|>> leftsI - last-rightI + left_indexI leftsI + sub_leftsI (|>> leftsI + last_rightI _.ISUB) - sub-tupleI (|>> (_.ALOAD 0) - last-rightI + sub_tupleI (|>> (_.ALOAD 0) + last_rightI _.AALOAD (_.CHECKCAST //.$Tuple)) recurI (: (-> Label Inst) (function (_ @loop) - (|>> sub-leftsI (_.ISTORE 1) - sub-tupleI (_.ASTORE 0) + (|>> sub_leftsI (_.ISTORE 1) + sub_tupleI (_.ASTORE 0) (_.GOTO @loop))))] - (|>> ($d.method #$.Public $.staticM "pm_fail" throw-methodT - (|>> (illegal-state-exception "Invalid expression for pattern-matching.") + (|>> ($d.method #$.Public $.staticM "pm_fail" throw_methodT + (|>> (illegal_state_exception "Invalid expression for pattern-matching.") _.ATHROW)) - ($d.method #$.Public $.staticM "apply_fail" throw-methodT - (|>> (illegal-state-exception "Error while applying function.") + ($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)]) (|>> _.ICONST_2 @@ -187,119 +187,119 @@ _.AASTORE _.ARETURN)) ($d.method #$.Public $.staticM "pm_variant" (type.method [(list //.$Variant $Tag $Flag) $Value (list)]) - (<| _.with-label (function (_ @loop)) - _.with-label (function (_ @perfect-match!)) - _.with-label (function (_ @tags-match!)) - _.with-label (function (_ @maybe-nested)) - _.with-label (function (_ @mismatch!)) + (<| _.with_label (function (_ @loop)) + _.with_label (function (_ @perfect_match!)) + _.with_label (function (_ @tags_match!)) + _.with_label (function (_ @maybe_nested)) + _.with_label (function (_ @mismatch!)) (let [$variant (_.ALOAD 0) $tag (_.ILOAD 1) $last? (_.ALOAD 2) - variant-partI (: (-> Nat Inst) + variant_partI (: (-> Nat Inst) (function (_ idx) (|>> (_.int (.int idx)) _.AALOAD))) ::tag (: Inst - (|>> (variant-partI 0) (_.unwrap type.int))) - ::last? (variant-partI 1) - ::value (variant-partI 2) + (|>> (variant_partI 0) (_.unwrap type.int))) + ::last? (variant_partI 1) + ::value (variant_partI 2) - super-nested-tag (|>> _.SWAP ## variant::tag, tag + super_nested_tag (|>> _.SWAP ## variant::tag, tag _.ISUB) - super-nested (|>> super-nested-tag ## super-tag - $variant ::last? ## super-tag, super-last - $variant ::value ## super-tag, super-last, super-value + super_nested (|>> super_nested_tag ## super_tag + $variant ::last? ## super_tag, super_last + $variant ::value ## super_tag, super_last, super_value ..variantI) - update-$tag _.ISUB - update-$variant (|>> $variant ::value + update_$tag _.ISUB + update_$variant (|>> $variant ::value (_.CHECKCAST //.$Variant) (_.ASTORE 0)) iterate! (: (-> Label Inst) (function (_ @loop) - (|>> update-$variant - update-$tag + (|>> update_$variant + update_$tag (_.GOTO @loop)))) - not-found _.NULL]) + not_found _.NULL]) (|>> $tag ## tag (_.label @loop) $variant ::tag ## tag, variant::tag - _.DUP2 (_.IF_ICMPEQ @tags-match!) ## tag, variant::tag - _.DUP2 (_.IF_ICMPGT @maybe-nested) ## tag, variant::tag + _.DUP2 (_.IF_ICMPEQ @tags_match!) ## tag, variant::tag + _.DUP2 (_.IF_ICMPGT @maybe_nested) ## tag, variant::tag $last? (_.IFNULL @mismatch!) ## tag, variant::tag - super-nested ## super-variant + super_nested ## super_variant _.ARETURN - (_.label @tags-match!) ## tag, variant::tag + (_.label @tags_match!) ## tag, variant::tag $last? ## tag, variant::tag, last? $variant ::last? ## tag, variant::tag, last?, variant::last? - (_.IF_ACMPEQ @perfect-match!) ## tag, variant::tag - (_.label @maybe-nested) ## tag, variant::tag + (_.IF_ACMPEQ @perfect_match!) ## tag, variant::tag + (_.label @maybe_nested) ## tag, variant::tag $variant ::last? ## tag, variant::tag, variant::last? (_.IFNULL @mismatch!) ## tag, variant::tag (iterate! @loop) - (_.label @perfect-match!) ## tag, variant::tag + (_.label @perfect_match!) ## tag, variant::tag ## _.POP2 $variant ::value _.ARETURN (_.label @mismatch!) ## tag, variant::tag ## _.POP2 - not-found + not_found _.ARETURN))) ($d.method #$.Public $.staticM "tuple_left" (type.method [(list //.$Tuple $Index) $Value (list)]) - (<| _.with-label (function (_ @loop)) - _.with-label (function (_ @recursive)) - (let [left-accessI (|>> (_.ALOAD 0) left-indexI _.AALOAD)]) + (<| _.with_label (function (_ @loop)) + _.with_label (function (_ @recursive)) + (let [left_accessI (|>> (_.ALOAD 0) left_indexI _.AALOAD)]) (|>> (_.label @loop) - leftsI last-rightI (_.IF_ICMPGE @recursive) - left-accessI + leftsI last_rightI (_.IF_ICMPGE @recursive) + left_accessI _.ARETURN (_.label @recursive) ## Recursive (recurI @loop)))) ($d.method #$.Public $.staticM "tuple_right" (type.method [(list //.$Tuple $Index) $Value (list)]) - (<| _.with-label (function (_ @loop)) - _.with-label (function (_ @not-tail)) - _.with-label (function (_ @slice)) - (let [right-indexI (|>> leftsI + (<| _.with_label (function (_ @loop)) + _.with_label (function (_ @not_tail)) + _.with_label (function (_ @slice)) + (let [right_indexI (|>> leftsI _.ICONST_1 _.IADD) - right-accessI (|>> (_.ALOAD 0) + right_accessI (|>> (_.ALOAD 0) _.SWAP _.AALOAD) - sub-rightI (|>> (_.ALOAD 0) - right-indexI - tuple-sizeI + sub_rightI (|>> (_.ALOAD 0) + right_indexI + tuple_sizeI (_.INVOKESTATIC (type.class "java.util.Arrays" (list)) "copyOfRange" (type.method [(list //.$Tuple $Index $Index) //.$Tuple (list)])))]) (|>> (_.label @loop) - last-rightI right-indexI - _.DUP2 (_.IF_ICMPNE @not-tail) + last_rightI right_indexI + _.DUP2 (_.IF_ICMPNE @not_tail) ## _.POP - right-accessI + right_accessI _.ARETURN - (_.label @not-tail) + (_.label @not_tail) (_.IF_ICMPGT @slice) ## Must recurse (recurI @loop) (_.label @slice) - sub-rightI + sub_rightI _.ARETURN ))) ))) (def: #export try (type.method [(list //.$Function) //.$Variant (list)])) -(def: io-methods +(def: io_methods Def (let [StringWriter (type.class "java.io.StringWriter" (list)) PrintWriter (type.class "java.io.PrintWriter" (list)) - string-writerI (|>> (_.NEW StringWriter) + string_writerI (|>> (_.NEW StringWriter) _.DUP - (_.INVOKESPECIAL StringWriter "" nullary-init-methodT)) - print-writerI (|>> (_.NEW PrintWriter) + (_.INVOKESPECIAL StringWriter "" nullary_init_methodT)) + print_writerI (|>> (_.NEW PrintWriter) _.SWAP _.DUP2 _.POP @@ -308,21 +308,21 @@ (_.INVOKESPECIAL PrintWriter "" (type.method [(list (type.class "java.io.Writer" (list)) type.boolean) type.void (list)])) )] (|>> ($d.method #$.Public $.staticM "try" ..try - (<| _.with-label (function (_ @from)) - _.with-label (function (_ @to)) - _.with-label (function (_ @handler)) + (<| _.with_label (function (_ @from)) + _.with_label (function (_ @to)) + _.with_label (function (_ @handler)) (|>> (_.try @from @to @handler $Throwable) (_.label @from) (_.ALOAD 0) _.NULL - (_.INVOKEVIRTUAL //.$Function apply-method (apply-signature 1)) + (_.INVOKEVIRTUAL //.$Function apply_method (apply_signature 1)) rightI _.ARETURN (_.label @to) (_.label @handler) - string-writerI ## TW + string_writerI ## TW _.DUP2 ## TWTW - print-writerI ## TWTP + 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 _.SWAP _.POP leftI @@ -334,49 +334,49 @@ (-> (Type (<| Return' Value' category)) Text)) (|>> type.reflection reflection.reflection)) -(def: translate-runtime +(def: translate_runtime (Operation [Text Binary]) - (let [runtime-class (..reflection //.$Runtime) - bytecode ($d.class #$.V1_6 #$.Public $.finalC runtime-class (list) (type.class "java.lang.Object" (list)) (list) - (|>> adt-methods - frac-methods - pm-methods - io-methods)) - directive [runtime-class bytecode]] + (let [runtime_class (..reflection //.$Runtime) + bytecode ($d.class #$.V1_6 #$.Public $.finalC runtime_class (list) (type.class "java.lang.Object" (list)) (list) + (|>> adt_methods + frac_methods + pm_methods + io_methods)) + directive [runtime_class bytecode]] (do phase.monad [_ (generation.execute! directive) _ (generation.save! "0" directive)] (wrap ["0" bytecode])))) -(def: translate-function +(def: translate_function (Operation [Text Binary]) - (let [applyI (|> (enum.range n.enum 2 num-apply-variants) + (let [applyI (|> (enum.range n.enum 2 num_apply_variants) (list@map (function (_ arity) - ($d.method #$.Public $.noneM apply-method (apply-signature arity) + ($d.method #$.Public $.noneM apply_method (apply_signature arity) (let [preI (|> (enum.range n.enum 0 (dec arity)) (list@map _.ALOAD) _.fuse)] (|>> preI - (_.INVOKEVIRTUAL //.$Function apply-method (apply-signature (dec arity))) + (_.INVOKEVIRTUAL //.$Function apply_method (apply_signature (dec arity))) (_.CHECKCAST //.$Function) (_.ALOAD arity) - (_.INVOKEVIRTUAL //.$Function apply-method (apply-signature 1)) + (_.INVOKEVIRTUAL //.$Function apply_method (apply_signature 1)) _.ARETURN))))) - (list& ($d.abstract-method #$.Public $.noneM apply-method (apply-signature 1))) + (list& ($d.abstract_method #$.Public $.noneM apply_method (apply_signature 1))) $d.fuse) $Object (type.class "java.lang.Object" (list)) - function-class (..reflection //.$Function) - bytecode ($d.abstract #$.V1_6 #$.Public $.noneC function-class (list) $Object (list) - (|>> ($d.field #$.Public $.finalF partials-field type.int) + 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)]) (|>> (_.ALOAD 0) - (_.INVOKESPECIAL $Object "" nullary-init-methodT) + (_.INVOKESPECIAL $Object "" nullary_init_methodT) (_.ALOAD 0) (_.ILOAD 1) - (_.PUTFIELD //.$Function partials-field type.int) + (_.PUTFIELD //.$Function partials_field type.int) _.RETURN)) applyI)) - directive [function-class bytecode]] + directive [function_class bytecode]] (do phase.monad [_ (generation.execute! directive) _ (generation.save! "1" directive)] @@ -385,12 +385,12 @@ (def: #export translate (Operation [Registry Output]) (do phase.monad - [runtime-payload ..translate-runtime - function-payload ..translate-function] + [runtime_payload ..translate_runtime + function_payload ..translate_function] (wrap [(|> artifact.empty artifact.resource product.right artifact.resource product.right) - (row.row runtime-payload - function-payload)]))) + (row.row runtime_payload + function_payload)]))) -- cgit v1.2.3