stage2 修复大量AI生成的风格问题 stage1 修复对于vm abi的错误生成

This commit is contained in:
zzy committed 2026-10-03 15:05:55 +08:00
1 parent 0e38858785
commit 76f980654c
40 files changed
+619 -938

No files matched your search

-1
View File
@@ -155,7 +155,6 @@ fn stable_sort(data: *u8, len: usize, elem_size: usize,
ret .Ok;
}
// ---- 测试 ----
type Item = struct {
key: i32,
-1
View File
@@ -127,7 +127,6 @@ fn drop(self: *Arena) {
self.current = 0;
}
// ---- 测试辅助 ----
fn is_aligned(p: *u8, align: usize): bool {
ret ((p as usize) & (align - 1)) == 0;
+1 -1
View File
@@ -26,7 +26,7 @@ fn new(): ByteBuffer {
fn with_capacity(cap: usize): ByteBuffer {
var b = new();
match reserve(&b, cap) { .Ok => {}, .Err(error) => {} }
reserve(&b, cap);
ret b;
}
+2 -4
View File
@@ -9,8 +9,8 @@ type .{ .ByteView } = @import("byte_view.spl");
type .{ .Value, .int, .uint, .char, .str, .addr } = @import("value.spl");
type .{ .BigInt, .Bits } = @import("mp.spl");
// 注意:radix 边界直接用字面量。stage1 刻意不做常量求值/折叠,
// 顶层 const 不应用于运行时表达式。
// radix 边界直接用字面量:顶层 const 不参与运行时常量折叠。
fn valid_radix(radix: u8): bool {
ret radix >= 2 && radix <= 36;
}
@@ -71,7 +71,6 @@ fn append_bool(out: *ByteBuffer, value: bool): Status {
ret ByteBuffer.append(out, "false");
}
// ---- 显式装箱值格式化 ----
// Int/Uint 落到整数;signed 仅对 Int 的十进制生效,其余按无符号位模式输出。
fn append_value_int(out: *ByteBuffer, value: Value, radix: u8, uppercase: bool,
@@ -223,7 +222,6 @@ fn format(out: *ByteBuffer, fmt: []u8, args: []Value): Status {
ret ByteBuffer.append(out, ByteBuffer.as_slice(temp));
}
// ---- 测试辅助 ----
fn expect_ok(result: Status) {
match result {
-2
View File
@@ -34,7 +34,6 @@ fn hash_usize_value(value: usize): usize {
ret h;
}
// ---- map 回调 ----
// 键按 usize 解释。
fn hash_usize(key: *u8): usize {
@@ -55,7 +54,6 @@ fn eq_view(a: *u8, b: *u8): bool {
ret ByteView.eq((a as *ByteView).*, (b as *ByteView).*);
}
// ---- 测试辅助 ----
fn expect_hash(view: []u8, expected: usize) {
var got = hash_bytes(view.ptr, view.len);
+2 -7
View File
@@ -1,11 +1,7 @@
// Expect retcode = 0
// I/O 便利层(构建在 sys/file 之上):
// - C 字符串路径/模式的 open 包装
// - 精确读取、完整写入和普通文件整读
// - stdout/stderr 打印
// 说明:read_all 会按文件大小一次性读入 ByteBuffer;不处理增长中的文件。
// 短读、短写后的零进展及关闭失败返回 Err(.Io);文件写入不承诺回滚。
// sys/file 之上的 I/O 便利层:C 字符串路径 open、精确读取/完整写入、整读、stdout/stderr 打印。
// 短读/短写零进展与关闭失败返回 Err(.Io);写入失败不承诺回滚。
type .{ .Error, .Status, .make } = @import("error.spl");
type .{ .ByteView } = @import("byte_view.spl");
@@ -130,7 +126,6 @@ fn read_all(path: ByteView, out: *ByteBuffer): Status {
ret .Ok;
}
// ---- 测试辅助 ----
fn view(text: []u8): ByteView {
ret ByteView.from_slice(text);
+3 -9
View File
@@ -1,10 +1,6 @@
// Expect retcode = 0
// 轻量 JSON 解析 / 输出器(递归下降 + 节点池),用于验证底层库的拼装,未来服务 LSP。
// 设计:
// - 输入 ByteView,字符串/数字以“源切片”借用,不做解码,round-trip 保真;
// - 节点池 Vec[JsonNode];数组/对象子项存 Vec[JsonChild],保留插入顺序;
// - 错误带字节位置(error.spl);输出写 ByteBuffer;缩进/数字用 ByteBuffer/fmt。
// 限制:不做字符串转义解码、数字不做数值化(原样保存);递归/输出深度上限见 max_depth()。
// 轻量 JSON 解析/输出器:输入按源切片借用、不解码(round-trip 保真),数字不做数值化。
// 节点/子项存 Vec 保留插入顺序;输出写 ByteBuffer。递归/输出深度上限见 max_depth()。
type .{ .Error, .Status, .make, .at } = @import("error.spl");
type .{ .ByteView, .ViewResult, .FindResult } = @import("byte_view.spl");
@@ -393,7 +389,7 @@ fn root_index(doc: *Json): usize {
ret doc.root;
}
// 枚举 tag 取整(stage1 枚举 == 有缺陷,用 @enum2int 比较更稳妥)。
// 枚举 tag 取整:枚举 == 不可靠,用 @enum2int 比较。
fn kind_code(kind: JsonKind): usize {
ret @enum2int(kind) as usize;
}
@@ -578,7 +574,6 @@ fn emit_pretty(out: *ByteBuffer, doc: *Json, indent: usize): Status {
ret emit(out, doc, doc.root, indent, 0);
}
// ---- 构造辅助(写 JSON 片段;字符串需由调用方保证已转义)----
fn write_int(out: *ByteBuffer, value: i64): Status {
ret append_i64(out, value, 10, false);
@@ -588,7 +583,6 @@ fn write_u64(out: *ByteBuffer, value: u64): Status {
ret append_u64(out, value, 10, false);
}
// ---- 测试辅助 ----
fn expect_ok(result: Status) {
match result {
-2
View File
@@ -89,7 +89,6 @@ fn fatal(self: *Logger, message: []u8) {
Exit.fail();
}
// ---- 格式化入口(显式装箱,见 value.spl / fmt.format)----
// 先格式化到临时缓冲;格式错误在写出前返回 Err(.InvalidFormat)。
fn logf(self: *Logger, level: Level, fmt: []u8, args: []Value): Status {
@@ -125,7 +124,6 @@ fn fatalf(self: *Logger, fmt: []u8, args: []Value) {
Exit.fail();
}
// ---- 测试 ----
fn expect_name(level: Level, expected: []u8) {
@assert(ByteView.eq(ByteView.from_slice(level_name(level)),
-1
View File
@@ -99,7 +99,6 @@ fn parse_frame(input: ByteView, body_out: *ByteBuffer): FrameResult {
ret .Ok(body_start + content_len);
}
// ---- 测试辅助 ----
fn expect_ok(result: Status) {
match result {
-1
View File
@@ -155,7 +155,6 @@ fn take(source: *Map): Map {
ret result;
}
// ---- 测试辅助 ----
fn expect_ok(result: Status) {
match result {
+13 -3
View File
@@ -1,13 +1,23 @@
// Expect retcode = 0
// 尺寸计算和字节移动;不分配、不释放内存,不改变任何资源的所有权。
// 尺寸计算、字节移动与内存分配统一门面(分配/释放转发自 sys/mem)。
// 本模块不改变任何资源的所有权。
type .{ .Error, .Status, .make } = @import("error.spl");
type SysMem = @import("../sys/mem.spl");
// 分配/释放/字节操作转发(core 只经本模块使用内存,不直接依赖 sys)。
fn alloc(sz: usize): *any { ret SysMem.alloc(sz); }
fn free(p: *any) { SysMem.free(p); }
fn realloc(p: *any, sz: usize): *any { ret SysMem.realloc(p, sz); }
fn copy(dst: *any, src: *any, n: usize): *any { ret SysMem.copy(dst, src, n); }
fn cmp(a: *any, b: *any, n: usize): isize { ret SysMem.cmp(a, b, n); }
fn set(dst: *any, byte: u8, n: usize): *any { ret SysMem.set(dst, byte, n); }
fn zero(dst: *any, n: usize): *any { ret SysMem.zero(dst, n); }
#extern(vm) fn vm_memcpy(dst: *any, src: *any, n: usize): *any;
#extern(vm) fn vm_memmove(dst: *any, src: *any, n: usize): *any;
fn ignore_ptr(p: *any) {}
type SizeResult = enum {
Ok: usize,
@@ -75,7 +85,7 @@ fn move(dst: []u8, src: []u8): Status {
if dst_addr == src_addr { ret .Ok; }
// 重叠安全,统一走原生 memmove。
ignore_ptr(vm_memmove(dst.ptr as *any, src.ptr as *any, count));
vm_memmove(dst.ptr as *any, src.ptr as *any, count);
ret .Ok;
}
-1
View File
@@ -297,7 +297,6 @@ fn normalize_into(out: *ByteBuffer, path: ByteView, style: PathStyle): Status {
ret .Ok;
}
// ---- 测试 ----
fn expect_ok(result: Status) {
match result { .Ok => {}, .Err(error) => { @assert(false, "unexpected path error"); }, }
}
+6 -12
View File
@@ -1,10 +1,7 @@
// Expect retcode = 0
// 全量热点/耗时记录器(配合 @file_name()/@line()/@col() 与 sys/time.spl)。
// 每个调用点聚合:count、独占(self)与包含(total)的 steps/ns。
// - total_* 含被调用者(嵌套会重复,跨站点求和会超过墙钟)
// - self_* = total_* - 子区间之和,用于定位真正的热点
// 用法(严格 LIFO,defer 正好满足):
// 采样热点记录器:每个调用点聚合 count 与 self/total 的 steps/ns(self = total 减子区间)。
// 严格 LIFO,用 defer 配对:
// var tok = Profile.begin(&prof, @file_name(), @line(), @col());
// defer { Profile.end(&prof, tok); }
@@ -139,7 +136,7 @@ fn begin(self: *Profile, fname: []u8, line: usize, col: usize): usize {
.Err(error) => { ret 0; },
}
var token = self.spans.len - 1;
match Vec.push(&self.stack, &token as *u8) { .Ok => {}, .Err(error) => {} }
Vec.push(&self.stack, &token as *u8);
ret token;
}
@@ -164,7 +161,7 @@ fn end(self: *Profile, token: usize) {
// 弹栈并把区间计入父 span(LIFO)。
var popped: usize = 0;
match Vec.pop(&self.stack, &popped as *u8) { .Ok => {}, .Err(error) => {} }
Vec.pop(&self.stack, &popped as *u8);
var n = self.stack.len;
if n > 0 {
var p = span_at(self, usize_at(&self.stack, n - 1));
@@ -175,7 +172,6 @@ fn end(self: *Profile, token: usize) {
}
}
// ---- dump / save ----
fn out_s(out: *ByteBuffer, s: []u8): bool {
match ByteBuffer.append(out, s) { .Ok => { ret true; }, .Err(error) => { ret false; } }
@@ -202,7 +198,7 @@ fn dump(self: *Profile, out: *ByteBuffer): bool {
defer { Vec.drop(&idx); }
var i: usize = 0;
while i < self.sites.len {
match Vec.push(&idx, &i as *u8) { .Ok => {}, .Err(error) => {} }
Vec.push(&idx, &i as *u8);
i = i + 1;
}
@@ -271,7 +267,6 @@ fn save(self: *Profile, path: ByteView): bool {
ret true;
}
// ---- 测试 ----
fn spin(n: usize): usize {
var i: usize = 0;
@@ -293,10 +288,9 @@ fn test_profile() {
@assert(s != null && s.count >= 1, "count");
@assert(s.total_steps > 0, "steps");
@assert(s.self_steps > 0, "self steps");
if v == 0 { ignore_usize(v + 1); }
if v == 0 { v + 1; }
}
fn ignore_usize(v: usize) {}
fn main() {
test_profile();
-1
View File
@@ -74,7 +74,6 @@ fn drop(self: *Set) {
Map.drop(&self.map);
}
// ---- 测试 ----
fn expect_ok(result: Status) {
match result {
-2
View File
@@ -123,7 +123,6 @@ fn drop(self: *Source) {
Vec.drop(&self.line_starts);
}
// ---- 多文件集合 ----
type Sources = struct {
items: Vec, // Source
@@ -191,7 +190,6 @@ fn set_drop(set: *Sources) {
Map.drop(&set.by_name);
}
// ---- 测试辅助 ----
fn view(text: []u8): ByteView {
ret ByteView.from_slice(text);
-1
View File
@@ -122,7 +122,6 @@ fn drop(self: *Str) {
ByteBuffer.drop(&self.storage);
}
// ---- 测试辅助 ----
fn expect_ok(result: Status) {
match result {
-1
View File
@@ -181,7 +181,6 @@ fn utf16_to_byte(data: *u8, len: usize, utf16_off: usize): usize {
ret i;
}
// ---- 测试辅助 ----
fn expect_ok(result: Status) {
match result {
-1
View File
@@ -43,7 +43,6 @@ fn addr(value: *any): Value {
ret .Ptr(value);
}
// ---- 测试 ----
fn test_int_and_uint() {
match int(-5) {