selfhost: graduate SK_* defs to skind enum
This commit is contained in:
@@ -861,7 +861,7 @@ fn cgdot(c: *cgen, n: *node) void = {
|
||||
};
|
||||
};
|
||||
// Module-qualified value reference: `mod.name` where `mod`
|
||||
// is N_IDENT bound as SK_USE and the leaf isn't a local.
|
||||
// is N_IDENT bound as skind.SK_USE and the leaf isn't a local.
|
||||
// Treat as a SB symbol — `MOVQ leaf(SB), AX`. Same fallback
|
||||
// the C cgen takes when bt is NULL/tyerr.
|
||||
if (lhs != nil) {
|
||||
|
||||
@@ -36,31 +36,31 @@ type checker = struct {
|
||||
// seedprimitives — install the built-in type names so `i32`, `str`,
|
||||
// etc. can be looked up like ordinary symbols.
|
||||
fn seedprimitives(c: *checker) void = {
|
||||
scopedefine(c.top, "void", SK_TYPE, c.tc.tyvoid, nil);
|
||||
scopedefine(c.top, "bool", SK_TYPE, c.tc.tybool, nil);
|
||||
scopedefine(c.top, "rune", SK_TYPE, c.tc.tyrune, nil);
|
||||
scopedefine(c.top, "i8", SK_TYPE, c.tc.tyi8, nil);
|
||||
scopedefine(c.top, "i16", SK_TYPE, c.tc.tyi16, nil);
|
||||
scopedefine(c.top, "i32", SK_TYPE, c.tc.tyi32, nil);
|
||||
scopedefine(c.top, "i64", SK_TYPE, c.tc.tyi64, nil);
|
||||
scopedefine(c.top, "u8", SK_TYPE, c.tc.tyu8, nil);
|
||||
scopedefine(c.top, "u16", SK_TYPE, c.tc.tyu16, nil);
|
||||
scopedefine(c.top, "u32", SK_TYPE, c.tc.tyu32, nil);
|
||||
scopedefine(c.top, "u64", SK_TYPE, c.tc.tyu64, nil);
|
||||
scopedefine(c.top, "int", SK_TYPE, c.tc.tyint, nil);
|
||||
scopedefine(c.top, "uint", SK_TYPE, c.tc.tyuint, nil);
|
||||
scopedefine(c.top, "uintptr", SK_TYPE, c.tc.tyuintptr, nil);
|
||||
scopedefine(c.top, "f32", SK_TYPE, c.tc.tyf32, nil);
|
||||
scopedefine(c.top, "f64", SK_TYPE, c.tc.tyf64, nil);
|
||||
scopedefine(c.top, "str", SK_TYPE, c.tc.tystr, nil);
|
||||
scopedefine(c.top, "never", SK_TYPE, c.tc.tynever, nil);
|
||||
scopedefine(c.top, "void", skind.SK_TYPE, c.tc.tyvoid, nil);
|
||||
scopedefine(c.top, "bool", skind.SK_TYPE, c.tc.tybool, nil);
|
||||
scopedefine(c.top, "rune", skind.SK_TYPE, c.tc.tyrune, nil);
|
||||
scopedefine(c.top, "i8", skind.SK_TYPE, c.tc.tyi8, nil);
|
||||
scopedefine(c.top, "i16", skind.SK_TYPE, c.tc.tyi16, nil);
|
||||
scopedefine(c.top, "i32", skind.SK_TYPE, c.tc.tyi32, nil);
|
||||
scopedefine(c.top, "i64", skind.SK_TYPE, c.tc.tyi64, nil);
|
||||
scopedefine(c.top, "u8", skind.SK_TYPE, c.tc.tyu8, nil);
|
||||
scopedefine(c.top, "u16", skind.SK_TYPE, c.tc.tyu16, nil);
|
||||
scopedefine(c.top, "u32", skind.SK_TYPE, c.tc.tyu32, nil);
|
||||
scopedefine(c.top, "u64", skind.SK_TYPE, c.tc.tyu64, nil);
|
||||
scopedefine(c.top, "int", skind.SK_TYPE, c.tc.tyint, nil);
|
||||
scopedefine(c.top, "uint", skind.SK_TYPE, c.tc.tyuint, nil);
|
||||
scopedefine(c.top, "uintptr", skind.SK_TYPE, c.tc.tyuintptr, nil);
|
||||
scopedefine(c.top, "f32", skind.SK_TYPE, c.tc.tyf32, nil);
|
||||
scopedefine(c.top, "f64", skind.SK_TYPE, c.tc.tyf64, nil);
|
||||
scopedefine(c.top, "str", skind.SK_TYPE, c.tc.tystr, nil);
|
||||
scopedefine(c.top, "never", skind.SK_TYPE, c.tc.tynever, nil);
|
||||
// `nil`, `true`, `false` are keywords — handled at the lex/parser
|
||||
// level, no symbol needed.
|
||||
// `len`, `alloc`, `free` are pseudo-builtins; scopedefine them so
|
||||
// their use sites resolve. The actual semantics live in cgen.
|
||||
scopedefine(c.top, "len", SK_FN, nil, nil);
|
||||
scopedefine(c.top, "alloc", SK_FN, nil, nil);
|
||||
scopedefine(c.top, "free", SK_FN, nil, nil);
|
||||
scopedefine(c.top, "len", skind.SK_FN, nil, nil);
|
||||
scopedefine(c.top, "alloc", skind.SK_FN, nil, nil);
|
||||
scopedefine(c.top, "free", skind.SK_FN, nil, nil);
|
||||
};
|
||||
|
||||
// installdecl — install the top-level decl's name into the top scope.
|
||||
@@ -70,11 +70,11 @@ fn installdecl(c: *checker, d: *node) void = {
|
||||
if (d == nil) { return; };
|
||||
let k: i32 = d.kind;
|
||||
let nm: str = d.str;
|
||||
if (k == N_USE) { scopedefine(c.top, nm, SK_USE, nil, d); return; };
|
||||
if (k == N_DEF) { scopedefine(c.top, nm, SK_DEF, nil, d); return; };
|
||||
if (k == N_TYPEDECL) { scopedefine(c.top, nm, SK_TYPE, nil, d); return; };
|
||||
if (k == N_FNDECL) { scopedefine(c.top, nm, SK_FN, nil, d); return; };
|
||||
if (k == N_LET) { scopedefine(c.top, nm, SK_VAR, nil, d); return; };
|
||||
if (k == N_USE) { scopedefine(c.top, nm, skind.SK_USE, nil, d); return; };
|
||||
if (k == N_DEF) { scopedefine(c.top, nm, skind.SK_DEF, nil, d); return; };
|
||||
if (k == N_TYPEDECL) { scopedefine(c.top, nm, skind.SK_TYPE, nil, d); return; };
|
||||
if (k == N_FNDECL) { scopedefine(c.top, nm, skind.SK_FN, nil, d); return; };
|
||||
if (k == N_LET) { scopedefine(c.top, nm, skind.SK_VAR, nil, d); return; };
|
||||
};
|
||||
|
||||
// resolvewalk — recursive AST walk that, for every N_IDENT and
|
||||
@@ -159,7 +159,7 @@ fn resolvewalk(c: *checker, n: *node) void = {
|
||||
if (n.lhs != nil) { resolvewalk(c, n.lhs); };
|
||||
let nm: str = n.str;
|
||||
if (nm.len > 0) {
|
||||
scopedefine(c.cur, nm, SK_VAR, nil, n);
|
||||
scopedefine(c.cur, nm, skind.SK_VAR, nil, n);
|
||||
};
|
||||
if (n.body != nil) { resolvewalk(c, n.body); };
|
||||
return;
|
||||
@@ -204,7 +204,7 @@ fn resolvewalk(c: *checker, n: *node) void = {
|
||||
if (k == N_LET) {
|
||||
let nm: str = n.str;
|
||||
if (nm.len > 0) {
|
||||
scopedefine(c.cur, nm, SK_VAR, nil, n);
|
||||
scopedefine(c.cur, nm, skind.SK_VAR, nil, n);
|
||||
};
|
||||
};
|
||||
};
|
||||
@@ -234,7 +234,7 @@ fn resolvealias(c: *checker, n: *node) *node = {
|
||||
if (cur.kind != N_TNAME) { return cur; };
|
||||
let s: *sym = scopelookup(c.cur, cur.str);
|
||||
if (s == nil) { return cur; };
|
||||
if (s.skind != SK_TYPE) { return cur; };
|
||||
if (s.skind != skind.SK_TYPE) { return cur; };
|
||||
let body: *node = nil;
|
||||
if (s.decl != nil) { body = s.decl.lhs; };
|
||||
if (body == nil) { return cur; };
|
||||
@@ -273,7 +273,7 @@ fn varianterr(c: *checker, v: *node) bool = {
|
||||
if (v.kind == N_TNAME) {
|
||||
let s: *sym = scopelookup(c.cur, v.str);
|
||||
if (s != nil) {
|
||||
if (s.skind == SK_TYPE) {
|
||||
if (s.skind == skind.SK_TYPE) {
|
||||
if (s.decl != nil) {
|
||||
if (s.decl.lhs != nil) {
|
||||
if (s.decl.lhs.kind == N_TBANG) {
|
||||
@@ -371,7 +371,7 @@ fn exprtype(c: *checker, e: *node) *node = {
|
||||
if (nm.len == 0) { return nil; };
|
||||
let s: *sym = scopelookup(c.cur, nm);
|
||||
if (s == nil) { return nil; };
|
||||
if (s.skind != SK_FN) { return nil; };
|
||||
if (s.skind != skind.SK_FN) { return nil; };
|
||||
if (s.decl == nil) { return nil; };
|
||||
return s.decl.lhs; // fn-decl's lhs is the return type
|
||||
};
|
||||
@@ -787,7 +787,7 @@ fn exprtypeoftry(c: *checker, e: *node) *node = {
|
||||
if (nm.len == 0) { return nil; };
|
||||
let s: *sym = scopelookup(c.cur, nm);
|
||||
if (s == nil) { return nil; };
|
||||
if (s.skind != SK_FN) { return nil; };
|
||||
if (s.skind != skind.SK_FN) { return nil; };
|
||||
if (s.decl == nil) { return nil; };
|
||||
return s.decl.lhs;
|
||||
};
|
||||
@@ -849,7 +849,7 @@ fn installparams(c: *checker, params: *node) void = {
|
||||
if (p.kind == N_PARAM) {
|
||||
let nm: str = p.str;
|
||||
if (nm.len > 0) {
|
||||
scopedefine(c.cur, nm, SK_PARAM, nil, p);
|
||||
scopedefine(c.cur, nm, skind.SK_PARAM, nil, p);
|
||||
};
|
||||
};
|
||||
p = p.next;
|
||||
|
||||
Reference in New Issue
Block a user