nomen-lang 0.3.0 → 0.5.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 (50) hide show
  1. package/NOMEN_AGENTS.md +7 -1
  2. package/core/System/Arena.nm +7 -7
  3. package/core/System/Awaitable.nm +21 -0
  4. package/core/System/BigInt.nm +5 -15
  5. package/core/System/Buffer.nm +140 -33
  6. package/core/System/Channel.nm +80 -29
  7. package/core/System/ClassBuffer.nm +89 -32
  8. package/core/System/Console.nm +4 -2
  9. package/core/System/Controls/Button.nm +4 -4
  10. package/core/System/Controls/CheckBox.nm +1 -1
  11. package/core/System/Controls/Text.nm +2 -2
  12. package/core/System/Controls/TextBox.nm +6 -6
  13. package/core/System/Controls/Window.nm +2 -2
  14. package/core/System/Fiber.nm +121 -0
  15. package/core/System/Graph.nm +4 -4
  16. package/core/System/LinkedList.nm +4 -4
  17. package/core/System/List.nm +6 -6
  18. package/core/System/Map.nm +30 -30
  19. package/core/System/Mutex.nm +57 -61
  20. package/core/System/Nursery.nm +10 -8
  21. package/core/System/Set.nm +24 -24
  22. package/core/System/Stream/Directory.nm +4 -4
  23. package/core/System/Stream/File.nm +19 -12
  24. package/core/System/Stream/Http.nm +83 -434
  25. package/core/System/Stream/Tcp.nm +441 -0
  26. package/core/System/String.nm +47 -18
  27. package/core/System/Task.nm +103 -4
  28. package/core/System/Text/JsonTree.nm +15 -15
  29. package/core/System/Thread.nm +83 -0
  30. package/core/System/bool.nm +2 -1
  31. package/core/System/char.nm +2 -1
  32. package/core/System/float.nm +2 -1
  33. package/core/System/float32.nm +2 -1
  34. package/core/System/float64.nm +2 -1
  35. package/core/System/int.nm +4 -2
  36. package/core/System/int16.nm +2 -1
  37. package/core/System/int32.nm +2 -1
  38. package/core/System/int64.nm +2 -1
  39. package/core/System/int8.nm +2 -1
  40. package/core/System/ufloat.nm +2 -1
  41. package/core/System/ufloat32.nm +2 -1
  42. package/core/System/ufloat64.nm +2 -1
  43. package/core/System/uint.nm +2 -1
  44. package/core/System/uint16.nm +2 -1
  45. package/core/System/uint32.nm +2 -1
  46. package/core/System/uint64.nm +2 -1
  47. package/core/System/uint8.nm +2 -1
  48. package/core/docs/System/BigInt.md +0 -1
  49. package/dist/index.mjs +20401 -13796
  50. package/package.json +1 -1
@@ -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
  }
@@ -0,0 +1,83 @@
1
+ // Thread — a task running on the shared worker pool (CLOSURE.md
2
+ // Phase 3b). `Thread(fn(args))` constructs a Thread value: the arguments are
3
+ // evaluated eagerly and packed into a task closure (a heap closure
4
+ // descriptor over the pooled-args environment — the same ABI every lambda
5
+ // lowers to); `.start()` submits that closure to the worker pool and yields
6
+ // a `Task<T>` handle; `.detach()` runs it as an unjoinable daemon.
7
+ //
8
+ // Because the construction is a real value, it can be STORED and started
9
+ // later:
10
+ //
11
+ // var t = Thread(work(n))
12
+ // ...later...
13
+ // var Task<uint64> handle = t.start()
14
+ //
15
+ // The pool starts at a configurable size (default 4, via Task.set_pool_size
16
+ // before the first spawn) and grows on demand up to 64 workers when every
17
+ // worker is busy, preventing deadlocks from nested spawns. The pool drains
18
+ // and joins all workers at process exit; Task.shutdown_pool does this
19
+ // explicitly.
20
+ //
21
+ // The pool infrastructure (types, worker loop, submit, shutdown, cancel
22
+ // thread-local) lives in build_spawn_node and is emitted as file-scope C
23
+ // on the first spawn — not in Thread's own methods — so that Thread can be
24
+ // generic without duplicating the pool per instantiation.
25
+ //
26
+ // MUST-START: a Thread value that is destroyed without ever being started
27
+ // is a programming error — #destroy reports it and aborts. start/detach
28
+ // (and nursery.start) transfer ownership of the packed task out of the
29
+ // value, so a started Thread destroys as a no-op.
30
+ //
31
+ // See ASYNC.md for the design.
32
+
33
+ /**
34
+ * A deferred function call, startable on the shared worker pool
35
+ **/
36
+ pub class Thread<T> : Sendable {
37
+ // The packed task closure (a `struct nomen_closure *`); owned by this
38
+ // value until start/detach/nursery.start transfers it to the runtime.
39
+ pub var uint64 task = 0
40
+ // Result-slot / cancel-flag / future handles for the (single) launch.
41
+ pub var uint64 result_slot = 0
42
+ pub var uint64 cancel_flag = 0
43
+ pub var uint64 future = 0
44
+ // Must-start flag: set by .start() / .detach() / nursery.start.
45
+ pub var started = false
46
+
47
+ // Destroying an unstarted Thread is a programming error (the wrapped
48
+ // call would silently never run) — report it and abort. A started
49
+ // Thread owns nothing: the launch transferred the task closure, result
50
+ // slot, cancel flag, and future to the runtime, and cleared the fields.
51
+ pub func #destroy = () {
52
+ ```
53
+ #arch: c
54
+ if (!self->started) {
55
+ __nomen_spawn_must_start_abort();
56
+ }
57
+ if (self->future) {
58
+ __nomen_future_release((struct nomen_future *)self->future);
59
+ self->future = 0;
60
+ self->result_slot = 0;
61
+ self->cancel_flag = 0;
62
+ }
63
+ ```
64
+ ```
65
+ #arch: aarch64
66
+ // if (!self->started) __nomen_spawn_must_start_abort()
67
+ ldrb w0, [x19, #40]
68
+ cbnz w0, .Lthr_started
69
+ bl ___nomen_spawn_must_start_abort
70
+ .Lthr_started:
71
+ // if (self->future) { release it (an unstarted task's future is
72
+ // unshared — refs == 1 — so this tears down slot + flag + future);
73
+ // zero the fields }
74
+ ldr x0, [x19, #32]
75
+ cbz x0, .Lthr_done
76
+ bl ___nomen_future_release
77
+ str xzr, [x19, #32]
78
+ str xzr, [x19, #16]
79
+ str xzr, [x19, #24]
80
+ .Lthr_done:
81
+ ```
82
+ }
83
+ }
@@ -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`