aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2022-08-26 09:58:48 +0200
committerlemon <lsof@mailbox.org>2022-08-26 09:58:48 +0200
commit5ba53665c99c01f407576406b4c619d180efd384 (patch)
tree36257820de7d3d8a9cf21eee6cea9d3e38f93eda /src
parentd42f8309b4af19966ad9c7b575918ee14421cee1 (diff)
some fixes + .[] syntax sugar
Diffstat (limited to 'src')
-rw-r--r--src/env.cff7
-rw-r--r--src/llvm.cff4
-rw-r--r--src/parse.cff7
3 files changed, 16 insertions, 2 deletions
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");
}