diff options
Diffstat (limited to 'stdlib/source/lux/compiler/meta/archive/document.lux')
-rw-r--r-- | stdlib/source/lux/compiler/meta/archive/document.lux | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/stdlib/source/lux/compiler/meta/archive/document.lux b/stdlib/source/lux/compiler/meta/archive/document.lux new file mode 100644 index 000000000..237b092da --- /dev/null +++ b/stdlib/source/lux/compiler/meta/archive/document.lux @@ -0,0 +1,51 @@ +(.module: + [lux (#- Module) + [control + ["ex" exception (#+ exception:)]] + [data + ["." error (#+ Error)] + [collection + ["." dictionary (#+ Dictionary)]]] + [type (#+ :share) + abstract]] + [// + ["." signature (#+ Signature)] + ["." key (#+ Key)] + ["." descriptor (#+ Module Descriptor)]]) + +## Document +(exception: #export (invalid-key {module Module} {expected (Key Any)} {actual (Key Any)}) + (ex.report ["Module" module] + ["Expected" (signature.description (get@ #key.signature expected))] + ["Actual" (signature.description (get@ #key.signature actual))])) + +(abstract: #export (Document d) + {} + + {#key (Key d) + #descriptor Descriptor + #content d} + + (def: #export (read key document) + (All [d] (-> (Key d) (Document Any) (Error d))) + (let [[document//key document//descriptor document//content] (:representation document)] + (if (:: signature.Equivalence<Signature> = + (get@ #key.signature key) + (get@ #key.signature document//key)) + (#error.Success (:share [e] + {(Key e) + key} + {e + document//content})) + (ex.throw invalid-key [(get@ #descriptor.name document//descriptor) key document//key])))) + + (def: #export (write key descriptor content) + (All [d] (-> (Key d) Descriptor d (Document d))) + (:abstraction {#key key + #descriptor descriptor + #content content})) + + (def: #export signature + (-> (Document Any) Signature) + (|>> :representation (get@ #key) (get@ #key.signature))) + ) |