aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEduardo Julian2019-10-16 00:51:45 -0400
committerEduardo Julian2019-10-16 00:51:45 -0400
commit688870c71829e1bee89c9f827cc2032507cc507b (patch)
tree8724a93a437936d8120143656d6e2926e68789cc
parent2b5351eb4624ce3c3ada994caaaea77c9d397eb8 (diff)
Small refactoring
-rw-r--r--new-luxc/source/luxc/lang/translation/jvm/function.lux49
-rw-r--r--stdlib/source/lux/tool/compiler/phase/generation/jvm.lux8
-rw-r--r--stdlib/source/test/lux.lux2
-rw-r--r--stdlib/source/test/lux/extension.lux2
4 files changed, 30 insertions, 31 deletions
diff --git a/new-luxc/source/luxc/lang/translation/jvm/function.lux b/new-luxc/source/luxc/lang/translation/jvm/function.lux
index d95c2c6c0..bd651f786 100644
--- a/new-luxc/source/luxc/lang/translation/jvm/function.lux
+++ b/new-luxc/source/luxc/lang/translation/jvm/function.lux
@@ -41,10 +41,6 @@
(-> Arity Bit)
(n.> 1 arity))
-(def: (reset-method return)
- (-> (Type Class) [(Signature Method) (Descriptor Method)])
- (type.method [(list) return (list)]))
-
(def: (captured-args env)
(-> Environment (List (Type Value)))
(list.repeat (list.size env) //.$Value))
@@ -100,22 +96,6 @@
(list.repeat amount)
_.fuse))
-(def: #export with-environment
- (-> Environment Def)
- (|>> list.enumerate
- (list@map (.function (_ [env-idx env-source])
- (def.field #$.Private $.finalF (reference.foreign-name env-idx) //.$Value)))
- def.fuse))
-
-(def: (with-partial arity)
- (-> Arity Def)
- (if (poly-arg? arity)
- (|> (list.n/range 0 (n.- 2 arity))
- (list@map (.function (_ idx)
- (def.field #$.Private $.finalF (reference.partial-name idx) //.$Value)))
- def.fuse)
- function.identity))
-
(def: (instance class arity env)
(-> (Type Class) Arity Environment (Operation Inst))
(do phase.monad
@@ -131,6 +111,10 @@
argsI
(_.INVOKESPECIAL class "<init>" (init-method env arity))))))
+(def: (reset-method return)
+ (-> (Type Class) [(Signature Method) (Descriptor Method)])
+ (type.method [(list) return (list)]))
+
(def: (with-reset class arity env)
(-> (Type Class) Arity Environment Def)
(def.method #$.Public $.noneM "reset" (reset-method class)
@@ -208,7 +192,7 @@
(let [num-partials (dec function-arity)
@default ($.new-label [])
@labels (list@map $.new-label (list.repeat num-partials []))
- arity-over-extent (|> (.int function-arity) (i.- (.int apply-arity)))
+ over-extent (|> (.int function-arity) (i.- (.int apply-arity)))
casesI (|> (list@compose @labels (list @default))
(list.zip2 (list.n/range 0 num-partials))
(list@map (.function (_ [stage @label])
@@ -217,7 +201,7 @@
(list@map (|>> reference.partial-name (load-fieldI class)))
_.fuse)
function.identity)]
- (cond (i.= arity-over-extent (.int stage))
+ (cond (i.= over-extent (.int stage))
(|>> (_.label @label)
(_.ALOAD 0)
(when> [(new> (n.> 0 stage) [])]
@@ -227,7 +211,7 @@
(_.INVOKEVIRTUAL class "impl" (implementation-method function-arity))
_.ARETURN)
- (i.> arity-over-extent (.int stage))
+ (i.> over-extent (.int stage))
(let [args-to-completion (|> function-arity (n.- stage))
args-left (|> apply-arity (n.- args-to-completion))]
(|>> (_.label @label)
@@ -239,7 +223,7 @@
(applysI (inc args-to-completion) args-left)
_.ARETURN))
- ## (i.< arity-over-extent (.int stage))
+ ## (i.< over-extent (.int stage))
(let [env-size (list.size env)
load-capturedI (|> (case env-size
0 (list)
@@ -270,11 +254,26 @@
failureI
))))
+(def: #export with-environment
+ (-> Environment Def)
+ (|>> list.enumerate
+ (list@map (.function (_ [env-idx env-source])
+ (def.field #$.Private $.finalF (reference.foreign-name env-idx) //.$Value)))
+ def.fuse))
+
+(def: (with-partial arity)
+ (-> Arity Def)
+ (if (poly-arg? arity)
+ (|> (list.n/range 0 (n.- 2 arity))
+ (list@map (.function (_ idx)
+ (def.field #$.Private $.finalF (reference.partial-name idx) //.$Value)))
+ def.fuse)
+ function.identity))
+
(def: #export (with-function @begin class env arity bodyI)
(-> Label Text Environment Arity Inst
(Operation [Def Inst]))
(let [classD (type.class class (list))
- env-size (list.size env)
applyD (: Def
(if (poly-arg? arity)
(|> (n.min arity runtime.num-apply-variants)
diff --git a/stdlib/source/lux/tool/compiler/phase/generation/jvm.lux b/stdlib/source/lux/tool/compiler/phase/generation/jvm.lux
index 23f3defea..b67ddcbcd 100644
--- a/stdlib/source/lux/tool/compiler/phase/generation/jvm.lux
+++ b/stdlib/source/lux/tool/compiler/phase/generation/jvm.lux
@@ -7,9 +7,9 @@
["#." primitive]
["#." structure]
["#." reference]
- ["#." function]
- ## ["." case]
- ## ["." loop]
+ ## ["#." function]
+ ## ["#." case]
+ ## ["#." loop]
["//#" ///
## ["." extension]
[//
@@ -58,7 +58,7 @@
## (/loop.recur generate updates)
## (^ (synthesis.function/abstraction abstraction))
- ## (/function.function generate abstraction)
+ ## (/function.abstraction generate abstraction)
## (^ (synthesis.function/apply application))
## (/function.apply generate application)
diff --git a/stdlib/source/test/lux.lux b/stdlib/source/test/lux.lux
index 4be2dcf27..34000d362 100644
--- a/stdlib/source/test/lux.lux
+++ b/stdlib/source/test/lux.lux
@@ -1,7 +1,7 @@
(.with-expansions [<host-modules> (.as-is [runtime (#+)]
[primitive (#+)]
[structure (#+)]
- [function (#+)]
+ ## [function (#+)]
[reference (#+)]
## [case (#+)]
## [loop (#+)]
diff --git a/stdlib/source/test/lux/extension.lux b/stdlib/source/test/lux/extension.lux
index f73ad63a1..645558d5f 100644
--- a/stdlib/source/test/lux/extension.lux
+++ b/stdlib/source/test/lux/extension.lux
@@ -41,6 +41,6 @@
(def: #export test
Test
(<| (_.context (%.name (name-of /._)))
- (_.test "Can define and user analysis & synthesis extensions."
+ (_.test "Can define and use analysis & synthesis extensions."
(text@= ("example YOLO")
"example YOLO"))))