stage2 ai重构

This commit is contained in:
zzy committed 2026-10-26 12:51:32 +08:00
1 parent 4c0317fcb5
commit 2c531f23de
26 files changed
+1251 -1578

No files matched your search

+6 -14
View File
@@ -74,14 +74,6 @@ fn span_at(self: *Profile, i: usize): *SpanRec {
ret null;
}
fn usize_at(v: *Vec, i: usize): usize {
match Vec.get(v, i) {
.Ok(ptr) => { ret (ptr as *usize).*; },
.Err(error) => { ret 0; },
}
ret 0;
}
fn find_site(self: *Profile, fname: []u8, line: usize, col: usize): usize {
var fv = ByteView.from_slice(fname);
var i: usize = 0;
@@ -164,7 +156,7 @@ fn end(self: *Profile, token: usize) {
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));
var p = span_at(self, Vec.usize_at(&self.stack, n - 1));
if p != null {
p.child_steps = p.child_steps + e_steps;
p.child_ns = p.child_ns + e_ns;
@@ -206,15 +198,15 @@ fn dump(self: *Profile, out: *ByteBuffer): bool {
while i < idx.len {
var j = i;
while j > 0 {
var a = site_at(self, usize_at(&idx, j - 1));
var b = site_at(self, usize_at(&idx, j));
var a = site_at(self, Vec.usize_at(&idx, j - 1));
var b = site_at(self, Vec.usize_at(&idx, j));
var swap = false;
if a != null && b != null {
if b.self_steps > a.self_steps { swap = true; }
}
if !swap { break; }
var tmp = usize_at(&idx, j - 1);
match Vec.get(&idx, j - 1) { .Ok(p) => { (p as *usize).* = usize_at(&idx, j); }, .Err(e) => {} }
var tmp = Vec.usize_at(&idx, j - 1);
match Vec.get(&idx, j - 1) { .Ok(p) => { (p as *usize).* = Vec.usize_at(&idx, j); }, .Err(e) => {} }
match Vec.get(&idx, j) { .Ok(p) => { (p as *usize).* = tmp; }, .Err(e) => {} }
j = j - 1;
}
@@ -223,7 +215,7 @@ fn dump(self: *Profile, out: *ByteBuffer): bool {
i = 0;
while i < idx.len {
var s = site_at(self, usize_at(&idx, i));
var s = site_at(self, Vec.usize_at(&idx, i));
if s != null {
if !out_u(out, s.count) { ret false; }
if !out_s(out, "\t") { ret false; }