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.
Files changed (41) hide show
  1. package/NOMEN_AGENTS.md +7 -1
  2. package/core/System/Arena.nm +7 -7
  3. package/core/System/BigInt.nm +5 -15
  4. package/core/System/Buffer.nm +133 -33
  5. package/core/System/ClassBuffer.nm +84 -32
  6. package/core/System/Console.nm +4 -2
  7. package/core/System/Controls/Button.nm +4 -4
  8. package/core/System/Controls/CheckBox.nm +1 -1
  9. package/core/System/Controls/Text.nm +2 -2
  10. package/core/System/Controls/TextBox.nm +6 -6
  11. package/core/System/Controls/Window.nm +2 -2
  12. package/core/System/Graph.nm +4 -4
  13. package/core/System/LinkedList.nm +4 -4
  14. package/core/System/List.nm +6 -6
  15. package/core/System/Map.nm +30 -30
  16. package/core/System/Set.nm +24 -24
  17. package/core/System/Stream/Directory.nm +4 -4
  18. package/core/System/Stream/File.nm +19 -12
  19. package/core/System/String.nm +47 -18
  20. package/core/System/Text/JsonTree.nm +15 -15
  21. package/core/System/bool.nm +2 -1
  22. package/core/System/char.nm +2 -1
  23. package/core/System/float.nm +2 -1
  24. package/core/System/float32.nm +2 -1
  25. package/core/System/float64.nm +2 -1
  26. package/core/System/int.nm +4 -2
  27. package/core/System/int16.nm +2 -1
  28. package/core/System/int32.nm +2 -1
  29. package/core/System/int64.nm +2 -1
  30. package/core/System/int8.nm +2 -1
  31. package/core/System/ufloat.nm +2 -1
  32. package/core/System/ufloat32.nm +2 -1
  33. package/core/System/ufloat64.nm +2 -1
  34. package/core/System/uint.nm +2 -1
  35. package/core/System/uint16.nm +2 -1
  36. package/core/System/uint32.nm +2 -1
  37. package/core/System/uint64.nm +2 -1
  38. package/core/System/uint8.nm +2 -1
  39. package/core/docs/System/BigInt.md +0 -1
  40. package/dist/index.mjs +2002 -1140
  41. package/package.json +1 -1
@@ -31,14 +31,36 @@ pub struct string: Stringable, Hashable, Equatable {
31
31
  return h
32
32
  }
33
33
 
34
- // Returns an OWNED copy of self (`move out string`). Both backends hand
35
- // back a fresh allocation the caller frees — never an alias of self's
36
- // storage — so the result can outlive the receiver (e.g. escape a match
37
- // branch that reclaims the scrutinee temp). Goes through the `strdup`
38
- // extern: the adapter marshals self.ptr to libc and re-wraps the copy
39
- // with its length.
34
+ // Returns an OWNED byte-exact copy of self (`move out string`). Fresh
35
+ // allocation, never an alias of self's storage — the result can outlive
36
+ // the receiver (e.g. escape a match branch that reclaims the scrutinee
37
+ // temp). Copies by tracked length, so embedded NULs survive (an extern
38
+ // strdup boundary would re-synthesize length via strlen and truncate).
40
39
  pub func to_string = (self, move out string) {
41
- return strdup(self)
40
+ ```
41
+ #arch: c
42
+ // Fat-string ABI: copy self.len bytes; no strlen anywhere.
43
+ char* buf = (char*)malloc(self.len + 1);
44
+ memcpy(buf, self.ptr, self.len);
45
+ buf[self.len] = 0;
46
+ return (nomen_string){ buf, self.len };
47
+ ```
48
+ ```
49
+ #arch: aarch64
50
+ // x19/x20 = self (ptr, len). malloc + memcpy of known length;
51
+ // memcpy returns the dst in x0, which becomes the return ptr half.
52
+ sub sp, sp, #16
53
+ str x20, [sp, #0]
54
+ add x0, x20, #1
55
+ bl _malloc
56
+ mov x1, x19
57
+ mov x2, x20
58
+ bl _memcpy
59
+ ldr x1, [sp, #0]
60
+ add x2, x0, x1
61
+ strb wzr, [x2] // NUL-terminate for libc consumers
62
+ add sp, sp, #16
63
+ ```
42
64
  }
