aboutsummaryrefslogtreecommitdiff
path: root/src/cffc.hff
blob: dcb91f7177765dfd4f05ddd99b52588d3ccd2630 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import "libc.hff";
import "mem.hff";
import "option.hff";

/// Types

struct Type;
struct Decl;
struct Expr;
struct Env;

struct Loc {
   fileid i16,
   col    i16,
   line   int,
   idx    isize,
}

#[lax]
enum TokT : i32 {
   // !sorted
   kw_and, kw_as, kw_break, kw_case, kw_const,
   kw_continue, kw_def, kw_defmacro, kw_do,
   kw_else, kw_enum, kw_extern, kw_fn,
   kw_for, kw_if, kw_import, kw_let, kw_not,
   kw_or, kw_return, kw_sizeof, kw_static,
   kw_struct, kw_switch, kw_typedef, kw_typeof,
   kw_union, kw_while,
   NUM_KEYWORDS,
   int = -100,
   flo,
   bool,
   str,
   chr,
   null,
   ident,
   macident,
   gensym,
   type,
   label,
   strify,
   eof,
}
def NUM_KEYWORDS = TokT:NUM_KEYWORDS;


struct Tok {
   t TokT,
   loc Loc,
   ty *const Type,
   u union {
      int i64,
      uint u64,
      flo f64,
      bool bool,
      str [#]const u8,
      ident *const u8,
   },
}

struct Type {
   size  usize,
   align usize,
   konst bool,
   id    uint,
   u enum union {
      Void,
      Bool,
      Int struct { sgn bool },
      Flo,
      Ptr *Type,
      Arr struct { child *Type, length i64  },
      Slice *Type,
   }
}

struct Parser {
   fp *FILE,
   alloc *Allocator,
   curfile *const u8,
   tokloc Loc,
   curloc Loc,
   eof bool,
   peekchr Option<int>,
   peektok Option<Tok>,
}

struct Decl {
   name *const u8,
}

struct DeclList {
   link *DeclList,
   decl Decl,
}

struct Targ {
   name *const u8,
   ptrsize    u8,
   intsize    u8,
   longsize   u8, longalign  u8,
   llongsize  u8, llongalign u8,
   sizesize   u8,
   f64align   u8,
   valistsize u8, valistalign u8,
   charsigned bool,
   shortenum  bool,
}

// parse.cff
extern fn parser_init(*Parser, path *const u8) void;
extern fn parse(*Parser) [#]Decl;

// fmt.cff
extern fn vpfmt(proc *fn(u8, *void) void, parg *void, fmt *const u8, va_list) void;
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 fatal(*Parser, Loc, fmt *const u8, ...) void;

// type.cff

// 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;