diff options
Diffstat (limited to 'src/parse.cff')
| -rw-r--r-- | src/parse.cff | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/parse.cff b/src/parse.cff index 43c4e7d..11c17cc 100644 --- a/src/parse.cff +++ b/src/parse.cff @@ -2092,17 +2092,18 @@ fn pstfor(P *Parser, loc Loc, label *const u8) Stmt { lexexpect(P, '{'); } let body [#]Stmt #?; - with_tmpchange(P.curloop, ++P.loopid) { + let id = ++P.loopid; + with_tmpchange(P.curloop, id) { let env = mkenv(P.curenv, P.alloc); defer envfree(env); pushenv(P, env); if label { - putdecl(P, loc, { label, loc, .u: :Label(P.loopid) }); + putdecl(P, loc, { label, loc, .u: :Label(id) }); } body = parseblock(P); popenv(P); } - return { loc, :For { ini, test, next, body, P.loopid }}; + return { loc, :For { ini, test, next, body, id }}; } fn pstiswitch(P *Parser, loc Loc, ex Expr) Stmt { @@ -2396,8 +2397,12 @@ 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, P.curfn ? P.curfn.id : 0, P.varid++ } }; - if !letp { + let decl Decl = { name, tok.loc, externp, :Let { ty, ini, fwd, P.curfn ? P.curfn.id : 0, } }; + if letp { + decl.u.Let.id = P.varid++; + } else { + static id int = 0; + decl.u.Static.id = id++; decl.u.#tag = :Static; } yield(putdecl(P, tok.loc, decl), yarg); @@ -2436,6 +2441,9 @@ fn parsefn(P *Parser, loc Loc, externp bool, name *const u8) *Decl { return decl; } + let varid = P.varid, loopid = P.loopid; + P.varid = 0; + P.loopid = 0; with_tmpchange(P.alloc, &Allocator { &Arena {}, &Arena:allocf }) { with_tmpchange(P.curfn, Fn) { let env = mkenv(P.curenv, P.alloc); @@ -2454,6 +2462,8 @@ fn parsefn(P *Parser, loc Loc, externp bool, name *const u8) *Decl { (as(*Arena)P.alloc.a)->destroy(); } } + P.varid = varid; + P.loopid = loopid; return decl; } |