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