From bc36487224f670c23002cc4575c0dba3e5dc1be1 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Tue, 15 Mar 2022 07:24:35 -0400 Subject: De-sigil-ification: ^ --- lux-jvm/source/luxc/lang/directive/jvm.lux | 40 +++++---- lux-jvm/source/luxc/lang/synthesis/variable.lux | 100 --------------------- lux-jvm/source/luxc/lang/translation/jvm/case.lux | 18 ++-- .../luxc/lang/translation/jvm/expression.lux | 74 +++++++-------- .../luxc/lang/translation/jvm/extension/host.lux | 69 +++++++------- lux-jvm/source/luxc/lang/translation/jvm/loop.lux | 56 ++++++------ .../source/luxc/lang/translation/jvm/primitive.lux | 12 +-- 7 files changed, 138 insertions(+), 231 deletions(-) delete mode 100644 lux-jvm/source/luxc/lang/synthesis/variable.lux (limited to 'lux-jvm/source/luxc/lang') diff --git a/lux-jvm/source/luxc/lang/directive/jvm.lux b/lux-jvm/source/luxc/lang/directive/jvm.lux index 323c337d5..f125192f5 100644 --- a/lux-jvm/source/luxc/lang/directive/jvm.lux +++ b/lux-jvm/source/luxc/lang/directive/jvm.lux @@ -22,6 +22,8 @@ ["[0]" dictionary {"+" Dictionary}] ["[0]" sequence {"+" Sequence} ("[1]#[0]" functor mix)] ["[0]" set {"+" Set}]]] + [macro + ["^" pattern]] [math [number ["[0]" nat]]] @@ -254,7 +256,7 @@ (def: (object instruction) (-> /.Object Inst) (case instruction - (^template [ ] + (^.template [ ] [{ class field_name field_type} ( class field_name field_type)]) ([/.#GETSTATIC _.GETSTATIC] @@ -267,7 +269,7 @@ {/.#INSTANCEOF type} (_.INSTANCEOF type) {/.#CHECKCAST type} (_.CHECKCAST type) - (^template [ ] + (^.template [ ] [{ class method_name method_type} ( class method_name method_type)]) ([/.#INVOKEINTERFACE _.INVOKEINTERFACE] @@ -434,7 +436,7 @@ (def: (relabel_branching [mapping instruction]) (Re_labeler /.Branching) (case instruction - (^template [] + (^.template [] [{ label} (let [[mapping label] (..relabel [mapping label])] [mapping { label}])]) @@ -476,7 +478,7 @@ (def: (relabel_control [mapping instruction]) (Re_labeler /.Control) (case instruction - (^template [ ] + (^.template [ ] [{ instruction} (let [[mapping instruction] ( [mapping instruction])] [mapping { instruction}])]) @@ -484,7 +486,7 @@ [/.#Branching ..relabel_branching] [/.#Exception ..relabel_exception]) - (^template [] + (^.template [] [{ instruction} [mapping { instruction}]]) ([/.#Concurrency] [/.#Return]) @@ -499,7 +501,7 @@ {/.#NOP} [mapping {/.#NOP}] - (^template [] + (^.template [] [{ instruction} [mapping { instruction}]]) ([/.#Constant] @@ -568,7 +570,7 @@ (-> jvm.Extender ..Handler) (function (handler extension_name phase archive inputsC+) (case inputsC+ - (^ (list nameC valueC)) + (pattern (list nameC valueC)) (do phase.monad [[_ _ name] (lux/.evaluate! archive Text nameC) [_ handlerV] (lux/.generator archive (:as Text name) ..Handler' valueC) @@ -740,15 +742,15 @@ (in (cache.all (list& body_dependencies all_super_ctor_dependencies)))) - (^or {#Override [[parent_name parent_variables] name strict_floating_point? annotations variables + (^.or {#Override [[parent_name parent_variables] name strict_floating_point? annotations variables + self arguments return exceptions + body]} + {#Virtual [name privacy final? strict_floating_point? annotations variables self arguments return exceptions body]} - {#Virtual [name privacy final? strict_floating_point? annotations variables - self arguments return exceptions - body]} - {#Static [name privacy strict_floating_point? annotations variables - arguments return exceptions - body]}) + {#Static [name privacy strict_floating_point? annotations variables + arguments return exceptions + body]}) (cache.dependencies archive body) {#Abstract _} @@ -1204,7 +1206,7 @@ (in [privacy strict_floating_point? annotations method_tvars exceptions self arguments constructor_argumentsS (case bodyS - (^ (method_body bodyS)) + (pattern (method_body bodyS)) bodyS _ @@ -1223,7 +1225,7 @@ (in [[super_name super_tvars] method_name strict_floating_point? annotations method_tvars self arguments returnJ exceptionsJ (case bodyS - (^ (method_body bodyS)) + (pattern (method_body bodyS)) bodyS _ @@ -1242,7 +1244,7 @@ (in [name privacy final? strict_floating_point? annotations method_tvars self arguments returnJ exceptionsJ (case bodyS - (^ (method_body bodyS)) + (pattern (method_body bodyS)) bodyS _ @@ -1261,7 +1263,7 @@ (in [name privacy strict_floating_point? annotations method_tvars arguments returnJ exceptionsJ (case bodyS - (^ (method_body bodyS)) + (pattern (method_body bodyS)) bodyS _ @@ -1500,7 +1502,7 @@ (list#each ..constraint type_variables) supers (|> method_declarations - (list#each (function (_ (^open "_[0]")) + (list#each (function (_ (open "_[0]")) (def.abstract_method {jvm.#Public} jvm.noneM _#name (/type.method [_#type_variables _#arguments _#return _#exceptions])))) def.fuse))]]] diff --git a/lux-jvm/source/luxc/lang/synthesis/variable.lux b/lux-jvm/source/luxc/lang/synthesis/variable.lux deleted file mode 100644 index f1ea56e27..000000000 --- a/lux-jvm/source/luxc/lang/synthesis/variable.lux +++ /dev/null @@ -1,100 +0,0 @@ -(.using - lux - (lux (data [library - [number]] - (coll [list "list/" Mix Monoid] - ["s" set]))) - (luxc (lang ["la" analysis] - ["ls" synthesis] - ["[0]L" variable {"+" Variable}]))) - -(def: (bound-vars path) - (-> ls.Path (List Variable)) - (case path - {ls.#BindP register} - (list (.int register)) - - (^or {ls.#SeqP pre post} - {ls.#AltP pre post}) - (list/composite (bound-vars pre) (bound-vars post)) - - _ - (list))) - -(def: (path-bodies path) - (-> ls.Path (List ls.Synthesis)) - (case path - {ls.#ExecP body} - (list body) - - {ls.#SeqP pre post} - (path-bodies post) - - {ls.#AltP pre post} - (list/composite (path-bodies pre) (path-bodies post)) - - _ - (list))) - -(def: (non-arg? arity var) - (-> ls.Arity Variable Bit) - (and (variableL.local? var) - (n/> arity (.nat var)))) - -(type: Tracker (s.Set Variable)) - -(def: init-tracker Tracker (s.new number.Hash)) - -(def: (unused-vars current-arity bound exprS) - (-> ls.Arity (List Variable) ls.Synthesis (List Variable)) - (let [tracker (loop [exprS exprS - tracker (list/mix s.has init-tracker bound)] - (case exprS - {ls.#Variable var} - (if (non-arg? current-arity var) - (s.lacks var tracker) - tracker) - - {ls.#Variant tag last? memberS} - (again memberS tracker) - - {ls.#Tuple membersS} - (list/mix again tracker membersS) - - {ls.#Call funcS argsS} - (list/mix again (again funcS tracker) argsS) - - (^or {ls.#Again argsS} - {ls.#Procedure name argsS}) - (list/mix again tracker argsS) - - {ls.#Let offset inputS outputS} - (|> tracker (again inputS) (again outputS)) - - {ls.#If testS thenS elseS} - (|> tracker (again testS) (again thenS) (again elseS)) - - {ls.#Loop offset initsS bodyS} - (again bodyS (list/mix again tracker initsS)) - - {ls.#Case inputS outputPS} - (let [tracker' (list/mix s.has - (again inputS tracker) - (bound-vars outputPS))] - (list/mix again tracker' (path-bodies outputPS))) - - {ls.#Function arity env bodyS} - (list/mix s.lacks tracker env) - - _ - tracker - ))] - (s.to-list tracker))) - -... (def: (optimize-register-use current-arity [pathS bodyS]) -... (-> ls.Arity [ls.Path ls.Synthesis] [ls.Path ls.Synthesis]) -... (let [bound (bound-vars pathS) -... unused (unused-vars current-arity bound bodyS) -... adjusted (adjust-vars unused bound)] -... [(|> pathS (clean-pattern adjusted) simplify-pattern) -... (clean-expression adjusted bodyS)])) diff --git a/lux-jvm/source/luxc/lang/translation/jvm/case.lux b/lux-jvm/source/luxc/lang/translation/jvm/case.lux index 9a5172966..8e90b4510 100644 --- a/lux-jvm/source/luxc/lang/translation/jvm/case.lux +++ b/lux-jvm/source/luxc/lang/translation/jvm/case.lux @@ -9,6 +9,8 @@ [data [collection ["[0]" list ("[1]@[0]" mix)]]] + [macro + ["^" pattern]] [math [number ["n" nat]]] @@ -128,7 +130,7 @@ (_.label @else) elseG)))) - (^template [ ] + (^.template [ ] [{ cons} (do [@ phase.monad] [forkG (: (Operation Inst) @@ -163,8 +165,8 @@ bodyI (_.GOTO @end)))) - (^template [ ] - [(^ ( lefts)) + (^.template [ ] + [(pattern ( lefts)) (operation@in (<| _.with_label (function (_ @success)) _.with_label (function (_ @fail)) (|>> peekI @@ -184,15 +186,15 @@ [synthesis.side/right true]) ... Extra optimization - (^template [ ] - [(^ ( lefts)) + (^.template [ ] + [(pattern ( lefts)) (operation@in (|>> peekI ( lefts) pushI)) - (^ (synthesis.path/seq - ( lefts) - (synthesis.!bind_top register thenP))) + (pattern (synthesis.path/seq + ( lefts) + (synthesis.!bind_top register thenP))) (do phase.monad [then! (path' stack_depth @else @end phase archive thenP)] (in (|>> peekI diff --git a/lux-jvm/source/luxc/lang/translation/jvm/expression.lux b/lux-jvm/source/luxc/lang/translation/jvm/expression.lux index 8749b2ef2..692835dc4 100644 --- a/lux-jvm/source/luxc/lang/translation/jvm/expression.lux +++ b/lux-jvm/source/luxc/lang/translation/jvm/expression.lux @@ -1,77 +1,77 @@ (.using - [library - [lux "*" - [tool - [compiler - [language - [lux - ["[0]" synthesis] - [phase - ["[0]" extension]]]]]]]] - [luxc - [lang - [host - [jvm {"+" Phase}]]]] - [// - ["[0]" primitive] - ["[0]" structure] - ["[0]" reference] - ["[0]" case] - ["[0]" loop] - ["[0]" function]]) + [library + [lux "*" + [tool + [compiler + [language + [lux + ["[0]" synthesis] + [phase + ["[0]" extension]]]]]]]] + [luxc + [lang + [host + [jvm {"+" Phase}]]]] + [// + ["[0]" primitive] + ["[0]" structure] + ["[0]" reference] + ["[0]" case] + ["[0]" loop] + ["[0]" function]]) (def: .public (translate archive synthesis) Phase (case synthesis - (^ (synthesis.bit value)) + (pattern (synthesis.bit value)) (primitive.bit value) - (^ (synthesis.i64 value)) + (pattern (synthesis.i64 value)) (primitive.i64 value) - (^ (synthesis.f64 value)) + (pattern (synthesis.f64 value)) (primitive.f64 value) - (^ (synthesis.text value)) + (pattern (synthesis.text value)) (primitive.text value) - (^ (synthesis.variant data)) + (pattern (synthesis.variant data)) (structure.variant translate archive data) - (^ (synthesis.tuple members)) + (pattern (synthesis.tuple members)) (structure.tuple translate archive members) - (^ (synthesis.variable variable)) + (pattern (synthesis.variable variable)) (reference.variable archive variable) - (^ (synthesis.constant constant)) + (pattern (synthesis.constant constant)) (reference.constant archive constant) - (^ (synthesis.branch/exec it)) + (pattern (synthesis.branch/exec it)) (case.exec translate archive it) - (^ (synthesis.branch/let data)) + (pattern (synthesis.branch/let data)) (case.let translate archive data) - (^ (synthesis.branch/if data)) + (pattern (synthesis.branch/if data)) (case.if translate archive data) - (^ (synthesis.branch/get data)) + (pattern (synthesis.branch/get data)) (case.get translate archive data) - (^ (synthesis.branch/case data)) + (pattern (synthesis.branch/case data)) (case.case translate archive data) - (^ (synthesis.loop/again data)) + (pattern (synthesis.loop/again data)) (loop.again translate archive data) - (^ (synthesis.loop/scope data)) + (pattern (synthesis.loop/scope data)) (loop.scope translate archive data) - (^ (synthesis.function/apply data)) + (pattern (synthesis.function/apply data)) (function.call translate archive data) - (^ (synthesis.function/abstraction data)) + (pattern (synthesis.function/abstraction data)) (function.function translate archive data) {synthesis.#Extension extension} 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 ee6f243f2..0ea499e92 100644 --- a/lux-jvm/source/luxc/lang/translation/jvm/extension/host.lux +++ b/lux-jvm/source/luxc/lang/translation/jvm/extension/host.lux @@ -20,6 +20,7 @@ ["[0]" dictionary {"+" Dictionary}] ["[0]" set {"+" Set}]]] [macro + ["^" pattern] ["[0]" template]] [math [number @@ -389,7 +390,7 @@ (-> (Type Primitive) Handler) (function (_ extension_name generate archive inputs) (case inputs - (^ (list lengthS)) + (pattern (list lengthS)) (do phase.monad [lengthI (generate archive lengthS)] (in (|>> lengthI @@ -412,7 +413,7 @@ (-> (Type Primitive) Inst Handler) (function (_ extension_name generate archive inputs) (case inputs - (^ (list idxS arrayS)) + (pattern (list idxS arrayS)) (do phase.monad [arrayI (generate archive arrayS) idxI (generate archive idxS)] @@ -441,7 +442,7 @@ (-> (Type Primitive) Inst Handler) (function (_ extension_name generate archive inputs) (case inputs - (^ (list idxS valueS arrayS)) + (pattern (list idxS valueS arrayS)) (do phase.monad [arrayI (generate archive arrayS) idxI (generate archive idxS) @@ -558,7 +559,7 @@ (def: (object::class extension_name generate archive inputs) Handler (case inputs - (^ (list (synthesis.text class))) + (pattern (list (synthesis.text class))) (do phase.monad [] (in (|>> (_.string class) @@ -581,7 +582,7 @@ (def: (object::cast extension_name generate archive inputs) Handler (case inputs - (^ (list (synthesis.text from) (synthesis.text to) valueS)) + (pattern (list (synthesis.text from) (synthesis.text to) valueS)) (do phase.monad [valueI (generate archive valueS)] (`` (cond (~~ (template [ ] @@ -835,14 +836,14 @@ [_ {synthesis.#Control {synthesis.#Branch {synthesis.#Case _ path}}}] (loop [path (: synthesis.Path path)] (case path - (^or {synthesis.#Pop} - {synthesis.#Access _} - {synthesis.#Bind _} - {synthesis.#Bit_Fork _} - {synthesis.#I64_Fork _} - {synthesis.#F64_Fork _} - {synthesis.#Text_Fork _} - {synthesis.#Alt _}) + (^.or {synthesis.#Pop} + {synthesis.#Access _} + {synthesis.#Bind _} + {synthesis.#Bit_Fork _} + {synthesis.#I64_Fork _} + {synthesis.#F64_Fork _} + {synthesis.#Text_Fork _} + {synthesis.#Alt _}) body {synthesis.#Seq _ next} @@ -884,17 +885,17 @@ (-> Path Path)) (function (again path) (case path - (^ (synthesis.path/then bodyS)) + (pattern (synthesis.path/then bodyS)) (synthesis.path/then (normalize bodyS)) - (^template [] - [(^ { leftP rightP}) + (^.template [] + [(pattern { leftP rightP}) { (again leftP) (again rightP)}]) ([synthesis.#Alt] [synthesis.#Seq]) - (^template [] - [(^ { _}) + (^.template [] + [(pattern { _}) path]) ([synthesis.#Pop] [synthesis.#Bind] @@ -903,7 +904,7 @@ {synthesis.#Bit_Fork when then else} {synthesis.#Bit_Fork when (again then) (maybe#each again else)} - (^template [] + (^.template [] [{ [[test then] elses]} { [[test (again then)] (list#each (function (_ [else_test else_then]) @@ -939,49 +940,49 @@ (-> Mapping Synthesis Synthesis) (function (again body) (case body - (^template [] - [(^ ) + (^.template [] + [(pattern ) body]) ([{synthesis.#Primitive _}] [(synthesis.constant _)]) - (^ (synthesis.variant [lefts right? sub])) + (pattern (synthesis.variant [lefts right? sub])) (synthesis.variant [lefts right? (again sub)]) - (^ (synthesis.tuple members)) + (pattern (synthesis.tuple members)) (synthesis.tuple (list#each again members)) - (^ (synthesis.variable var)) + (pattern (synthesis.variable var)) (|> mapping (dictionary.value body) (maybe.else var) synthesis.variable) - (^ (synthesis.branch/case [inputS pathS])) + (pattern (synthesis.branch/case [inputS pathS])) (synthesis.branch/case [(again inputS) (normalize_path again pathS)]) - (^ (synthesis.branch/exec [this that])) + (pattern (synthesis.branch/exec [this that])) (synthesis.branch/exec [(again this) (again that)]) - (^ (synthesis.branch/let [inputS register outputS])) + (pattern (synthesis.branch/let [inputS register outputS])) (synthesis.branch/let [(again inputS) register (again outputS)]) - (^ (synthesis.branch/if [testS thenS elseS])) + (pattern (synthesis.branch/if [testS thenS elseS])) (synthesis.branch/if [(again testS) (again thenS) (again elseS)]) - (^ (synthesis.branch/get [path recordS])) + (pattern (synthesis.branch/get [path recordS])) (synthesis.branch/get [path (again recordS)]) - (^ (synthesis.loop/scope [offset initsS+ bodyS])) + (pattern (synthesis.loop/scope [offset initsS+ bodyS])) (synthesis.loop/scope [offset (list#each again initsS+) (again bodyS)]) - (^ (synthesis.loop/again updatesS+)) + (pattern (synthesis.loop/again updatesS+)) (synthesis.loop/again (list#each again updatesS+)) - (^ (synthesis.function/abstraction [environment arity bodyS])) + (pattern (synthesis.function/abstraction [environment arity bodyS])) (synthesis.function/abstraction [(list#each (function (_ captured) (case captured - (^ (synthesis.variable var)) + (pattern (synthesis.variable var)) (|> mapping (dictionary.value captured) (maybe.else var) @@ -993,7 +994,7 @@ arity bodyS]) - (^ (synthesis.function/apply [functionS inputsS+])) + (pattern (synthesis.function/apply [functionS inputsS+])) (synthesis.function/apply [(again functionS) (list#each again inputsS+)]) {synthesis.#Extension [name inputsS+]} diff --git a/lux-jvm/source/luxc/lang/translation/jvm/loop.lux b/lux-jvm/source/luxc/lang/translation/jvm/loop.lux index 7c4c0fd36..92b8c0286 100644 --- a/lux-jvm/source/luxc/lang/translation/jvm/loop.lux +++ b/lux-jvm/source/luxc/lang/translation/jvm/loop.lux @@ -1,36 +1,36 @@ (.using - [library - [lux "*" - [abstract - ["[0]" monad {"+" do}]] - [control - ["[0]" function]] - [data - [collection - ["[0]" list ("[1]@[0]" functor monoid)]]] - [math - [number - ["n" nat]]] - [tool - [compiler - ["[0]" phase] - [reference - [variable {"+" Register}]] - [language - [lux - ["[0]" synthesis {"+" Synthesis}] - ["[0]" generation]]]]]]] - [luxc - [lang - [host - [jvm {"+" Inst Operation Phase Generator} - ["_" inst]]]]] - ["[0]" //]) + [library + [lux "*" + [abstract + ["[0]" monad {"+" do}]] + [control + ["[0]" function]] + [data + [collection + ["[0]" list ("[1]@[0]" functor monoid)]]] + [math + [number + ["n" nat]]] + [tool + [compiler + ["[0]" phase] + [reference + [variable {"+" Register}]] + [language + [lux + ["[0]" synthesis {"+" Synthesis}] + ["[0]" generation]]]]]]] + [luxc + [lang + [host + [jvm {"+" Inst Operation Phase Generator} + ["_" inst]]]]] + ["[0]" //]) (def: (invariant? expected actual) (-> Register Synthesis Bit) (case actual - (^ (synthesis.variable/local actual)) + (pattern (synthesis.variable/local actual)) (n.= expected actual) _ diff --git a/lux-jvm/source/luxc/lang/translation/jvm/primitive.lux b/lux-jvm/source/luxc/lang/translation/jvm/primitive.lux index 016639f2e..49bc10ff3 100644 --- a/lux-jvm/source/luxc/lang/translation/jvm/primitive.lux +++ b/lux-jvm/source/luxc/lang/translation/jvm/primitive.lux @@ -2,6 +2,8 @@ [library [lux {"-" i64} ["[0]" ffi {"+" import:}] + [macro + ["^" pattern]] [math [number ["i" int]]] @@ -36,13 +38,13 @@ (def: .public (i64 value) (-> (I64 Any) (Operation Inst)) (case (.int value) - (^template [ ] + (^.template [ ] [ (operation@in (|>> (_.wrap type.long)))]) ([+0 _.LCONST_0] [+1 _.LCONST_1]) - (^template [ ] + (^.template [ ] [ (operation@in (|>> _.I2L (_.wrap type.long)))]) ([-1 _.ICONST_M1] @@ -77,17 +79,17 @@ (def: .public (f64 value) (-> Frac (Operation Inst)) (case value - (^template [ ] + (^.template [ ] [ (operation@in (|>> (_.wrap type.double)))]) ([+1.0 _.DCONST_1]) - (^template [ ] + (^.template [ ] [ (operation@in (|>> _.F2D (_.wrap type.double)))]) ([+2.0 _.FCONST_2]) - (^template [ ] + (^.template [ ] [ (operation@in (|>> _.I2D (_.wrap type.double)))]) ([-1.0 _.ICONST_M1] -- cgit v1.2.3