nomen-lang 0.3.0 → 0.4.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.
- package/NOMEN_AGENTS.md +7 -1
- package/core/System/Arena.nm +7 -7
- package/core/System/BigInt.nm +5 -15
- package/core/System/Buffer.nm +133 -33
- package/core/System/ClassBuffer.nm +84 -32
- package/core/System/Console.nm +4 -2
- package/core/System/Controls/Button.nm +4 -4
- package/core/System/Controls/CheckBox.nm +1 -1
- package/core/System/Controls/Text.nm +2 -2
- package/core/System/Controls/TextBox.nm +6 -6
- package/core/System/Controls/Window.nm +2 -2
- package/core/System/Graph.nm +4 -4
- package/core/System/LinkedList.nm +4 -4
- package/core/System/List.nm +6 -6
- package/core/System/Map.nm +30 -30
- package/core/System/Set.nm +24 -24
- package/core/System/Stream/Directory.nm +4 -4
- package/core/System/Stream/File.nm +19 -12
- package/core/System/String.nm +47 -18
- package/core/System/Text/JsonTree.nm +15 -15
- package/core/System/bool.nm +2 -1
- package/core/System/char.nm +2 -1
- package/core/System/float.nm +2 -1
- package/core/System/float32.nm +2 -1
- package/core/System/float64.nm +2 -1
- package/core/System/int.nm +4 -2
- package/core/System/int16.nm +2 -1
- package/core/System/int32.nm +2 -1
- package/core/System/int64.nm +2 -1
- package/core/System/int8.nm +2 -1
- package/core/System/ufloat.nm +2 -1
- package/core/System/ufloat32.nm +2 -1
- package/core/System/ufloat64.nm +2 -1
- package/core/System/uint.nm +2 -1
- package/core/System/uint16.nm +2 -1
- package/core/System/uint32.nm +2 -1
- package/core/System/uint64.nm +2 -1
- package/core/System/uint8.nm +2 -1
- package/core/docs/System/BigInt.md +0 -1
- package/dist/index.mjs +2002 -1140
- package/package.json +1 -1
package/core/System/Console.nm
CHANGED
|
@@ -5,7 +5,9 @@ pub struct Console {
|
|
|
5
5
|
pub func write = (string line) {
|
|
6
6
|
```
|
|
7
7
|
#arch: c
|
|
8
|
-
printf
|
|
8
|
+
// Fat-string ABI: strings pass their ptr half. printf %s stops at
|
|
9
|
+
// the first embedded NUL on both backends (known display limit).
|
|
10
|
+
printf("%s", line.ptr);
|
|
9
11
|
```
|
|
10
12
|
```
|
|
11
13
|
#arch: aarch64
|
|
@@ -25,7 +27,7 @@ pub struct Console {
|
|
|
25
27
|
pub func write_line = (string line) {
|
|
26
28
|
```
|
|
27
29
|
#arch: c
|
|
28
|
-
printf("%s\n", line);
|
|
30
|
+
printf("%s\n", line.ptr);
|
|
29
31
|
```
|
|
30
32
|
```
|
|
31
33
|
#arch: aarch64
|
|
@@ -17,7 +17,7 @@ pub class Button : Control {
|
|
|
17
17
|
((void(*)(id, SEL, id))objc_msgSend)(
|
|
18
18
|
btn, sel_registerName("setTitle:"),
|
|
19
19
|
((id(*)(id, SEL, const char*))objc_msgSend)(
|
|
20
|
-
(id)objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), title));
|
|
20
|
+
(id)objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), title.ptr));
|
|
21
21
|
id contentView = ((id(*)(id, SEL))objc_msgSend)(
|
|
22
22
|
(id)window->handle, sel_registerName("contentView"));
|
|
23
23
|
((void(*)(id, SEL, id))objc_msgSend)(
|
|
@@ -53,7 +53,7 @@ pub class Button : Control {
|
|
|
53
53
|
((void(*)(id, SEL, unsigned long, id, id))objc_msgSend)(
|
|
54
54
|
btn, sel_registerName("setTitle:forState:"),
|
|
55
55
|
((id(*)(id, SEL, const char*))objc_msgSend)(
|
|
56
|
-
(id)objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), title),
|
|
56
|
+
(id)objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), title.ptr),
|
|
57
57
|
0); // UIControlStateNormal = 0
|
|
58
58
|
id parentView = ((id(*)(id, SEL))objc_msgSend)(
|
|
59
59
|
((id(*)(id, SEL))objc_msgSend)(
|
|
@@ -123,7 +123,7 @@ pub class Button : Control {
|
|
|
123
123
|
((void(*)(id, SEL, id))objc_msgSend)(
|
|
124
124
|
(id)self->handle, sel_registerName("setTitle:"),
|
|
125
125
|
((id(*)(id, SEL, const char*))objc_msgSend)(
|
|
126
|
-
(id)objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), title));
|
|
126
|
+
(id)objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), title.ptr));
|
|
127
127
|
```
|
|
128
128
|
```
|
|
129
129
|
#arch: aarch64_use_c
|
|
@@ -139,7 +139,7 @@ pub class Button : Control {
|
|
|
139
139
|
((void(*)(id, SEL, unsigned long, id, id))objc_msgSend)(
|
|
140
140
|
(id)self->handle, sel_registerName("setTitle:forState:"),
|
|
141
141
|
((id(*)(id, SEL, const char*))objc_msgSend)(
|
|
142
|
-
(id)objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), title),
|
|
142
|
+
(id)objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), title.ptr),
|
|
143
143
|
0); // UIControlStateNormal = 0
|
|
144
144
|
```
|
|
145
145
|
```
|
|
@@ -109,7 +109,7 @@ pub class CheckBox : Control {
|
|
|
109
109
|
((void(*)(id, SEL, id))objc_msgSend)(
|
|
110
110
|
(id)self->handle, sel_registerName("setTitle:"),
|
|
111
111
|
((id(*)(id, SEL, const char*))objc_msgSend)(
|
|
112
|
-
(id)objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), title));
|
|
112
|
+
(id)objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), title.ptr));
|
|
113
113
|
```
|
|
114
114
|
```
|
|
115
115
|
#arch: aarch64_use_c
|
|
@@ -100,7 +100,7 @@ pub class Text: Control {
|
|
|
100
100
|
((void(*)(id, SEL, id))objc_msgSend)(
|
|
101
101
|
(id)self->handle, sel_registerName("setStringValue:"),
|
|
102
102
|
((id(*)(id, SEL, const char*))objc_msgSend)(
|
|
103
|
-
(id)objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), text));
|
|
103
|
+
(id)objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), text.ptr));
|
|
104
104
|
```
|
|
105
105
|
```
|
|
106
106
|
#arch: aarch64_use_c
|
|
@@ -116,7 +116,7 @@ pub class Text: Control {
|
|
|
116
116
|
((void(*)(id, SEL, id))objc_msgSend)(
|
|
117
117
|
(id)self->handle, sel_registerName("setText:"),
|
|
118
118
|
((id(*)(id, SEL, const char*))objc_msgSend)(
|
|
119
|
-
(id)objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), text));
|
|
119
|
+
(id)objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), text.ptr));
|
|
120
120
|
```
|
|
121
121
|
```
|
|
122
122
|
#arch: aarch64_use_c
|
|
@@ -133,7 +133,7 @@ pub class TextBox : Control {
|
|
|
133
133
|
((void(*)(id, SEL, id))objc_msgSend)(
|
|
134
134
|
(id)self->handle, sel_registerName("setStringValue:"),
|
|
135
135
|
((id(*)(id, SEL, const char*))objc_msgSend)(
|
|
136
|
-
(id)objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), text));
|
|
136
|
+
(id)objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), text.ptr));
|
|
137
137
|
```
|
|
138
138
|
```
|
|
139
139
|
#arch: aarch64_use_c
|
|
@@ -149,7 +149,7 @@ pub class TextBox : Control {
|
|
|
149
149
|
((void(*)(id, SEL, id))objc_msgSend)(
|
|
150
150
|
(id)self->handle, sel_registerName("setText:"),
|
|
151
151
|
((id(*)(id, SEL, const char*))objc_msgSend)(
|
|
152
|
-
(id)objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), text));
|
|
152
|
+
(id)objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), text.ptr));
|
|
153
153
|
```
|
|
154
154
|
```
|
|
155
155
|
#arch: aarch64_use_c
|
|
@@ -169,7 +169,7 @@ pub class TextBox : Control {
|
|
|
169
169
|
(id)self->handle, sel_registerName("stringValue"));
|
|
170
170
|
const char *cstr = ((const char*(*)(id, SEL))objc_msgSend)(
|
|
171
171
|
str, sel_registerName("UTF8String"));
|
|
172
|
-
return strdup(cstr);
|
|
172
|
+
return (nomen_string){ strdup(cstr), (long)strlen(cstr) };
|
|
173
173
|
```
|
|
174
174
|
```
|
|
175
175
|
#arch: aarch64_use_c
|
|
@@ -178,7 +178,7 @@ pub class TextBox : Control {
|
|
|
178
178
|
(id)self->handle, sel_registerName("stringValue"));
|
|
179
179
|
const char *cstr = ((const char*(*)(id, SEL))objc_msgSend)(
|
|
180
180
|
str, sel_registerName("UTF8String"));
|
|
181
|
-
return strdup(cstr);
|
|
181
|
+
return (nomen_string){ strdup(cstr), (long)strlen(cstr) };
|
|
182
182
|
```
|
|
183
183
|
```
|
|
184
184
|
#arch: c
|
|
@@ -187,7 +187,7 @@ pub class TextBox : Control {
|
|
|
187
187
|
(id)self->handle, sel_registerName("text"));
|
|
188
188
|
const char *cstr = ((const char*(*)(id, SEL))objc_msgSend)(
|
|
189
189
|
str, sel_registerName("UTF8String"));
|
|
190
|
-
return strdup(cstr);
|
|
190
|
+
return (nomen_string){ strdup(cstr), (long)strlen(cstr) };
|
|
191
191
|
```
|
|
192
192
|
```
|
|
193
193
|
#arch: aarch64_use_c
|
|
@@ -196,7 +196,7 @@ pub class TextBox : Control {
|
|
|
196
196
|
(id)self->handle, sel_registerName("text.ptr"));
|
|
197
197
|
const char *cstr = ((const char*(*)(id, SEL))objc_msgSend)(
|
|
198
198
|
str, sel_registerName("UTF8String"));
|
|
199
|
-
return strdup(cstr);
|
|
199
|
+
return (nomen_string){ strdup(cstr), (long)strlen(cstr) };
|
|
200
200
|
```
|
|
201
201
|
}
|
|
202
202
|
|
|
@@ -22,7 +22,7 @@ pub class Window: Control {
|
|
|
22
22
|
((id(*)(id, SEL, id))objc_msgSend)(
|
|
23
23
|
win, sel_registerName("setTitle:"),
|
|
24
24
|
((id(*)(id, SEL, const char*))objc_msgSend)(
|
|
25
|
-
(id)objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), title));
|
|
25
|
+
(id)objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), title.ptr));
|
|
26
26
|
((void(*)(id, SEL, double, double))objc_msgSend)(
|
|
27
27
|
win, sel_registerName("setFrameTopLeftPoint:"), 100.0, 100.0);
|
|
28
28
|
((void(*)(id, SEL, id))objc_msgSend)(win, sel_registerName("makeKeyAndOrderFront:"), (id)0);
|
|
@@ -115,7 +115,7 @@ pub class Window: Control {
|
|
|
115
115
|
((id(*)(id, SEL, id))objc_msgSend)(
|
|
116
116
|
(id)self->handle, sel_registerName("setTitle:"),
|
|
117
117
|
((id(*)(id, SEL, const char*))objc_msgSend)(
|
|
118
|
-
(id)objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), title));
|
|
118
|
+
(id)objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), title.ptr));
|
|
119
119
|
```
|
|
120
120
|
```
|
|
121
121
|
#arch: aarch64_use_c
|
package/core/System/Graph.nm
CHANGED
|
@@ -16,8 +16,8 @@ pub struct Graph<T>: Enumerable {
|
|
|
16
16
|
|
|
17
17
|
pub func add_node = (ref self, move T value) {
|
|
18
18
|
var int idx = self.node_count
|
|
19
|
-
self.values.
|
|
20
|
-
self.values.
|
|
19
|
+
self.values.grow(idx + 1)
|
|
20
|
+
self.values.store(idx, value)
|
|
21
21
|
self.head_edge.grow_int(idx + 1)
|
|
22
22
|
self.head_edge.store_int(idx, -1)
|
|
23
23
|
self.node_count = self.node_count + 1
|
|
@@ -50,11 +50,11 @@ pub struct Graph<T>: Enumerable {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
pub func first = (self: self.node_count > 0, out T) {
|
|
53
|
-
return self.values.
|
|
53
|
+
return self.values.load(0)
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
pub func at = (self, int idx: idx >= 0 && idx < self.node_count, out T) {
|
|
57
|
-
return self.values.
|
|
57
|
+
return self.values.load(idx)
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
pub func node_length = (self, out int) {
|
|
@@ -15,8 +15,8 @@ pub struct LinkedList<T>: Enumerable {
|
|
|
15
15
|
|
|
16
16
|
pub func add = (ref self, move T value) {
|
|
17
17
|
var int idx = self.count
|
|
18
|
-
self.values.
|
|
19
|
-
self.values.
|
|
18
|
+
self.values.grow(idx + 1)
|
|
19
|
+
self.values.store(idx, value)
|
|
20
20
|
self.nexts.grow_int(idx + 1)
|
|
21
21
|
self.nexts.store_int(idx, -1)
|
|
22
22
|
self.prevs.grow_int(idx + 1)
|
|
@@ -50,11 +50,11 @@ pub struct LinkedList<T>: Enumerable {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
pub func first = (self: self.count > 0, out T) {
|
|
53
|
-
return self.values.
|
|
53
|
+
return self.values.load(0)
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
pub func at = (self, int idx: idx >= 0 && idx < self.count, out T) {
|
|
57
|
-
return self.values.
|
|
57
|
+
return self.values.load(idx)
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
// Bounds-checked access: `fallback` when idx is outside [0, self.count).
|
package/core/System/List.nm
CHANGED
|
@@ -12,23 +12,23 @@ pub struct List<T>: Viewable {
|
|
|
12
12
|
if old_cap >= 4 {
|
|
13
13
|
new_cap = old_cap * 2
|
|
14
14
|
}
|
|
15
|
-
self.items.
|
|
15
|
+
self.items.grow(new_cap)
|
|
16
16
|
}
|
|
17
|
-
self.items.
|
|
17
|
+
self.items.store(self.length, value)
|
|
18
18
|
self.length += 1
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
pub func pop = (ref self, move out T) {
|
|
22
22
|
if self.length <= 0 {
|
|
23
|
-
return self.items.
|
|
23
|
+
return self.items.move(0)
|
|
24
24
|
}
|
|
25
25
|
var int idx = self.length - 1
|
|
26
26
|
self.length = idx
|
|
27
|
-
return self.items.
|
|
27
|
+
return self.items.move(idx)
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
pub inline func at = (self, int i: i >= 0 && i < self.length, out T) {
|
|
31
|
-
return self.items.
|
|
31
|
+
return self.items.load(i)
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
// Bounds-checked access: `fallback` when i is outside [0, self.length) —
|
|
@@ -58,7 +58,7 @@ pub struct List<T>: Viewable {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
pub func set = (ref self, int i: i >= 0 && i < self.length, move T value) {
|
|
61
|
-
self.items.
|
|
61
|
+
self.items.replace(i, value)
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
// A deep copy: a fresh List<T> with an independent copy of every element.
|
package/core/System/Map.nm
CHANGED
|
@@ -30,22 +30,22 @@ pub struct Map<TK: Hashable + Equatable, TV> {
|
|
|
30
30
|
// alloc_T: for Buffer<TK> it is T_SIZE-aware (string keys are
|
|
31
31
|
// 16-byte slots); for ClassBuffer<TV> it delegates to alloc_int
|
|
32
32
|
// (one pointer per slot). Both have it for generic parity.
|
|
33
|
-
cap = self.keys.
|
|
34
|
-
self.values.
|
|
35
|
-
self.used.
|
|
33
|
+
cap = self.keys.alloc(8)
|
|
34
|
+
self.values.alloc(8)
|
|
35
|
+
self.used.alloc_u32(8)
|
|
36
36
|
}
|
|
37
37
|
if self.length * 4 >= cap * 3 {
|
|
38
38
|
self.rehash(cap * 2)
|
|
39
39
|
cap = self.keys.cap
|
|
40
40
|
}
|
|
41
41
|
var int idx = self.find_slot(key, cap)
|
|
42
|
-
if self.used.
|
|
43
|
-
self.used.
|
|
44
|
-
self.keys.
|
|
45
|
-
self.values.
|
|
42
|
+
if self.used.load_u32(idx) == 0 {
|
|
43
|
+
self.used.store_u32(idx, 1)
|
|
44
|
+
self.keys.store(idx, key)
|
|
45
|
+
self.values.store(idx, value)
|
|
46
46
|
self.length += 1
|
|
47
47
|
} else {
|
|
48
|
-
self.values.
|
|
48
|
+
self.values.replace(idx, value)
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
|
|
@@ -55,10 +55,10 @@ pub struct Map<TK: Hashable + Equatable, TV> {
|
|
|
55
55
|
return 0
|
|
56
56
|
}
|
|
57
57
|
var int idx = self.find_slot(key, cap)
|
|
58
|
-
if self.used.
|
|
58
|
+
if self.used.load_u32(idx) == 0 {
|
|
59
59
|
return 0
|
|
60
60
|
}
|
|
61
|
-
return self.values.
|
|
61
|
+
return self.values.load(idx)
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
// Fused lookup-with-fallback: one probe instead of the `has` + `get`
|
|
@@ -69,10 +69,10 @@ pub struct Map<TK: Hashable + Equatable, TV> {
|
|
|
69
69
|
return fallback
|
|
70
70
|
}
|
|
71
71
|
var int idx = self.find_slot(key, cap)
|
|
72
|
-
if self.used.
|
|
72
|
+
if self.used.load_u32(idx) == 0 {
|
|
73
73
|
return fallback
|
|
74
74
|
}
|
|
75
|
-
return self.values.
|
|
75
|
+
return self.values.load(idx)
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
// Lookup that traps when the key is absent — for when a missing key is
|
|
@@ -83,10 +83,10 @@ pub struct Map<TK: Hashable + Equatable, TV> {
|
|
|
83
83
|
panic("key not found")
|
|
84
84
|
}
|
|
85
85
|
var int idx = self.find_slot(key, cap)
|
|
86
|
-
if self.used.
|
|
86
|
+
if self.used.load_u32(idx) == 0 {
|
|
87
87
|
panic("key not found")
|
|
88
88
|
}
|
|
89
|
-
return self.values.
|
|
89
|
+
return self.values.load(idx)
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
pub func has = (self, TK key, out bool) {
|
|
@@ -95,7 +95,7 @@ pub struct Map<TK: Hashable + Equatable, TV> {
|
|
|
95
95
|
return false
|
|
96
96
|
}
|
|
97
97
|
var int idx = self.find_slot(key, cap)
|
|
98
|
-
return self.used.
|
|
98
|
+
return self.used.load_u32(idx) != 0
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
pub func remove = (ref self, TK key) {
|
|
@@ -104,7 +104,7 @@ pub struct Map<TK: Hashable + Equatable, TV> {
|
|
|
104
104
|
return
|
|
105
105
|
}
|
|
106
106
|
var int idx = self.find_slot(key, cap)
|
|
107
|
-
if self.used.
|
|
107
|
+
if self.used.load_u32(idx) == 0 {
|
|
108
108
|
return
|
|
109
109
|
}
|
|
110
110
|
// Backward-shift deletion for linear probing. `gap` is the empty slot
|
|
@@ -124,10 +124,10 @@ pub struct Map<TK: Hashable + Equatable, TV> {
|
|
|
124
124
|
if k >= cap {
|
|
125
125
|
k = 0
|
|
126
126
|
}
|
|
127
|
-
if self.used.
|
|
127
|
+
if self.used.load_u32(k) == 0 {
|
|
128
128
|
break
|
|
129
129
|
}
|
|
130
|
-
var int home = (self.keys.
|
|
130
|
+
var int home = (self.keys.load(k).hash() as int) & (cap - 1)
|
|
131
131
|
var int dgap = gap - home
|
|
132
132
|
if dgap < 0 {
|
|
133
133
|
dgap = dgap + cap
|
|
@@ -142,13 +142,13 @@ pub struct Map<TK: Hashable + Equatable, TV> {
|
|
|
142
142
|
// would strdup a fresh copy into gap while leaving the source
|
|
143
143
|
// slot's pointer stranded at the vacated slot — leaked once
|
|
144
144
|
// used.store marks it empty (the buffer destroy skips it).
|
|
145
|
-
self.keys.
|
|
146
|
-
self.values.
|
|
147
|
-
self.used.
|
|
145
|
+
self.keys.shift(gap, k)
|
|
146
|
+
self.values.shift(gap, k)
|
|
147
|
+
self.used.store_u32(gap, 1)
|
|
148
148
|
gap = k
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
|
-
self.used.
|
|
151
|
+
self.used.store_u32(gap, 0)
|
|
152
152
|
self.length = self.length - 1
|
|
153
153
|
}
|
|
154
154
|
|
|
@@ -156,8 +156,8 @@ pub struct Map<TK: Hashable + Equatable, TV> {
|
|
|
156
156
|
// cap is a power of two, so this is `hash mod cap` via a mask —
|
|
157
157
|
// non-negative for any hash (two's complement), no adjustment.
|
|
158
158
|
var int idx = (key.hash() as int) & (cap - 1)
|
|
159
|
-
while self.used.
|
|
160
|
-
if self.keys.
|
|
159
|
+
while self.used.load_u32(idx) != 0 {
|
|
160
|
+
if self.keys.load(idx) == key {
|
|
161
161
|
return idx
|
|
162
162
|
}
|
|
163
163
|
idx += 1
|
|
@@ -174,14 +174,14 @@ pub struct Map<TK: Hashable + Equatable, TV> {
|
|
|
174
174
|
var Buffer<int> old_used = move self.used swap Buffer<int>()
|
|
175
175
|
var int old_cap = old_keys.cap
|
|
176
176
|
|
|
177
|
-
self.keys.
|
|
178
|
-
self.values.
|
|
179
|
-
self.used.
|
|
177
|
+
self.keys.alloc(new_cap)
|
|
178
|
+
self.values.alloc(new_cap)
|
|
179
|
+
self.used.alloc_u32(new_cap)
|
|
180
180
|
self.length = 0
|
|
181
181
|
|
|
182
182
|
var i = 0
|
|
183
183
|
while i < old_cap; i += 1 {
|
|
184
|
-
if old_used.
|
|
184
|
+
if old_used.load_u32(i) != 0 {
|
|
185
185
|
// move_T (not load_T) relinquishes the old slot, so each
|
|
186
186
|
// key/value is owned by exactly one buffer (the new self)
|
|
187
187
|
// afterwards. load_T would leave the old slot referencing
|
|
@@ -191,8 +191,8 @@ pub struct Map<TK: Hashable + Equatable, TV> {
|
|
|
191
191
|
// store_T strdup's) is freed here once the new buffer has
|
|
192
192
|
// made its own copy — passing them inline would orphan the
|
|
193
193
|
// move_T results.
|
|
194
|
-
var TK k = old_keys.
|
|
195
|
-
var TV v = old_values.
|
|
194
|
+
var TK k = old_keys.move(i)
|
|
195
|
+
var TV v = old_values.move(i)
|
|
196
196
|
self.set(move k, move v)
|
|
197
197
|
}
|
|
198
198
|
}
|
package/core/System/Set.nm
CHANGED
|
@@ -15,17 +15,17 @@ pub struct Set<T: Hashable + Equatable> {
|
|
|
15
15
|
pub func add = (ref self, move T value) {
|
|
16
16
|
var int cap = self.slots.cap
|
|
17
17
|
if cap == 0 {
|
|
18
|
-
cap = self.slots.
|
|
19
|
-
self.used.
|
|
18
|
+
cap = self.slots.alloc(8)
|
|
19
|
+
self.used.alloc_u32(8)
|
|
20
20
|
}
|
|
21
21
|
if self.length * 4 >= cap * 3 {
|
|
22
22
|
self.rehash(cap * 2)
|
|
23
23
|
cap = self.slots.cap
|
|
24
24
|
}
|
|
25
25
|
var int idx = self.find_slot(value, cap)
|
|
26
|
-
if self.used.
|
|
27
|
-
self.used.
|
|
28
|
-
self.slots.
|
|
26
|
+
if self.used.load_u32(idx) == 0 {
|
|
27
|
+
self.used.store_u32(idx, 1)
|
|
28
|
+
self.slots.store(idx, value)
|
|
29
29
|
self.length += 1
|
|
30
30
|
}
|
|
31
31
|
}
|
|
@@ -36,7 +36,7 @@ pub struct Set<T: Hashable + Equatable> {
|
|
|
36
36
|
return false
|
|
37
37
|
}
|
|
38
38
|
var int idx = self.find_slot(value, cap)
|
|
39
|
-
return self.used.
|
|
39
|
+
return self.used.load_u32(idx) != 0
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
pub func get = (self, T key, out T) {
|
|
@@ -45,10 +45,10 @@ pub struct Set<T: Hashable + Equatable> {
|
|
|
45
45
|
return 0
|
|
46
46
|
}
|
|
47
47
|
var int idx = self.find_slot(key, cap)
|
|
48
|
-
if self.used.
|
|
48
|
+
if self.used.load_u32(idx) == 0 {
|
|
49
49
|
return 0
|
|
50
50
|
}
|
|
51
|
-
return self.slots.
|
|
51
|
+
return self.slots.load(idx)
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
// Membership lookup with a fallback value: `fallback` when the value is
|
|
@@ -59,10 +59,10 @@ pub struct Set<T: Hashable + Equatable> {
|
|
|
59
59
|
return fallback
|
|
60
60
|
}
|
|
61
61
|
var int idx = self.find_slot(key, cap)
|
|
62
|
-
if self.used.
|
|
62
|
+
if self.used.load_u32(idx) == 0 {
|
|
63
63
|
return fallback
|
|
64
64
|
}
|
|
65
|
-
return self.slots.
|
|
65
|
+
return self.slots.load(idx)
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
// Membership lookup that traps when the value is not in the set.
|
|
@@ -72,10 +72,10 @@ pub struct Set<T: Hashable + Equatable> {
|
|
|
72
72
|
panic("value not found in set")
|
|
73
73
|
}
|
|
74
74
|
var int idx = self.find_slot(key, cap)
|
|
75
|
-
if self.used.
|
|
75
|
+
if self.used.load_u32(idx) == 0 {
|
|
76
76
|
panic("value not found in set")
|
|
77
77
|
}
|
|
78
|
-
return self.slots.
|
|
78
|
+
return self.slots.load(idx)
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
pub func remove = (ref self, T value) {
|
|
@@ -84,7 +84,7 @@ pub struct Set<T: Hashable + Equatable> {
|
|
|
84
84
|
return
|
|
85
85
|
}
|
|
86
86
|
var int idx = self.find_slot(value, cap)
|
|
87
|
-
if self.used.
|
|
87
|
+
if self.used.load_u32(idx) == 0 {
|
|
88
88
|
return
|
|
89
89
|
}
|
|
90
90
|
// Backward-shift deletion for linear probing. `gap` is the empty slot
|
|
@@ -104,10 +104,10 @@ pub struct Set<T: Hashable + Equatable> {
|
|
|
104
104
|
if k >= cap {
|
|
105
105
|
k = 0
|
|
106
106
|
}
|
|
107
|
-
if self.used.
|
|
107
|
+
if self.used.load_u32(k) == 0 {
|
|
108
108
|
break
|
|
109
109
|
}
|
|
110
|
-
var int home = (self.slots.
|
|
110
|
+
var int home = (self.slots.load(k).hash() as int) & (cap - 1)
|
|
111
111
|
var int dgap = gap - home
|
|
112
112
|
if dgap < 0 {
|
|
113
113
|
dgap = dgap + cap
|
|
@@ -122,12 +122,12 @@ pub struct Set<T: Hashable + Equatable> {
|
|
|
122
122
|
// fresh copy into gap while stranding the source slot's
|
|
123
123
|
// pointer at the vacated slot (leaked once used.store marks it
|
|
124
124
|
// empty; the buffer destroy skips unused slots).
|
|
125
|
-
self.slots.
|
|
126
|
-
self.used.
|
|
125
|
+
self.slots.shift(gap, k)
|
|
126
|
+
self.used.store_u32(gap, 1)
|
|
127
127
|
gap = k
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
|
-
self.used.
|
|
130
|
+
self.used.store_u32(gap, 0)
|
|
131
131
|
self.length = self.length - 1
|
|
132
132
|
}
|
|
133
133
|
|
|
@@ -135,8 +135,8 @@ pub struct Set<T: Hashable + Equatable> {
|
|
|
135
135
|
// cap is a power of two: `hash mod cap` via a mask, non-negative
|
|
136
136
|
// for any hash — no adjustment needed.
|
|
137
137
|
var int idx = (value.hash() as int) & (cap - 1)
|
|
138
|
-
while self.used.
|
|
139
|
-
if self.slots.
|
|
138
|
+
while self.used.load_u32(idx) != 0 {
|
|
139
|
+
if self.slots.load(idx) == value {
|
|
140
140
|
return idx
|
|
141
141
|
}
|
|
142
142
|
idx += 1
|
|
@@ -152,13 +152,13 @@ pub struct Set<T: Hashable + Equatable> {
|
|
|
152
152
|
var Buffer<int> old_used = move self.used swap Buffer<int>()
|
|
153
153
|
var int old_cap = old_slots.cap
|
|
154
154
|
|
|
155
|
-
self.slots.
|
|
156
|
-
self.used.
|
|
155
|
+
self.slots.alloc(new_cap)
|
|
156
|
+
self.used.alloc_u32(new_cap)
|
|
157
157
|
self.length = 0
|
|
158
158
|
|
|
159
159
|
var i = 0
|
|
160
160
|
while i < old_cap; i += 1 {
|
|
161
|
-
if old_used.
|
|
161
|
+
if old_used.load_u32(i) != 0 {
|
|
162
162
|
// move_T (not load_T) relinquishes the old slot, so each value
|
|
163
163
|
// is owned by exactly one buffer (the new self) afterwards.
|
|
164
164
|
// load_T would leave the old slot referencing the same class
|
|
@@ -167,7 +167,7 @@ pub struct Set<T: Hashable + Equatable> {
|
|
|
167
167
|
// `Buffer<string>` slot, which store_T strdup's) is freed here
|
|
168
168
|
// once the new buffer has made its own copy — passing it inline
|
|
169
169
|
// would orphan the move_T result.
|
|
170
|
-
var T v = old_slots.
|
|
170
|
+
var T v = old_slots.move(i)
|
|
171
171
|
self.add(move v)
|
|
172
172
|
}
|
|
173
173
|
}
|
|
@@ -43,7 +43,7 @@ pub struct Directory {
|
|
|
43
43
|
```
|
|
44
44
|
```
|
|
45
45
|
#arch: c
|
|
46
|
-
if (mkdir(path, 0777)) return errno;
|
|
46
|
+
if (mkdir(path.ptr, 0777)) return errno;
|
|
47
47
|
return 0;
|
|
48
48
|
```
|
|
49
49
|
```
|
|
@@ -76,7 +76,7 @@ pub struct Directory {
|
|
|
76
76
|
func raw_remove = (string path, out int) {
|
|
77
77
|
```
|
|
78
78
|
#arch: c
|
|
79
|
-
if (rmdir(path)) return errno;
|
|
79
|
+
if (rmdir(path.ptr)) return errno;
|
|
80
80
|
return 0;
|
|
81
81
|
```
|
|
82
82
|
```
|
|
@@ -109,7 +109,7 @@ pub struct Directory {
|
|
|
109
109
|
```
|
|
110
110
|
#arch: c
|
|
111
111
|
struct stat st;
|
|
112
|
-
return stat(path, &st) == 0 ? 1 : 0;
|
|
112
|
+
return stat(path.ptr, &st) == 0 ? 1 : 0;
|
|
113
113
|
```
|
|
114
114
|
```
|
|
115
115
|
#arch: aarch64
|
|
@@ -147,7 +147,7 @@ pub struct Directory {
|
|
|
147
147
|
```
|
|
148
148
|
#arch: c
|
|
149
149
|
Result_string_DirectoryError r;
|
|
150
|
-
DIR *d = opendir(path);
|
|
150
|
+
DIR *d = opendir(path.ptr);
|
|
151
151
|
if (!d) {
|
|
152
152
|
int e = errno;
|
|
153
153
|
long de = 4;
|
|
@@ -72,7 +72,8 @@ pub struct File {
|
|
|
72
72
|
```
|
|
73
73
|
```
|
|
74
74
|
#arch: c
|
|
75
|
-
|
|
75
|
+
// Fat-string ABI: strings pass their ptr half at FFI boundaries.
|
|
76
|
+
self->handle = (unsigned long long)fopen(path.ptr, mode.ptr);
|
|
76
77
|
if (self->handle) {
|
|
77
78
|
self->error = 0;
|
|
78
79
|
} else {
|
|
@@ -236,21 +237,24 @@ pub struct File {
|
|
|
236
237
|
#arch: c
|
|
237
238
|
FILE *f = (FILE*)(unsigned long long)self->handle;
|
|
238
239
|
if (!f) { self->error = 9; return; }
|
|
239
|
-
fputs
|
|
240
|
+
// Byte-exact write of the tracked length (fputs stopped at the
|
|
241
|
+
// first embedded NUL).
|
|
242
|
+
fwrite(data.ptr, 1, data.len, f);
|
|
240
243
|
self->error = 0;
|
|
241
244
|
```
|
|
242
245
|
```
|
|
243
246
|
#arch: aarch64
|
|
244
|
-
// Fat-string ABI: data = (x1, x2).
|
|
247
|
+
// Fat-string ABI: data = (x1 ptr, x2 len).
|
|
245
248
|
ldr x3, [x19, #8]
|
|
246
249
|
cbnz x3, .Lfile_write_all_go
|
|
247
250
|
mov x0, #9
|
|
248
251
|
str x0, [x19, #24]
|
|
249
252
|
b .return_File_raw_write_all
|
|
250
253
|
.Lfile_write_all_go:
|
|
254
|
+
// fwrite(ptr, 1, len, f) — byte-exact (fputs truncated at NUL)
|
|
251
255
|
mov x0, x1
|
|
252
|
-
mov x1,
|
|
253
|
-
bl
|
|
256
|
+
mov x1, #1
|
|
257
|
+
bl _fwrite
|
|
254
258
|
str xzr, [x19, #24]
|
|
255
259
|
```
|
|
256
260
|
}
|
|
@@ -375,22 +379,25 @@ pub struct File {
|
|
|
375
379
|
#arch: c
|
|
376
380
|
FILE *f = (FILE*)(unsigned long long)self->handle;
|
|
377
381
|
if (!f) { self->error = 9; return; }
|
|
378
|
-
fputs
|
|
382
|
+
// Byte-exact write of the tracked length (fputs stopped at the
|
|
383
|
+
// first embedded NUL).
|
|
384
|
+
fwrite(data.ptr, 1, data.len, f);
|
|
379
385
|
fputc('\n', f);
|
|
380
386
|
self->error = 0;
|
|
381
387
|
```
|
|
382
388
|
```
|
|
383
389
|
#arch: aarch64
|
|
384
|
-
// Fat-string ABI: data = (x1, x2).
|
|
390
|
+
// Fat-string ABI: data = (x1 ptr, x2 len).
|
|
385
391
|
ldr x3, [x19, #8]
|
|
386
392
|
cbnz x3, .Lfile_write_line_go
|
|
387
393
|
mov x0, #9
|
|
388
394
|
str x0, [x19, #24]
|
|
389
395
|
b .return_File_raw_write_line
|
|
390
396
|
.Lfile_write_line_go:
|
|
397
|
+
// fwrite(ptr, 1, len, f) — byte-exact (fputs truncated at NUL)
|
|
391
398
|
mov x0, x1
|
|
392
|
-
mov x1,
|
|
393
|
-
bl
|
|
399
|
+
mov x1, #1
|
|
400
|
+
bl _fwrite
|
|
394
401
|
mov w0, #10
|
|
395
402
|
ldr x1, [x19, #8]
|
|
396
403
|
bl _fputc
|
|
@@ -476,7 +483,7 @@ pub struct File {
|
|
|
476
483
|
#arch: c
|
|
477
484
|
FILE *f = (FILE*)(unsigned long long)self->handle;
|
|
478
485
|
if (!f) { self->error = 9; return; }
|
|
479
|
-
fwrite(data, 1, size, f);
|
|
486
|
+
fwrite(data.ptr, 1, size, f);
|
|
480
487
|
self->error = 0;
|
|
481
488
|
```
|
|
482
489
|
```
|
|
@@ -513,7 +520,7 @@ pub struct File {
|
|
|
513
520
|
```
|
|
514
521
|
#arch: c
|
|
515
522
|
struct stat st;
|
|
516
|
-
return stat(path, &st) == 0 ? 1 : 0;
|
|
523
|
+
return stat(path.ptr, &st) == 0 ? 1 : 0;
|
|
517
524
|
```
|
|
518
525
|
```
|
|
519
526
|
#arch: aarch64
|
|
@@ -532,7 +539,7 @@ pub struct File {
|
|
|
532
539
|
func raw_delete = (string path, out int) {
|
|
533
540
|
```
|
|
534
541
|
#arch: c
|
|
535
|
-
if (remove(path)) return errno;
|
|
542
|
+
if (remove(path.ptr)) return errno;
|
|
536
543
|
return 0;
|
|
537
544
|
```
|
|
538
545
|
```
|