From 2ef832fb45f7044f64746bdb422a4dfac20cefe9 Mon Sep 17 00:00:00 2001 From: Leo Tenenbaum Date: Mon, 13 Jul 2020 23:08:11 -0400 Subject: fixing some problems with eval --- eval.c | 4 ++++ main.c | 1 + types.c | 7 +++++++ 3 files changed, 12 insertions(+) diff --git a/eval.c b/eval.c index 9c55a06..f0b53b9 100644 --- a/eval.c +++ b/eval.c @@ -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; diff --git a/main.c b/main.c index 4934520..78e79a9 100644 --- a/main.c +++ b/main.c @@ -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 diff --git a/types.c b/types.c index 52ea5e0..166bda0 100644 --- a/types.c +++ b/types.c @@ -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; -- cgit v1.2.3