@shd101wyy/yo 0.1.30 → 0.1.32
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/.github/skills/yo-syntax/syntax-cheatsheet.md +38 -0
- package/out/cjs/index.cjs +800 -633
- package/out/cjs/yo-cli.cjs +1007 -840
- package/out/cjs/yo-lsp.cjs +890 -723
- package/out/esm/index.mjs +804 -637
- package/out/types/src/codegen/index.d.ts +1 -1
- package/out/types/src/compiler-utils.d.ts +1 -1
- package/out/types/src/evaluator/builtins/contracts.d.ts +35 -0
- package/out/types/src/evaluator/memory-safety.d.ts +1 -1
- package/out/types/src/evaluator/types/function.d.ts +2 -0
- package/out/types/src/evaluator/utils/closure.d.ts +2 -1
- package/out/types/src/evaluator/utils.d.ts +3 -0
- package/out/types/src/evaluator/values/impl.d.ts +14 -0
- package/out/types/src/expr.d.ts +6 -0
- package/out/types/src/tests/contracts-comptime-violation.test.d.ts +1 -0
- package/out/types/src/tests/contracts-runtime-violation.test.d.ts +1 -0
- package/out/types/src/tests/thread-safety-codegen.test.d.ts +1 -0
- package/out/types/src/types/creators.d.ts +3 -1
- package/out/types/src/types/definitions.d.ts +2 -0
- package/out/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/std/build.yo +5 -2
- package/std/imm/list.yo +1 -1
- package/std/imm/sorted_map.yo +1 -1
- package/std/libc/stdatomic.yo +285 -1
- package/std/prelude.yo +56 -3
- package/std/spec/numeric.yo +30 -0
- package/std/spec/refine.yo +43 -0
- package/std/string/rune.yo +4 -0
- package/std/sync/atomic.yo +557 -0
- package/std/sync/channel.yo +57 -42
- package/std/sync/cond.yo +7 -3
- package/std/sync/mutex.yo +75 -15
- package/std/sync/once.yo +25 -19
- package/std/sync/rwlock.yo +18 -15
- package/std/sync/waitgroup.yo +25 -16
|
@@ -506,6 +506,44 @@ test("Async test", {
|
|
|
506
506
|
- `comptime_assert(condition)` — compile-time assertion
|
|
507
507
|
- `comptime_expect_error(expr)` — verify code produces a compile error
|
|
508
508
|
|
|
509
|
+
## Design-by-contract clauses
|
|
510
|
+
|
|
511
|
+
`plans/FORMAL_VERIFICATION.md` Phase 0. No SMT verifier yet — these
|
|
512
|
+
lower to runtime `assert(...)` (runtime fns) or `comptime_assert(...)`
|
|
513
|
+
(comptime fns, returning `comptime(T)`).
|
|
514
|
+
|
|
515
|
+
```rust
|
|
516
|
+
// requires/ensures are SIGNATURE clauses, after params and where(...).
|
|
517
|
+
// ENFORCED order: forall, params, where, requires, ensures — a clause
|
|
518
|
+
// out of order is a syntax error ("X appears after Y").
|
|
519
|
+
divide :: (fn(x : i32, y : i32, requires(y != i32(0)), ensures(result == (x / y))) -> i32)(
|
|
520
|
+
x / y
|
|
521
|
+
);
|
|
522
|
+
|
|
523
|
+
// Inside ensures: `result` = return value, old(expr) = entry-time value.
|
|
524
|
+
increment :: (fn(ref(n) : i32, ensures(n == (old(n) + i32(1)))) -> unit)({ n = (n + i32(1)); });
|
|
525
|
+
|
|
526
|
+
// invariant(...) must be the FIRST statement of a while body.
|
|
527
|
+
while(runtime(i < n), {
|
|
528
|
+
invariant(i <= n, acc >= i32(0));
|
|
529
|
+
i = (i + i32(1)); acc = (acc + i);
|
|
530
|
+
});
|
|
531
|
+
|
|
532
|
+
// ghost binding vs ghost function (SEPARATE builtins):
|
|
533
|
+
ghost(snap := (a + b));
|
|
534
|
+
is_pos :: ghost_fn((fn(x : i32) -> bool)(x > i32(0)));
|
|
535
|
+
```
|
|
536
|
+
|
|
537
|
+
- One `requires(...)` and one `ensures(...)` max per signature; put
|
|
538
|
+
multiple predicates inside the single call: `requires(a, b)`. Two
|
|
539
|
+
`requires(...)` clauses, or a zero-arg `requires()`, is a syntax error.
|
|
540
|
+
- `result` is a wrapper-bound local (NOT a reserved word) — it coexists
|
|
541
|
+
with `result` used as an ordinary variable name elsewhere.
|
|
542
|
+
- `pragma(Pragma.NoContracts);` erases contracts; `pragma(Pragma.Verify);`
|
|
543
|
+
parses but warns "verify mode not implemented".
|
|
544
|
+
- `std/spec/` exposes refinement aliases (`NonZero`, `Bounded`,
|
|
545
|
+
`Positive`, …) — Phase 0 they are plain aliases for the base type.
|
|
546
|
+
|
|
509
547
|
## Common pitfalls
|
|
510
548
|
|
|
511
549
|
### `&&` short-circuit with `match`/`cond` on RHS causes C codegen scope bug
|