summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2019-12-15 16:39:59 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2019-12-15 16:39:59 -0500
commitdb4f51dd64ae0f428468338af01a582aaed26fde (patch)
tree457432f217f12fb159db862b2246a4eea6f8f2db
parent7f6d17ddf505e5c3744f50e59449fc882c088b2e (diff)
got rid of parse_printing_after_types; still working on call inference
-rw-r--r--infer.c18
-rw-r--r--main.c1
-rw-r--r--parse.c32
-rw-r--r--types.c1
4 files changed, 15 insertions, 37 deletions
diff --git a/infer.c b/infer.c
index 24a1706..28b11a2 100644
--- a/infer.c
+++ b/infer.c
@@ -23,6 +23,7 @@ static bool infer_from_expr(Typer *tr, Expression *match, Expression *to, Identi
break;
case EXPR_CALL: {
if (to->kind != EXPR_CALL) return true; /* give up */
+ puts("wow call");
Argument *m_args = match->call.args;
Expression *t_args = to->call.arg_exprs;
size_t nargs = arr_len(m_args);
@@ -108,6 +109,7 @@ static bool infer_from_type(Typer *tr, Type *match, Type *to, Identifier *idents
} break;
case TYPE_EXPR: {
Expression *to_expr = to->was_expr;
+ print_type(to);
Expression e = {0};
if (!to_expr) {
to_expr = &e;
@@ -144,7 +146,7 @@ static bool infer_from_type(Typer *tr, Type *match, Type *to, Identifier *idents
match and to are dynamic arrays of equal size
idents is a dyn array of distinct identifiers
find the value of each ident by matching match[i] to to[i], i = 0..arr_len(match)-1
-all the types in match must be resolved, and all the types in to must be unresolved
+all the types in match must be unresolved, and all the types in to must be resolved
*/
static bool infer_ident_vals(Typer *tr, Type **match, Type **to, Identifier *idents, Value *vals, Type *types) {
size_t ntypes = arr_len(match);
@@ -163,20 +165,6 @@ static bool infer_ident_vals(Typer *tr, Type **match, Type **to, Identifier *ide
return false;
++match, ++to;
}
-
-
-
-#if 0 /* TODO DELME */
- Value *val = vals;
- Type *type = types;
- val->type = calloc(1,sizeof(Type));
- val->type->flags = TYPE_IS_RESOLVED;
- val->type->kind = TYPE_BUILTIN;
- val->type->builtin = BUILTIN_I64;
- type->flags = TYPE_IS_RESOLVED;
- type->kind = TYPE_TYPE;
- type->was_expr = NULL;
-#endif
return true;
}
diff --git a/main.c b/main.c
index 7a5e3db..b93c8f5 100644
--- a/main.c
+++ b/main.c
@@ -136,7 +136,6 @@ int main(int argc, char **argv) {
err_fprint(TEXT_IMPORTANT("Errors occured while determining types.\n"));
return EXIT_FAILURE;
}
- parse_printing_after_types = true;
fprint_parsed_file(stdout, &f);
FILE *out = fopen(out_filename, "w");
diff --git a/parse.c b/parse.c
index 087ae73..38447d0 100644
--- a/parse.c
+++ b/parse.c
@@ -778,9 +778,10 @@ static bool parser_is_definitely_type(Parser *p, Token **end) {
}
static bool parse_block(Parser *p, Block *b) {
- b->flags = 0;
Tokenizer *t = p->tokr;
Block *prev_block = p->block;
+ b->flags = 0;
+ b->ret_expr = NULL;
p->block = b;
if (!token_is_kw(t->token, KW_LBRACE)) {
tokr_err(t, "Expected '{' to open block.");
@@ -1952,9 +1953,6 @@ static bool parse_file(Parser *p, ParsedFile *f) {
#define PARSE_PRINT_LOCATION(l) /* fprintf(out, "[l%lu]", (unsigned long)(l).line); */
-/* in theory, this shouldn't be global, but these functions are mostly for debugging anyways */
-static bool parse_printing_after_types;
-
static void fprint_expr(FILE *out, Expression *e);
static void fprint_stmt(FILE *out, Statement *s);
static void fprint_decl(FILE *out, Declaration *d);
@@ -1978,7 +1976,7 @@ static void fprint_block(FILE *out, Block *b) {
fprint_stmt(out, stmt);
}
fprintf(out, "}");
- if (parse_printing_after_types && b->ret_expr) {
+ if (b->ret_expr) {
fprintf(out, " returns ");
fprint_expr(out, b->ret_expr);
}
@@ -1986,10 +1984,6 @@ static void fprint_block(FILE *out, Block *b) {
}
static void fprint_fn_expr(FILE *out, FnExpr *f) {
- bool anyc = fn_has_any_const_params(f);
- bool prev = parse_printing_after_types;
- if (anyc)
- parse_printing_after_types = false;
fprintf(out, "fn (");
arr_foreach(f->params, Declaration, decl) {
if (decl != f->params)
@@ -2000,8 +1994,6 @@ static void fprint_fn_expr(FILE *out, FnExpr *f) {
fprint_type(out, &f->ret_type);
fprintf(out, " ");
fprint_block(out, &f->body);
- if (anyc)
- parse_printing_after_types = prev;
}
static void fprint_args(FILE *out, Argument *args) {
@@ -2030,6 +2022,7 @@ static void fprint_val(FILE *f, Value v, Type *t);
static void fprint_expr(FILE *out, Expression *e) {
PARSE_PRINT_LOCATION(e->where);
+ bool found_type = (e->flags & EXPR_FOUND_TYPE) != 0;
switch (e->kind) {
case EXPR_LITERAL_INT:
fprintf(out, "%lld", (long long)e->intl);
@@ -2050,17 +2043,10 @@ static void fprint_expr(FILE *out, Expression *e) {
fprint_ident(out, e->ident);
break;
case EXPR_BINARY_OP: {
- bool prev = parse_printing_after_types;
fprintf(out, "(");
fprint_expr(out, e->binary.lhs);
fprintf(out, ")%s(", binary_op_to_str(e->binary.op));
- if (e->binary.op == BINARY_DOT) {
- parse_printing_after_types = false; /* don't show types for rhs of . */
- }
fprint_expr(out, e->binary.rhs);
- if (e->binary.op == BINARY_DOT) {
- parse_printing_after_types = prev;
- }
fprintf(out, ")");
} break;
case EXPR_UNARY_OP:
@@ -2115,7 +2101,7 @@ static void fprint_expr(FILE *out, Expression *e) {
fprintf(out, "= ");
if (ea->flags & EACH_IS_RANGE) {
fprint_expr(out, ea->range.from);
- if (parse_printing_after_types) {
+ if (found_type) {
if (ea->range.stepval) {
fprintf(out, ",");
fprint_val(out, *ea->range.stepval, &ea->type);
@@ -2138,7 +2124,7 @@ static void fprint_expr(FILE *out, Expression *e) {
} break;
case EXPR_CALL:
fprint_expr(out, e->call.fn);
- if (parse_printing_after_types) {
+ if (found_type) {
fprint_arg_exprs(out, e->call.arg_exprs);
} else {
fprint_args(out, e->call.args);
@@ -2186,12 +2172,16 @@ static void fprint_expr(FILE *out, Expression *e) {
fprint_val(out, e->val, &e->type);
break;
}
- if (parse_printing_after_types) {
+ if (found_type) {
fprintf(out, ":");
fprint_type(out, &e->type);
}
}
+static void print_expr(Expression *e) {
+ fprint_expr(stdout, e);
+ printf("\n");
+}
static void fprint_decl(FILE *out, Declaration *d) {
PARSE_PRINT_LOCATION(d->where);
diff --git a/types.c b/types.c
index 6bdf9fa..8a097f7 100644
--- a/types.c
+++ b/types.c
@@ -501,6 +501,7 @@ static bool type_resolve(Typer *tr, Type *t, Location where) {
Value typeval;
if (!types_expr(tr, t->expr))
return false;
+ print_expr(t->expr);
t->was_expr = t->expr;
if (!eval_expr(tr->evalr, t->expr, &typeval))
return false;