cli: bootstrap verified std bytes and math with source imports

This commit is contained in:
dev committed 2026-10-06 14:51:10 +03:00
1 parent 268926ca0f
commit 10a370471b
52 files changed
+1000 -22

No files matched your search

@@ -0,0 +1,11 @@
// expect: run
// result: 7
// equivalent: std/minimum.air
// phase: 6
// spec: docs/spec/16-standard-library.md
module test.minimum
import std.math;
fn main() -> u64
effects []
{ return std.math.min_u64(7, 11); }
@@ -0,0 +1,9 @@
// expect: reject E2101 E2101
// phase: 6
// spec: docs/spec/16-standard-library.md; docs/spec/15-source-language.md §13
module test.standard
import std.bytes;
fn main() -> u8
effects []
{ var b: [u8; 2] = zero; ref saved = b; std.bytes.fill(mut b, 1); return 0; }
+45
View File
@@ -0,0 +1,45 @@
// expect: run
// result: 0
// phase: 6
// spec: docs/spec/16-standard-library.md; docs/spec/15-source-language.md §13
module test.standard
import std.bytes;
fn main() -> u8
effects []
{
var storage: [u8; 1] = zero;
ref empty = storage[0..0];
assert(std.bytes.equal(ref empty, ref empty));
assert(std.bytes.equal(b"a\0\xff", b"a\0\xff"));
assert(not std.bytes.equal(b"a", b"ab"));
assert(not std.bytes.equal(b"ab", b"ax"));
assert(std.bytes.compare(ref empty, ref empty) == 0);
assert(std.bytes.compare(ref empty, b"a") == -1);
assert(std.bytes.compare(b"a", ref empty) == 1);
assert(std.bytes.compare(b"ab", b"ab") == 0);
assert(std.bytes.compare(b"a", b"ab") == -1);
assert(std.bytes.compare(b"ab", b"a") == 1);
assert(std.bytes.compare(b"abc", b"abd") == -1);
assert(std.bytes.compare(b"abd", b"abc") == 1);
assert(std.bytes.compare(b"\x80", b"\x7f") == 1);
assert(std.bytes.compare(b"\0", b"\xff") == -1);
assert(std.bytes.find(ref empty, 0) == 0usize);
assert(std.bytes.find(b"aba", 97) == 0usize);
assert(std.bytes.find(b"abc", 99) == 2usize);
assert(std.bytes.find(b"abc", 100) == 3usize);
assert(std.bytes.find(b"a\0\xff", 0) == 1usize);
assert(std.bytes.starts_with(ref empty, ref empty));
assert(std.bytes.ends_with(ref empty, ref empty));
assert(std.bytes.starts_with(b"abc", ref empty));
assert(std.bytes.ends_with(b"abc", ref empty));
assert(std.bytes.starts_with(b"abc", b"abc"));
assert(std.bytes.ends_with(b"abc", b"abc"));
assert(std.bytes.starts_with(b"abc", b"ab"));
assert(std.bytes.ends_with(b"abc", b"bc"));
assert(not std.bytes.starts_with(b"a", b"ab"));
assert(not std.bytes.ends_with(b"a", b"ab"));
assert(not std.bytes.starts_with(b"abc", b"x"));
assert(not std.bytes.ends_with(b"abc", b"x"));
return 0;
}
@@ -0,0 +1,10 @@
// expect: run
// trap: T0002
// phase: 6
// spec: docs/spec/16-standard-library.md; docs/spec/15-source-language.md §13
module test.standard
import std.math;
fn main() -> u64
effects []
{ return std.math.clamp_u64(5, 9, 4); }
@@ -0,0 +1,10 @@
// expect: reject E7006
// phase: 6
// spec: docs/spec/16-standard-library.md; docs/spec/15-source-language.md §13
module test.standard
import std.bytes;
import std.bytes;
fn main() -> u8
effects []
{ return 0; }
@@ -0,0 +1,28 @@
// expect: run
// result: 0
// phase: 6
// spec: docs/spec/16-standard-library.md; docs/spec/15-source-language.md §13
module test.standard
import std.bytes;
fn main() -> u8
effects []
{
var buf: [u8; 5] = zero;
std.bytes.fill(mut buf[1..4], 255);
assert(buf[0] == 0 and buf[4] == 0);
assert(buf[1] == 255 and buf[2] == 255 and buf[3] == 255);
std.bytes.fill(mut buf[2..2], 42);
assert(buf[2] == 255);
let index = std.bytes.find(ref buf, 255);
if index < buf.len { assert(buf[index] == 255); }
assert(index == 1usize);
for n in 0u16..256u16 {
let byte = n as% u8;
std.bytes.fill(mut buf, byte);
assert(std.bytes.compare(ref buf, ref buf) == 0);
assert(std.bytes.find(ref buf, byte) == 0usize);
for i in 0..buf.len { assert(buf[i] == byte); }
}
return 0;
}
@@ -0,0 +1,9 @@
// expect: reject E7005
// phase: 6
// spec: docs/spec/16-standard-library.md; docs/spec/15-source-language.md §13
module test.standard
import std.bytes;
fn main() -> u8
effects []
{ var b: [u8; 2] = zero; std.bytes.fill(b, 1); return 0; }
@@ -0,0 +1,10 @@
// expect: reject E7001
// phase: 6
// spec: docs/spec/16-standard-library.md; docs/spec/15-source-language.md §13
module test.standard
fn main() -> u8
effects []
{ return 0; }
import std.bytes;
@@ -0,0 +1,24 @@
// expect: run
// result: 19
// phase: 6
// spec: docs/spec/15-source-language.md §13
module test.collision
import std.math;
struct __aji_std_math_max_u64 { value: u8 }
fn __aji_std_math_min_u64(a: u64, b: u64) -> u64
effects []
{ return a + b; }
fn import(value: u64) -> u64
effects []
{ return value; }
fn main() -> u64
effects []
{
let import = std.math.min_u64(4, 9);
assert(std.math.max_u64(4, 9) == 9);
return __aji_std_math_min_u64(import, 15);
}
+23
View File
@@ -0,0 +1,23 @@
// expect: run
// result: 0
// phase: 6
// spec: docs/spec/16-standard-library.md; docs/spec/15-source-language.md §13
module test.standard
import std.math;
fn main() -> u64
effects []
{
assert(std.math.min_u64(0, 18446744073709551615) == 0);
assert(std.math.min_u64(7, 7) == 7);
assert(std.math.min_u64(9, 4) == 4);
assert(std.math.max_u64(0, 18446744073709551615) == 18446744073709551615);
assert(std.math.max_u64(7, 7) == 7);
assert(std.math.max_u64(9, 4) == 9);
assert(std.math.clamp_u64(0, 4, 9) == 4);
assert(std.math.clamp_u64(20, 4, 9) == 9);
assert(std.math.clamp_u64(7, 4, 9) == 7);
assert(std.math.clamp_u64(7, 4, 4) == 4);
assert(std.math.clamp_u64(18446744073709551615, 0, 18446744073709551615) == 18446744073709551615);
return 0;
}
@@ -0,0 +1,9 @@
// expect: reject E7002
// phase: 6
// spec: docs/spec/16-standard-library.md; docs/spec/15-source-language.md §13
module test.standard
fn main() -> u8
effects []
{ assert(std.bytes.equal(b"a", b"a")); return 0; }
@@ -0,0 +1,9 @@
// expect: reject E7001
// phase: 6
// spec: docs/spec/16-standard-library.md; docs/spec/15-source-language.md §13
module test.standard
import std.bytes
fn main() -> u8
effects []
{ return 0; }
@@ -0,0 +1,19 @@
// expect: run
// result: 11
// phase: 6
// spec: docs/spec/16-standard-library.md; docs/spec/15-source-language.md §13
module test.standard
import std.math;
import std.bytes;
fn equal(a: u64, b: u64) -> u64
effects []
{ return a + b; }
fn main() -> u64
effects []
{
let std: u64 = 7;
assert(std.bytes.equal(b"a", b"a"));
return equal(std, std.math.min_u64(4, 9));
}
@@ -0,0 +1,9 @@
// expect: reject E7001
// phase: 6
// spec: docs/spec/16-standard-library.md; docs/spec/15-source-language.md §13
module test.standard
import std.math;
fn main() -> u8
effects []
{ std.math.min_u64<u64>(1, 2); return 0; }
@@ -0,0 +1,9 @@
// expect: reject E7005
// phase: 6
// spec: docs/spec/16-standard-library.md; docs/spec/15-source-language.md §13
module test.standard
import std.bytes;
fn main() -> u8
effects []
{ var b: [u8; 2] = zero; std.bytes.fill(ref b, 1); return 0; }
@@ -0,0 +1,8 @@
// expect: reject E7002
// phase: 6
// spec: docs/spec/15-source-language.md §13
module test.long_name
import std.bytes;
fn main() -> u8
effects []
{ std.bytes.missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_missing_(); return 0; }
@@ -0,0 +1,9 @@
// expect: reject E7002
// phase: 6
// spec: docs/spec/16-standard-library.md; docs/spec/15-source-language.md §13
module test.standard
import std.bytes;
fn main() -> u8
effects []
{ std.bytes.missing(); return 0; }
@@ -0,0 +1,9 @@
// expect: reject E7002
// phase: 6
// spec: docs/spec/16-standard-library.md; docs/spec/15-source-language.md §13
module test.standard
import std.missing;
fn main() -> u8
effects []
{ return 0; }
@@ -0,0 +1,9 @@
// expect: reject E7002
// phase: 6
// spec: docs/spec/16-standard-library.md; docs/spec/15-source-language.md §13
module test.standard
import std.bytes;
fn main() -> u8
effects []
{ fill(0); return 0; }
@@ -0,0 +1,9 @@
// expect: reject E7005
// phase: 6
// spec: docs/spec/16-standard-library.md; docs/spec/15-source-language.md §13
module test.standard
import std.math;
fn main() -> u8
effects []
{ std.math.min_u64(1); return 0; }
@@ -0,0 +1,9 @@
// expect: reject E7005
// phase: 6
// spec: docs/spec/16-standard-library.md; docs/spec/15-source-language.md §13
module test.standard
import std.bytes;
fn main() -> u8
effects []
{ std.bytes.find(b"x", 0u64); return 0; }