nomen-lang 0.9.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/core/System/Arena.nm +9 -7
  2. package/core/System/Array.nm +1 -1
  3. package/core/System/Atomic.nm +3 -3
  4. package/core/System/BigInt.nm +182 -23
  5. package/core/System/Buffer.nm +37 -35
  6. package/core/System/ClassBuffer.nm +18 -18
  7. package/core/System/Controls/Alert.nm +1 -1
  8. package/core/System/Controls/App.nm +5 -5
  9. package/core/System/Controls/Button.nm +1 -1
  10. package/core/System/Controls/CheckBox.nm +1 -1
  11. package/core/System/Controls/ColorPicker.nm +1 -1
  12. package/core/System/Controls/ComboBox.nm +1 -1
  13. package/core/System/Controls/Container.nm +34 -34
  14. package/core/System/Controls/DatePicker.nm +1 -1
  15. package/core/System/Controls/Form.nm +2 -2
  16. package/core/System/Controls/GroupBox.nm +1 -1
  17. package/core/System/Controls/ImageView.nm +1 -1
  18. package/core/System/Controls/Layout.nm +5 -5
  19. package/core/System/Controls/LevelIndicator.nm +1 -1
  20. package/core/System/Controls/ListView.nm +1 -1
  21. package/core/System/Controls/Menu.nm +1 -1
  22. package/core/System/Controls/NumberInput.nm +3 -3
  23. package/core/System/Controls/OtpInput.nm +2 -2
  24. package/core/System/Controls/OutlineView.nm +1 -1
  25. package/core/System/Controls/Pagination.nm +6 -6
  26. package/core/System/Controls/Popover.nm +1 -1
  27. package/core/System/Controls/Progress.nm +1 -1
  28. package/core/System/Controls/Radio.nm +1 -1
  29. package/core/System/Controls/Scrollable.nm +1 -1
  30. package/core/System/Controls/SearchField.nm +1 -1
  31. package/core/System/Controls/SecureField.nm +1 -1
  32. package/core/System/Controls/Segmented.nm +1 -1
  33. package/core/System/Controls/Select.nm +1 -1
  34. package/core/System/Controls/Separator.nm +1 -1
  35. package/core/System/Controls/Sheet.nm +1 -1
  36. package/core/System/Controls/Slider.nm +1 -1
  37. package/core/System/Controls/Spinner.nm +3 -3
  38. package/core/System/Controls/SplitView.nm +2 -2
  39. package/core/System/Controls/Stepper.nm +1 -1
  40. package/core/System/Controls/Switch.nm +1 -1
  41. package/core/System/Controls/Table.nm +1 -1
  42. package/core/System/Controls/Tabs.nm +1 -1
  43. package/core/System/Controls/Text.nm +1 -1
  44. package/core/System/Controls/TextBox.nm +1 -1
  45. package/core/System/Controls/TextView.nm +1 -1
  46. package/core/System/Controls/Toggle.nm +1 -1
  47. package/core/System/Controls/Toolbar.nm +1 -1
  48. package/core/System/Controls/Window.nm +11 -3
  49. package/core/System/Fiber.nm +16 -3
  50. package/core/System/Format.nm +751 -0
  51. package/core/System/Graph.nm +2 -2
  52. package/core/System/LinkedList.nm +8 -6
  53. package/core/System/List.nm +16 -13
  54. package/core/System/Map.nm +11 -9
  55. package/core/System/Random.nm +3 -3
  56. package/core/System/Set.nm +9 -7
  57. package/core/System/StableList.nm +7 -7
  58. package/core/System/Stream/File.nm +16 -16
  59. package/core/System/Stream/Http.nm +3 -3
  60. package/core/System/Stream/Tcp.nm +5 -5
  61. package/core/System/StringBuilder.nm +16 -16
  62. package/core/System/Task.nm +56 -64
  63. package/core/System/Test.nm +18 -18
  64. package/core/System/Text/Chars.nm +1 -1
  65. package/core/System/Text/Json.nm +12 -12
  66. package/core/System/Text/JsonTree.nm +8 -8
  67. package/core/System/Text/Regex.nm +20 -20
  68. package/core/System/Thread.nm +26 -3
  69. package/core/System/Tree.nm +19 -3
  70. package/dist/index.mjs +3423 -1849
  71. package/package.json +1 -1
  72. package/src/docs.ts +10 -1
