nomen-lang 0.1.0 → 0.2.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 +3 -3
- package/core/System/Buffer.nm +2 -2
- package/core/System/Channel.nm +1 -1
- package/core/System/ClassBuffer.nm +2 -2
- package/core/System/Console.nm +4 -4
- package/core/System/Graph.nm +1 -1
- package/core/System/LinkedList.nm +1 -1
- package/core/System/List.nm +3 -3
- package/core/System/Map.nm +5 -5
- package/core/System/Result.nm +1 -1
- package/core/System/Set.nm +4 -4
- package/core/System/Stream/File.nm +7 -7
- package/core/System/Stream/Http.nm +2 -2
- package/core/System/String.nm +3 -3
- package/core/System/Task.nm +2 -2
- package/core/System/Text/Json.nm +4 -4
- package/core/System/Text/Regex.nm +2 -2
- package/core/System/Tree.nm +1 -1
- package/core/System/bool.nm +1 -1
- package/core/System/char.nm +1 -1
- package/core/System/float.nm +1 -1
- package/core/System/float32.nm +1 -1
- package/core/System/float64.nm +1 -1
- package/core/System/int.nm +1 -1
- package/core/System/int16.nm +1 -1
- package/core/System/int32.nm +1 -1
- package/core/System/int64.nm +1 -1
- package/core/System/int8.nm +1 -1
- package/core/System/ufloat.nm +1 -1
- package/core/System/ufloat32.nm +1 -1
- package/core/System/ufloat64.nm +1 -1
- package/core/System/uint.nm +1 -1
- package/core/System/uint16.nm +1 -1
- package/core/System/uint32.nm +1 -1
- package/core/System/uint64.nm +1 -1
- package/core/System/uint8.nm +1 -1
- package/core/docs/System/Result.md +2 -2
- package/dist/index.mjs +3573 -3463
- package/package.json +1 -1
- package/src/index.ts +6 -1
- package/src/test.ts +47 -3
package/NOMEN_AGENTS.md
CHANGED
|
@@ -100,7 +100,7 @@ func safe = (string[] s, int i: i >= 0 && i < s.length, out string) {
|
|
|
100
100
|
| -------- | ---------------------------------------------- |
|
|
101
101
|
| `ref T` | mutable borrow; caller must also write `ref` |
|
|
102
102
|
| `view T` | read-only borrow |
|
|
103
|
-
| `
|
|
103
|
+
| `move T` | transfer ownership; caller writes `move` |
|
|
104
104
|
| `out T` | output parameter, assigned inside the function |
|
|
105
105
|
|
|
106
106
|
`const` values cannot be passed to `ref` — rebind the caller as `var` first.
|
|
@@ -150,10 +150,10 @@ declarations, so never import a sibling. Only cross-namespace references
|
|
|
150
150
|
Failures are signalled via return values — nullable results, status structs,
|
|
151
151
|
or boolean + out-parameter pairs. There is no `throw`/`try`/`catch`.
|
|
152
152
|
|
|
153
|
-
`Result<T, E>` is declared `
|
|
153
|
+
`Result<T, E>` is declared `must_use`: a call returning it must bind or match
|
|
154
154
|
the value (`var _ = f.close()` to discard deliberately; a bare `f.close()`
|
|
155
155
|
statement is a compile error). Any enum or bitset can opt into this with the
|
|
156
|
-
`
|
|
156
|
+
`must_use` modifier.
|
|
157
157
|
|
|
158
158
|
## Tests
|
|
159
159
|
|
package/core/System/Buffer.nm
CHANGED
|
@@ -445,11 +445,11 @@ pub struct Buffer<T> {
|
|
|
445
445
|
}
|
|
446
446
|
|
|
447
447
|
// Move a value out of a T_SIZE-sized slot: return it and zero the slot so the
|
|
448
|
-
// buffer no longer holds a (possibly owning) copy. Declared `
|
|
448
|
+
// buffer no longer holds a (possibly owning) copy. Declared `move out T` so
|
|
449
449
|
// the result is treated as OWNED by the borrow checker — the slot is
|
|
450
450
|
// relinquished, so the caller is the sole remaining owner. The value
|
|
451
451
|
// counterpart of ClassBuffer.move_int — used by List.pop for any value T.
|
|
452
|
-
inline func move_T = (ref self, int i: i >= 0 && i < self.cap,
|
|
452
|
+
inline func move_T = (ref self, int i: i >= 0 && i < self.cap, move out T) {
|
|
453
453
|
```
|
|
454
454
|
#arch: c
|
|
455
455
|
T* _slots = (T*)(unsigned long long)self->data;
|
package/core/System/Channel.nm
CHANGED
|
@@ -218,7 +218,7 @@ pub class Channel: Sendable {
|
|
|
218
218
|
// (the node's copy is moved out — the payload leaves the channel, and a
|
|
219
219
|
// second receive of the same message is not possible). The fat (ptr, len)
|
|
220
220
|
// pair survives intact. Pair with send_string.
|
|
221
|
-
pub func receive_string = (self,
|
|
221
|
+
pub func receive_string = (self, move out string) {
|
|
222
222
|
```
|
|
223
223
|
#arch: c
|
|
224
224
|
pthread_mutex_lock((pthread_mutex_t *)self->mu);
|
|
@@ -175,14 +175,14 @@ pub struct ClassBuffer<T> {
|
|
|
175
175
|
}
|
|
176
176
|
|
|
177
177
|
// Move a class pointer out of a slot: return it and zero the slot so the
|
|
178
|
-
// buffer no longer references it. Declared `
|
|
178
|
+
// buffer no longer references it. Declared `move out T` so the borrow
|
|
179
179
|
// checker treats the result as OWNED — the slot is relinquished, so the
|
|
180
180
|
// caller is the sole remaining owner. This is the owning-extract primitive
|
|
181
181
|
// (parallel to List.pop); use it (not load_T) when transferring ownership
|
|
182
182
|
// out of a ClassBuffer slot, or moving a value into a fresh owning
|
|
183
183
|
// container — load_T returns a BORROW (the slot is unchanged) and storing
|
|
184
184
|
// it elsewhere would create shared ownership (double-free at destroy).
|
|
185
|
-
inline func move_T = (ref self, int i: i >= 0 && i < self.cap,
|
|
185
|
+
inline func move_T = (ref self, int i: i >= 0 && i < self.cap, move out T) {
|
|
186
186
|
```
|
|
187
187
|
#arch: c
|
|
188
188
|
long *slots = (long*)(unsigned long long)self->data;
|
package/core/System/Console.nm
CHANGED
|
@@ -42,8 +42,8 @@ pub struct Console {
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
// Read one line from stdin (newline stripped). The raw body mallocs the
|
|
45
|
-
// buffer — `
|
|
46
|
-
pub func read_line = (
|
|
45
|
+
// buffer — `move out string` transfers ownership to the caller.
|
|
46
|
+
pub func read_line = (move out string) {
|
|
47
47
|
```
|
|
48
48
|
#arch: c
|
|
49
49
|
int cap = 16;
|
|
@@ -125,8 +125,8 @@ pub struct Console {
|
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
// The platform name ("macos" / "ios" / …). The raw body strdups a static
|
|
128
|
-
// string — `
|
|
129
|
-
pub func platform = (
|
|
128
|
+
// string — `move out string` transfers the owned copy to the caller.
|
|
129
|
+
pub func platform = (move out string) {
|
|
130
130
|
```
|
|
131
131
|
#arch: c
|
|
132
132
|
#platform: macos
|
package/core/System/Graph.nm
CHANGED
|
@@ -14,7 +14,7 @@ pub 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,
|
|
17
|
+
pub func add_node = (ref self, move T value) {
|
|
18
18
|
var int idx = self.node_count
|
|
19
19
|
self.values.grow_T(idx + 1)
|
|
20
20
|
self.values.store_T(idx, value)
|
|
@@ -13,7 +13,7 @@ pub struct LinkedList<T>: Enumerable {
|
|
|
13
13
|
var int head = -1
|
|
14
14
|
var count = 0
|
|
15
15
|
|
|
16
|
-
pub func add = (ref self,
|
|
16
|
+
pub func add = (ref self, move T value) {
|
|
17
17
|
var int idx = self.count
|
|
18
18
|
self.values.grow_T(idx + 1)
|
|
19
19
|
self.values.store_T(idx, value)
|
package/core/System/List.nm
CHANGED
|
@@ -5,7 +5,7 @@ pub struct List<T>: Viewable {
|
|
|
5
5
|
var length = 0
|
|
6
6
|
var Buffer<T> items = Buffer<T>()
|
|
7
7
|
|
|
8
|
-
pub func push = (ref self,
|
|
8
|
+
pub func push = (ref self, move T value) {
|
|
9
9
|
if self.length >= self.items.cap {
|
|
10
10
|
var new_cap = 4
|
|
11
11
|
var int old_cap = self.items.cap
|
|
@@ -18,7 +18,7 @@ pub struct List<T>: Viewable {
|
|
|
18
18
|
self.length += 1
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
pub func pop = (ref self,
|
|
21
|
+
pub func pop = (ref self, move out T) {
|
|
22
22
|
if self.length <= 0 {
|
|
23
23
|
return self.items.move_T(0)
|
|
24
24
|
}
|
|
@@ -57,7 +57,7 @@ pub struct List<T>: Viewable {
|
|
|
57
57
|
return self.items.slice(start, end)
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
pub func set = (ref self, int i: i >= 0 && i < self.length,
|
|
60
|
+
pub func set = (ref self, int i: i >= 0 && i < self.length, move T value) {
|
|
61
61
|
self.items.replace_T(i, value)
|
|
62
62
|
}
|
|
63
63
|
|
package/core/System/Map.nm
CHANGED
|
@@ -24,7 +24,7 @@ pub struct Map<TK: Hashable + Equatable, TV> {
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
pub func set = (ref self,
|
|
27
|
+
pub func set = (ref self, move TK key, move TV value) {
|
|
28
28
|
var int cap = self.keys.cap
|
|
29
29
|
if cap == 0 {
|
|
30
30
|
cap = self.keys.alloc_T(8)
|
|
@@ -166,9 +166,9 @@ pub struct Map<TK: Hashable + Equatable, TV> {
|
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
func rehash = (ref self, int new_cap) {
|
|
169
|
-
var Buffer<TK> old_keys =
|
|
170
|
-
var Buffer<TV> old_values =
|
|
171
|
-
var Buffer<int> old_used =
|
|
169
|
+
var Buffer<TK> old_keys = move self.keys swap Buffer<TK>()
|
|
170
|
+
var Buffer<TV> old_values = move self.values swap Buffer<TV>()
|
|
171
|
+
var Buffer<int> old_used = move self.used swap Buffer<int>()
|
|
172
172
|
var int old_cap = old_keys.cap
|
|
173
173
|
|
|
174
174
|
self.keys.alloc_T(new_cap)
|
|
@@ -190,7 +190,7 @@ pub struct Map<TK: Hashable + Equatable, TV> {
|
|
|
190
190
|
// move_T results.
|
|
191
191
|
var TK k = old_keys.move_T(i)
|
|
192
192
|
var TV v = old_values.move_T(i)
|
|
193
|
-
self.set(
|
|
193
|
+
self.set(move k, move v)
|
|
194
194
|
}
|
|
195
195
|
}
|
|
196
196
|
}
|
package/core/System/Result.nm
CHANGED
package/core/System/Set.nm
CHANGED
|
@@ -12,7 +12,7 @@ pub struct Set<T: Hashable + Equatable> {
|
|
|
12
12
|
var Buffer<T> slots = Buffer<T>()
|
|
13
13
|
var used = Buffer<int>()
|
|
14
14
|
|
|
15
|
-
pub func add = (ref self,
|
|
15
|
+
pub func add = (ref self, move T value) {
|
|
16
16
|
var int cap = self.slots.cap
|
|
17
17
|
if cap == 0 {
|
|
18
18
|
cap = self.slots.alloc_T(8)
|
|
@@ -148,8 +148,8 @@ pub struct Set<T: Hashable + Equatable> {
|
|
|
148
148
|
}
|
|
149
149
|
|
|
150
150
|
func rehash = (ref self, int new_cap) {
|
|
151
|
-
var Buffer<T> old_slots =
|
|
152
|
-
var Buffer<int> old_used =
|
|
151
|
+
var Buffer<T> old_slots = move self.slots swap Buffer<T>()
|
|
152
|
+
var Buffer<int> old_used = move self.used swap Buffer<int>()
|
|
153
153
|
var int old_cap = old_slots.cap
|
|
154
154
|
|
|
155
155
|
self.slots.alloc_T(new_cap)
|
|
@@ -168,7 +168,7 @@ pub struct Set<T: Hashable + Equatable> {
|
|
|
168
168
|
// once the new buffer has made its own copy — passing it inline
|
|
169
169
|
// would orphan the move_T result.
|
|
170
170
|
var T v = old_slots.move_T(i)
|
|
171
|
-
self.add(
|
|
171
|
+
self.add(move v)
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
174
|
}
|
|
@@ -156,9 +156,9 @@ pub struct File {
|
|
|
156
156
|
}
|
|
157
157
|
|
|
158
158
|
// Read every byte from the current position to EOF and return it. Sets
|
|
159
|
-
// `eof` and `error`. Declared `
|
|
159
|
+
// `eof` and `error`. Declared `move out string`: the raw body mallocs a
|
|
160
160
|
// fresh buffer and hands ownership to the caller.
|
|
161
|
-
func raw_read_all = (ref self,
|
|
161
|
+
func raw_read_all = (ref self, move out string) {
|
|
162
162
|
```
|
|
163
163
|
#arch: c
|
|
164
164
|
FILE *f = (FILE*)(unsigned long long)self->handle;
|
|
@@ -268,8 +268,8 @@ pub struct File {
|
|
|
268
268
|
|
|
269
269
|
// Read up to the next '\n' (the newline is not included). Sets `eof`
|
|
270
270
|
// when the end of the file is reached and `error` on failure. The raw
|
|
271
|
-
// body mallocs a fresh buffer — `
|
|
272
|
-
func raw_read_line = (ref self,
|
|
271
|
+
// body mallocs a fresh buffer — `move out string` transfers it.
|
|
272
|
+
func raw_read_line = (ref self, move out string) {
|
|
273
273
|
```
|
|
274
274
|
#arch: c
|
|
275
275
|
FILE *f = (FILE*)(unsigned long long)self->handle;
|
|
@@ -409,8 +409,8 @@ pub struct File {
|
|
|
409
409
|
|
|
410
410
|
// Read up to `size` bytes from the current position. Sets `eof` if fewer
|
|
411
411
|
// than `size` bytes remain and `error` on failure. The raw body mallocs a
|
|
412
|
-
// fresh buffer — `
|
|
413
|
-
func raw_read_chunk = (ref self, int size,
|
|
412
|
+
// fresh buffer — `move out string` transfers it.
|
|
413
|
+
func raw_read_chunk = (ref self, int size, move out string) {
|
|
414
414
|
```
|
|
415
415
|
#arch: c
|
|
416
416
|
FILE *f = (FILE*)(unsigned long long)self->handle;
|
|
@@ -583,7 +583,7 @@ pub struct File {
|
|
|
583
583
|
|
|
584
584
|
// (static) Write `data` to `path` (replacing any existing contents) in
|
|
585
585
|
// one open/write/close. A write failure is reported as `.error`, not
|
|
586
|
-
// silently swallowed (the `
|
|
586
|
+
// silently swallowed (the `must_use` Result discard check forces this to
|
|
587
587
|
// be deliberate).
|
|
588
588
|
pub func write_all = (string path, string data, out Result<bool, FileError>) {
|
|
589
589
|
var Result<bool, FileError> result = .error(FileError.other)
|
|
@@ -53,9 +53,9 @@ pub struct Http {
|
|
|
53
53
|
// method string ("GET" / "POST"); a leading 'P' selects POST semantics
|
|
54
54
|
// (sends `body` and the Content-* headers). Sets self->status (0 on
|
|
55
55
|
// failure) and self->error, and returns the response body (empty string
|
|
56
|
-
// on failure). The raw body mallocs the response — `
|
|
56
|
+
// on failure). The raw body mallocs the response — `move out string`
|
|
57
57
|
// transfers ownership to the caller.
|
|
58
|
-
func raw_exchange = (ref self, string method, string url, string body,
|
|
58
|
+
func raw_exchange = (ref self, string method, string url, string body, move out string) {
|
|
59
59
|
```
|
|
60
60
|
#arch: c
|
|
61
61
|
#scope: file
|
package/core/System/String.nm
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// FFI: the C library's heap-copy entry point (string.h). The adapter
|
|
2
2
|
// marshals the fat string to the thin char* the C ABI expects; the string
|
|
3
3
|
// result is re-wrapped with its length.
|
|
4
|
-
extern func strdup = (string s,
|
|
4
|
+
extern func strdup = (string s, move out string)
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* A UTF-8 text string — a heap-owned, length-tracked sequence of bytes
|
|
@@ -18,13 +18,13 @@ pub struct string: Stringable, Hashable, Equatable {
|
|
|
18
18
|
return h
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
// Returns an OWNED copy of self (`
|
|
21
|
+
// Returns an OWNED copy of self (`move out string`). Both backends hand
|
|
22
22
|
// back a fresh allocation the caller frees — never an alias of self's
|
|
23
23
|
// storage — so the result can outlive the receiver (e.g. escape a match
|
|
24
24
|
// branch that reclaims the scrutinee temp). Goes through the `strdup`
|
|
25
25
|
// extern: the adapter marshals self.ptr to libc and re-wraps the copy
|
|
26
26
|
// with its length.
|
|
27
|
-
pub func to_string = (self,
|
|
27
|
+
pub func to_string = (self, move out string) {
|
|
28
28
|
return strdup(self)
|
|
29
29
|
}
|
|
30
30
|
|
package/core/System/Task.nm
CHANGED
|
@@ -69,10 +69,10 @@ pub class Task<T> : Sendable {
|
|
|
69
69
|
// the full return value — including the 16-byte fat-string pair — and the
|
|
70
70
|
// trampoline writes the function's return value there before exiting.
|
|
71
71
|
// The result is MOVED OUT: the slot is zeroed as the value leaves, and
|
|
72
|
-
// `
|
|
72
|
+
// `move out T` marks the caller as the owner. Call it once; a second call
|
|
73
73
|
// returns the zero value. For tasks with no return value (void
|
|
74
74
|
// functions), returns the zero value.
|
|
75
|
-
pub func result = (ref self,
|
|
75
|
+
pub func result = (ref self, move out T) {
|
|
76
76
|
```
|
|
77
77
|
#arch: c
|
|
78
78
|
if (self->future) {
|
package/core/System/Text/Json.nm
CHANGED
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
**/
|
|
15
15
|
pub struct Json {
|
|
16
16
|
// Serialize a string to a JSON string literal, escaping the special
|
|
17
|
-
// characters ", \, newline, tab and carriage return. `
|
|
17
|
+
// characters ", \, newline, tab and carriage return. `move out string`:
|
|
18
18
|
// returns the StringBuilder's owned heap copy.
|
|
19
|
-
pub func serialize = (string value,
|
|
19
|
+
pub func serialize = (string value, move out string) {
|
|
20
20
|
var sb = StringBuilder()
|
|
21
21
|
sb.append_char('"')
|
|
22
22
|
var i = 0
|
|
@@ -50,8 +50,8 @@ pub struct Json {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
// Deserialize a JSON string literal to the raw, unescaped value.
|
|
53
|
-
// `
|
|
54
|
-
pub func deserialize = (string json,
|
|
53
|
+
// `move out string`: returns the StringBuilder's owned heap copy.
|
|
54
|
+
pub func deserialize = (string json, move out string) {
|
|
55
55
|
var sb = StringBuilder()
|
|
56
56
|
var int len = json.length
|
|
57
57
|
var i = 0
|
|
@@ -30,9 +30,9 @@ pub struct Regex {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
// Return the first substring of input matching pattern, or "" if none.
|
|
33
|
-
// `
|
|
33
|
+
// `move out string`: the built match (or the copied empty literal) is
|
|
34
34
|
// handed to the caller as an owned value.
|
|
35
|
-
pub func match = (string pattern, string input,
|
|
35
|
+
pub func match = (string pattern, string input, move out string) {
|
|
36
36
|
var match_result = ""
|
|
37
37
|
var int pat_len = pattern.length
|
|
38
38
|
var int len = input.length
|
package/core/System/Tree.nm
CHANGED
package/core/System/bool.nm
CHANGED
|
@@ -12,7 +12,7 @@ pub struct bool: Stringable, Hashable, Equatable {
|
|
|
12
12
|
* @param self: the boolean
|
|
13
13
|
* @out string: the boolean as a string value (`"true"` or `"false"`)
|
|
14
14
|
**/
|
|
15
|
-
pub func to_string = (self,
|
|
15
|
+
pub func to_string = (self, move out string) {
|
|
16
16
|
```
|
|
17
17
|
#arch: c
|
|
18
18
|
int length = snprintf(NULL, 0, "%s", self ? "true" : "false");
|
package/core/System/char.nm
CHANGED
package/core/System/float.nm
CHANGED
package/core/System/float32.nm
CHANGED
package/core/System/float64.nm
CHANGED
package/core/System/int.nm
CHANGED
package/core/System/int16.nm
CHANGED
package/core/System/int32.nm
CHANGED
package/core/System/int64.nm
CHANGED
package/core/System/int8.nm
CHANGED
package/core/System/ufloat.nm
CHANGED
package/core/System/ufloat32.nm
CHANGED
package/core/System/ufloat64.nm
CHANGED
package/core/System/uint.nm
CHANGED
package/core/System/uint16.nm
CHANGED
package/core/System/uint32.nm
CHANGED
package/core/System/uint64.nm
CHANGED
package/core/System/uint8.nm
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# Result
|
|
2
2
|
|
|
3
|
-
## `
|
|
3
|
+
## `must_use enum Result<T, E>`
|
|
4
4
|
|
|
5
5
|
A generic result type with an `ok(T value)` success case and an
|
|
6
6
|
`error(E error)` failure case. Monomorphized per concrete type-argument pair
|
|
7
7
|
(e.g. `Result<int, string>`).
|
|
8
8
|
|
|
9
|
-
`Result` is declared `
|
|
9
|
+
`Result` is declared `must_use`: a statement-position call that returns a
|
|
10
10
|
`Result` is a compile error unless the value is bound or matched. Ignore it
|
|
11
11
|
deliberately with `var _ = f.close()`, or handle both cases with `match`.
|
|
12
12
|
|