aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2024-04-27 00:09:48 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2024-04-27 00:09:48 +0300
commit515ad657ec6ef685c9c91479540518a0091f1516 (patch)
tree68b5ae0e8d83bcc7bd1bd6b84648780729e20f9b /src
parent966f97ad7c92f559ae54d0214db90c370e3b48eb (diff)
downloadposthaste-515ad657ec6ef685c9c91479540518a0091f1516.tar.gz
posthaste-515ad657ec6ef685c9c91479540518a0091f1516.zip
documentation
Diffstat (limited to 'src')
-rw-r--r--src/check.c20
-rw-r--r--src/lower.c3
2 files changed, 16 insertions, 7 deletions
diff --git a/src/check.c b/src/check.c
index 85e5459..0858c67 100644
--- a/src/check.c
+++ b/src/check.c
@@ -216,6 +216,12 @@ static int analyze_formal_def(struct state *state, struct scope *scope,
if (analyze_type(scope, n))
return -1;
+ if (!concrete_type(n->t)) {
+ semantic_error(scope, n, "illegal type for formal parameter: %s",
+ type_str(n->t));
+ return -1;
+ }
+
if (scope_add_formal(scope, n))
return -1;
@@ -653,7 +659,7 @@ static int analyze_proc_call(struct state *state, struct scope *scope,
foreach_node(a, args) {
if (a->t != formal->t) {
- semantic_error(scope, c, "expected %s, got %s",
+ semantic_error(scope, a, "expected %s, got %s",
type_str(formal->t), type_str(a->t));
return -1;
}
@@ -723,9 +729,9 @@ static int analyze_until(struct state *state, struct scope *scope,
if (analyze(state, until_scope, cond))
return -1;
- if (cond->t != TYPE_BOOL) {
- semantic_error(scope, cond, "expected %s, got %s",
- type_str(TYPE_BOOL), type_str(cond->t));
+ if (cond->t != TYPE_BOOL && cond->t != TYPE_INT) {
+ semantic_error(scope, cond, "expected truthy type, got %s",
+ type_str(cond->t));
return -1;
}
@@ -749,9 +755,9 @@ static int analyze_unless(struct state *state, struct scope *scope,
if (analyze(state, scope, cond))
return -1;
- if (cond->t != TYPE_BOOL) {
- semantic_error(scope, cond, "expected %s, got %s",
- type_str(TYPE_BOOL), type_str(cond->t));
+ if (cond->t != TYPE_BOOL && cond->t != TYPE_INT) {
+ semantic_error(scope, cond, "expected truthy type, got %s",
+ type_str(cond->t));
return -1;
}
diff --git a/src/lower.c b/src/lower.c
index 1949bd5..af9f9d4 100644
--- a/src/lower.c
+++ b/src/lower.c
@@ -605,6 +605,9 @@ static void lower_global_var(struct fn *f, struct ast *n) {
static void add_proc(struct ast *n) {
size_t idx = vec_len(&fns);
+ /* global locs are effectively just indexes, so this is a nifty way to
+ * encode the procedure index into the AST for later use by
+ * lower_proc_call and so on */
n->l = build_global_loc(idx);
struct fn f = {.name = proc_id(n),
.idx = idx,