aboutsummaryrefslogtreecommitdiff
path: root/src/cffc.hff
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2022-08-16 05:28:18 +0200
committerlemon <lsof@mailbox.org>2022-08-16 05:28:18 +0200
commit73f68a9c5ed4c8139cc1c4f7695da29e5a3fb4c8 (patch)
treeb2cebcf1f6b6073eeeb0595710d6fdf05fcb06fb /src/cffc.hff
parentb3159bfd93c8bdce71f7437abdc521b5ccb72367 (diff)
stuff
Diffstat (limited to 'src/cffc.hff')
-rw-r--r--src/cffc.hff40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/cffc.hff b/src/cffc.hff
index 2b6faaf..3824a14 100644
--- a/src/cffc.hff
+++ b/src/cffc.hff
@@ -75,6 +75,10 @@ struct Type {
variadic bool,
ret *const Type,
},
+ },
+
+ fn is(ty *const Type, tag typeof((Type{}).u.#tag)) bool {
+ return ty.u.#tag == tag;
}
}
@@ -90,6 +94,18 @@ struct Parser {
peektok Option<Tok>,
}
+enum UnOp {
+ neg,
+ lnot,
+ compl,
+ deref,
+ addrof,
+ postinc,
+ preinc,
+ postdec,
+ predec,
+}
+
struct Expr {
loc Loc,
ty *const Type,
@@ -100,6 +116,9 @@ struct Expr {
BoolLit bool,
NullLit,
Symbol *Decl,
+ BinOp struct { op TokT, lhs *Expr, rhs *Expr },
+ UnOp struct { op UnOp, ex *Expr },
+ Cond struct { test *Expr, t *Expr, f *Expr },
Call struct { lhs *Expr, args [#]Expr }
}
}
@@ -120,10 +139,19 @@ struct Fn {
body Option<[#]Stmt>
}
+struct Var {
+ ty *const Type,
+ ini Option<Expr>,
+ fnid int,
+}
+
struct Decl {
name *const u8,
loc Loc,
+ externp bool,
u enum union {
+ Let Var,
+ Static Var,
Fn Fn,
Ty *const Type,
},
@@ -159,6 +187,7 @@ extern fn pfmt(proc *fn(u8, *void) void, parg *void, fmt *const u8, ...) void;
extern fn vefmt(fmt *const u8, ap va_list) void;
extern fn efmt(fmt *const u8, ...) void;
extern fn ssfmt(fmt *const u8, ...) *const u8;
+extern fn err(P *Parser, Loc, fmt *const u8, ...) void;
extern fn fatal(*Parser, Loc, fmt *const u8, ...) void;
// targ.cff
@@ -195,6 +224,14 @@ fn constify(ty *const Type) *const Type {
ty2.konst = #t;
return interntype(ty2);
}
+fn unconstify(ty *const Type) *const Type {
+ if not ty.konst {
+ return ty;
+ }
+ let ty2 = *ty;
+ ty2.konst = #f;
+ return interntype(ty2);
+}
fn mkarrtype(len i64, konst bool, child *const Type) *const Type {
return interntype({
len * child.size,
@@ -208,9 +245,12 @@ fn mkptrtype(child *const Type) *const Type {
.u: :Ptr child
});
}
+extern fn isnumtype(ty *const Type) bool;
+extern fn typeof2(a *const Type, b *const Type) *const Type;
// env.cff
extern fn mkenv(parent *Env, alloc *Allocator) *Env;
+extern fn envparent(*Env) *Env;
extern fn envput(*Env, Decl, **const Decl) *Decl;
extern fn envfind(*Env, *const u8) *Decl;
extern fn envfree(*Env) void;