aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/source
diff options
context:
space:
mode:
Diffstat (limited to 'new-luxc/source')
-rw-r--r--new-luxc/source/luxc/lang/translation/jvm.lux6
-rw-r--r--new-luxc/source/luxc/lang/translation/jvm/case.lux14
-rw-r--r--new-luxc/source/luxc/lang/translation/jvm/function.lux11
-rw-r--r--new-luxc/source/luxc/lang/translation/jvm/procedure/common.lux7
-rw-r--r--new-luxc/source/luxc/lang/translation/jvm/runtime.lux26
-rw-r--r--new-luxc/source/luxc/lang/translation/jvm/structure.lux2
-rw-r--r--new-luxc/source/program.lux5
7 files changed, 37 insertions, 34 deletions
diff --git a/new-luxc/source/luxc/lang/translation/jvm.lux b/new-luxc/source/luxc/lang/translation/jvm.lux
index 86d7f9b9a..fccbd14bf 100644
--- a/new-luxc/source/luxc/lang/translation/jvm.lux
+++ b/new-luxc/source/luxc/lang/translation/jvm.lux
@@ -148,9 +148,7 @@
(def: define!
(..define! library loader)))))))
-(def: #export runtime-class "LuxRuntime")
-(def: #export function-class "LuxFunction")
-
(def: #export $Variant (type.array ..$Value))
(def: #export $Tuple (type.array ..$Value))
-(def: #export $Function (type.class ..function-class (list)))
+(def: #export $Function (type.class "LuxFunction" (list)))
+(def: #export $Runtime (type.class "LuxRuntime" (list)))
diff --git a/new-luxc/source/luxc/lang/translation/jvm/case.lux b/new-luxc/source/luxc/lang/translation/jvm/case.lux
index c157a5776..484604323 100644
--- a/new-luxc/source/luxc/lang/translation/jvm/case.lux
+++ b/new-luxc/source/luxc/lang/translation/jvm/case.lux
@@ -26,8 +26,6 @@
["." //
["." runtime]])
-(def: $Runtime (type.class //.runtime-class (list)))
-
(def: (pop-altI stack-depth)
(-> Nat Inst)
(.case stack-depth
@@ -45,7 +43,7 @@
(def: pushI
Inst
- (|>> (_.INVOKESTATIC $Runtime "pm_push" (type.method [(list runtime.$Stack //.$Value) runtime.$Stack (list)]))))
+ (|>> (_.INVOKESTATIC //.$Runtime "pm_push" (type.method [(list runtime.$Stack //.$Value) runtime.$Stack (list)]))))
(def: (path' phase stack-depth @else @end path)
(-> Phase Nat Label Label Path (Operation Inst))
@@ -100,7 +98,7 @@
(_.CHECKCAST //.$Variant)
(_.int (.int (<prepare> idx)))
<flag>
- (_.INVOKESTATIC $Runtime "pm_variant" (type.method [(list //.$Variant runtime.$Tag runtime.$Flag) runtime.$Value (list)]))
+ (_.INVOKESTATIC //.$Runtime "pm_variant" (type.method [(list //.$Variant runtime.$Tag runtime.$Flag) runtime.$Value (list)]))
_.DUP
(_.IFNULL @fail)
(_.GOTO @success)
@@ -118,7 +116,7 @@
_.AALOAD
lefts
- (_.INVOKESTATIC $Runtime "tuple_left" (type.method [(list //.$Tuple runtime.$Index) //.$Value (list)])))]
+ (_.INVOKESTATIC //.$Runtime "tuple_left" (type.method [(list //.$Tuple runtime.$Index) //.$Value (list)])))]
(|>> peekI
(_.CHECKCAST //.$Tuple)
(_.int (.int lefts))
@@ -129,7 +127,7 @@
(operation@wrap (|>> peekI
(_.CHECKCAST //.$Tuple)
(_.int (.int lefts))
- (_.INVOKESTATIC $Runtime "tuple_right" (type.method [(list //.$Tuple runtime.$Index) //.$Value (list)]))
+ (_.INVOKESTATIC //.$Runtime "tuple_right" (type.method [(list //.$Tuple runtime.$Index) //.$Value (list)]))
pushI))
## Extra optimization
@@ -155,7 +153,7 @@
(wrap (|>> peekI
(_.CHECKCAST //.$Tuple)
(_.int (.int lefts))
- (_.INVOKESTATIC $Runtime <getter> (type.method [(list //.$Tuple runtime.$Index) //.$Value (list)]))
+ (_.INVOKESTATIC //.$Runtime <getter> (type.method [(list //.$Tuple runtime.$Index) //.$Value (list)]))
(_.ASTORE register)
then!))))
([synthesis.member/left "tuple_left"]
@@ -188,7 +186,7 @@
(wrap (|>> pathI
(_.label @else)
_.POP
- (_.INVOKESTATIC $Runtime "pm_fail" (type.method [(list) type.void (list)]))
+ (_.INVOKESTATIC //.$Runtime "pm_fail" (type.method [(list) type.void (list)]))
_.NULL
(_.GOTO @end)))))
diff --git a/new-luxc/source/luxc/lang/translation/jvm/function.lux b/new-luxc/source/luxc/lang/translation/jvm/function.lux
index 56ef21b46..d95c2c6c0 100644
--- a/new-luxc/source/luxc/lang/translation/jvm/function.lux
+++ b/new-luxc/source/luxc/lang/translation/jvm/function.lux
@@ -258,15 +258,16 @@
(_.INVOKESPECIAL class "<init>" (init-method env function-arity))
_.ARETURN))
))))
- _.fuse)]
+ _.fuse)
+ failureI (|>> (_.INVOKESTATIC //.$Runtime "apply_fail" (type.method [(list) type.void (list)]))
+ _.NULL
+ _.ARETURN)]
(def.method #$.Public $.noneM runtime.apply-method (runtime.apply-signature apply-arity)
(|>> get-amount-of-partialsI
(_.TABLESWITCH +0 (|> num-partials dec .int)
@default @labels)
casesI
- (_.INVOKESTATIC runtime.$Runtime "apply_fail" (type.method [(list) type.void (list)]))
- _.NULL
- _.ARETURN
+ failureI
))))
(def: #export (with-function @begin class env arity bodyI)
@@ -309,7 +310,7 @@
[function-class
(def.class #$.V1_6 #$.Public $.finalC
function-class (list)
- ($.simple-class //.function-class) (list)
+ //.$Function (list)
functionD)])]
(wrap instanceI)))
diff --git a/new-luxc/source/luxc/lang/translation/jvm/procedure/common.lux b/new-luxc/source/luxc/lang/translation/jvm/procedure/common.lux
index 9ed40a99a..a46813232 100644
--- a/new-luxc/source/luxc/lang/translation/jvm/procedure/common.lux
+++ b/new-luxc/source/luxc/lang/translation/jvm/procedure/common.lux
@@ -16,7 +16,8 @@
["." dictionary]]]
[target
[jvm
- ["." type]]]
+ ["." type
+ ["." signature]]]]
[tool
[compiler
["." synthesis (#+ Synthesis %synthesis)]
@@ -128,7 +129,7 @@
(Unary Inst)
(|>> riskyI
(_.CHECKCAST ///.$Function)
- (_.INVOKESTATIC runtime.$Runtime "try" (type.method [(list ///.$Function) ///.$Variant (list)]))))
+ (_.INVOKESTATIC ///.$Runtime "try" runtime.try)))
(template [<name> <op>]
[(def: (<name> [maskI inputI])
@@ -216,7 +217,7 @@
[f64::encode (_.unwrap type.double)
(_.INVOKESTATIC (type.class "java.lang.Double" (list)) "toString" (type.method [(list type.double) $String (list)]))]
[f64::decode ..check-stringI
- (_.INVOKESTATIC runtime.$Runtime "decode_frac" (type.method [(list $String) ///.$Variant (list)]))]
+ (_.INVOKESTATIC ///.$Runtime "decode_frac" (type.method [(list $String) ///.$Variant (list)]))]
)
(def: (text::size inputI)
diff --git a/new-luxc/source/luxc/lang/translation/jvm/runtime.lux b/new-luxc/source/luxc/lang/translation/jvm/runtime.lux
index 11f8870eb..d616d62e9 100644
--- a/new-luxc/source/luxc/lang/translation/jvm/runtime.lux
+++ b/new-luxc/source/luxc/lang/translation/jvm/runtime.lux
@@ -11,7 +11,8 @@
["." type (#+ Type)
["." category (#+ Void Value Return Primitive Object Class Array Var Parameter Method)]
["." descriptor (#+ Descriptor)]
- ["." signature (#+ Signature)]]]]
+ ["." signature (#+ Signature)]
+ ["." reflection]]]]
[tool
[compiler
[arity (#+ Arity)]
@@ -33,7 +34,6 @@
(def: #export $Index type.int)
(def: #export $Stack (type.array $Value))
(def: $Throwable (type.class "java.lang.Throwable" (list)))
-(def: #export $Runtime (type.class "java.lang.Runtime" (list)))
(def: nullary-init-methodT
(type.method [(list) type.void (list)]))
@@ -55,7 +55,7 @@
(def: #export variantI
Inst
- (_.INVOKESTATIC (type.class //.runtime-class (list)) "variant_make" variant-method))
+ (_.INVOKESTATIC //.$Runtime "variant_make" variant-method))
(def: #export leftI
Inst
@@ -82,7 +82,7 @@
(_.string synthesis.unit)
variantI))
-(def: (try-methodI unsafeI)
+(def: (tryI unsafeI)
(-> Inst Inst)
(<| _.with-label (function (_ @from))
_.with-label (function (_ @to))
@@ -128,7 +128,7 @@
(def: frac-methods
Def
(|>> ($d.method #$.Public $.staticM "decode_frac" (type.method [(list $Text) //.$Variant (list)])
- (try-methodI
+ (tryI
(|>> (_.ALOAD 0)
(_.INVOKESTATIC (type.class "java.lang.Double" (list)) "parseDouble" (type.method [(list $Text) type.double (list)]))
(_.wrap type.double))))
@@ -280,6 +280,8 @@
)))
)))
+(def: #export try (type.method [(list //.$Function) //.$Variant (list)]))
+
(def: io-methods
Def
(let [StringWriter (type.class "java.io.StringWriter" (list))
@@ -295,7 +297,7 @@
(_.boolean true)
(_.INVOKESPECIAL PrintWriter "<init>" (type.method [(list (type.class "java.io.Writer" (list)) type.boolean) type.void (list)]))
)]
- (|>> ($d.method #$.Public $.staticM "try" (type.method [(list //.$Function) //.$Variant (list)])
+ (|>> ($d.method #$.Public $.staticM "try" ..try
(<| _.with-label (function (_ @from))
_.with-label (function (_ @to))
_.with-label (function (_ @handler))
@@ -317,15 +319,18 @@
_.ARETURN)))
)))
+(def: reflection (|>> type.reflection reflection.reflection))
+
(def: translate-runtime
(Operation ByteCode)
- (let [bytecode ($d.class #$.V1_6 #$.Public $.finalC //.runtime-class (list) (type.class "java.lang.Object" (list)) (list)
+ (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))]
(do phase.monad
- [_ (generation.execute! //.runtime-class [//.runtime-class bytecode])]
+ [_ (generation.execute! runtime-class [runtime-class bytecode])]
(wrap bytecode))))
(def: translate-function
@@ -345,7 +350,8 @@
(list& ($d.abstract-method #$.Public $.noneM apply-method (apply-signature 1)))
$d.fuse)
$Object (type.class "java.lang.Object" (list))
- bytecode ($d.abstract #$.V1_6 #$.Public $.noneC //.function-class (list) $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)
($d.method #$.Public $.noneM "<init>" (type.method [(list type.int) type.void (list)])
(|>> (_.ALOAD 0)
@@ -356,7 +362,7 @@
_.RETURN))
applyI))]
(do phase.monad
- [_ (generation.execute! //.function-class [//.function-class bytecode])]
+ [_ (generation.execute! function-class [function-class bytecode])]
(wrap bytecode))))
(def: #export translate
diff --git a/new-luxc/source/luxc/lang/translation/jvm/structure.lux b/new-luxc/source/luxc/lang/translation/jvm/structure.lux
index f7e66a75a..10c9bacb9 100644
--- a/new-luxc/source/luxc/lang/translation/jvm/structure.lux
+++ b/new-luxc/source/luxc/lang/translation/jvm/structure.lux
@@ -68,7 +68,7 @@
lefts)))
(flagI right?)
memberI
- (_.INVOKESTATIC (type.class //.runtime-class (list))
+ (_.INVOKESTATIC //.$Runtime
"variant_make"
(type.method [(list //runtime.$Tag //runtime.$Flag //runtime.$Value)
//.$Variant
diff --git a/new-luxc/source/program.lux b/new-luxc/source/program.lux
index 43cc9e9cd..b579b0df0 100644
--- a/new-luxc/source/program.lux
+++ b/new-luxc/source/program.lux
@@ -136,10 +136,9 @@
($i.label @end)
$i.POP
($i.ASTORE 0)))
- $Function ($t.class jvm.function-class (list))
- run-ioI (|>> ($i.CHECKCAST $Function)
+ run-ioI (|>> ($i.CHECKCAST jvm.$Function)
$i.NULL
- ($i.INVOKEVIRTUAL $Function runtime.apply-method (runtime.apply-signature 1)))
+ ($i.INVOKEVIRTUAL jvm.$Function runtime.apply-method (runtime.apply-signature 1)))
main-type ($t.method [(list ($t.array ($t.class "java.lang.String" (list))))
$t.void
(list)])