https://github.com/akkartik/mu/blob/master/043space.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 :(before "End Mu Types Initialization")
17 put(Type_abbreviations, "space", new_type_tree("address:array:location"));
18
19 :(scenario set_default_space)
20 def main [
21
22 10:num/alloc-id, 11:num <- copy 0, 1000
23
24 1000:num <- copy 0
25 1001:num <- copy 5
26
27 default-space:space <- copy 10:&:@:location
28
29
30
31
32
33
34 2:num <- copy 93
35 ]
36 +mem: storing 93 in location 1004
37
38 :(scenario lookup_sidesteps_default_space)
39 def main [
40
41 10:num/alloc-id, 11:num <- copy 0, 1000
42
43 1000:num <- copy 0
44 1001:num <- copy 5
45
46 2000:num/alloc-id, 2001:num <- copy 0, 34
47
48 default-space:space <- copy 10:&:@:location
49
50 2:num, 3:num <- copy 0, 2000
51 20:num/raw <- copy *2:&:num
52 ]
53 +mem: storing 2000 in location 1005
54 +mem: storing 34 in location 20
55
56
57
58 :(scenarios transform)
59 :(scenario convert_names_passes_default_space)
60 % Hide_errors = true;
61 def main [
62 default-space:num <- copy 0
63 x:num <- copy 1
64 ]
65 +name: assign x 2
66 -name: assign default-space 1
67 -name: assign default-space 2
68 :(scenarios run)
69
70 :(before "End is_disqualified Special-cases")
71 if (x.name == "default-space")
72 x.initialized = true;
73 :(before "End is_special_name Special-cases")
74 if (s == "default-space") return true;
75
76
77
78 :(before "End call Fields")
79 int default_space;
80 :(before "End call Constructor")
81 default_space = 0;
82
83 :(before "Begin canonize(x) Lookups")
84 absolutize(x);
85 :(code)
86 void absolutize(reagent& x) {
87 if (is_raw(x) || is_dummy(x)) return;
88 if (x.name == "default-space") return;
89 if (!x.initialized)
90 raise << to_original_string(current_instruction()) << ": reagent not initialized: '" << x.original_string << "'\n" << end();
91 x.set_value(address(x.value, space_base(x)));
92 x.properties.push_back(pair<string, string_tree*>("raw", NULL));
93 assert(is_raw(x));
94 }
95
96
97 int space_base(const reagent& x) {
98 return current_call().default_space ? (current_call().default_space + 1) : 0;
99 }
100
101 int address(int offset, int base) {
102 assert(offset >= 0);
103 if (base == 0) return offset;
104 int size = get_or_insert(Memory, base);
105 if (offset >= size) {
106
107 raise << current_recipe_name() << ": location " << offset << " is out of bounds " << size << " at " << base << '\n' << end();
108 DUMP("");
109 exit(1);
110 return 0;
111 }
112 return base + 1 + offset;
113 }
114
115
116
117 :(after "Begin Preprocess write_memory(x, data)")
118 if (x.name == "default-space") {
119 if (!is_mu_space(x))
120 raise << maybe(current_recipe_name()) << "'default-space' should be of type address:array:location, but is " << to_string(x.type) << '\n' << end();
121 if (SIZE(data) != 2)
122 raise << maybe(current_recipe_name()) << "'default-space' getting data from non-address\n" << end();
123 current_call().default_space = data.at(1);
124 return;
125 }
126 :(code)
127 bool is_mu_space(reagent x) {
128 canonize_type(x);
129 if (!is_compound_type_starting_with(x.type, "addpackage imap
import (
"github.com/emersion/go-imap"
"git.sr.ht/~rjarry/aerc/models"
"git.sr.ht/~rjarry/aerc/worker/types"
)
func (imapw *IMAPWorker) handleListDirectories(msg *types.ListDirectories) {
mailboxes := make(chan *imap.MailboxInfo)
imapw.worker.Logger.Println("Listing mailboxes")
done := make(chan interface{})
go func() {
for mbox := range mailboxes {
if !canOpen(mbox) {
// no need to pass this to handlers if it can't be opened
continue
}
imapw.worker.PostMessage(&types.Directory{
Message: types.RespondTo(msg),
Dir: &models.Directory{
Name: mbox.Name,
Attributes: mbox.Attributes,
},
}, nil)
}
done <- nil
}()
if err := imapw.client.List("", "*", mailboxes); err != nil {
<-done
imapw.worker.PostMessage(&types.Error{
Message: types.RespondTo(msg),
Error: err,
}, nil)
} else {
<-done
imapw.worker.PostMessage(
&types.Done{types.RespondTo(msg)}, nil)
}
}
func canOpen(mbox *imap.MailboxInfo) bool {
for _, attr := range mbox.Attributes {
if attr == imap.NoSelectAttr {
return false
}
}
return true
}
func (imapw *IMAPWorker) handleSearchDirectory(msg *types.SearchDirectory) {
emitError := func(err error) {
imapw.worker.PostMessage(&types.Error{
Message: types.RespondTo(msg),
Error: err,
}, nil)
}
imapw.worker.Logger.Println("Executing search")
criteria, err := parseSearch(msg.Argv)
if err != nil {
emitError(err)
return
}
uids, err := imapw.client.UidSearch(criteria)
if err != nil {
emitError(err)
return
}
imapw.worker.PostMessage(&types.SearchResults{
Message: types.RespondTo(msg),
Uids: uids,
}, nil)
}