blob: 4edb82a5eb2c0d3c2eed6e9510e364a8c358e355 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
(.module:
[library
[lux (#- Module)
[abstract
["." monad (#+ Monad do)]]
[control
["." try (#+ Try)]
["." exception (#+ exception:)]
[concurrency
["." promise (#+ Promise) ("#\." monad)]]
["<>" parser
["<.>" binary]]]
[data
[binary (#+ Binary)]
["." text
["%" format (#+ format)]]
[collection
["." dictionary (#+ Dictionary)]
["." row]]
[format
["." tar]]]
[tool
[compiler
[meta
[archive
[descriptor (#+ Module)]]]]]
[world
["." file]]]]
[//
[cli (#+ Library)]])
(def: Action
(type (All [a] (Promise (Try a)))))
(exception: #export useless_tar_entry)
(exception: #export (duplicate {library Library} {module Module})
(exception.report
["Module" (%.text module)]
["Library" (%.text library)]))
(type: #export Import
(Dictionary file.Path Binary))
(def: (import_library system library import)
(-> (file.System Promise) Library Import (Action Import))
(let [! promise.monad]
(|> library
(\ system read)
(\ ! map (let [! try.monad]
(|>> (\ ! map (<binary>.run tar.parser))
(\ ! join)
(\ ! map (|>> row.to_list
(monad.fold ! (function (_ entry import)
(case entry
(#tar.Normal [path instant mode ownership content])
(let [path (tar.from_path path)]
(case (dictionary.try_put path (tar.data content) import)
(#try.Failure error)
(exception.throw ..duplicate [library path])
import'
import'))
_
(exception.throw ..useless_tar_entry [])))
import)))
(\ ! join)))))))
(def: #export (import system libraries)
(-> (file.System Promise) (List Library) (Action Import))
(monad.fold (: (Monad Action)
(try.with promise.monad))
(..import_library system)
(dictionary.new text.hash)
libraries))
|