Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
2018-02-03 (0.12.12)
COMMON: restore 6d array handling
COMMON: increase default stack size

2018-01-13 (0.12.12)
Fix osx crash

2017-11-28 (0.12.11)
Fix img.save(dat) to build correct indexes
Fix ESCm implementation bug
Expand Down
4 changes: 2 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
dnl
dnl Configure script for SmallBASIC
dnl
dnl Copyright(C) 2001-2016 Chris Warren-Smith.
dnl Copyright(C) 2001-2018 Chris Warren-Smith.
dnl
dnl This program is distributed under the terms of the GPL v2.0
dnl Download the GNU Public License (GPL) from www.gnu.org
dnl

AC_INIT([smallbasic], [0.12.11])
AC_INIT([smallbasic], [0.12.12])
AC_CONFIG_SRCDIR([configure.ac])

AC_CANONICAL_TARGET
Expand Down
5 changes: 5 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
smallbasic (0.12.12) unstable; urgency=low
* Various see web site

-- Chris Warren-Smith <cwarrensmith@gmail.com> Sat, 13 Jan 2018 09:45:25 +1000

smallbasic (0.12.11) unstable; urgency=low
* Various see web site

Expand Down
4 changes: 2 additions & 2 deletions ide/android/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.sourceforge.smallbasic"
android:installLocation="preferExternal"
android:versionCode="26"
android:versionName="0.12.11">
android:versionCode="27"
android:versionName="0.12.12">
<uses-sdk android:minSdkVersion="15"/>

<!-- support large + xlarge screens to avoid compatibility mode -->
Expand Down
20 changes: 20 additions & 0 deletions samples/distro-examples/tests/array.bas
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,23 @@ camera = {
if (camera.x != 512) then throw "invalid x"
if (camera.height != 78) then throw "invalid height"
if (camera.distance != 800) then throw "invalid distance"

rem --- 6d arrays
dim a6d(0 to 5, 0 to 5, 0 to 5, 0 to 5, 0 to 5, 4 to 5)
a6d(0,1,2,3,4,5)=99
if (a6d(0,1,2,3,4,5) <> 99) then
throw "a6d error 1"
endif
dim m(1 to 11, 2 to 12, 3 to 13, 4 to 14, 5 to 15, 6 to 16)
for i = 1 to 6
if (lbound(m,i) != i) then
throw "lbound error"
endif
if (ubound(m,i) != 10+i) then
throw "ubound error"
endif
next i
m[1,2,3,4,5,6]=999
if (999 <> m[1,2,3,4,5,6]) then
throw "e"
endif
1 change: 0 additions & 1 deletion src/common/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ libsb_common_a_SOURCES = \
blib_sound.c \
brun.c \
ceval.c \
decomp.c \
device.c device.h \
screen.c \
system.c \
Expand Down
191 changes: 102 additions & 89 deletions src/common/blib.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,62 @@ void cmd_packed_let() {
}
}

uint8_t get_dimensions(int32_t **lbound, int32_t **ubound) {
uint8_t count = 0;
if (code_peek() == kwTYPE_LEVEL_BEGIN) {
code_skipnext();
while (code_peek() != kwTYPE_LEVEL_END && !prog_error) {
if (count == MAXDIM) {
err_matdim();
break;
}
var_t arg;
v_init(&arg);
eval(&arg);
if (prog_error) {
break;
}
int dim = v_getint(&arg);
v_free(&arg);

if (count) {
// allocate for extra dimension
*lbound = (int32_t *)realloc(*lbound, (sizeof(int32_t) * (count + 1)));
*ubound = (int32_t *)realloc(*ubound, (sizeof(int32_t) * (count + 1)));
} else {
// allocate for first dimension
*lbound = (int32_t *)malloc(sizeof(int32_t));
*ubound = (int32_t *)malloc(sizeof(int32_t));
}

if (code_peek() == kwTO) {
(*lbound)[count] = dim;
code_skipnext();
eval(&arg);
(*ubound)[count] = v_getint(&arg);
v_free(&arg);
} else {
(*lbound)[count] = opt_base;
(*ubound)[count] = dim;
}

count++;

// skip separator
if (code_peek() == kwTYPE_SEP) {
code_skipnext();
if (code_getnext() != ',') {
err_missing_comma();
break;
}
}
}
// skip end separator
code_skipnext();
}
return count;
}

