diff options
Diffstat (limited to 'stdlib/source/library/lux/meta/compiler/reference.lux')
-rw-r--r-- | stdlib/source/library/lux/meta/compiler/reference.lux | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/stdlib/source/library/lux/meta/compiler/reference.lux b/stdlib/source/library/lux/meta/compiler/reference.lux new file mode 100644 index 000000000..340cf1a0d --- /dev/null +++ b/stdlib/source/library/lux/meta/compiler/reference.lux @@ -0,0 +1,93 @@ +(.require + [library + [lux (.except local) + [abstract + [equivalence (.only Equivalence)] + [hash (.only Hash)]] + [control + ["[0]" pipe]] + [data + [text + ["%" \\format (.only Format)]]] + [math + [number + ["n" nat]]] + [meta + ["[0]" symbol] + [macro + ["^" pattern]]]]] + ["[0]" / + ["[1][0]" variable (.only Variable)]]) + +(type .public Constant + Symbol) + +(type .public Reference + (Variant + {#Variable Variable} + {#Constant Constant})) + +(def .public equivalence + (Equivalence Reference) + (implementation + (def (= reference sample) + (case [reference sample] + (^.with_template [<tag> <equivalence>] + [[{<tag> reference} {<tag> sample}] + (at <equivalence> = reference sample)]) + ([#Variable /variable.equivalence] + [#Constant symbol.equivalence]) + + _ + false)))) + +(def .public hash + (Hash Reference) + (implementation + (def equivalence + ..equivalence) + + (def (hash value) + (case value + (^.with_template [<factor> <tag> <hash>] + [{<tag> value} + (|> value + (at <hash> hash) + (n.* <factor>))]) + ([2 #Variable /variable.hash] + [3 #Constant symbol.hash]) + )))) + +(with_template [<name> <family> <tag>] + [(def .public <name> + (template (<name> content) + [(<| {<family>} + {<tag>} + content)]))] + + [local ..#Variable /variable.#Local] + [foreign ..#Variable /variable.#Foreign] + ) + +(with_template [<name> <tag>] + [(def .public <name> + (template (<name> content) + [(<| {<tag>} + content)]))] + + [variable ..#Variable] + [constant ..#Constant] + ) + +(`` (def .public self + (template (self) + [(..variable (,, (/variable.self)))]))) + +(def .public format + (Format Reference) + (|>> (pipe.case + {#Variable variable} + (/variable.format variable) + + {#Constant constant} + (%.symbol constant)))) |