summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2020-03-21 14:23:11 -0400
committerLeo Tenenbaum <pommicket@gmail.com>2020-03-21 14:23:11 -0400
commit54f2ec8827cca60d1f31b50a60f23c6e107a0fe4 (patch)
tree985ce9358d1d949aa75aace0d1eb0215a4d63ef8
parent8d465df791f8dfe2d90bd885237301712ca62919 (diff)
started use
-rw-r--r--cgen.c3
-rw-r--r--copy.c3
-rw-r--r--decls_cgen.c6
-rw-r--r--eval.c2
-rw-r--r--main.c2
-rw-r--r--parse.c11
-rw-r--r--types.h16
7 files changed, 36 insertions, 7 deletions
diff --git a/cgen.c b/cgen.c
index 3554699..8a06c57 100644
--- a/cgen.c
+++ b/cgen.c
@@ -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;
}
}
diff --git a/copy.c b/copy.c
index a68b6e5..7bc26e2 100644
--- a/copy.c
+++ b/copy.c
@@ -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;
}
}
diff --git a/eval.c b/eval.c
index 48a324c..b98b898 100644
--- a/eval.c
+++ b/eval.c
@@ -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;
}
diff --git a/main.c b/main.c
index 134d86e..d60b10d 100644
--- a/main.c
+++ b/main.c
@@ -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
diff --git a/parse.c b/parse.c
index 1e29129..8c11bb5 100644
--- a/parse.c
+++ b/parse.c
@@ -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;
}
}
diff --git a/types.h b/types.h
index 132a92f..195c97e 100644
--- a/types.h
+++ b/types.h
@@ -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;