43
65
 
44
66
  // The indexing primitive everything string code builds on — `unsafe`
@@ -80,8 +102,9 @@ pub struct string: Stringable, Hashable, Equatable {
80
102
  ) {
81
103
  ```
82
104
  #arch: c
105
+ // Fat-string ABI: slice out of the tracked buffer — no NUL scan.
83
106
  nomen_view _r;
84
- _r.ptr = (void*)(self + start);
107
+ _r.ptr = (void*)(self.ptr + start);
85
108
  _r.len = (long)(end - start);
86
109
  return _r;
87
110
  ```
@@ -104,7 +127,9 @@ pub struct string: Stringable, Hashable, Equatable {
104
127
  pub func #op_eq = (self, string other, out bool) {
105
128
  ```
106
129
  #arch: c
107
- return strcmp(self, other) == 0;
130
+ // Length-aware compare: equal lengths + equal bytes. Embedded
131
+ // NULs are data, not terminators (strcmp truncated at the first).
132
+ return self.len == other.len && memcmp(self.ptr, other.ptr, self.len) == 0;
108
133
  ```
109
134
  ```
110
135
  #arch: aarch64
@@ -130,12 +155,15 @@ pub struct string: Stringable, Hashable, Equatable {
130
155
  pub func #op_add = (self, string other, out string) {
131
156
  ```
132
157
  #arch: c
133
- int left_len = strlen(self);
134
- int right_len = strlen(other);
135
- char* result = malloc(left_len + right_len + 1);
136
- strcpy(result, self);
137
- strcat(result, other);
138
- return result;
158
+ // Fat-string ABI: one malloc sized by the tracked lens, two
159
+ // memcpys, NUL-terminate for libc consumers. No strlen/strcpy.
160
+ long left_len = self.len;
161
+ long right_len = other.len;
162
+ char* result = (char*)malloc(left_len + right_len + 1);
163
+ memcpy(result, self.ptr, left_len);
164
+ memcpy(result + left_len, other.ptr, right_len);
165
+ result[left_len + right_len] = 0;
166
+ return (nomen_string){ result, left_len + right_len };
139
167
  ```
140
168
  ```
141
169
  #arch: aarch64
@@ -168,16 +196,17 @@ pub struct string: Stringable, Hashable, Equatable {
168
196
  pub func #op_mul = (self, int count, out string) {
169
197
  ```
170
198
  #arch: c
171
- size_t str_len = strlen(self);
199
+ // Fat-string ABI: memcpy loop of the tracked stride. No strlen.
200
+ size_t str_len = self.len;
172
201
  size_t total = str_len * (size_t)count + 1;
173
202
  char* buf = malloc(total);
174
203
  char* p = buf;
175
204
  for (int i = 0; i < count; i++) {
176
- memcpy(p, self, str_len);
205
+ memcpy(p, self.ptr, str_len);
177
206
  p += str_len;
178
207
  }
179
208
  *p = 0;
180
- return buf;
209
+ return (nomen_string){ buf, total - 1 };
181
210
  ```
182
211
  ```
183
212
  #arch: aarch64
@@ -28,10 +28,10 @@ pub struct JsonTree {
28
28
 
29
29
  func alloc_node = (ref self, out int) {
30
30
  var int idx = self.count
31
- self.nodes.grow_T(idx + 1)
31
+ self.nodes.grow(idx + 1)
32
32
  self.count = idx + 1
33
33
  var default = JsonNode()
34
- self.nodes.store_T(idx, default)
34
+ self.nodes.store(idx, default)
35
35
  // store_T deep-copies the owning `text` field (strdup of the shared
36
36
  // empty-string literal) into the slot. JsonTree manages node texts
37
37
  // manually (set_text strdup's into the slab; free_text/release frees
@@ -106,51 +106,51 @@ pub struct JsonTree {
106
106
  }
107
107
 
108
108
  func set_kind = (ref self, int idx, int val) {
109
- var JsonNode n = self.nodes.load_T(idx)
109
+ var JsonNode n = self.nodes.load(idx)
110
110
  n.kind = val
111
- self.nodes.store_T(idx, n)
111
+ self.nodes.store(idx, n)
112
112
  }
113
113
 
114
114
  func set_child = (ref self, int idx, int val) {
115
- var JsonNode n = self.nodes.load_T(idx)
115
+ var JsonNode n = self.nodes.load(idx)
116
116
  n.child = val
117
- self.nodes.store_T(idx, n)
117
+ self.nodes.store(idx, n)
118
118
  }
119
119
 
120
120
  func set_next = (ref self, int idx, int val) {
121
- var JsonNode n = self.nodes.load_T(idx)
121
+ var JsonNode n = self.nodes.load(idx)
122
122
  n.next = val
123
- self.nodes.store_T(idx, n)
123
+ self.nodes.store(idx, n)
124
124
  }
125
125
 
126
126
  func set_val = (ref self, int idx, int val) {
127
- var JsonNode n = self.nodes.load_T(idx)
127
+ var JsonNode n = self.nodes.load(idx)
128
128
  n.val = val
129
- self.nodes.store_T(idx, n)
129
+ self.nodes.store(idx, n)
130
130
  }
131
131
 
132
132
  func get_kind = (self, int idx, out int) {
133
- var JsonNode n = self.nodes.load_T(idx)
133
+ var JsonNode n = self.nodes.load(idx)
134
134
  return n.kind
135
135
  }
136
136
 
137
137
  func get_text = (self, int idx, out string) {
138
- var JsonNode n = self.nodes.load_T(idx)
138
+ var JsonNode n = self.nodes.load(idx)
139
139
  return n.text
140
140
  }
141
141
 
142
142
  func get_child = (self, int idx, out int) {
143
- var JsonNode n = self.nodes.load_T(idx)
143
+ var JsonNode n = self.nodes.load(idx)
144
144
  return n.child
145
145
  }
146
146
 
147
147
  func get_next = (self, int idx, out int) {
148
- var JsonNode n = self.nodes.load_T(idx)
148
+ var JsonNode n = self.nodes.load(idx)
149
149
  return n.next
150
150
  }
151
151
 
152
152
  func get_val = (self, int idx, out int) {
153
- var JsonNode n = self.nodes.load_T(idx)
153
+ var JsonNode n = self.nodes.load(idx)
154
154
  return n.val
155
155
  }
156
156
  }
@@ -18,7 +18,8 @@ pub struct bool: Stringable, Hashable, Equatable {
18
18
  int length = snprintf(NULL, 0, "%s", self ? "true" : "false");
19
19
  char* str = malloc(length + 1);
20
20
  snprintf(str, length + 1, "%s", self ? "true" : "false");
21
- return str;
21
+ // Fat-string ABI: snprintf already counted the bytes.
22
+ return (nomen_string){ str, length };
22
23
  ```
23
24
  ```
24
25
  #arch: aarch64
@@ -12,7 +12,8 @@ pub struct char: Stringable, Hashable, Equatable {
12
12
  int length = snprintf(NULL, 0, "%c", self);
13
13
  char* str = malloc(length + 1);
14
14
  snprintf(str, length + 1, "%c", self);
15
- return str;
15
+ // Fat-string ABI: snprintf already counted the bytes.
16
+ return (nomen_string){ str, length };
16
17
  ```
17
18
  ```
18
19
  #arch: aarch64
@@ -8,7 +8,8 @@ pub struct float: Stringable {
8
8
  int length = snprintf(NULL, 0, "%f", self);
9
9
  char* str = malloc(length + 1);
10
10
  snprintf(str, length + 1, "%f", self);
11
- return str;
11
+ // Fat-string ABI: snprintf already counted the bytes.
12
+ return (nomen_string){ str, length };
12
13
  ```
13
14
  ```
14
15
  #arch: aarch64
@@ -8,7 +8,8 @@ pub struct float32: Stringable {
8
8
  int length = snprintf(NULL, 0, "%f", self);
9
9
  char* str = malloc(length + 1);
10
10
  snprintf(str, length + 1, "%f", self);
11
- return str;
11
+ // Fat-string ABI: snprintf already counted the bytes.
12
+ return (nomen_string){ str, length };
12
13
  ```
13
14
  ```
14
15
  #arch: aarch64
@@ -8,7 +8,8 @@ pub struct float64: Stringable {
8
8
  int length = snprintf(NULL, 0, "%f", self);
9
9
  char* str = malloc(length + 1);
10
10
  snprintf(str, length + 1, "%f", self);
11
- return str;
11
+ // Fat-string ABI: snprintf already counted the bytes.
12
+ return (nomen_string){ str, length };
12
13
  ```
13
14
  ```
14
15
  #arch: aarch64
@@ -12,7 +12,8 @@ pub struct int: Stringable, Hashable, Equatable {
12
12
  int length = snprintf(NULL, 0, "%ld", self);
13
13
  char* str = malloc(length + 1);
14
14
  snprintf(str, length + 1, "%ld", self);
15
- return str;
15
+ // Fat-string ABI: snprintf already counted the bytes.
16
+ return (nomen_string){ str, length };
16
17
  ```
17
18
  ```
18
19
  #arch: aarch64
@@ -49,10 +50,11 @@ pub struct int: Stringable, Hashable, Equatable {
49
50
  pub func parse = (string s, out int) {
50
51
  ```
51
52
  #arch: c
52
- return atoi(s);
53
+ return atoi(s.ptr);
53
54
  ```
54
55
  ```
55
56
  #arch: aarch64
57
+ // Fat-string ABI: s = (x0 ptr, x1 len); atoi takes the ptr half.
56
58
  bl _atoi
57
59
  ```
58
60
  }
@@ -12,7 +12,8 @@ pub struct int16: Stringable, Hashable, Equatable {
12
12
  int length = snprintf(NULL, 0, "%d", self);
13
13
  char* str = malloc(length + 1);
14
14
  snprintf(str, length + 1, "%d", self);
15
- return str;
15
+ // Fat-string ABI: snprintf already counted the bytes.
16
+ return (nomen_string){ str, length };
16
17
  ```
17
18
  ```
18
19
  #arch: aarch64
@@ -12,7 +12,8 @@ pub struct int32: Stringable, Hashable, Equatable {
12
12
  int length = snprintf(NULL, 0, "%d", self);
13
13
  char* str = malloc(length + 1);
14
14
  snprintf(str, length + 1, "%d", self);
15
- return str;
15
+ // Fat-string ABI: snprintf already counted the bytes.
16
+ return (nomen_string){ str, length };
16
17
  ```
17
18
  ```
18
19
  #arch: aarch64
@@ -12,7 +12,8 @@ pub struct int64: Stringable, Hashable, Equatable {
12
12
  int length = snprintf(NULL, 0, "%lld", self);
13
13
  char* str = malloc(length + 1);
14
14
  snprintf(str, length + 1, "%lld", self);
15
- return str;
15
+ // Fat-string ABI: snprintf already counted the bytes.
16
+ return (nomen_string){ str, length };
16
17
  ```
17
18
  ```
18
19
  #arch: aarch64
@@ -12,7 +12,8 @@ pub struct int8: Stringable, Hashable, Equatable {
12
12
  int length = snprintf(NULL, 0, "%d", self);
13
13
  char* str = malloc(length + 1);
14
14
  snprintf(str, length + 1, "%d", self);
15
- return str;
15
+ // Fat-string ABI: snprintf already counted the bytes.
16
+ return (nomen_string){ str, length };
16
17
  ```
17
18
  ```
18
19
  #arch: aarch64
@@ -8,7 +8,8 @@ pub struct ufloat: Stringable {
8
8
  int length = snprintf(NULL, 0, "%f", self);
9
9
  char* str = malloc(length + 1);
10
10
  snprintf(str, length + 1, "%f", self);
11
- return str;
11
+ // Fat-string ABI: snprintf already counted the bytes.
12
+ return (nomen_string){ str, length };
12
13
  ```
13
14
  ```
14
15
  #arch: aarch64
@@ -8,7 +8,8 @@ pub struct ufloat32: Stringable {
8
8
  int length = snprintf(NULL, 0, "%f", self);
9
9
  char* str = malloc(length + 1);
10
10
  snprintf(str, length + 1, "%f", self);
11
- return str;
11
+ // Fat-string ABI: snprintf already counted the bytes.
12
+ return (nomen_string){ str, length };
12
13
  ```
13
14
  ```
14
15
  #arch: aarch64
@@ -8,7 +8,8 @@ pub struct ufloat64: Stringable {
8
8
  int length = snprintf(NULL, 0, "%f", self);
9
9
  char* str = malloc(length + 1);
10
10
  snprintf(str, length + 1, "%f", self);
11
- return str;
11
+ // Fat-string ABI: snprintf already counted the bytes.
12
+ return (nomen_string){ str, length };
12
13
  ```
13
14
  ```
14
15
  #arch: aarch64
@@ -12,7 +12,8 @@ pub struct uint: Stringable, Hashable, Equatable {
12
12
  int length = snprintf(NULL, 0, "%ld", self);
13
13
  char* str = malloc(length + 1);
14
14
  snprintf(str, length + 1, "%ld", self);
15
- return str;
15
+ // Fat-string ABI: snprintf already counted the bytes.
16
+ return (nomen_string){ str, length };
16
17
  ```
17
18
  ```
18
19
  #arch: aarch64
@@ -12,7 +12,8 @@ pub struct uint16: Stringable, Hashable, Equatable {
12
12
  int length = snprintf(NULL, 0, "%u", self);
13
13
  char* str = malloc(length + 1);
14
14
  snprintf(str, length + 1, "%u", self);
15
- return str;
15
+ // Fat-string ABI: snprintf already counted the bytes.
16
+ return (nomen_string){ str, length };
16
17
  ```
17
18
  ```
18
19
  #arch: aarch64
@@ -12,7 +12,8 @@ pub struct uint32: Stringable, Hashable, Equatable {
12
12
  int length = snprintf(NULL, 0, "%u", self);
13
13
  char* str = malloc(length + 1);
14
14
  snprintf(str, length + 1, "%u", self);
15
- return str;
15
+ // Fat-string ABI: snprintf already counted the bytes.
16
+ return (nomen_string){ str, length };
16
17
  ```
17
18
  ```
18
19
  #arch: aarch64
@@ -12,7 +12,8 @@ pub struct uint64: Stringable, Hashable, Equatable {
12
12
  int length = snprintf(NULL, 0, "%llu", self);
13
13
  char* str = malloc(length + 1);
14
14
  snprintf(str, length + 1, "%llu", self);
15
- return str;
15
+ // Fat-string ABI: snprintf already counted the bytes.
16
+ return (nomen_string){ str, length };
16
17
  ```
17
18
  ```
18
19
  #arch: aarch64
@@ -12,7 +12,8 @@ pub struct uint8: Stringable, Hashable, Equatable {
12
12
  int length = snprintf(NULL, 0, "%d", self);
13
13
  char* str = malloc(length + 1);
14
14
  snprintf(str, length + 1, "%d", self);
15
- return str;
15
+ // Fat-string ABI: snprintf already counted the bytes.
16
+ return (nomen_string){ str, length };
16
17
  ```
17
18
  ```
18
19
  #arch: aarch64
@@ -6,7 +6,6 @@ An arbitrary-precision integer
6
6
 
7
7
  **Members:**
8
8
 
9
- - `new(int val) -> BigInt`
10
9
  - `get(int i) -> uint64`
11
10
  - `set(int i, uint64 val)`
12
11
  - `data_ptr() -> uint64`