summaryrefslogtreecommitdiff
path: root/parse.c
diff options
context:
space:
mode:
Diffstat (limited to 'parse.c')
-rw-r--r--parse.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/parse.c b/parse.c
index f3e7efa..ec6afaa 100644
--- a/parse.c
+++ b/parse.c
@@ -51,9 +51,9 @@ typedef struct Block {
} Block;
typedef enum {
- EXPR_INT_LITERAL,
- EXPR_FLOAT_LITERAL,
- EXPR_STR_LITERAL,
+ EXPR_LITERAL_FLOAT,
+ EXPR_LITERAL_INT,
+ EXPR_LITERAL_STR,
EXPR_IDENT, /* variable or constant */
EXPR_BINARY_OP,
EXPR_UNARY_OP,
@@ -79,6 +79,12 @@ typedef struct {
Array args; /* of Expression */
} DirectExpr;
+typedef struct {
+ struct Expression *fn;
+ Array args; /* of Expression */
+ unsigned long out_var; /* which out variable is used for this call (used by cgen) */
+} CallExpr;
+
typedef struct Expression {
Location where;
ExprKind kind;
@@ -96,11 +102,7 @@ typedef struct Expression {
struct Expression *lhs;
struct Expression *rhs;
} binary;
- struct {
- struct Expression *fn;
- Array args; /* of Expression */
- unsigned long out_var; /* which out variable is used for this call (used by cgen) */
- } call;
+ CallExpr call;
DirectExpr direct;
Identifier ident;
struct FnExpr *fn;
@@ -620,9 +622,11 @@ static bool parse_expr(Parser *p, Expression *e, Token *end) {
NumLiteral *num = &t->token->num;
switch (num->kind) {
case NUM_LITERAL_FLOAT:
+ e->kind = EXPR_LITERAL_FLOAT;
e->floatl = num->floatval;
break;
case NUM_LITERAL_INT:
+ e->kind = EXPR_LITERAL_INT;
e->intl = num->intval;
break;
}
@@ -632,7 +636,7 @@ static bool parse_expr(Parser *p, Expression *e, Token *end) {
e->ident = t->token->ident;
break;
case TOKEN_STR_LITERAL:
- e->kind = EXPR_STR_LITERAL;
+ e->kind = EXPR_LITERAL_STR;
e->strl = t->token->str;
break;
default:
@@ -1217,13 +1221,13 @@ static void fprint_args(FILE *out, Array *args) {
static void fprint_expr(FILE *out, Expression *e) {
PARSE_PRINT_LOCATION(e->where);
switch (e->kind) {
- case EXPR_INT_LITERAL:
+ case EXPR_LITERAL_INT:
fprintf(out, "%lld", (long long)e->intl);
break;
- case EXPR_FLOAT_LITERAL:
+ case EXPR_LITERAL_FLOAT:
fprintf(out, "%f", (double)e->floatl);
break;
- case EXPR_STR_LITERAL:
+ case EXPR_LITERAL_STR:
fprintf(out, "\"%s\"", e->strl.str);
break;
case EXPR_IDENT: