diff --git a/HISTORY b/HISTORY index 5f72bf7..9aac08e 100755 --- a/HISTORY +++ b/HISTORY @@ -1,5 +1,6 @@ Feb. 25 2016 Fixed a bug with the END and RETURN statement with FOR loop +Fixed an array index calculation bug Feb. 24 2016 Added a TO_ARRAY statement diff --git a/core/my_basic.c b/core/my_basic.c index 897a726..341f7c4 100755 --- a/core/my_basic.c +++ b/core/my_basic.c @@ -5807,6 +5807,7 @@ static int _get_array_pos(mb_interpreter_t* s, _array_t* arr, int* d, int c) { int result = 0; int i = 0; int n = 0; + int f = 1; mb_assert(s && arr && d); @@ -5822,10 +5823,8 @@ static int _get_array_pos(mb_interpreter_t* s, _array_t* arr, int* d, int c) { goto _exit; } - if(result) - result *= n; - else - result += n; + result += n * f; + f *= arr->dimensions[i]; } _exit: @@ -5842,6 +5841,7 @@ static int _get_array_index(mb_interpreter_t* s, _ls_node_t** l, _object_t* c, u _object_t* subscript_ptr = 0; mb_value_u val; int dcount = 0; + int f = 1; unsigned int idx = 0; mb_assert(s && l && index); @@ -5898,14 +5898,12 @@ static int _get_array_index(mb_interpreter_t* s, _ls_node_t** l, _object_t* c, u if((int)val.integer >= arr->data.array->dimensions[dcount]) { _handle_error_on_obj(s, SE_RN_ARRAY_OUT_OF_BOUND, s->source_file, DON(ast), MB_FUNC_ERR, _exit, result); } - if(idx) - idx *= (unsigned int)val.integer; - else - idx += (unsigned int)val.integer; + idx += (unsigned int)val.integer * f; /* Comma? */ if(_IS_SEP(ast->data, ',')) ast = ast->next; + f *= arr->data.array->dimensions[dcount]; ++dcount; } *index = idx; diff --git a/output/my_basic.exe b/output/my_basic.exe index fca3cb3..57f9e25 100755 Binary files a/output/my_basic.exe and b/output/my_basic.exe differ