nomen-lang 0.6.6 → 0.6.8
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 +12 -3
- package/core/System/Buffer.nm +38 -0
- package/dist/index.mjs +942 -229
- package/package.json +1 -1
- package/src/args.ts +1 -1
- package/src/index.ts +1 -0
- package/src/test.ts +40 -3
package/NOMEN_AGENTS.md
CHANGED
|
@@ -219,9 +219,9 @@ Special function names: `#init` (constructor), `#destroy` (auto-raii destructor)
|
|
|
219
219
|
|
|
220
220
|
```nomen
|
|
221
221
|
if cond { ... }
|
|
222
|
-
switch
|
|
223
|
-
0 { ... }
|
|
224
|
-
1 { ... }
|
|
222
|
+
switch {
|
|
223
|
+
case x == 0 { ... }
|
|
224
|
+
case x == 1 { ... }
|
|
225
225
|
else { ... }
|
|
226
226
|
}
|
|
227
227
|
for i of 0 .. 10 { ... } // exclusive range
|
|
@@ -280,6 +280,15 @@ const typed = Array<int>(1, 2, 3)
|
|
|
280
280
|
for n of nums { Console.write("\{n}\n") }
|
|
281
281
|
```
|
|
282
282
|
|
|
283
|
+
### Compile-time embedding
|
|
284
|
+
|
|
285
|
+
```nomen
|
|
286
|
+
const corpus = #embed_file("bench/full-markdown.md") // string literal of the
|
|
287
|
+
// file's contents; path
|
|
288
|
+
// resolves from the
|
|
289
|
+
// package root
|
|
290
|
+
```
|
|
291
|
+
|
|
283
292
|
## Reference
|
|
284
293
|
|
|
285
294
|
- Full language spec: [SPEC.md](https://github.com/andrewjk/nomen/blob/main/SPEC.md)
|
package/core/System/Buffer.nm
CHANGED
|
@@ -510,6 +510,17 @@ pub struct Buffer<T> {
|
|
|
510
510
|
```
|
|
511
511
|
}
|
|
512
512
|
|
|
513
|
+
// Move-taking write, mirroring `List.set`: the caller's value is
|
|
514
|
+
// consumed and an independent copy is installed in the slot (replace
|
|
515
|
+
// deep-copies owning elements). The owning entry point a caller uses
|
|
516
|
+
// when it wants to hand over a value — `replace`'s by-value parameter
|
|
517
|
+
// cannot accept the `move` keyword, so a borrow being transferred
|
|
518
|
+
// (e.g. a loaded element) must go through here rather than be bound to
|
|
519
|
+
// a freed local.
|
|
520
|
+
pub func set = (ref self, int i: i >= 0 && i < self.cap, move T value) {
|
|
521
|
+
self.replace(i, value)
|
|
522
|
+
}
|
|
523
|
+
|
|
513
524
|
// Move slot src into slot dst: overwrite dst with src's bytes and zero
|
|
514
525
|
// src, so exactly ONE slot owns the value afterwards. The
|
|
515
526
|
// ownership-transferring primitive behind backward-shift deletion
|
|
@@ -620,6 +631,33 @@ pub struct Buffer<T> {
|
|
|
620
631
|
memset(self.data, 0, len * T_SIZE)
|
|
621
632
|
}
|
|
622
633
|
|
|
634
|
+
// An independent copy: fresh slab, per-element deep copies. Each slot
|
|
635
|
+
// round-trips load→replace through a local, so owning element types get
|
|
636
|
+
// the same treatment a List<T>.copy slot does (the load materializes an
|
|
637
|
+
// owned copy, replace gives the destination its own). Class elements
|
|
638
|
+
// never reach this body (a `Buffer<T>` with T a class monomorphizes to
|
|
639
|
+
// `ClassBuffer<T>`, which has no copy).
|
|
640
|
+
pub func copy = (self, out Buffer<T>: out.cap == self.cap) {
|
|
641
|
+
var dst = Buffer<T>()
|
|
642
|
+
if self.cap > 0 {
|
|
643
|
+
dst.alloc(self.cap)
|
|
644
|
+
var i = 0
|
|
645
|
+
while i < self.cap {
|
|
646
|
+
// Bind the loaded element and hand it to `set` (move): for a
|
|
647
|
+
// string element load returns a BORROW of the source slot, and
|
|
648
|
+
// the move transfers it into the write without a scope-exit
|
|
649
|
+
// reclaim (which would free the source's buffer); for an owning
|
|
650
|
+
// struct element load returns an owned copy that transfers the
|
|
651
|
+
// same way. Mirrors List.copy's `var T v = self.at(i)` +
|
|
652
|
+
// `dst.push(v)`.
|
|
653
|
+
var T v = self.load(i)
|
|
654
|
+
dst.set(i, v)
|
|
655
|
+
i += 1
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
return dst
|
|
659
|
+
}
|
|
660
|
+
|
|
623
661
|
internal inline func store_or_int = (ref self, int i: i >= 0 && i < self.cap, int val) {
|
|
624
662
|
```
|
|
625
663
|
#arch: c
|