void printStackDEBUG(naContext ctx);
////////////////////////////////////////////////////////////////////////
-#ifdef _MSC_VER
-#define vsnprintf _vsnprintf
-#endif
-
struct Globals* globals = 0;
static naRef bindFunction(naContext ctx, struct Frame* f, naRef code);
args += c->nOptArgs;
if(c->needArgVector || nargs > 0) {
naRef argv = naNewVector(ctx);
- naVec_setsize(argv, nargs > 0 ? nargs : 0);
+ naVec_setsize(ctx, argv, nargs > 0 ? nargs : 0);
for(i=0; i<nargs; i++)
PTR(argv).vec->rec->array[i] = *args++;
naiHash_newsym(PTR(f->locals).hash, &c->constants[c->restArgSym], &argv);
if(IS_VEC(l) && IS_VEC(r)) {
int i, ls = naVec_size(l), rs = naVec_size(r);
naRef v = naNewVector(ctx);
- naVec_setsize(v, ls + rs);
+ naVec_setsize(ctx, v, ls + rs);
for(i=0; i<ls; i+=1) naVec_set(v, i, naVec_get(l, i));
for(i=0; i<rs; i+=1) naVec_set(v, i+ls, naVec_get(r, i));
return v;
// FIXME: unify with almost identical checkVec() above
static int vbound(naContext ctx, naRef v, naRef ir, int end)
{
- int i = IS_NIL(ir) ? (end ? -1 : 0) : numify(ctx, ir);
- if(i < 0) i += naVec_size(v);
- if(i < 0 || i >= naVec_size(v))
+ int sz=naVec_size(v), i = IS_NIL(ir) ? (end ? -1 : 0) : numify(ctx, ir);
+ if(IS_NIL(ir) && !sz) return i;
+ if(i < 0) i += sz;
+ if(i < 0 || i >= sz)
naRuntimeError(ctx, "slice index %d out of bounds (size: %d)",
- i, naVec_size(v));
+ i, sz);
return i;
}
static void evalSlice(naContext ctx, naRef src, naRef dst, naRef idx)
{
if(!IS_VEC(src)) ERR(ctx, "cannot slice non-vector");
- naVec_append(dst, naVec_get(src, vbound(ctx, src, idx, 0)));
+ naVec_append(dst, naVec_get(src, checkVec(ctx, src, idx)));
}
static void evalSlice2(naContext ctx, naRef src, naRef dst,