diff options
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/lux/language/compiler/synthesis/expression.lux | 119 |
1 files changed, 55 insertions, 64 deletions
diff --git a/stdlib/source/lux/language/compiler/synthesis/expression.lux b/stdlib/source/lux/language/compiler/synthesis/expression.lux index f6d68fc05..be20b7b0b 100644 --- a/stdlib/source/lux/language/compiler/synthesis/expression.lux +++ b/stdlib/source/lux/language/compiler/synthesis/expression.lux @@ -1,24 +1,20 @@ (.module: [lux (#- primitive) [control - [monad (#+ do)] - ["ex" exception (#+ exception:)]] + [monad (#+ do)]] [data [maybe] [collection [list ("list/" Functor<List>)] ["dict" dictionary (#+ Dictionary)]]]] - [// (#+ Synthesis) + [// (#+ Synthesis Compiler) [function] [case] - [/// - [reference] - ["." compiler ("operation/" Monad<Operation>) - [analysis (#+ Analysis)] - [extension (#+ Extension)]]]]) - -(exception: #export (unknown-synthesis-extension {name Text}) - name) + ["/." // ("operation/" Monad<Operation>) + [analysis (#+ Analysis)] + [extension] + [// + [reference]]]]) (def: (primitive analysis) (-> analysis.Primitive //.Primitive) @@ -40,64 +36,59 @@ [#analysis.Int #//.I64] [#analysis.Rev #//.I64]))) -(def: #export (synthesizer extensions) - (-> (Extension extension.Synthesis) //.Synthesizer) - (function (synthesize analysis) - (case analysis - (#analysis.Primitive analysis') - (operation/wrap (#//.Primitive (..primitive analysis'))) +(def: #export (synthesize analysis) + Compiler + (case analysis + (#analysis.Primitive analysis') + (operation/wrap (#//.Primitive (..primitive analysis'))) - (#analysis.Structure composite) - (case (analysis.variant analysis) - (#.Some variant) - (do compiler.Monad<Operation> - [valueS (synthesize (get@ #analysis.value variant))] - (wrap (#//.Structure (#//.Variant (set@ #analysis.value valueS variant))))) + (#analysis.Structure composite) + (case (analysis.variant analysis) + (#.Some variant) + (do ///.Monad<Operation> + [valueS (synthesize (get@ #analysis.value variant))] + (wrap (#//.Structure (#//.Variant (set@ #analysis.value valueS variant))))) - _ - (do compiler.Monad<Operation> - [tupleS (monad.map @ synthesize (analysis.tuple analysis))] - (wrap (#//.Structure (#//.Tuple tupleS))))) + _ + (do ///.Monad<Operation> + [tupleS (monad.map @ synthesize (analysis.tuple analysis))] + (wrap (#//.Structure (#//.Tuple tupleS))))) - (#analysis.Apply _) - (function.apply (|>> synthesize //.indirectly) analysis) + (#analysis.Apply _) + (function.apply (|>> synthesize //.indirectly) analysis) - (#analysis.Function environmentA bodyA) - (function.function synthesize environmentA bodyA) + (#analysis.Function environmentA bodyA) + (function.function synthesize environmentA bodyA) - (#analysis.Extension name args) - (case (dict.get name extensions) - #.None - (compiler.throw unknown-synthesis-extension name) - - (#.Some extension) - (extension (|>> synthesize //.indirectly) args)) + (#analysis.Extension name args) + (extension.apply (|>> synthesize //.indirectly) + [name args]) - (#analysis.Reference reference) - (case reference - (#reference.Constant constant) - (operation/wrap (#//.Reference reference)) + (#analysis.Reference reference) + (case reference + (#reference.Constant constant) + (operation/wrap (#//.Reference reference)) - (#reference.Variable var) - (do compiler.Monad<Operation> - [resolver //.resolver] - (case var - (#reference.Local register) - (do @ - [arity //.scope-arity] - (wrap (if (function.nested? arity) - (if (n/= +0 register) - (|> (dec arity) - (list.n/range +1) - (list/map (|>> //.variable/local)) - [(//.variable/local +0)] - //.function/apply) - (#//.Reference (#reference.Variable (function.adjust arity #0 var)))) - (#//.Reference (#reference.Variable var))))) - - (#reference.Foreign register) - (wrap (|> resolver (dict.get var) (maybe.default var) #reference.Variable #//.Reference))))) + (#reference.Variable var) + (do ///.Monad<Operation> + [resolver //.resolver] + (case var + (#reference.Local register) + (do @ + [arity //.scope-arity] + (wrap (if (function.nested? arity) + (if (n/= +0 register) + (|> (dec arity) + (list.n/range +1) + (list/map (|>> //.variable/local)) + [(//.variable/local +0)] + //.function/apply) + (#//.Reference (#reference.Variable (function.adjust arity #0 var)))) + (#//.Reference (#reference.Variable var))))) + + (#reference.Foreign register) + (wrap (|> resolver (dict.get var) (maybe.default var) #reference.Variable #//.Reference))))) - (#analysis.Case inputA branchesAB+) - (case.synthesize (|>> synthesize //.indirectly) inputA branchesAB+) - ))) + (#analysis.Case inputA branchesAB+) + (case.synthesize (|>> synthesize //.indirectly) inputA branchesAB+) + )) |