aboutsummaryrefslogtreecommitdiff
path: root/src/cffc.hff
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2022-08-15 12:22:47 +0200
committerlemon <lsof@mailbox.org>2022-08-15 12:22:47 +0200
commitf906d0b350b0b4ceb747669c9a9845d11bd0e486 (patch)
tree5f09a7b714e6ce93f6094a06e5f736513110fb8d /src/cffc.hff
parentf802bb99263aaa5be492999babd44cd2fdb1c65f (diff)
self hosted progress
Diffstat (limited to 'src/cffc.hff')
-rw-r--r--src/cffc.hff103
1 files changed, 93 insertions, 10 deletions
diff --git a/src/cffc.hff b/src/cffc.hff
index dcb91f7..6910179 100644
--- a/src/cffc.hff
+++ b/src/cffc.hff
@@ -41,8 +41,7 @@ enum TokT : i32 {
strify,
eof,
}
-def NUM_KEYWORDS = TokT:NUM_KEYWORDS;
-
+def NUM_KEYWORDS int = TokT:NUM_KEYWORDS;
struct Tok {
t TokT,
@@ -69,8 +68,13 @@ struct Type {
Int struct { sgn bool },
Flo,
Ptr *Type,
- Arr struct { child *Type, length i64 },
+ Arr struct { child *const Type, length i64 },
Slice *Type,
+ Fn struct {
+ params [#]*const Type,
+ variadic bool,
+ ret *const Type,
+ },
}
}
@@ -78,6 +82,7 @@ struct Parser {
fp *FILE,
alloc *Allocator,
curfile *const u8,
+ curenv *Env,
tokloc Loc,
curloc Loc,
eof bool,
@@ -85,8 +90,41 @@ struct Parser {
peektok Option<Tok>,
}
+struct Expr {
+ loc Loc,
+ ty *const Type,
+ u enum union {
+ IntLit union { i i64, u u64 },
+ FloLit f64,
+ StrLit [#]const u8,
+ BoolLit bool,
+ NullLit,
+ }
+}
+
+struct Stmt {
+ loc Loc,
+ u enum union {
+ Block [#]Stmt,
+ Expr Expr,
+ }
+}
+
+struct Fn {
+ ty *const Type,
+ paramnames [#]*const u8,
+ variadic bool,
+ id int,
+ body Option<[#]Stmt>
+}
+
struct Decl {
name *const u8,
+ loc Loc,
+ u enum union {
+ Fn Fn,
+ Ty *const Type,
+ },
}
struct DeclList {
@@ -98,6 +136,7 @@ struct Targ {
name *const u8,
ptrsize u8,
intsize u8,
+ i64align u8,
longsize u8, longalign u8,
llongsize u8, llongalign u8,
sizesize u8,
@@ -108,6 +147,7 @@ struct Targ {
}
// parse.cff
+extern static keyword2str [NUM_KEYWORDS]*const u8;
extern fn parser_init(*Parser, path *const u8) void;
extern fn parse(*Parser) [#]Decl;
@@ -116,16 +156,59 @@ extern fn vpfmt(proc *fn(u8, *void) void, parg *void, fmt *const u8, va_list) vo
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;
-
-// .. util.cff ..
+extern fn ssfmt(fmt *const u8, ...) *const u8;
extern fn fatal(*Parser, Loc, fmt *const u8, ...) void;
+// targ.cff
+extern static g_targ *const Targ;
+extern fn targ_ini(name *const u8) bool;
+
// type.cff
+extern static ty_void *const Type,
+ ty_bool *const Type,
+ ty_i8 *const Type,
+ ty_u8 *const Type,
+ ty_i16 *const Type,
+ ty_u16 *const Type,
+ ty_i32 *const Type,
+ ty_u32 *const Type,
+ ty_int *const Type,
+ ty_uint *const Type,
+ ty_i64 *const Type,
+ ty_u64 *const Type,
+ ty_isize *const Type,
+ ty_usize *const Type,
+ ty_iptrint *const Type,
+ ty_uptrint *const Type,
+ ty_f32 *const Type,
+ ty_f64 *const Type,
+ ty_voidptr *const Type;
+extern fn interntype(Type) *const Type;
+extern fn putprimtypes(env *Env) void;
+fn constify(ty *const Type) *const Type {
+ if ty.konst or ty.u.#tag == :Fn {
+ return ty;
+ }
+ let ty2 = *ty;
+ ty2.konst = #t;
+ return interntype(ty2);
+}
+fn mkarrtype(len i64, konst bool, child *const Type) *const Type {
+ return interntype({
+ len * child.size,
+ child.align,
+ .u: :Arr { konst ? constify(child) : child, len }
+ });
+}
+fn mkptrtype(child *const Type) *const Type {
+ return interntype({
+ g_targ.ptrsize,
+ .u: :Ptr child
+ });
+}
// env.cff
extern fn mkenv(parent *Env, alloc *Allocator) *Env;
-extern fn envput(*Env, *const Decl) *Decl;
-
-// targ.cff
-extern static g_targ *const Targ;
-extern fn targ_ini(name *const u8) bool;
+extern fn envput(*Env, Decl, **const Decl) *Decl;
+extern fn envfind(*Env, *const u8) *Decl;
+extern fn envfree(*Env) void;