diff options
Diffstat (limited to 'stdlib/source/lux/tool/compiler/phase/generation/reference.lux')
-rw-r--r-- | stdlib/source/lux/tool/compiler/phase/generation/reference.lux | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/stdlib/source/lux/tool/compiler/phase/generation/reference.lux b/stdlib/source/lux/tool/compiler/phase/generation/reference.lux new file mode 100644 index 000000000..878d96e83 --- /dev/null +++ b/stdlib/source/lux/tool/compiler/phase/generation/reference.lux @@ -0,0 +1,81 @@ +(.module: + [lux #* + [control + pipe] + [data + [text + format]] + [type (#+ :share)]] + ["." // + ["/." // ("#/." monad) + [// + [synthesis (#+ Synthesis)] + ["." reference (#+ Register Variable Reference)]]]]) + +(signature: #export (System expression) + (: (-> Register expression) + local) + (: (-> Register expression) + foreign) + (: (All [anchor statement] + (-> Variable (//.Operation anchor expression statement))) + variable) + (: (All [anchor statement] + (-> Name (//.Operation anchor expression statement))) + constant) + (: (All [anchor statement] + (-> Reference (//.Operation anchor expression statement))) + reference)) + +(def: (variable-maker prefix variable) + (All [expression] + (-> Text (-> Text expression) + (-> Register expression))) + (|>> %n (format prefix) variable)) + +(def: #export foreign + (All [expression] + (-> (-> Text expression) + (-> Register expression))) + (variable-maker "f")) + +(def: #export local + (All [expression] + (-> (-> Text expression) + (-> Register expression))) + (variable-maker "l")) + +(def: #export (system constant variable) + (All [expression] + (-> (-> Text expression) (-> Text expression) + (System expression))) + (let [local (..local variable) + foreign (..foreign variable) + variable (:share [expression] + {(-> Text expression) + variable} + {(All [anchor statement] + (-> Variable (//.Operation anchor expression statement))) + (|>> (case> (#reference.Local register) + (local register) + + (#reference.Foreign register) + (foreign register)) + ////wrap)}) + constant (:share [expression] + {(-> Text expression) + constant} + {(All [anchor statement] + (-> Name (//.Operation anchor expression statement))) + (|>> //.remember (////map constant))})] + (structure + (def: local local) + (def: foreign foreign) + (def: variable variable) + (def: constant constant) + (def: reference + (|>> (case> (#reference.Constant value) + (constant value) + + (#reference.Variable value) + (variable value))))))) |