diff options
-rw-r--r-- | cgen.c | 3 | ||||
-rw-r--r-- | copy.c | 3 | ||||
-rw-r--r-- | decls_cgen.c | 6 | ||||
-rw-r--r-- | eval.c | 2 | ||||
-rw-r--r-- | main.c | 2 | ||||
-rw-r--r-- | parse.c | 11 | ||||
-rw-r--r-- | types.h | 16 |
7 files changed, 36 insertions, 7 deletions
@@ -2162,6 +2162,9 @@ static void cgen_defs_stmt(CGenerator *g, Statement *s) { case STMT_DEFER: cgen_defs_stmt(g, s->defer); break; + case STMT_USE: + cgen_defs_expr(g, &s->use); + break; } } @@ -441,6 +441,9 @@ static void copy_stmt(Copier *c, Statement *out, Statement *in) { case STMT_BREAK: case STMT_CONT: break; + case STMT_USE: + copy_expr(c, &out->use, &in->use); + break; } } diff --git a/decls_cgen.c b/decls_cgen.c index c1749a1..46db767 100644 --- a/decls_cgen.c +++ b/decls_cgen.c @@ -162,6 +162,9 @@ static void cgen_sdecls_stmt(CGenerator *g, Statement *s) { case STMT_DEFER: cgen_sdecls_stmt(g, s->defer); break; + case STMT_USE: + cgen_sdecls_expr(g, &s->use); + break; } } @@ -391,6 +394,9 @@ static void cgen_decls_stmt(CGenerator *g, Statement *s) { case STMT_DEFER: cgen_decls_stmt(g, s->defer); break; + case STMT_USE: + cgen_sdecls_expr(g, &s->use); + break; } } @@ -1710,6 +1710,8 @@ static Status eval_stmt(Evaluator *ev, Statement *stmt) { case STMT_DEFER: *(Statement **)arr_add(&ev->typer->block->deferred) = stmt->defer; break; + case STMT_USE: + break; } return true; } @@ -8,9 +8,9 @@ /* TODO: -simplify eval macros with val_to_u/i64 use - use with a decl, e.g. use p : Point; +simplify eval macros with val_to_u/i64 &&, || start making a standard library... (printf; stringbuilder would be nice to have) switch @@ -2400,6 +2400,13 @@ static Status parse_stmt(Parser *p, Statement *s, bool *was_a_statement) { } goto success; } + case KW_USE: { + ++t->token; + s->kind = STMT_USE; + if (!parse_expr(p, &s->use, expr_find_end(p, 0))) + return false; + goto success; + } default: break; } } else if (t->token->kind == TOKEN_DIRECT) { @@ -2888,6 +2895,10 @@ static void fprint_stmt(FILE *out, Statement *s) { fprintf(out, "defer "); fprint_stmt(out, s->defer); break; + case STMT_USE: + fprintf(out, "use "); + fprint_expr(out, &s->use); + break; } } @@ -253,9 +253,10 @@ typedef enum { DIRECT_COUNT } Directive; -static const char *directives[DIRECT_COUNT] = - {"C", "sizeof", "alignof", "export", "foreign", "builtin", "include", "force", "if", "error", "warn", - "info"}; +static const char *directives[DIRECT_COUNT] = { + "C", "sizeof", "alignof", "export", "foreign", "builtin", "include", "force", "if", "error", "warn", + "info" +}; typedef enum { KW_SEMICOLON, @@ -320,6 +321,7 @@ typedef enum { KW_TRUE, KW_FALSE, KW_NMS, + KW_USE, KW_TYPEOF, KW_SIZEOF, KW_ALIGNOF, @@ -336,8 +338,8 @@ static const char *const keywords[KW_COUNT] = { "continue", "defer", "fn", "as", "struct", "int", "i8", "i16", "i32", "i64", "u8", "u16", "u32", "u64", "float", "f32", "f64", "Type", - "Namespace", - "char", "bool", "true", "false", "nms", "typeof", "sizeof", "alignof" + "Namespace", "char", "bool", "true", "false", "nms", "use", + "typeof", "sizeof", "alignof" }; typedef enum { @@ -915,7 +917,8 @@ typedef enum { STMT_CONT, STMT_INCLUDE, STMT_MESSAGE, - STMT_DEFER + STMT_DEFER, + STMT_USE } StatementKind; enum { @@ -981,6 +984,7 @@ typedef struct Statement { Message message; /* #error, #warn, #info */ Block *referring_to; /* for break/continue; set during typing */ struct Statement *defer; + Expression use; }; } Statement; |