/**
* DIM var([lower TO] uppper [, ...])
*/
Expand All @@ -131,95 +187,52 @@ void cmd_dim(int preserve) {
byte code = code_peek();
if (code == kwTYPE_LINE || code == kwTYPE_EOC) {
exitf = 1;
} else {
var_t array;
array.v.a.maxdim = 0;
if (code_peek() == kwTYPE_SEP) {
code_skipnext();
if (code_getnext() != ',') {
err_missing_comma();
}
break;
}
if (code_peek() == kwTYPE_SEP) {
code_skipnext();
if (code_getnext() != ',') {
err_missing_comma();
break;
}
}

var_t *var_p = code_getvarptr_parens(1);
byte zero_length = 1;
var_t *var_p = code_getvarptr_parens(1);
if (prog_error) {
break;
}

if (!prog_error) {
if (code_peek() == kwTYPE_LEVEL_BEGIN) {
code_skipnext();
while (code_peek() != kwTYPE_LEVEL_END) {
zero_length = 0;
var_t arg;
v_init(&arg);
eval(&arg);
if (prog_error) {
return;
}
if (code_peek() == kwTO) {
array.v.a.lbound[array.v.a.maxdim] = v_getint(&arg);
code_skipnext();
eval(&arg);
if (prog_error) {
return;
}
array.v.a.ubound[array.v.a.maxdim] = v_getint(&arg);
} else {
array.v.a.lbound[array.v.a.maxdim] = opt_base;
array.v.a.ubound[array.v.a.maxdim] = v_getint(&arg);
}
v_free(&arg);
array.v.a.maxdim++;

// skip separator
if (code_peek() == kwTYPE_SEP) {
code_skipnext();
if (code_getnext() != ',') {
err_missing_comma();
}
}
}
// skip end separator
code_skipnext();
} else {
zero_length = 1;
}
} else {
rt_raise(ERR_SYNTAX);
int32_t *lbound = NULL;
int32_t *ubound = NULL;
uint8_t dimensions = get_dimensions(&lbound, &ubound);
if (!prog_error) {
if (!preserve || var_p->type != V_ARRAY) {
v_free(var_p);
}

//
// run...
//
if (!prog_error) {
if (zero_length) {
v_toarray1(var_p, 0);
} else {
int i;
int size = 1;
for (i = 0; i < array.v.a.maxdim; i++) {
size = size * (ABS(array.v.a.ubound[i] - array.v.a.lbound[i]) + 1);
}
if (!preserve) {
v_toarray1(var_p, size);
} else {
if (var_p->type == V_ARRAY) {
v_resize_array(var_p, size);
} else {
v_toarray1(var_p, size);
}
}

// dim
var_p->v.a.maxdim = array.v.a.maxdim;
for (i = 0; i < array.v.a.maxdim; i++) {
var_p->v.a.lbound[i] = array.v.a.lbound[i];
var_p->v.a.ubound[i] = array.v.a.ubound[i];
}
}
if (!dimensions) {
v_toarray1(var_p, 0);
continue;
}
uint32_t size = 1;
for (int i = 0; i < dimensions; i++) {
size = size * (ABS(ubound[i] - lbound[i]) + 1);
}
if (!preserve || var_p->type != V_ARRAY) {
v_new_array(var_p, size);
} else if (v_maxdim(var_p) != dimensions) {
err_matdim();
} else {
exitf = 1;
// preserve previous array contents
v_resize_array(var_p, size);
}
v_maxdim(var_p) = dimensions;
for (int i = 0; i < dimensions; i++) {
v_lbound(var_p, i) = lbound[i];
v_ubound(var_p, i) = ubound[i];
}
}
free(lbound);
free(ubound);
} while (!exitf && !prog_error);
}

Expand Down Expand Up @@ -328,7 +341,7 @@ void cmd_lins() {
if (prog_error) {
return;
}
idx -= var_p->v.a.lbound[0];
idx -= v_lbound(var_p, 0);

par_getcomma();
if (prog_error) {
Expand Down Expand Up @@ -412,7 +425,7 @@ void cmd_ldel() {
if (prog_error) {
return;
}
idx -= var_p->v.a.lbound[0];
idx -= v_lbound(var_p, 0);
if ((idx >= size) || (idx < 0)) {
err_out_of_range();
return;
Expand Down Expand Up @@ -513,7 +526,7 @@ void cmd_print(int output) {
byte last_op = 0;
byte exitf = 0;
byte use_format = 0;
int handle = 0;
intptr_t handle = 0;
var_t var;

// prefix - # (file)
Expand Down Expand Up @@ -654,7 +667,7 @@ void cmd_input(int input) {
byte print_crlf = 1;
var_t prompt;
var_t *vuser_p = NULL;
int handle = 0;
intptr_t handle = 0;
char *inps = NULL;

v_init(&prompt);
Expand Down Expand Up @@ -2520,7 +2533,7 @@ void cmd_sort() {
if (!errf) {
if (v_asize(var_p) > 1) {
static_qsort_last_use_ip = use_ip;
qsort(var_p->v.a.data, v_asize(var_p), sizeof(var_t), qs_cmp);
qsort(v_data(var_p), v_asize(var_p), sizeof(var_t), qs_cmp);
}
}
// NO RTE anymore... there is no meaning on this because of empty
Expand Down Expand Up @@ -2585,12 +2598,12 @@ void cmd_search() {
}
// search
if (!errf) {
rv_p->v.i = var_p->v.a.lbound[0] - 1;
rv_p->v.i = v_lbound(var_p, 0) - 1;
for (int i = 0; i < v_asize(var_p); i++) {
var_t *elem_p = v_elem(var_p, i);
int bcmp = sb_qcmp(elem_p, &vkey, use_ip);
if (bcmp == 0) {
rv_p->v.i = i + var_p->v.a.lbound[0];
rv_p->v.i = i + v_lbound(var_p, 0);
break;
}
}
Expand Down
Loading