aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2022-08-31 16:00:34 +0200
committerlemon <lsof@mailbox.org>2022-08-31 16:00:34 +0200
commitb4310d08333fcb9ae4f3e4bf1e0e5fc6599ada4e (patch)
tree6b38da06b027db62bd4ab21f6241282b904435d3 /src
parent047a978be814f0ff46482689ef60582061a5c08b (diff)
def x = expr -> defmacro x = expr, def const -> def
Diffstat (limited to 'src')
-rw-r--r--src/cffc.hff2
-rw-r--r--src/fmt.cff2
-rw-r--r--src/fold.cff6
-rw-r--r--src/libc.hff2
-rw-r--r--src/parse.cff17
5 files changed, 19 insertions, 10 deletions
diff --git a/src/cffc.hff b/src/cffc.hff
index 3e6a66f..7338b8a 100644
--- a/src/cffc.hff
+++ b/src/cffc.hff
@@ -41,7 +41,7 @@ enum TokT : i32 {
typearg,
eof,
}
-def NUM_KEYWORDS = as(int)TokT:NUM_KEYWORDS;
+def NUM_KEYWORDS int = TokT:NUM_KEYWORDS;
struct Tok {
t TokT,
diff --git a/src/fmt.cff b/src/fmt.cff
index befde61..60ee5f9 100644
--- a/src/fmt.cff
+++ b/src/fmt.cff
@@ -392,7 +392,7 @@ extern fn warn(P *Parser, loc Loc, fmt *const u8, ...) void {
extern fn err(P *Parser, loc Loc, fmt *const u8, ...) void {
P.error = #t;
static nerr int = 0;
- if nerr++ == 20 {
+ if nerr++ == 7 {
efmt("Aborting due to too many errors.\n");
exit(1);
}
diff --git a/src/fold.cff b/src/fold.cff
index 8814d32..be08256 100644
--- a/src/fold.cff
+++ b/src/fold.cff
@@ -24,16 +24,18 @@ fn numcast(ex *Expr, to *const Type) void {
*f = *f;
case from->is(:Bool);
iu.i = *b ? 1 : 0;
- case from->is(:Int) and to == ty_u8;
+ case from->is(:Int) and to == ty_i8;
iu.i = as(i8)iu.i;
case from->is(:Int) and to == ty_u8;
iu.i = as(u8)iu.i;
case from->is(:Int) and to == ty_i16;
iu.i = as(i16)iu.i;
case from->is(:Int) and to == ty_u16;
- iu.i = as(u8)iu.i;
+ iu.i = as(u16)iu.i;
case from->is(:Int) and to == ty_i32;
iu.i = as(i32)iu.i;
+ case from->is(:Int) and to == ty_u32;
+ iu.i = as(u32)iu.i;
case from->is(:Int) and to == ty_i64;
iu.i = as(i64)iu.i;
case from->is(:Int) and to == ty_u64;
diff --git a/src/libc.hff b/src/libc.hff
index 0744d35..533a933 100644
--- a/src/libc.hff
+++ b/src/libc.hff
@@ -42,4 +42,4 @@ extern fn tolower(int) int;
// errno.h
extern fn c_errno() int;
-def errno = c_errno();
+defmacro errno = c_errno();
diff --git a/src/parse.cff b/src/parse.cff
index b1dca70..112c432 100644
--- a/src/parse.cff
+++ b/src/parse.cff
@@ -3159,8 +3159,6 @@ fn parsedecls(P *Parser, loc Loc, yield DeclYielder, yarg *void, toplevel bool)
case lexmatch(P, &tok, :kw_def);
do {
- let konst = lexmatch(P, #null, :kw_const);
-
let tok = lexexpect(P, :ident),
name = tok.u.ident,
ini Expr #?,
@@ -3177,8 +3175,10 @@ fn parsedecls(P *Parser, loc Loc, yield DeclYielder, yarg *void, toplevel bool)
if !typematchestarg(ty, ini.ty) {
err(P, ini.loc, "incompatible initializer (%t, expected %t)", ini.ty, ty);
}
- let f = fold(&ini);
- if konst and !f {
+ if ty != ini.ty {
+ ini = { ini.loc, ty, :Cast(exprdup(P.alloc, ini)) };
+ }
+ if !fold(&ini) {
err(P, ini.loc, "cannot evaluate expression at compile time");
}
decl = putdecl(P, tok.loc, { name, tok.loc, .u: :Def(ini) });
@@ -3194,7 +3194,14 @@ fn parsedecls(P *Parser, loc Loc, yield DeclYielder, yarg *void, toplevel bool)
case lexmatch(P, &tok, :kw_defmacro);
let name = lexexpects(P, :ident, "macro name").u.ident;
- decl = parsemacro(P, tok.loc, name);
+ if lexmatch(P, &tok, '=') {
+ // defmacro x = expr
+ let ini = parseexpr(P);
+ decl = putdecl(P, tok.loc, { name, tok.loc, .u: :Def(ini) });
+ lexexpect(P, ';');
+ } else {
+ decl = parsemacro(P, tok.loc, name);
+ }
case lexmatch(P, &tok, :kw_typedef);
let name = lexexpects(P, :ident, "typedef name").u.ident;