summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cgen.c6
-rw-r--r--eval.c2
-rw-r--r--main.c4
-rw-r--r--parse.c10
-rw-r--r--scope.c10
-rw-r--r--test.toc14
-rwxr-xr-xtests/test.sh2
-rw-r--r--types.c4
-rw-r--r--types.h37
9 files changed, 53 insertions, 36 deletions
diff --git a/cgen.c b/cgen.c
index 46e221b..1b959d2 100644
--- a/cgen.c
+++ b/cgen.c
@@ -10,8 +10,10 @@ static void cgen_create(CGenerator *g, FILE *out, Identifiers *ids, Evaluator *e
}
static bool cgen_stmt(CGenerator *g, Statement *s);
-#define CGEN_BLOCK_NOENTER 0x01 /* should cgen_block actually enter and exit the block? */
-#define CGEN_BLOCK_NOBRACES 0x02 /* should it use braces? */
+enum {
+ CGEN_BLOCK_NOENTER = 0x01, /* should cgen_block actually enter and exit the block? */
+ CGEN_BLOCK_NOBRACES = 0x02, /* should it use braces? */
+};
static bool cgen_block(CGenerator *g, Block *b, const char *ret_name, uint16_t flags);
static bool cgen_expr_pre(CGenerator *g, Expression *e);
static bool cgen_expr(CGenerator *g, Expression *e);
diff --git a/eval.c b/eval.c
index f4e00a1..2ac4170 100644
--- a/eval.c
+++ b/eval.c
@@ -4,7 +4,7 @@ static bool type_resolve(Typer *tr, Type *t, Location where);
static size_t compiler_sizeof(Type *t);
static bool eval_block(Evaluator *ev, Block *b, Type *t, Value *v);
static bool eval_expr(Evaluator *ev, Expression *e, Value *v);
-static bool block_enter(Block *b, Statement *stmts, U32 flags);
+static bool block_enter(Block *b, Statement *stmts, U16 flags);
static void block_exit(Block *b, Statement *stmts);
static void evalr_create(Evaluator *ev, Typer *tr, Allocator *allocr) {
diff --git a/main.c b/main.c
index 39d2c0e..632e160 100644
--- a/main.c
+++ b/main.c
@@ -1,11 +1,9 @@
/*
TODO:
-switch to enums for flags
-
struct parameters
+packages
don't allow while {3; 5} (once break is added)
any odd number of "s for a string
-modifiable string literals
make sure futurely/currently-declared types are only used by pointer/slice
allow omission of trailing ; in foo @= fn() {}?
*/
diff --git a/parse.c b/parse.c
index 7268bdc..bcadbe8 100644
--- a/parse.c
+++ b/parse.c
@@ -1,7 +1,9 @@
static bool parse_expr(Parser *p, Expression *e, Token *end);
static bool parse_stmt(Parser *p, Statement *s);
-#define PARSE_DECL_ALLOW_CONST_WITH_NO_EXPR 0x01
-#define PARSE_DECL_ALLOW_SEMI_CONST 0x02
+enum {
+ PARSE_DECL_ALLOW_CONST_WITH_NO_EXPR = 0x01,
+ PARSE_DECL_ALLOW_SEMI_CONST = 0x02,
+};
static bool parse_decl(Parser *p, Declaration *d, DeclEndKind ends_with, uint16_t flags);
static bool is_decl(Tokenizer *t);
@@ -378,7 +380,9 @@ static Token *expr_find_end(Parser *p, ExprEndFlags flags, bool *is_vbs) {
}
}
-#define PARSE_TYPE_EXPR 0x01 /* this might actually be an expression */
+enum {
+ PARSE_TYPE_EXPR = 0x01, /* this might actually be an expression */
+};
static bool parse_type(Parser *p, Type *type) {
Tokenizer *t = p->tokr;
type->where = t->token->where;
diff --git a/scope.c b/scope.c
index ab123fe..cae7107 100644
--- a/scope.c
+++ b/scope.c
@@ -1,9 +1,11 @@
-#define SCOPE_CHECK_REDECL 0x0001
+enum {
+ SCOPE_CHECK_REDECL = 0x01,
+};
static void val_free(Value *v, Type *t);
-static bool add_ident_decls(Block *b, Declaration *d, U32 flags) {
+static bool add_ident_decls(Block *b, Declaration *d, U16 flags) {
bool ret = true;
arr_foreach(d->idents, Identifier, ident) {
IdentDecl *decls = (*ident)->decls;
@@ -41,7 +43,7 @@ static void remove_ident_decls(Block *b, Declaration *d) {
}
/* pass NULL for block for global scope */
-static bool block_enter(Block *b, Statement *stmts, uint32_t flags) {
+static bool block_enter(Block *b, Statement *stmts, U16 flags) {
bool ret = true;
arr_foreach(stmts, Statement, stmt) {
if (stmt->kind == STMT_DECL) {
@@ -63,7 +65,7 @@ static void block_exit(Block *b, Statement *stmts) {
}
/* does NOT enter function's block body */
-static bool fn_enter(FnExpr *f, U32 flags) {
+static bool fn_enter(FnExpr *f, U16 flags) {
arr_foreach(f->params, Declaration, decl)
if (!add_ident_decls(&f->body, decl, flags))
return false;
diff --git a/test.toc b/test.toc
index 6272493..df83adc 100644
--- a/test.toc
+++ b/test.toc
@@ -7,17 +7,11 @@ puti @= fn(x: int) {
// ");
// };
-
-f @= fn(t @ Type, x: t) t {
- x + 1
-};
-
-g @= fn(x, y @ Type) int {
-(3 as x) + (5 as y)
+Foo @= struct(x @ int) {
+ a: [x]float;
};
main @= fn() {
- puti(f(int, 3));
- puti(f(u8, 255) as int);
- puti(g(int, int));
+ f : Foo(13);
+ puti(f.a[12]);
}; \ No newline at end of file
diff --git a/tests/test.sh b/tests/test.sh
index 470251e..b0ee8e6 100755
--- a/tests/test.sh
+++ b/tests/test.sh
@@ -9,12 +9,12 @@ fi
echo $$
compile() {
- $TOC $DIR/$1/$1.toc -o $DIR/$1/$1.c > /dev/null || exit 1
$CC $EXTRA_CFLAGS $CFLAGS -o $DIR/$1/$1.bin $DIR/$1/$1.c || exit 1
}
STARTPWD="$(pwd)"
+valgrind -q $TOC $DIR/bf/bf.toc -o $DIR/bf/bf.c > /dev/null || exit 1
for CC in $COMPILERS; do
for EXTRA_CFLAGS in "-O0 -g" "-O3 -s"; do
diff --git a/types.c b/types.c
index 5e2a4b3..2bbe4df 100644
--- a/types.c
+++ b/types.c
@@ -189,7 +189,9 @@ static bool expr_must_lval(Expression *e) {
return false;
}
-#define TYPE_OF_FN_NO_COPY_EVEN_IF_CONST 0x01
+enum {
+ TYPE_OF_FN_NO_COPY_EVEN_IF_CONST = 0x01,
+};
static bool type_of_fn(Typer *tr, FnExpr *f, Location where, Type *t, U16 flags) {
t->kind = TYPE_FN;
diff --git a/types.h b/types.h
index 7db9b0d..ec9d79f 100644
--- a/types.h
+++ b/types.h
@@ -113,7 +113,9 @@ typedef union Value {
struct Type *type;
} Value;
-#define IDECL_HAS_VAL 0x01
+enum {
+ IDECL_HAS_VAL = 0x01,
+};
typedef enum {
IDECL_DECL,
@@ -314,9 +316,11 @@ typedef struct {
size_t offset; /* offset during compile time */
} Field;
-#define TYPE_IS_FLEXIBLE 0x01
-#define TYPE_IS_RESOLVED 0x02
-#define TYPE_STRUCT_FOUND_OFFSETS 0x04
+enum {
+ TYPE_IS_FLEXIBLE = 0x01,
+ TYPE_IS_RESOLVED = 0x02,
+ TYPE_STRUCT_FOUND_OFFSETS = 0x04,
+};
typedef U8 Constness;
@@ -363,8 +367,10 @@ typedef struct Type {
};
} Type;
-#define BLOCK_IS_FN 0x01
-#define BLOCK_FOUND_TYPES 0x02
+enum {
+ BLOCK_IS_FN = 0x01,
+ BLOCK_FOUND_TYPES = 0x02,
+};
typedef struct Block {
U16 flags;
Location start;
@@ -464,8 +470,10 @@ typedef struct {
} WhileExpr;
-#define EACH_IS_RANGE 0x01
-#define EACH_ANNOTATED_TYPE 0x02
+enum {
+ EACH_IS_RANGE = 0x01,
+ EACH_ANNOTATED_TYPE = 0x02,
+};
typedef struct EachExpr {
U16 flags;
@@ -541,7 +549,9 @@ typedef struct {
} c;
} SliceExpr;
-#define EXPR_FOUND_TYPE 0x01
+enum {
+ EXPR_FOUND_TYPE = 0x01
+};
typedef struct Expression {
Type type;
@@ -638,13 +648,18 @@ typedef enum {
STMT_RET
} StatementKind;
-#define RET_HAS_EXPR 0x01
+enum {
+ RET_HAS_EXPR = 0x01,
+};
typedef struct {
uint16_t flags;
Expression expr;
} Return;
-#define STMT_VOIDED_EXPR 0x01 /* the "4;" in fn () { 4; } is a voided expression, but the "4" in fn () int { 4 } is not */
+enum {
+ STMT_VOIDED_EXPR = 0x01, /* the "4;" in fn () { 4; } is a voided expression, but the "4" in fn () int { 4 } is not */
+};
+
typedef struct Statement {
Location where;
StatementKind kind;