stage3 ai编写新语法语义 同时提供fflush

This commit is contained in:
zzy committed 2026-11-05 09:48:43 +08:00
1 parent bb8761d392
commit 126b979f72
170 files changed
+10729 -3175

No files matched your search

+26 -2
View File
@@ -68,6 +68,7 @@ type Body = enum {
ExprNullLit,
ExprUndefinedLit,
ExprIdent: struct { name: ByteView },
ExprLambda: struct { params: Vec, ret_type: usize, body: usize },
ExprUnary: struct { op: Punct, operand: usize },
ExprBinary: struct { op: Punct, left: usize, right: usize },
ExprCall: struct { callee: usize, args: Vec },
@@ -112,7 +113,7 @@ type Body = enum {
TypeSlice: struct { elem_type: usize },
TypeFn: struct { is_comptime: bool, params: Vec, ret_type: usize },
TypeParen: struct { types: Vec },
TypeAggregate: struct { kind_name: ByteView, members: Vec },
TypeAggregate: struct { kind_name: ByteView, conforms: Vec, members: Vec },
TypeComptimeCall: struct { name: ByteView, args: Vec },
PatternIdent: struct { name: ByteView },
PatternUnderscore,
@@ -124,6 +125,10 @@ type Body = enum {
PatternRef: struct { pat: usize },
ExprComptime: struct { body: usize },
ExprComptimeInit: struct { name: ByteView, args: Vec, fields: Vec },
AssocDecl: struct { attr_list: Vec, name: ByteView },
TypeShapeApply: struct { base: ByteView, binds: Vec },
TypeAssocBind: struct { name: ByteView, ty: usize },
TypeShapeUse: struct { adapter: ByteView, shapes: Vec },
}
fn kind_name(body: Body): []u8 {
@@ -139,6 +144,7 @@ fn kind_name(body: Body): []u8 {
.VarDecl(_) => { ret "var_decl"; },
.ConstDecl(_) => { ret "const_decl"; },
.TypeDecl(_) => { ret "type_decl"; },
.AssocDecl(_) => { ret "assoc_decl"; },
.MemberDecl(_) => { ret "member_decl"; },
.ParamDecl(_) => { ret "param_decl"; },
.StatementRet(_) => { ret "statement_ret"; },
@@ -162,6 +168,7 @@ fn kind_name(body: Body): []u8 {
.ExprNullLit => { ret "null_lit"; },
.ExprUndefinedLit => { ret "undefined_lit"; },
.ExprIdent(_) => { ret "ident"; },
.ExprLambda(_) => { ret "lambda"; },
.ExprUnary(_) => { ret "unary"; },
.ExprBinary(_) => { ret "binary"; },
.ExprCall(_) => { ret "call"; },
@@ -191,6 +198,9 @@ fn kind_name(body: Body): []u8 {
.TypeFn(_) => { ret "type_fn"; },
.TypeParen(_) => { ret "type_paren"; },
.TypeAggregate(_) => { ret "type_aggregate"; },
.TypeShapeApply(_) => { ret "type_shape_apply"; },
.TypeAssocBind(_) => { ret "type_assoc_bind"; },
.TypeShapeUse(_) => { ret "type_shape_use"; },
.TypeComptimeCall(_) => { ret "type_comptime_call"; },
.PatternIdent(_) => { ret "pattern_ident"; },
.PatternUnderscore => { ret "pattern_underscore"; },
@@ -442,6 +452,9 @@ fn dump_node(ast: *Ast, buf: *ByteBuffer, stack: *Vec, ref: usize, last: bool):
dump_opt(ast, buf, stack, d.pattern, false) &&
dump_opt(ast, buf, stack, d.type_expr, true);
},
.AssocDecl(d) => {
ok = dump_list(ast, buf, stack, d.attr_list);
},
.MemberDecl(d) => {
ok = dump_list(ast, buf, stack, d.attr_list) &&
dump_opt(ast, buf, stack, d.type_expr, false) &&
@@ -482,6 +495,11 @@ fn dump_node(ast: *Ast, buf: *ByteBuffer, stack: *Vec, ref: usize, last: bool):
.ExprNullLit => {},
.ExprUndefinedLit => {},
.ExprIdent(x) => {},
.ExprLambda(x) => {
ok = dump_list(ast, buf, stack, x.params) &&
dump_opt(ast, buf, stack, x.ret_type, false) &&
dump_opt(ast, buf, stack, x.body, true);
},
.ExprUnary(u) => { ok = dump_opt(ast, buf, stack, u.operand, true); },
.ExprBinary(b) => {
ok = dump_opt(ast, buf, stack, b.left, false) &&
@@ -568,7 +586,13 @@ fn dump_node(ast: *Ast, buf: *ByteBuffer, stack: *Vec, ref: usize, last: bool):
dump_opt(ast, buf, stack, f.ret_type, true);
},
.TypeParen(p) => { ok = dump_list(ast, buf, stack, p.types); },
.TypeAggregate(a) => { ok = dump_list(ast, buf, stack, a.members); },
.TypeAggregate(a) => {
ok = dump_list(ast, buf, stack, a.conforms) &&
dump_list(ast, buf, stack, a.members);
},
.TypeShapeApply(a) => { ok = dump_list(ast, buf, stack, a.binds); },
.TypeAssocBind(a) => { ok = dump_opt(ast, buf, stack, a.ty, true); },
.TypeShapeUse(a) => { ok = dump_list(ast, buf, stack, a.shapes); },
.TypeComptimeCall(c) => { ok = dump_list(ast, buf, stack, c.args); },
.PatternIdent(x) => {},
.PatternUnderscore => {},