diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2020-07-13 23:08:11 -0400 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2020-07-13 23:08:11 -0400 |
commit | 2ef832fb45f7044f64746bdb422a4dfac20cefe9 (patch) | |
tree | 9c1fa2e2f7ce10ffecbe70766cc5e90c3aba5a61 | |
parent | 28de7a9c80524aac38a985ede651e782985bde67 (diff) |
fixing some problems with eval
-rw-r--r-- | eval.c | 4 | ||||
-rw-r--r-- | main.c | 1 | ||||
-rw-r--r-- | types.c | 7 |
3 files changed, 12 insertions, 0 deletions
@@ -594,6 +594,10 @@ static void eval_deref_set(void *set, Value *to, Type *type) { } static Status eval_val_ptr_at_index(Location where, void *arr_ptr, U64 i, Type *arr_type, void **ptr, Type **type) { + if (arr_type->kind == TYPE_PTR) { + arr_type = arr_type->ptr; + arr_ptr = *(void **)arr_ptr; + } switch (arr_type->kind) { case TYPE_ARR: { U64 arr_sz = (U64)arr_type->arr->n; @@ -9,6 +9,7 @@ see development.md for development information @TODO: see note in types.c : we probably shouldn't go to the trouble of evaluating this (just do this stuff if it's an ident) +ensure that in s[a:b] s is an l-value figure out how printf is gonna work make error when you give too few arguments better when putf is done, migrate tests to new std @@ -2792,6 +2792,13 @@ static Status types_expr(Typer *tr, Expression *e) { if (lhs_type->kind == TYPE_PTR) { lhs_type = lhs_type->ptr; } + + // in order to index an array, we need a pointer to it + if (lhs_type->kind == TYPE_ARR && !expr_must_lval(lhs, "access an index of")) { + info_print(lhs->where, "Maybe try extracting this into a variable."); + return false; + } + switch (lhs_type->kind) { case TYPE_ARR: *t = *lhs_type->arr->of; |