toCells, throw stack overflows
This commit is contained in:
parent
d8751e709f
commit
9bdacbbd7d
3
src/h.h
3
src/h.h
@ -204,7 +204,7 @@ B mm_alloc(usz sz, u8 type, u64 tag) {
|
||||
return b((u64)mm_allocN(sz,type) | tag);
|
||||
}
|
||||
|
||||
void gsAdd(B x);
|
||||
void gsAdd(B x); // may throw
|
||||
B gsPop();
|
||||
|
||||
// some primitive actions
|
||||
@ -221,6 +221,7 @@ u8 fillElType(B x); // doesn't consume
|
||||
bool eqShape(B w, B x); // doesn't consume
|
||||
usz arr_csz(B x); // doesn't consume
|
||||
bool atomEqual(B w, B x); // doesn't consume
|
||||
B toCells(B x); // consumes
|
||||
bool eqShPrefix(usz* w, usz* x, ur len);
|
||||
|
||||
B m_v1(B a ); // consumes all
|
||||
|
||||
17
src/harr.c
17
src/harr.c
@ -71,6 +71,23 @@ B m_hunit(B x) {
|
||||
r.a[0] = x;
|
||||
return r.b;
|
||||
}
|
||||
B toCells(B x) {
|
||||
assert(isArr(x) && rnk(x)>1);
|
||||
usz cam = a(x)->sh[0];
|
||||
usz csz = arr_csz(x);
|
||||
usz i = 0;
|
||||
HArr_p r = m_harrs(cam, &i);
|
||||
BS2B slice = TI(x).slice;
|
||||
usz p = 0;
|
||||
for (; i < cam; i++) {
|
||||
B s = slice(inc(x), p);
|
||||
arr_shVec(s, csz);
|
||||
r.a[i] = s;
|
||||
p+= csz;
|
||||
}
|
||||
dec(x);
|
||||
return harr_fv(r);
|
||||
}
|
||||
|
||||
|
||||
B* harr_ptr(B x) { VT(x,t_harr); return c(HArr,x)->a; }
|
||||
|
||||
8
src/vm.c
8
src/vm.c
@ -313,7 +313,7 @@ void gsReserve(u64 am) {
|
||||
gStackEnd = gStackStart+n;
|
||||
}
|
||||
#elif DEBUG
|
||||
if (am>gStackEnd-gStack) err("stack overflow");
|
||||
if (am>gStackEnd-gStack) thrM("Stack overflow");
|
||||
#endif
|
||||
}
|
||||
#ifdef GS_REALLOC
|
||||
@ -323,8 +323,8 @@ void gsReserveR(u64 am) { gsReserve(am); }
|
||||
void gsAdd(B x) {
|
||||
#ifdef GS_REALLOC
|
||||
if (gStack==gStackEnd) gsReserveR(1);
|
||||
#elif DEBUG
|
||||
if (gStack==gStackEnd) err("early stack overflow");
|
||||
#else
|
||||
if (gStack==gStackEnd) thrM("Stack overflow");
|
||||
#endif
|
||||
*(gStack++) = x;
|
||||
}
|
||||
@ -355,7 +355,7 @@ Env* envStart;
|
||||
Env* envEnd;
|
||||
|
||||
static inline void pushEnv(Scope* sc, i32** bc) {
|
||||
if (envCurr==envEnd) thrM("stack overflow");
|
||||
if (envCurr==envEnd) thrM("Stack overflow");
|
||||
envCurr->sc = sc;
|
||||
#if VM_POS
|
||||
envCurr->bcP = bc;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user