cli: add bounded std copy/search and checked arithmetic

This commit is contained in:
dev committed 2026-10-06 15:40:57 +03:00
1 parent a2ca293506
commit 6397a317e2
36 files changed
+1533 -7

No files matched your search

@@ -0,0 +1,33 @@
; expect: run
; result: {"variant":"overflow","payload":[]}
; phase: 0
; spec: docs/spec/16-standard-library.md §2.1.1; docs/spec/07a-air-instructions.md
module test.bounded_arithmetic
air 0
lang 0.1
features [effects]
type @U64Result = enum { ok(u64), overflow }
fn @main() -> @U64Result
effects []
entry:
%a = const.u64 18446744073709551615
%b = const.u64 1
%result = call @checked_add(%a, %b)
ret %result
fn @checked_add(%a: u64, %b: u64) -> @U64Result
effects []
entry:
%maximum = const.u64 18446744073709551615
%remaining = sub.checked.u64 %maximum, %a
%overflows = gt.u64 %b, %remaining
cbr %overflows, @failure(), @success()
failure:
%error = enum.make @U64Result.overflow()
ret %error
success:
%sum = add.checked.u64 %a, %b
%ok = enum.make @U64Result.ok(%sum)
ret %ok