spl 编写编译器基础框架 ai修复出现的stage2和stage3问题并提供新语法
This commit is contained in:
1 parent
126b979f72
commit
50ee126d44
87 files changed
+3168
-394
No files matched your search
@@ -25,11 +25,11 @@ type tid = usize;
|
||||
|
||||
fn hook_find_binding(user: *any, s: []u8): usize { ret find_binding(user as *Sema, s); }
|
||||
fn hook_builtin_tag_id(user: *any, fnref: Ref): Builtin { ret builtin_tag_id(user as *Sema, fnref); }
|
||||
|
||||
|
||||
fn hook_has_tag(user: *any, fnref: Ref, name: []u8): bool { ret has_tag(user as *Sema, fnref, name); }
|
||||
fn hook_has_builtin_tag(user: *any, fnref: Ref): bool { ret has_builtin_tag(user as *Sema, fnref); }
|
||||
fn hook_insert_method_receiver(user: *any, callee_ref: Ref, callee: Ref, args: []Ref, out: *HookParamResult) {
|
||||
insert_method_receiver(user as *Sema, callee_ref, callee, args, out);
|
||||
}
|
||||
|
||||
fn hook_collect_builtins(user: *any) { collect_builtins(user as *Sema); }
|
||||
fn hook_list_has_tag(user: *any, l: []Ref, tag: []u8): bool { ret list_has_tag(user as *Sema, l, tag); }
|
||||
fn builtin_tag_raw(self: *Sema, fnref: Ref): []u8 { ret tag_arg_raw(self, fnref, "builtin"); }
|
||||
@@ -44,7 +44,7 @@ fn hooks(): BindingHooks {
|
||||
.builtin_tag_id = hook_builtin_tag_id,
|
||||
.has_tag = hook_has_tag,
|
||||
.has_builtin_tag = hook_has_builtin_tag,
|
||||
.insert_method_receiver = hook_insert_method_receiver,
|
||||
|
||||
.collect_builtins = hook_collect_builtins,
|
||||
.list_has_tag = hook_list_has_tag,
|
||||
.raw_tag = hook_raw_tag,
|
||||
@@ -252,42 +252,7 @@ fn param_has_at(self: *Sema, param: Ref): bool {
|
||||
ret false;
|
||||
}
|
||||
|
||||
// 方法调用 `obj.f(args)`:obj 总是作为隐式 receiver;hook 只负责变换 receiver。
|
||||
fn insert_method_receiver(self: *Sema, callee_ref: Ref, callee: Ref, args: []Ref,
|
||||
out: *HookParamResult) {
|
||||
out.args = args;
|
||||
out.changed = false;
|
||||
var fnp = Bld.node_ptr(&self.hir, callee_ref);
|
||||
if fnp == null { ret; }
|
||||
var recv: Ref = 0;
|
||||
var cn = Bld.node_ptr(&self.hir, callee);
|
||||
if cn == null { ret; }
|
||||
match cn.kind {
|
||||
.Field(f) => { recv = f.obj; },
|
||||
_ => {},
|
||||
}
|
||||
if recv == 0 { ret; }
|
||||
// 模块级函数不是方法;只有聚合/语言类型的方法才插入 receiver。
|
||||
var csym = SemaM.node_fn(self, callee);
|
||||
if csym == 0 || SemaM.sym_at(self, csym - 1).owner == 0 { ret; }
|
||||
match fnp.kind {
|
||||
.FnDecl(f) => {
|
||||
if f.params.len == 0 || args.len + 1 != f.params.len { ret; }
|
||||
var buf = Vec.blank(@sizeof(Ref), @alignof(Ref));
|
||||
defer { Vec.drop(&buf); }
|
||||
match Vec.push(&buf, &recv as *u8) { .Ok => {}, .Err(error) => { ret; } }
|
||||
var i: usize = 0;
|
||||
while i < args.len {
|
||||
var a = args[i];
|
||||
match Vec.push(&buf, &a as *u8) { .Ok => {}, .Err(error) => { ret; } }
|
||||
i = i + 1;
|
||||
}
|
||||
out.args = Bld.dup_refs(&self.hir, (buf.data as *Ref)[0..buf.len]);
|
||||
out.changed = true;
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn is_meta_module(self: *Sema, m: usize): bool {
|
||||
var p = SemaM.module_at(self, m).path;
|
||||
|
||||
Reference in new issue
Block a user