aboutsummaryrefslogtreecommitdiff
path: root/src/parse.cff
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2022-08-20 14:02:48 +0200
committerlemon <lsof@mailbox.org>2022-08-20 14:02:48 +0200
commit0ede7e7f9d6235092d9e3ae2df8b25445fb89c38 (patch)
tree54df7ec7aeeab5e2209c6e4be33dc6c5ed696848 /src/parse.cff
parent46e1f128fd310bd29a2b4335b36c60d6cc0aa3a7 (diff)
more IR progress
Diffstat (limited to 'src/parse.cff')
-rw-r--r--src/parse.cff14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/parse.cff b/src/parse.cff
index e32b758..43c4e7d 100644
--- a/src/parse.cff
+++ b/src/parse.cff
@@ -692,7 +692,7 @@ fn parseagg(P *Parser, loc Loc, kind AggKind, name *const u8, retdecl **Decl) *c
if decl {
switch decl.u {
case Ty ty;
- if !ty->is(:Agg) or !ty.u.Agg.fwd or ty.u.Agg.kind != kind {
+ if !ty->is(:Agg) or !ty.u.Agg.fwd or ty.u.Agg.kind != kind or !streq(ty.u.Agg.name, name) {
decl = #null;
}
case else
@@ -701,6 +701,7 @@ fn parseagg(P *Parser, loc Loc, kind AggKind, name *const u8, retdecl **Decl) *c
}
let ty = decl ? decl.u.Ty : interntype({ .u: :Agg { kind, name, id++ }});
let ty = as(*Type)ty;
+ let constty = as(*Type)constify(ty);
let agg = &ty.u.Agg;
if name != #null {
@@ -754,6 +755,8 @@ fn parseagg(P *Parser, loc Loc, kind AggKind, name *const u8, retdecl **Decl) *c
ty.size = size;
ty.align = align;
agg.flds = flds.dat[0::flds.len];
+ *constty = *ty;
+ constty.konst = #t;
if kind == :EUnion {
// add enum tag field on top and offset every other field down
static id int = 0;
@@ -780,6 +783,8 @@ fn parseagg(P *Parser, loc Loc, kind AggKind, name *const u8, retdecl **Decl) *c
ty.size += off;
align = MAX(align, enumty.align);
ty.size = ALIGNUP(ty.size, align);
+ *constty = *ty;
+ constty.konst = #t;
foreach_ptr(fld, _, agg.flds) {
fld.off += off;
@@ -787,6 +792,7 @@ fn parseagg(P *Parser, loc Loc, kind AggKind, name *const u8, retdecl **Decl) *c
}
if havedecls {
agg.decls = mkenv(P.curenv, P.alloc);
+ constty.u.Agg.decls = agg.decls;
pushenv(P, agg.decls);
while !lexmatch(P, #null, '}') {
parsedecls(P, tok.loc, #null, #null, #{toplevel} #f);
@@ -2178,7 +2184,7 @@ fn psteuswitch(P *Parser, loc Loc, test Expr) Stmt {
}
pushenv(P, env);
putdecl(P, tok.loc, {
- c.capt, tok.loc, .u: :Let { c.captty = ty, :None, #f, P.curfn.id }
+ c.capt, tok.loc, .u: :Let { c.captty = ty, :None, #f, P.curfn.id, P.varid++ }
});
}
lexexpect(P, ';');
@@ -2390,7 +2396,7 @@ fn parsevardecl(P *Parser, toplevel bool, externp bool, letp bool, yield DeclYie
ty = constify(ty);
}
- let decl Decl = { name, tok.loc, externp, :Let { ty, ini, fwd, 0 } };
+ let decl Decl = { name, tok.loc, externp, :Let { ty, ini, fwd, P.curfn ? P.curfn.id : 0, P.varid++ } };
if !letp {
decl.u.#tag = :Static;
}
@@ -2438,7 +2444,7 @@ fn parsefn(P *Parser, loc Loc, externp bool, name *const u8) *Decl {
foreach(name, i, Fn.paramnames) {
if name {
putdecl(P, loc, { name, loc, .u: :Let {
- Fn.ty.u.Fn.params[i], :None, #f, Fn.id,
+ Fn.ty.u.Fn.params[i], :None, #f, Fn.id, P.varid++
}});
}
}