Move number parsing, version ordering and constraints, version sorting and solver literals into src/kernel, with contracts checked by moon prove under overflow-checked integers. Replace the semver behaviour tests with those proofs, keep tests for string parsing, and run the proofs in CI. Version numbers are now 64-bit: the old parser silently wrapped at 2^31. Drop pick_tag, which only tests called. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
34 lines
843 B
MoonBit
34 lines
843 B
MoonBit
///|
|
|
/// Value of the decimal code points `s`, or -1 if `s` is empty, has a
|
|
/// non-digit, or is 10^18 or more.
|
|
pub fn parse_nat(
|
|
s : FixedArray[Int64],
|
|
) -> Int64 where {
|
|
proof_require: s.length() < 2147483647,
|
|
proof_ensure: r => parse_post(s, r),
|
|
proof_ensure: r => valid_or_rejected(r),
|
|
} {
|
|
let t = FixedArray::make(s.length() + 1, 0L)
|
|
for i in 0..<s.length() {
|
|
let n = t[i]
|
|
let c = s[i]
|
|
t[i + 1] = if n < 0L || n > 99999999999999999L || c < 48L || c > 57L {
|
|
-1L
|
|
} else {
|
|
n * 10L + (c - 48L)
|
|
}
|
|
} where {
|
|
proof_invariant: 0 <= i && i <= s.length(),
|
|
proof_invariant: trace(s, t, i, t[i]),
|
|
proof_invariant: valid_or_rejected(t[i]),
|
|
}
|
|
let r = t[s.length()]
|
|
proof_assert trace(s, t, s.length(), r)
|
|
proof_assert decimal(s, r)
|
|
if s.length() == 0 {
|
|
-1L
|
|
} else {
|
|
r
|
|
}
|
|
}
|