@@ -14,7 +14,7 @@ pub mv struct Graph<T>: Enumerable {
14
14
  var node_count = 0
15
15
  var edge_count = 0
16
16
 
17
- pub func add_node = (ref self, mv T value) {
17
+ pub func add_node = (ref self { head_edge, values }, mv T value) {
18
18
  var int idx = self.node_count
19
19
  self.values.grow(idx + 1)
20
20
  self.values.store(idx, value)
@@ -23,7 +23,7 @@ pub mv struct Graph<T>: Enumerable {
23
23
  self.node_count = self.node_count + 1
24
24
  }
25
25
 
26
- pub func add_edge = (ref self, int from, int to) {
26
+ pub func add_edge = (ref self { edge_next, edge_target, head_edge }, int from, int to) {
27
27
  var int e = self.edge_count
28
28
  self.edge_target.grow_int(e + 1)
29
29
  self.edge_target.store_int(e, to)
@@ -13,13 +13,15 @@ pub mv struct LinkedList<T>: Enumerable {
13
13
  var int head = -1
14
14
  var count = 0
15
15
 
16
- pub func add = (ref self, mv T value) {
16
+ pub func add = (ref self { nexts, prevs, values }, mv T value) {
17
17
  var int idx = self.count
18
18
  self.values.grow(idx + 1)
19
19
  // The value arrives owned (`mv T value`): move a value-struct element
20
- // into the fresh slot (the caller's storage zeroes, no deep copy);
21
- // strings keep the deep-copying store (their pair arrives by value).
22
- if T_IS_VALUE_STRUCT {
20
+ // that OWNS resources into the fresh slot (the caller's storage
21
+ // zeroes, no deep copy). A non-owning value struct is a legal bare
22
+ // argument, so it keeps the copying store; strings keep the
23
+ // deep-copying store too (their pair arrives by value).
24
+ if T_TAKES_OWNERSHIP {
23
25
  self.values.store_take(idx, value)
24
26
  } else {
25
27
  self.values.store(idx, value)
@@ -34,14 +36,14 @@ pub mv struct LinkedList<T>: Enumerable {
34
36
  }
35
37
  }
36
38
 
37
- pub func set_next = (ref self, int idx, int next) {
39
+ pub func set_next = (ref self { nexts, prevs }, int idx, int next) {
38
40
  self.nexts.store_int(idx, next)
39
41
  if next >= 0 && next < self.prevs.cap {
40
42
  self.prevs.store_int(next, idx)
41
43
  }
42
44
  }
43
45
 
44
- pub func set_previous = (ref self, int idx, int prev) {
46
+ pub func set_previous = (ref self { nexts, prevs }, int idx, int prev) {
45
47
  self.prevs.store_int(idx, prev)
46
48
  if prev >= 0 && prev < self.nexts.cap {
47
49
  self.nexts.store_int(prev, idx)
@@ -5,13 +5,16 @@ pub mv struct List<T>: Viewable {
5
5
  var length = 0
6
6
  var items = Buffer<T>()
7
7
 
8
- pub func push = (ref self, mv T value) {
8
+ pub func push = (ref self { items }, mv T value) {
9
9
  if self.length < self.items.cap {
10
10
  // The value arrives owned (`mv T value`): a value-struct element
11
- // moves into the fresh slot (store_take — the caller's storage
12
- // zeroes, no deep copy); strings and scalars keep the
13
- // deep-copying store.
14
- if T_IS_VALUE_STRUCT {
11
+ // that OWNS resources moves into the fresh slot (store_take — the
12
+ // caller's storage zeroes, no deep copy). A non-owning value
13
+ // struct (a handle pair) is a legal bare argument (the checker
14
+ // does not demand `mv`), so taking it would silently zero the
15
+ // caller's copy — it keeps the copying store, like strings and
16
+ // scalars.
17
+ if T_TAKES_OWNERSHIP {
15
18
  self.items.store_take(self.length, value)
16
19
  } else {
17
20
  self.items.store(self.length, value)
@@ -20,7 +23,7 @@ pub mv struct List<T>: Viewable {
20
23
  return
21
24
  }
22
25
  self.reserve(1)
23
- if T_IS_VALUE_STRUCT {
26
+ if T_TAKES_OWNERSHIP {
24
27
  self.items.store_take(self.length, value)
25
28
  } else {
26
29
  self.items.store(self.length, value)
@@ -38,7 +41,7 @@ pub mv struct List<T>: Viewable {
38
41
  // #4). Sound for extra=1 by the same proof as push's old inline growth:
39
42
  // length + 1 > cap grows to exactly the capacity push would have grown
40
43
  // to.
41
- internal func reserve = (ref self, int extra: extra >= 0, out int) {
44
+ internal func reserve = (ref self { items }, int extra: extra >= 0, out int) {
42
45
  if self.length + extra <= self.items.cap {
43
46
  return self.items.cap
44
47
  }
@@ -52,7 +55,7 @@ pub mv struct List<T>: Viewable {
52
55
  return self.items.cap
53
56
  }
54
57
 
55
- pub func pop = (ref self, mv out T) {
58
+ pub func pop = (ref self { items }, mv out T) {
56
59
  if self.length <= 0 {
57
60
  return self.items.move(0)
58
61
  }
@@ -91,7 +94,7 @@ pub mv struct List<T>: Viewable {
91
94
  return self.items.slice(start, end)
92
95
  }
93
96
 
94
- pub func set = (ref self, int i: i >= 0 && i < self.length, mv T value) {
97
+ pub func set = (ref self { items }, int i: i >= 0 && i < self.length, mv T value) {
95
98
  self.items.replace(i, value)
96
99
  }
97
100
 
@@ -99,7 +102,7 @@ pub mv struct List<T>: Viewable {
99
102
  // for indices that can't be proven at compile time (cross-module calls
100
103
  // can never discharge `set`'s parameter constraint) and out-of-range is
101
104
  // a bug, not a case.
102
- pub func set_or_panic = (ref self, int i, mv T value) {
105
+ pub func set_or_panic = (ref self { items }, int i, mv T value) {
103
106
  if i >= 0 && i < self.length {
104
107
  self.set(i, value)
105
108
  return
@@ -111,7 +114,7 @@ pub mv struct List<T>: Viewable {
111
114
  // lowering's destination primitive, the in-place push contract). reserve must have
112
115
  // run, so the slot exists. Offsets mirror the mono layout: length @8,
113
116
  // items.data @24 (the Buffer mono is {_vt, data, cap} = 24 bytes).
114
- internal func append_slot_ptr = (ref self, out ptr T) {
117
+ internal func append_slot_ptr = (ref self { items }, out ptr T) {
115
118
  ```
116
119
  #arch: c
117
120
  // Byte math + void* — the body must compile for EVERY element kind
@@ -139,7 +142,7 @@ pub mv struct List<T>: Viewable {
139
142
  // rules. The length constraint is the caller's proof obligation — the
140
143
  // handler desugar's synthesized loops satisfy it from the loop
141
144
  // condition, exactly like `.at`.
142
- internal func slot_ptr = (ref self, int i: i >= 0 && i < self.length, out ptr T) {
145
+ internal func slot_ptr = (ref self { items }, int i: i >= 0 && i < self.length, out ptr T) {
143
146
  return self.items.slot_ptr(i)
144
147
  }
145
148
 
@@ -150,7 +153,7 @@ pub mv struct List<T>: Viewable {
150
153
  // resources are reclaimed when the binding's scope ends — binding the
151
154
  // result in a nested block is the way to free an owning element at a
152
155
  // chosen point (its #destroy runs at the block's closing brace).
153
- pub func remove_at_or_panic = (ref self, int i, mv out T) {
156
+ pub func remove_at_or_panic = (ref self { items }, int i, mv out T) {
154
157
  if i < 0 || i >= self.length {
155
158
  panic("index out of range")
156
159
  }
@@ -39,7 +39,7 @@ pub mv struct Map<TK: Hashable + Equatable, TV> {
39
39
  }
40
40
  }
41
41
 
42
- pub func set = (ref self, mv TK key, mv TV value) {
42
+ pub func set = (ref self { hashes, keys, used, values }, mv TK key, mv TV value) {
43
43
  var int cap = self.keys.cap
44
44
  if cap == 0 {
45
45
  // alloc_T: for Buffer<TK> it is T_SIZE-aware (string keys are
@@ -59,15 +59,17 @@ pub mv struct Map<TK: Hashable + Equatable, TV> {
59
59
  if self.used.load_u32(idx) == 0 {
60
60
  self.used.store_u32(idx, 1)
61
61
  // Both arrive owned (`mv TK key, mv TV value`): a value-struct
62
- // key/value moves into its fresh slot (the caller's storage
63
- // zeroes, no deep copy); strings keep the deep-copying store
64
- // (their pair arrives by value).
65
- if TK_IS_VALUE_STRUCT {
62
+ // key/value that OWNS resources moves into its fresh slot
63
+ // (store_take — the caller's storage zeroes, no deep copy). A
64
+ // non-owning value struct is a legal bare argument and keeps the
65
+ // copying store; strings keep the deep-copying store too (their
66
+ // pair arrives by value).
67
+ if TK_TAKES_OWNERSHIP {
66
68
  self.keys.store_take(idx, key)
67
69
  } else {
68
70
  self.keys.store(idx, key)
69
71
  }
70
- if TV_IS_VALUE_STRUCT {
72
+ if TV_TAKES_OWNERSHIP {
71
73
  self.values.store_take(idx, value)
72
74
  } else {
73
75
  self.values.store(idx, value)
@@ -92,7 +94,7 @@ pub mv struct Map<TK: Hashable + Equatable, TV> {
92
94
  // primitive: the raw pointer must not cross the library boundary, and
93
95
  // the caller must overwrite the slot before it is read or destroyed
94
96
  // again (both paths leave it owning nothing).
95
- internal func set_slot_ptr = (ref self, TK key, out ptr TV) {
97
+ internal func set_slot_ptr = (ref self { hashes, keys, used, values }, TK key, out ptr TV) {
96
98
  var int cap = self.keys.cap
97
99
  if cap == 0 {
98
100
  // alloc_T: for Buffer<TK> it is T_SIZE-aware (string keys are
@@ -195,7 +197,7 @@ pub mv struct Map<TK: Hashable + Equatable, TV> {
195
197
  return self.used.load_u32(idx) != 0
196
198
  }
197
199
 
198
- pub func remove = (ref self, TK key) {
200
+ pub func remove = (ref self { hashes, keys, used, values }, TK key) {
199
201
  var int cap = self.keys.cap
200
202
  if cap == 0 {
201
203
  return
@@ -330,7 +332,7 @@ pub mv struct Map<TK: Hashable + Equatable, TV> {
330
332
  // the other half of the Swiss-table trick; the old form re-inserted via
331
333
  // `self.set(mv k, mv v)`, re-hashing every key and re-comparing keys on
332
334
  // every probed slot.
333
- func rehash = (ref self, int new_cap) {
335
+ func rehash = (ref self { hashes, keys, used, values }, int new_cap) {
334
336
  var Buffer<TK> old_keys = mv self.keys swap Buffer<TK>()
335
337
  var Buffer<TV> old_values = mv self.values swap Buffer<TV>()
336
338
  var Buffer<int> old_used = mv self.used swap Buffer<int>()
@@ -44,7 +44,7 @@ pub mv struct Random {
44
44
  // operators, and hex literals all lower directly; the aarch64 64-bit
45
45
  // arithmetic folds (PERF_PLAN item 15) keep the emission within a few
46
46
  // instructions of a hand-written `#arch` body.
47
- pub func next = (ref self, out uint64) {
47
+ pub func next = (ref self {}, out uint64) {
48
48
  self.state = self.state + 0x9E3779B97F4A7C15
49
49
  var uint64 z = self.state
50
50
  z = (z ^ (z >> 30)) * 0xBF58476D1CE4E5B9
@@ -54,7 +54,7 @@ pub mv struct Random {
54
54
 
55
55
  // The next value in [0, bound). A bound of 0 returns 0. Slight modulo
56
56
  // bias for very large bounds — irrelevant at demo scale.
57
- pub func below = (ref self, uint64 bound, out uint64) {
57
+ pub func below = (ref self {}, uint64 bound, out uint64) {
58
58
  if bound == 0 {
59
59
  return 0
60
60
  }
@@ -63,7 +63,7 @@ pub mv struct Random {
63
63
 
64
64
  // The next value in [lo, hi], both ends inclusive. A hi <= lo
65
65
  // returns lo.
66
- pub func range = (ref self, uint64 lo, uint64 hi, out uint64) {
66
+ pub func range = (ref self {}, uint64 lo, uint64 hi, out uint64) {
67
67
  if hi <= lo {
68
68
  return lo
69
69
  }
@@ -20,7 +20,7 @@ pub mv struct Set<T: Hashable + Equatable> {
20
20
  var used = Buffer<int>()
21
21
  var hashes = Buffer<int>()
22
22
 
23
- pub func add = (ref self, mv T value) {
23
+ pub func add = (ref self { hashes, slots, used }, mv T value) {
24
24
  var int cap = self.slots.cap
25
25
  if cap == 0 {
26
26
  cap = self.slots.alloc(8)
@@ -37,10 +37,12 @@ pub mv struct Set<T: Hashable + Equatable> {
37
37
  self.used.store_u32(idx, 1)
38
38
  // The value arrives owned (`mv T value`): a value-struct element
39
39
  // moves into the fresh slot (store_take — the caller's storage is
40
- // zeroed, no deep copy); a string's by-value pair keeps the
41
- // deep-copying store (the caller still owns its buffer), and a
42
- // class/trait handle is a pointer store either way.
43
- if T_IS_VALUE_STRUCT {
40
+ // zeroed, no deep copy) when it OWNS resources; a non-owning value
41
+ // struct is a legal bare argument and keeps the copying store, a
42
+ // string's by-value pair keeps the deep-copying store (the caller
43
+ // still owns its buffer), and a class/trait handle is a pointer
44
+ // store either way.
45
+ if T_TAKES_OWNERSHIP {
44
46
  self.slots.store_take(idx, value)
45
47
  } else {
46
48
  self.slots.store(idx, value)
@@ -98,7 +100,7 @@ pub mv struct Set<T: Hashable + Equatable> {
98
100
  return self.slots.load(idx)
99
101
  }
100
102
 
101
- pub func remove = (ref self, T value) {
103
+ pub func remove = (ref self { hashes, slots, used }, T value) {
102
104
  var int cap = self.slots.cap
103
105
  if cap == 0 {
104
106
  return
@@ -222,7 +224,7 @@ pub mv struct Set<T: Hashable + Equatable> {
222
224
  // compares (values arrive unique — they came from a valid set). The old
223
225
  // form re-inserted via `self.add(mv v)`, re-hashing every value and
224
226
  // re-comparing values on every probed slot.
225
- func rehash = (ref self, int new_cap) {
227
+ func rehash = (ref self { hashes, slots, used }, int new_cap) {
226
228
  var Buffer<T> old_slots = mv self.slots swap Buffer<T>()
227
229
  var Buffer<int> old_used = mv self.used swap Buffer<int>()
228
230
  var Buffer<int> old_hashes = mv self.hashes swap Buffer<int>()
@@ -40,7 +40,7 @@ pub mv struct StableList<T> {
40
40
  // slab is always null, so its field destroy reclaims nothing.
41
41
  var stage = Buffer<T>()
42
42
 
43
- pub func push = (ref self, mv T value) {
43
+ pub func push = (ref self { chunks, items, stage }, mv T value) {
44
44
  if self.items.cap == 0 {
45
45
  self.items.alloc(256)
46
46
  }
@@ -75,7 +75,7 @@ pub mv struct StableList<T> {
75
75
  // and constructs the callee's result directly into the append slot
76
76
  // (the in-place push contract). Byte-identical policy for extra=1: the same
77
77
  // alloc/dir-grow/first-touch sequence push's inline branches performed.
78
- internal func reserve = (ref self, int extra: extra >= 0, out int) {
78
+ internal func reserve = (ref self { chunks, items, stage }, int extra: extra >= 0, out int) {
79
79
  if self.items.cap == 0 {
80
80
  self.items.alloc(256)
81
81
  }
@@ -93,7 +93,7 @@ pub mv struct StableList<T> {
93
93
  // Calloc the directory chunk's slab on first touch (zero words mark
94
94
  // empty chunks) — push's tail store and the in-place append both rely on
95
95
  // the slab existing before a slot address is taken from it.
96
- internal func ensure_chunk = (ref self, int dir_index) {
96
+ internal func ensure_chunk = (ref self { chunks, items, stage }, int dir_index) {
97
97
  ```
98
98
  #arch: c
99
99
  if (((unsigned long long*)self->chunks.data)[dir_index] == 0) {
@@ -130,7 +130,7 @@ pub mv struct StableList<T> {
130
130
  // call's result straight through this address (sole ownership transfers
131
131
  // into the slot — the chunk slab is calloc'd on first touch by
132
132
  // `reserve`'s `ensure_chunk` before the slot address is taken).
133
- internal func append_slot_ptr = (ref self, out ptr T) {
133
+ internal func append_slot_ptr = (ref self { chunks, items, stage }, out ptr T) {
134
134
  ```
135
135
  #arch: c
136
136
  unsigned long long idx = (unsigned long long)self->length;
@@ -236,7 +236,7 @@ pub mv struct StableList<T> {
236
236
  // invalidation for this type, so the alias stays live and writes through
237
237
  // it land in the list. The length constraint is the caller's proof
238
238
  // obligation, exactly like `.at`.
239
- internal func slot_ptr = (ref self, int i: i >= 0 && i < self.length, out ptr T) {
239
+ internal func slot_ptr = (ref self { items }, int i: i >= 0 && i < self.length, out ptr T) {
240
240
  if i < self.items.cap {
241
241
  return self.items.slot_ptr(i)
242
242
  }
@@ -303,13 +303,13 @@ pub mv struct StableList<T> {
303
303
  // nothing.
304
304
  // (The old `stage` relay field is gone — push's tail path stores into
305
305
  // the chunk through a `Buffer.init_view` view.)
306
- func #destroy = (ref self) {
306
+ func #destroy = (ref self { chunks, items, stage }) {
307
307
  self.destroy_tails()
308
308
  }
309
309
 
310
310
  // Raw: destroy directory chunks 1.. — per chunk, `filled` slots + the
311
311
  // slab, via `T_buffer_destroy` on a cap=filled view.
312
- internal func destroy_tails = (ref self) {
312
+ internal func destroy_tails = (ref self { chunks, items, stage }) {
313
313
  ```
314
314
  #arch: c
315
315
  long n_dir = (self->length - 1L) / 256L;
@@ -63,7 +63,7 @@ pub struct File {
63
63
 
64
64
  // Open the file at `path` with a C mode string ("r", "w", "a", …).
65
65
  // Stores the handle and records errno (0 on success) in `error`.
66
- func raw_open = (ref self, string path, string mode) {
66
+ func raw_open = (ref self {}, string path, string mode) {
67
67
  ```
68
68
  #arch: c
69
69
  #scope: file
@@ -99,7 +99,7 @@ pub struct File {
99
99
 
100
100
  // Open the file at `path` with a C mode string ("r", "w", "a", …).
101
101
  // `.ok(true)` on success; `.error(FileError)` otherwise.
102
- pub func open = (ref self, string path, string mode, out Result<bool, FileError>) {
102
+ pub func open = (ref self {}, string path, string mode, out Result<bool, FileError>) {
103
103
  self.raw_open(path, mode)
104
104
  if self.error == 0 {
105
105
  return Result.ok(true)
@@ -110,7 +110,7 @@ pub struct File {
110
110
  // Close the handle, recording errno in `error` (0 on success). Also
111
111
  // performed automatically by #destroy; calling close explicitly releases
112
112
  // the resource early.
113
- func raw_close = (ref self) {
113
+ func raw_close = (ref self {}) {
114
114
  ```
115
115
  #arch: c
116
116
  if (self->handle) {
@@ -147,7 +147,7 @@ pub struct File {
147
147
  // Close the handle. Also performed automatically by #destroy; calling
148
148
  // close explicitly releases the resource early. Closing an unopened (or
149
149
  // already closed) File is `.ok(true)`.
150
- pub func close = (ref self, out Result<bool, FileError>) {
150
+ pub func close = (ref self {}, out Result<bool, FileError>) {
151
151
  self.raw_close()
152
152
  if self.error == 0 {
153
153
  return Result.ok(true)
@@ -158,7 +158,7 @@ pub struct File {
158
158
  // Read every byte from the current position to EOF and return it. Sets
159
159
  // `eof` and `error`. Declared `mv out string`: the raw body mallocs a
160
160
  // fresh buffer and hands ownership to the caller.
161
- func raw_read_all = (ref self, mv out string) {
161
+ func raw_read_all = (ref self {}, mv out string) {
162
162
  ```
163
163
  #arch: c
164
164
  FILE *f = (FILE*)(unsigned long long)self->handle;
@@ -222,7 +222,7 @@ pub struct File {
222
222
  // Read every byte from the current position to EOF. `.ok(text)` with the
223
223
  // remaining bytes (and `eof` set), or `.error(FileError)` — including
224
224
  // `not_open` when the handle was never opened.
225
- pub func readAll = (ref self, out Result<string, FileError>) {
225
+ pub func readAll = (ref self {}, out Result<string, FileError>) {
226
226
  const string body = self.raw_read_all()
227
227
  if self.error == 0 {
228
228
  return Result.ok(body)
@@ -231,7 +231,7 @@ pub struct File {
231
231
  }
232
232
 
233
233
  // Write a string at the current position.
234
- func raw_write_all = (ref self, string data) {
234
+ func raw_write_all = (ref self {}, string data) {
235
235
  ```
236
236
  #arch: c
237
237
  FILE *f = (FILE*)(unsigned long long)self->handle;
@@ -261,7 +261,7 @@ pub struct File {
261
261
  // Write a string at the current position. `.ok(true)`, or
262
262
  // `.error(FileError)` — including `not_open` when the handle was never
263
263
  // opened.
264
- pub func writeAll = (ref self, string data, out Result<bool, FileError>) {
264
+ pub func writeAll = (ref self {}, string data, out Result<bool, FileError>) {
265
265
  self.raw_write_all(data)
266
266
  if self.error == 0 {
267
267
  return Result.ok(true)
@@ -272,7 +272,7 @@ pub struct File {
272
272
  // Read up to the next '\n' (the newline is not included). Sets `eof`
273
273
  // when the end of the file is reached and `error` on failure. The raw
274
274
  // body mallocs a fresh buffer — `mv out string` transfers it.
275
- func raw_read_line = (ref self, mv out string) {
275
+ func raw_read_line = (ref self {}, mv out string) {
276
276
  ```
277
277
  #arch: c
278
278
  FILE *f = (FILE*)(unsigned long long)self->handle;
@@ -364,7 +364,7 @@ pub struct File {
364
364
 
365
365
  // Read up to the next '\n' (the newline is not included). `.ok(text)`
366
366
  // and `eof` set at end of file, or `.error(FileError)`.
367
- pub func readLine = (ref self, out Result<string, FileError>) {
367
+ pub func readLine = (ref self {}, out Result<string, FileError>) {
368
368
  const string line = self.raw_read_line()
369
369
  if self.error == 0 {
370
370
  return Result.ok(line)
@@ -373,7 +373,7 @@ pub struct File {
373
373
  }
374
374
 
375
375
  // Write a string followed by '\n'.
376
- func raw_write_line = (ref self, string data) {
376
+ func raw_write_line = (ref self {}, string data) {
377
377
  ```
378
378
  #arch: c
379
379
  FILE *f = (FILE*)(unsigned long long)self->handle;
@@ -405,7 +405,7 @@ pub struct File {
405
405
  }
406
406
 
407
407
  // Write a string followed by '\n'. `.ok(true)`, or `.error(FileError)`.
408
- pub func writeLine = (ref self, string data, out Result<bool, FileError>) {
408
+ pub func writeLine = (ref self {}, string data, out Result<bool, FileError>) {
409
409
  self.raw_write_line(data)
410
410
  if self.error == 0 {
411
411
  return Result.ok(true)
@@ -416,7 +416,7 @@ pub struct File {
416
416
  // Read up to `size` bytes from the current position. Sets `eof` if fewer
417
417
  // than `size` bytes remain and `error` on failure. The raw body mallocs a
418
418
  // fresh buffer — `mv out string` transfers it.
419
- func raw_read_chunk = (ref self, int size, mv out string) {
419
+ func raw_read_chunk = (ref self {}, int size, mv out string) {
420
420
  ```
421
421
  #arch: c
422
422
  FILE *f = (FILE*)(unsigned long long)self->handle;
@@ -468,7 +468,7 @@ pub struct File {
468
468
 
469
469
  // Read up to `size` bytes from the current position. `.ok(text)`
470
470
  // (`eof` set if fewer bytes remained), or `.error(FileError)`.
471
- pub func readChunk = (ref self, int size, out Result<string, FileError>) {
471
+ pub func readChunk = (ref self {}, int size, out Result<string, FileError>) {
472
472
  const string chunk = self.raw_read_chunk(size)
473
473
  if self.error == 0 {
474
474
  return Result.ok(chunk)
@@ -477,7 +477,7 @@ pub struct File {
477
477
  }
478
478
 
479
479
  // Write the first `size` bytes of `data` at the current position.
480
- func raw_write_chunk = (ref self, string data, int size) {
480
+ func raw_write_chunk = (ref self {}, string data, int size) {
481
481
  ```
482
482
  #arch: c
483
483
  FILE *f = (FILE*)(unsigned long long)self->handle;
@@ -505,7 +505,7 @@ pub struct File {
505
505
 
506
506
  // Write the first `size` bytes of `data` at the current position.
507
507
  // `.ok(true)`, or `.error(FileError)`.
508
- pub func writeChunk = (ref self, string data, int size, out Result<bool, FileError>) {
508
+ pub func writeChunk = (ref self {}, string data, int size, out Result<bool, FileError>) {
509
509
  self.raw_write_chunk(data, size)
510
510
  if self.error == 0 {
511
511
  return Result.ok(true)
@@ -58,7 +58,7 @@ pub struct Http {
58
58
  // (sends `body` and the Content-* headers). Sets self->status (0 on
59
59
  // failure) and self->error, and returns the response body (empty string
60
60
  // on failure).
61
- func raw_exchange = (ref self, string method, string url, string body, mv out string) {
61
+ func raw_exchange = (ref self {}, string method, string url, string body, mv out string) {
62
62
  // Parse the URL: [http://]host[:port][/path]
63
63
  var host_start = 0
64
64
  if url.starts_with("http://") {
@@ -145,7 +145,7 @@ pub struct Http {
145
145
  // Issue a GET request to `url`. `.ok(body)` with the response body and
146
146
  // `self.status` set to the response's status code, or
147
147
  // `.error(HttpError)` (`status` is 0).
148
- pub func get = (ref self, string url, out Result<string, HttpError>) {
148
+ pub func get = (ref self {}, string url, out Result<string, HttpError>) {
149
149
  const string response = self.raw_exchange("GET", url, "")
150
150
  if self.error == 0 {
151
151
  return Result.ok(response)
@@ -156,7 +156,7 @@ pub struct Http {
156
156
  // Issue a POST request to `url` with `body` as the payload.
157
157
  // `.ok(body)` with the response body and `self.status` set to the
158
158
  // response's status code, or `.error(HttpError)` (`status` is 0).
159
- pub func post = (ref self, string url, string body, out Result<string, HttpError>) {
159
+ pub func post = (ref self {}, string url, string body, out Result<string, HttpError>) {
160
160
  const string response = self.raw_exchange("POST", url, body)
161
161
  if self.error == 0 {
162
162
  return Result.ok(response)
@@ -59,7 +59,7 @@ pub mv struct Tcp {
59
59
  ```
60
60
  }
61
61
 
62
- pub func close = (ref self) {
62
+ pub func close = (ref self {}) {
63
63
  Tcp.close_fd(self.fd)
64
64
  self.fd = -1
65
65
  }
@@ -81,7 +81,7 @@ pub mv struct Tcp {
81
81
  // Accept the next connection, parking the fiber while the backlog is
82
82
  // empty. The returned socket is -1 if the listener was cancelled or
83
83
  // failed.
84
- pub func accept = (ref self, mv out Tcp) {
84
+ pub func accept = (ref self {}, mv out Tcp) {
85
85
  var int handle = Tcp.accept_fd(self.fd)
86
86
  var t = Tcp(handle)
87
87
  if handle < 0 {
@@ -114,18 +114,18 @@ pub mv struct Tcp {
114
114
 
115
115
  // Send every byte of `data`. Parks the fiber while the send buffer is
116
116
  // full. Returns false on error or cancellation.
117
- pub func send = (ref self, string data, out bool) {
117
+ pub func send = (ref self {}, string data, out bool) {
118
118
  return Tcp.send_all(self.fd, data)
119
119
  }
120
120
 
121
121
  // Receive up to `max` bytes. Parks the fiber until data arrives; returns
122
122
  // the empty string at end-of-stream, on error, or when cancelled.
123
- pub func recv = (ref self, int max, mv out string) {
123
+ pub func recv = (ref self {}, int max, mv out string) {
124
124
  return Tcp.recv_some(self.fd, max)
125
125
  }
126
126
 
127
127
  // Receive until the peer closes (how Connection: close HTTP works).
128
- pub func recv_all = (ref self, mv out string) {
128
+ pub func recv_all = (ref self {}, mv out string) {
129
129
  return Tcp.recv_until_close(self.fd)
130
130
  }
131
131