inline objects

This commit is contained in:
dzaima 2021-05-28 01:03:29 +03:00
parent a0ec9c02c9
commit 1b89661308
2 changed files with 14 additions and 10 deletions

View File

@ -54,13 +54,13 @@ void gc_visitRoots() {
} }
u64 gc_lastAlloc; u64 gc_lastAlloc;
void gc_forceGC() { void gc_forceGC() {
#ifdef ENABLE_GC
#ifdef LOG_GC #ifdef LOG_GC
u64 start = nsTime(); u64 start = nsTime();
gc_visitBytes = 0; gc_freedBytes = 0; gc_visitBytes = 0; gc_freedBytes = 0;
gc_visitCount = 0; gc_freedCount = 0; gc_visitCount = 0; gc_freedCount = 0;
u64 startAllocB = allocB; u64 startAllocB = allocB;
#endif #endif
#ifdef ENABLE_GC
gc_visitRoots(); gc_visitRoots();
mm_forHeap(gc_tryFree); mm_forHeap(gc_tryFree);
gc_tagNew = gc_tagCurr; gc_tagNew = gc_tagCurr;

View File

@ -165,10 +165,12 @@ Block* compileBlock(B block, Comp* comp, bool* bDone, i32* bc, usz bcIA, B block
i32* n = nextBC(c); i32* n = nextBC(c);
if (n-bc-1 >= bcIA) thrM("VM compiler: No RETN/RETD found before end of bytecode"); if (n-bc-1 >= bcIA) thrM("VM compiler: No RETN/RETD found before end of bytecode");
bool ret = false; bool ret = false;
#define A64(X) { u64 a64=(X); TSADD(nBCT, (u32)a64); TSADD(nBCT, a64>>32); }
switch (*c) { switch (*c) {
case PUSH: case PUSH:
TSADD(nBCT, isVal(comp->objs->a[c[1]])? ADDI : ADDU); B obj = comp->objs->a[c[1]];
TSADD(nBCT, c[1]); TSADD(nBCT, isVal(obj)? ADDI : ADDU);
A64(obj.u);
break; break;
case RETN: if(h!=1) thrM("VM compiler: Wrong stack size before RETN"); case RETN: if(h!=1) thrM("VM compiler: Wrong stack size before RETN");
TSADD(nBCT, RETN); TSADD(nBCT, RETN);
@ -412,6 +414,7 @@ B evalBC(Body* b, Scope* sc) { // doesn't consume
#define ADD(X) { *(lgStack++) = X; } // fine, as, if an error occurs, lgStack is ignored anyways #define ADD(X) { *(lgStack++) = X; } // fine, as, if an error occurs, lgStack is ignored anyways
#define GS_UPD { gStack = lgStack; } #define GS_UPD { gStack = lgStack; }
#endif #endif
#define L64 ({ u64 r = (u32)bc[0] | ((u64)(u32)bc[1])<<32; bc+= 2; r; })
#if VM_POS #if VM_POS
#define POS_UPD (envCurr-1)->bcL = bc-1; #define POS_UPD (envCurr-1)->bcL = bc-1;
#else #else
@ -436,13 +439,13 @@ B evalBC(Body* b, Scope* sc) { // doesn't consume
break; break;
} }
case ADDI: { case ADDI: {
B o = objs[*bc++]; B o = b(L64);
ptr_inc(v(o)); ptr_inc(v(o));
ADD(o); ADD(o);
break; break;
} }
case ADDU: { case ADDU: {
ADD(objs[*bc++]); ADD(b(L64));
break; break;
} }
case FN1C: { P(f)P(x) case FN1C: { P(f)P(x)
@ -585,6 +588,7 @@ B evalBC(Body* b, Scope* sc) { // doesn't consume
GS_UPD; GS_UPD;
popEnv(); popEnv();
return r; return r;
#undef L64
#undef P #undef P
#undef ADD #undef ADD
#undef POP #undef POP