bi_emptyHVec, actually fix !GS_REALLOC
This commit is contained in:
parent
6c349fc3ed
commit
8ed4019edf
2
src/h.h
2
src/h.h
@ -393,7 +393,7 @@ TypeInfo ti[t_COUNT];
|
||||
#define TI(x) (ti[v(x)->type])
|
||||
|
||||
|
||||
B bi_N, bi_noVar, bi_badHdr, bi_optOut, bi_noFill;
|
||||
B bi_N, bi_noVar, bi_badHdr, bi_optOut, bi_noFill, bi_emptyHVec;
|
||||
|
||||
void do_nothing(B x) { }
|
||||
bool isNothing(B b) { return b.u==bi_N.u; }
|
||||
|
||||
@ -174,4 +174,6 @@ static inline void harr_init() {
|
||||
ti[t_harr].print = arr_print; ti[t_hslice].print = arr_print; ti[t_harrPartial].print = harrP_print;
|
||||
ti[t_harr].isArr = true; ti[t_hslice].isArr = true;
|
||||
ti[t_harr].canStore = harr_canStore;
|
||||
bi_emptyHVec = m_harrUv(0).b;
|
||||
gc_add(bi_emptyHVec);
|
||||
}
|
||||
|
||||
@ -167,13 +167,12 @@ B sys_c1(B t, B x) {
|
||||
for (; i < a(x)->ia; i++) {
|
||||
B c = xgetU(x,i);
|
||||
if (eqStr(c, U"internal")) r.a[i] = inc(bi_internal);
|
||||
else if (eqStr(c, U"eq")) r.a[i] = inc(bi_feq);
|
||||
else if (eqStr(c, U"decompose")) r.a[i] = inc(bi_decp);
|
||||
else if (eqStr(c, U"primind")) r.a[i] = inc(bi_primInd);
|
||||
else if (eqStr(c, U"type")) r.a[i] = inc(bi_type);
|
||||
else if (eqStr(c, U"out")) r.a[i] = inc(bi_out);
|
||||
else if (eqStr(c, U"show")) r.a[i] = inc(bi_show);
|
||||
else thrM("Unknown system function");
|
||||
else { dec(x); thrM("Unknown system function"); }
|
||||
}
|
||||
return harr_fcd(r, x);
|
||||
}
|
||||
|
||||
32
src/vm.c
32
src/vm.c
@ -290,6 +290,18 @@ void gsAdd(B x) {
|
||||
B gsPop() {
|
||||
return *--gStack;
|
||||
}
|
||||
void gsPrint() {
|
||||
B* c = gStackStart;
|
||||
i32 i = 0;
|
||||
while (c!=gStack) {
|
||||
printf("%d: ", i);
|
||||
print(*c);
|
||||
printf(", refc=%d\n", v(*c)->refc);
|
||||
c++;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
B evalBC(Body* b, Scope* sc) { // doesn't consume
|
||||
#ifdef DEBUG_VM
|
||||
bcDepth+= 2;
|
||||
@ -359,11 +371,17 @@ B evalBC(Body* b, Scope* sc) { // doesn't consume
|
||||
}
|
||||
case ARRO: case ARRM: {
|
||||
i32 sz = *bc++;
|
||||
HArr_p r = m_harrUv(sz);
|
||||
bool allNum = true;
|
||||
for (i32 i = 0; i < sz; i++) if (!isNum(r.a[sz-i-1] = POP)) allNum = false;
|
||||
GS_UPD;
|
||||
ADD(allNum && sz? withFill(r.b, m_f64(0)) : r.b);
|
||||
if (sz==0) {
|
||||
ADD(inc(bi_emptyHVec));
|
||||
} else {
|
||||
HArr_p r = m_harrUv(sz);
|
||||
bool allNum = true;
|
||||
for (i32 i = 0; i < sz; i++) if (!isNum(r.a[sz-i-1] = POP)) allNum = false;
|
||||
if (allNum) {
|
||||
GS_UPD;
|
||||
ADD(withFill(r.b, m_f64(0)));
|
||||
} else ADD(r.b);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case DFND: {
|
||||
@ -428,7 +446,9 @@ B evalBC(Body* b, Scope* sc) { // doesn't consume
|
||||
#ifdef DEBUG_VM
|
||||
bcDepth-= 2;
|
||||
#endif
|
||||
return POP;
|
||||
B r = POP;
|
||||
GS_UPD;
|
||||
return r;
|
||||
#undef P
|
||||
#undef ADD
|
||||
#undef POP
|
||||
|
||||
Loading…
Reference in New Issue
Block a user