aboutsummaryrefslogtreecommitdiff
path: root/lux-jvm/source/luxc/lang/translation/jvm/function.lux
diff options
context:
space:
mode:
authorEduardo Julian2020-12-29 00:38:21 -0400
committerEduardo Julian2020-12-29 00:38:21 -0400
commit832a9361b632331e82a64c07baa560487ca8abde (patch)
tree5fec882399315def4d789ecef1746d90e761df93 /lux-jvm/source/luxc/lang/translation/jvm/function.lux
parent92dca9f487c625d27f6c291784ef709b0cc13a72 (diff)
Moved "lux/data/number" to "lux/math/number".
Diffstat (limited to '')
-rw-r--r--lux-jvm/source/luxc/lang/translation/jvm/function.lux228
1 files changed, 114 insertions, 114 deletions
diff --git a/lux-jvm/source/luxc/lang/translation/jvm/function.lux b/lux-jvm/source/luxc/lang/translation/jvm/function.lux
index 97b32f8c2..0fe7717fb 100644
--- a/lux-jvm/source/luxc/lang/translation/jvm/function.lux
+++ b/lux-jvm/source/luxc/lang/translation/jvm/function.lux
@@ -42,35 +42,35 @@
["#." runtime]
["." reference]])
-(def: arity-field Text "arity")
+(def: arity_field Text "arity")
-(def: (poly-arg? arity)
+(def: poly_arg?
(-> Arity Bit)
- (n.> 1 arity))
+ (n.> 1))
-(def: (captured-args env)
+(def: (captured_args env)
(-> (Environment Synthesis) (List (Type Value)))
(list.repeat (list.size env) //.$Value))
-(def: (init-method env arity)
+(def: (init_method env arity)
(-> (Environment Synthesis) Arity (Type Method))
- (if (poly-arg? arity)
- (type.method [(list.concat (list (captured-args env)
+ (if (poly_arg? arity)
+ (type.method [(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 [(captured_args env) type.void (list)])))
-(def: (implementation-method arity)
+(def: (implementation_method arity)
(type.method [(list.repeat arity //.$Value) //.$Value (list)]))
-(def: get-amount-of-partialsI
+(def: get_amount_of_partialsI
Inst
(|>> (_.ALOAD 0)
- (_.GETFIELD //.$Function //runtime.partials-field type.int)))
+ (_.GETFIELD //.$Function //runtime.partials_field type.int)))
-(def: (load-fieldI class field)
+(def: (load_fieldI class field)
(-> (Type Class) Text Inst)
(|>> (_.ALOAD 0)
(_.GETFIELD class field //.$Value)))
@@ -83,16 +83,16 @@
(def: (applysI start amount)
(-> Register Nat Inst)
- (let [max-args (n.min amount //runtime.num-apply-variants)
- later-applysI (if (n.> //runtime.num-apply-variants amount)
- (applysI (n.+ //runtime.num-apply-variants start) (n.- //runtime.num-apply-variants amount))
+ (let [max_args (n.min amount //runtime.num_apply_variants)
+ later_applysI (if (n.> //runtime.num_apply_variants amount)
+ (applysI (n.+ //runtime.num_apply_variants start) (n.- //runtime.num_apply_variants amount))
function.identity)]
(|>> (_.CHECKCAST //.$Function)
- (inputsI start max-args)
- (_.INVOKEVIRTUAL //.$Function //runtime.apply-method (//runtime.apply-signature max-args))
- later-applysI)))
+ (inputsI start max_args)
+ (_.INVOKEVIRTUAL //.$Function //runtime.apply_method (//runtime.apply_signature max_args))
+ later_applysI)))
-(def: (inc-intI by)
+(def: (inc_intI by)
(-> Nat Inst)
(|>> (_.int (.int by))
_.IADD))
@@ -107,7 +107,7 @@
(-> Phase Archive (Type Class) Arity (Environment Synthesis) (Operation Inst))
(do {@ phase.monad}
[captureI+ (monad.map @ (generate archive) env)
- #let [argsI (if (poly-arg? arity)
+ #let [argsI (if (poly_arg? arity)
(|> (nullsI (dec arity))
(list (_.int +0))
_.fuse)
@@ -116,23 +116,23 @@
_.DUP
(_.fuse captureI+)
argsI
- (_.INVOKESPECIAL class "<init>" (init-method env arity))))))
+ (_.INVOKESPECIAL class "<init>" (init_method env arity))))))
-(def: (reset-method return)
+(def: (reset_method return)
(-> (Type Class) (Type Method))
(type.method [(list) return (list)]))
-(def: (with-reset class arity env)
+(def: (with_reset class arity env)
(-> (Type Class) Arity (Environment Synthesis) Def)
- (def.method #$.Public $.noneM "reset" (reset-method class)
- (if (poly-arg? arity)
- (let [env-size (list.size env)
- captureI (|> (case env-size
+ (def.method #$.Public $.noneM "reset" (reset_method class)
+ (if (poly_arg? arity)
+ (let [env_size (list.size env)
+ captureI (|> (case env_size
0 (list)
- _ (enum.range n.enum 0 (dec env-size)))
+ _ (enum.range n.enum 0 (dec env_size)))
(list@map (.function (_ source)
(|>> (_.ALOAD 0)
- (_.GETFIELD class (reference.foreign-name source) //.$Value))))
+ (_.GETFIELD class (reference.foreign_name source) //.$Value))))
_.fuse)
argsI (|> (nullsI (dec arity))
(list (_.int +0))
@@ -141,159 +141,159 @@
_.DUP
captureI
argsI
- (_.INVOKESPECIAL class "<init>" (init-method env arity))
+ (_.INVOKESPECIAL class "<init>" (init_method env arity))
_.ARETURN))
(|>> (_.ALOAD 0)
_.ARETURN))))
-(def: (with-implementation arity @begin bodyI)
+(def: (with_implementation arity @begin bodyI)
(-> Nat Label Inst Def)
- (def.method #$.Public $.strictM "impl" (implementation-method arity)
+ (def.method #$.Public $.strictM "impl" (implementation_method arity)
(|>> (_.label @begin)
bodyI
_.ARETURN)))
-(def: function-init-method
+(def: function_init_method
(type.method [(list type.int) type.void (list)]))
-(def: (function-init arity env-size)
+(def: (function_init arity env_size)
(-> Arity Nat Inst)
(if (n.= 1 arity)
(|>> (_.int +0)
- (_.INVOKESPECIAL //.$Function "<init>" function-init-method))
- (|>> (_.ILOAD (inc env-size))
- (_.INVOKESPECIAL //.$Function "<init>" function-init-method))))
+ (_.INVOKESPECIAL //.$Function "<init>" function_init_method))
+ (|>> (_.ILOAD (inc env_size))
+ (_.INVOKESPECIAL //.$Function "<init>" function_init_method))))
-(def: (with-init class env arity)
+(def: (with_init class env arity)
(-> (Type Class) (Environment Synthesis) Arity Def)
- (let [env-size (list.size env)
- offset-partial (: (-> Nat Nat)
- (|>> inc (n.+ env-size)))
- store-capturedI (|> (case env-size
+ (let [env_size (list.size env)
+ offset_partial (: (-> Nat Nat)
+ (|>> inc (n.+ env_size)))
+ store_capturedI (|> (case env_size
0 (list)
- _ (enum.range n.enum 0 (dec env-size)))
+ _ (enum.range n.enum 0 (dec env_size)))
(list@map (.function (_ register)
(|>> (_.ALOAD 0)
(_.ALOAD (inc register))
- (_.PUTFIELD class (reference.foreign-name register) //.$Value))))
+ (_.PUTFIELD class (reference.foreign_name register) //.$Value))))
_.fuse)
- store-partialI (if (poly-arg? arity)
+ store_partialI (if (poly_arg? arity)
(|> (enum.range n.enum 0 (n.- 2 arity))
(list@map (.function (_ idx)
- (let [register (offset-partial idx)]
+ (let [register (offset_partial idx)]
(|>> (_.ALOAD 0)
(_.ALOAD (inc register))
- (_.PUTFIELD class (reference.partial-name idx) //.$Value)))))
+ (_.PUTFIELD class (reference.partial_name idx) //.$Value)))))
_.fuse)
function.identity)]
- (def.method #$.Public $.noneM "<init>" (init-method env arity)
+ (def.method #$.Public $.noneM "<init>" (init_method env arity)
(|>> (_.ALOAD 0)
- (function-init arity env-size)
- store-capturedI
- store-partialI
+ (function_init arity env_size)
+ store_capturedI
+ store_partialI
_.RETURN))))
-(def: (with-apply class env function-arity @begin bodyI apply-arity)
+(def: (with_apply class env function_arity @begin bodyI apply_arity)
(-> (Type Class) (Environment Synthesis) Arity Label Inst Arity
Def)
- (let [num-partials (dec function-arity)
- @default ($.new-label [])
- @labels (list@map $.new-label (list.repeat num-partials []))
- over-extent (|> (.int function-arity) (i.- (.int apply-arity)))
+ (let [num_partials (dec function_arity)
+ @default ($.new_label [])
+ @labels (list@map $.new_label (list.repeat num_partials []))
+ over_extent (|> (.int function_arity) (i.- (.int apply_arity)))
casesI (|> (list@compose @labels (list @default))
- (list.zip/2 (enum.range n.enum 0 num-partials))
+ (list.zip/2 (enum.range n.enum 0 num_partials))
(list@map (.function (_ [stage @label])
- (let [load-partialsI (if (n.> 0 stage)
+ (let [load_partialsI (if (n.> 0 stage)
(|> (enum.range n.enum 0 (dec stage))
- (list@map (|>> reference.partial-name (load-fieldI class)))
+ (list@map (|>> reference.partial_name (load_fieldI class)))
_.fuse)
function.identity)]
- (cond (i.= over-extent (.int stage))
+ (cond (i.= over_extent (.int stage))
(|>> (_.label @label)
(_.ALOAD 0)
(when> [(new> (n.> 0 stage) [])]
- [(_.INVOKEVIRTUAL class "reset" (reset-method class))])
- load-partialsI
- (inputsI 1 apply-arity)
- (_.INVOKEVIRTUAL class "impl" (implementation-method function-arity))
+ [(_.INVOKEVIRTUAL class "reset" (reset_method class))])
+ load_partialsI
+ (inputsI 1 apply_arity)
+ (_.INVOKEVIRTUAL class "impl" (implementation_method function_arity))
_.ARETURN)
- (i.> over-extent (.int stage))
- (let [args-to-completion (|> function-arity (n.- stage))
- args-left (|> apply-arity (n.- args-to-completion))]
+ (i.> over_extent (.int stage))
+ (let [args_to_completion (|> function_arity (n.- stage))
+ args_left (|> apply_arity (n.- args_to_completion))]
(|>> (_.label @label)
(_.ALOAD 0)
- (_.INVOKEVIRTUAL class "reset" (reset-method class))
- load-partialsI
- (inputsI 1 args-to-completion)
- (_.INVOKEVIRTUAL class "impl" (implementation-method function-arity))
- (applysI (inc args-to-completion) args-left)
+ (_.INVOKEVIRTUAL class "reset" (reset_method class))
+ load_partialsI
+ (inputsI 1 args_to_completion)
+ (_.INVOKEVIRTUAL class "impl" (implementation_method function_arity))
+ (applysI (inc args_to_completion) args_left)
_.ARETURN))
- ## (i.< over-extent (.int stage))
- (let [env-size (list.size env)
- load-capturedI (|> (case env-size
+ ## (i.< over_extent (.int stage))
+ (let [env_size (list.size env)
+ load_capturedI (|> (case env_size
0 (list)
- _ (enum.range n.enum 0 (dec env-size)))
- (list@map (|>> reference.foreign-name (load-fieldI class)))
+ _ (enum.range n.enum 0 (dec env_size)))
+ (list@map (|>> reference.foreign_name (load_fieldI class)))
_.fuse)]
(|>> (_.label @label)
(_.NEW class)
_.DUP
- load-capturedI
- get-amount-of-partialsI
- (inc-intI apply-arity)
- load-partialsI
- (inputsI 1 apply-arity)
- (nullsI (|> num-partials (n.- apply-arity) (n.- stage)))
- (_.INVOKESPECIAL class "<init>" (init-method env function-arity))
+ load_capturedI
+ get_amount_of_partialsI
+ (inc_intI apply_arity)
+ load_partialsI
+ (inputsI 1 apply_arity)
+ (nullsI (|> num_partials (n.- apply_arity) (n.- stage)))
+ (_.INVOKESPECIAL class "<init>" (init_method env function_arity))
_.ARETURN))
))))
_.fuse)]
- (def.method #$.Public $.noneM //runtime.apply-method (//runtime.apply-signature apply-arity)
- (|>> get-amount-of-partialsI
- (_.TABLESWITCH +0 (|> num-partials dec .int)
+ (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
))))
-(def: #export with-environment
+(def: #export with_environment
(-> (Environment Synthesis) Def)
(|>> list.enumeration
- (list@map (.function (_ [env-idx env-source])
- (def.field #$.Private $.finalF (reference.foreign-name env-idx) //.$Value)))
+ (list@map (.function (_ [env_idx env_source])
+ (def.field #$.Private $.finalF (reference.foreign_name env_idx) //.$Value)))
def.fuse))
-(def: (with-partial arity)
+(def: (with_partial arity)
(-> Arity Def)
- (if (poly-arg? arity)
+ (if (poly_arg? arity)
(|> (enum.range n.enum 0 (n.- 2 arity))
(list@map (.function (_ idx)
- (def.field #$.Private $.finalF (reference.partial-name idx) //.$Value)))
+ (def.field #$.Private $.finalF (reference.partial_name idx) //.$Value)))
def.fuse)
function.identity))
-(def: #export (with-function generate archive @begin class env arity bodyI)
+(def: #export (with_function generate archive @begin class env arity bodyI)
(-> Phase Archive Label Text (Environment Synthesis) Arity Inst
(Operation [Def Inst]))
(let [classD (type.class class (list))
applyD (: Def
- (if (poly-arg? arity)
- (|> (n.min arity //runtime.num-apply-variants)
+ (if (poly_arg? arity)
+ (|> (n.min arity //runtime.num_apply_variants)
(enum.range n.enum 1)
- (list@map (with-apply classD env arity @begin bodyI))
- (list& (with-implementation arity @begin bodyI))
+ (list@map (with_apply classD env arity @begin bodyI))
+ (list& (with_implementation arity @begin bodyI))
def.fuse)
- (def.method #$.Public $.strictM //runtime.apply-method (//runtime.apply-signature 1)
+ (def.method #$.Public $.strictM //runtime.apply_method (//runtime.apply_signature 1)
(|>> (_.label @begin)
bodyI
_.ARETURN))))
functionD (: Def
- (|>> (def.int-field #$.Public ($_ $.++F $.staticF $.finalF) arity-field (.int arity))
- (with-environment env)
- (with-partial arity)
- (with-init classD env arity)
- (with-reset classD arity env)
+ (|>> (def.int_field #$.Public ($_ $.++F $.staticF $.finalF) arity_field (.int arity))
+ (with_environment env)
+ (with_partial arity)
+ (with_init classD env arity)
+ (with_reset classD arity env)
applyD
))]
(do phase.monad
@@ -303,19 +303,19 @@
(def: #export (function generate archive [env arity bodyS])
(Generator Abstraction)
(do phase.monad
- [@begin _.make-label
- [function-context bodyI] (generation.with-new-context archive
- (generation.with-anchor [@begin 1]
+ [@begin _.make_label
+ [function_context bodyI] (generation.with_new_context archive
+ (generation.with_anchor [@begin 1]
(generate archive bodyS)))
- #let [function-class (//.class-name function-context)]
- [functionD instanceI] (..with-function generate archive @begin function-class env arity bodyI)
- #let [directive [function-class
+ #let [function_class (//.class_name function_context)]
+ [functionD instanceI] (..with_function generate archive @begin function_class env arity bodyI)
+ #let [directive [function_class
(def.class #$.V1_6 #$.Public $.finalC
- function-class (list)
+ function_class (list)
//.$Function (list)
functionD)]]
_ (generation.execute! directive)
- _ (generation.save! (%.nat (product.right function-context)) directive)]
+ _ (generation.save! (%.nat (product.right function_context)) directive)]
(wrap instanceI)))
(def: #export (call generate archive [functionS argsS])
@@ -324,11 +324,11 @@
[functionI (generate archive functionS)
argsI (monad.map @ (generate archive) argsS)
#let [applyI (|> argsI
- (list.chunk //runtime.num-apply-variants)
+ (list.chunk //runtime.num_apply_variants)
(list@map (.function (_ chunkI+)
(|>> (_.CHECKCAST //.$Function)
(_.fuse chunkI+)
- (_.INVOKEVIRTUAL //.$Function //runtime.apply-method (//runtime.apply-signature (list.size chunkI+))))))
+ (_.INVOKEVIRTUAL //.$Function //runtime.apply_method (//runtime.apply_signature (list.size chunkI+))))))
_.fuse)]]
(wrap (|>> functionI
applyI))))