diff options
Diffstat (limited to 'stdlib/source/lux/tool/compiler/reference/variable.lux')
-rw-r--r-- | stdlib/source/lux/tool/compiler/reference/variable.lux | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/stdlib/source/lux/tool/compiler/reference/variable.lux b/stdlib/source/lux/tool/compiler/reference/variable.lux new file mode 100644 index 000000000..10c080c6e --- /dev/null +++ b/stdlib/source/lux/tool/compiler/reference/variable.lux @@ -0,0 +1,59 @@ +(.module: + [lux #* + [abstract + [equivalence (#+ Equivalence)] + [hash (#+ Hash)]] + [control + [pipe (#+ case>)]] + [data + [number + ["n" nat] + ["i" int]] + [text + ["%" format (#+ Format)]]]]) + +(type: #export Register Nat) + +(type: #export Variable + (#Local Register) + (#Foreign Register)) + +(structure: #export equivalence + (Equivalence Variable) + + (def: (= reference sample) + (case [reference sample] + (^template [<tag>] + [(<tag> reference') (<tag> sample')] + (n.= reference' sample')) + ([#Local] [#Foreign]) + + _ + #0))) + +(structure: #export hash + (Hash Variable) + + (def: &equivalence ..equivalence) + (def: hash + (|>> (case> (#Local register) + register + + (#Foreign register) + (|> register .int (i.* -1) .nat))))) + +(def: #export self? + (-> Variable Bit) + (|>> (case> (^ (#Local 0)) + true + + _ + false))) + +(def: #export format + (Format Variable) + (|>> (case> (#Local local) + (%.format "+" (%.nat local)) + + (#Foreign foreign) + (%.format "-" (%.nat foreign))))) |