diff options
| author | 2022-08-26 09:58:48 +0200 | |
|---|---|---|
| committer | 2022-08-26 09:58:48 +0200 | |
| commit | 5ba53665c99c01f407576406b4c619d180efd384 (patch) | |
| tree | 36257820de7d3d8a9cf21eee6cea9d3e38f93eda | |
| parent | d42f8309b4af19966ad9c7b575918ee14421cee1 (diff) | |
some fixes + .[] syntax sugar
| -rw-r--r-- | examples/life.cff | 6 | ||||
| -rw-r--r-- | src/env.cff | 7 | ||||
| -rw-r--r-- | src/llvm.cff | 4 | ||||
| -rw-r--r-- | src/parse.cff | 7 |
4 files changed, 19 insertions, 5 deletions
diff --git a/examples/life.cff b/examples/life.cff index 8b58cf4..064f88c 100644 --- a/examples/life.cff +++ b/examples/life.cff @@ -8,15 +8,15 @@ static board Board = {}; fn get(b *Board, x uint, y uint) bool { x %= W; y %= H; let idx = x + (y * W); - return (*b)[idx / 8] & (1 << (idx % 8)) != 0; + return b.[idx / 8] & (1 << (idx % 8)) != 0; } fn set(b *Board, x uint, y uint, set bool) void { x %= W; y %= H; let idx = x + (y * W); - (*b)[idx / 8] &= ~(1 << (idx % 8)); + b.[idx / 8] &= ~(1 << (idx % 8)); if set { - (*b)[idx / 8] |= (1 << (idx % 8)); + b.[idx / 8] |= (1 << (idx % 8)); } } diff --git a/src/env.cff b/src/env.cff index d45e373..1c525b9 100644 --- a/src/env.cff +++ b/src/env.cff @@ -34,12 +34,19 @@ extern fn envput_alloc(env *Env, alloc *Allocator, decl Decl, old **const Decl) and decl.u.Fn.ty == old.u.Fn.ty and (old.u.Fn.body->empty() or decl.u.Fn.body->empty()); decl.u.Fn.id = old.u.Fn.id; + case old.u.#tag == :Fn and decl.u.#tag == :Fn + and memcmp(&old.u.Fn, &decl.u.Fn, sizeof(old.u.Fn)) == 0; + case old.u.#tag == :Ty and decl.u.#tag == :Ty and old.u.Ty == decl.u.Ty; case old.u.#tag == :Def and decl.u.#tag == :Def and memcmp(&old.u.Def, &decl.u.Def, sizeof(old.u.Def)) == 0; case old.u.#tag == :Static and decl.u.#tag == :Static + and decl.u.Static.ty == old.u.Static.ty and (old.u.Static.fwd or decl.u.Static.fwd); + decl.u.Static.id = old.u.Static.id; + + case old.u.#tag == :Static and decl.u.#tag == :Static and memcmp(&old.u.Static, &decl.u.Static, sizeof(old.u.Static)) == 0; case old.u.#tag == :Macro and decl.u.#tag == :Macro diff --git a/src/llvm.cff b/src/llvm.cff index f3db972..16abb93 100644 --- a/src/llvm.cff +++ b/src/llvm.cff @@ -606,7 +606,7 @@ fn genexpr(f *Fn, ex *Expr) Value { let tmpvar = mktmp(mkptrtype(ex.ty)); let res = mktmp(ex.ty); gen("\t%v = alloca %t\n", tmpvar, ex.ty); - gen("\t%v = icmp ne %t %v, 0\n", cnd, lhs.ty, lhs); + gen("\t%v = icmp ne %t %v, %s\n", cnd, lhs.ty, lhs, lhs.ty->is(:Ptr) ? "null" : "0"); gen("\tbr i1 %v, label %%CondT%d, label %%CondF%d\n", cnd, id, id); gen("CondT%d: ", id); let t = convert(f, ex.ty, cond.t); @@ -1195,7 +1195,7 @@ extern fn llvm_genstatic(externp bool, name *const u8, var *Var) void { extern fn llvm_fini() void { vec_each(s, i, strs) { - gen("@.str.%z = internal constant [%z x i8] c%S;\n", i, s.#len + 1, s); + gen("@.str.%z = private unnamed_addr constant [%z x i8] c%S;\n", i, s.#len + 1, s); } map_each(g, k, globls) { if g.t != :Decl { diff --git a/src/parse.cff b/src/parse.cff index f03e13a..d4b8b7a 100644 --- a/src/parse.cff +++ b/src/parse.cff @@ -1658,6 +1658,13 @@ fn pexpostfix(P *Parser) Expr { let enumty = ty.u.Agg.enumty; ex = { tok.loc, ty.konst ? constify(enumty) : enumty, :EUTag(exprdup(P.alloc, ex)) }; + case lexpeek(P).t == '['; + // sugar: expr.[idx] -> (*expr)[idx] + if !ex.ty->is(:Ptr) { + fatal(P, ex.loc, "`.[]' operator takes a pointer (got %t)", ex.ty); + } + ex = { ex.loc, ex.ty.u.Ptr, .u: :UnOp { :deref, exprdup(P.alloc, ex) }}; + case else; lexexpects(P, :ident, "field name"); } |