ref: 11fd8f604dd6f75a66540ddda149bbc860811550
parent: d857c97435a6da3d727f04bb7a038476d238e913
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Thu Feb 13 22:08:03 EST 2025
vm: apply_cl: remove most of the function-local variables - prefer op-local ones instead
--- a/src/flisp.c
+++ b/src/flisp.c
@@ -864,38 +864,22 @@
apply_cl(uint32_t nargs)
{
uint32_t top_frame = FL(curr_frame);
- uint32_t n, bp;
- const uint8_t *ip;
- fixnum_t s, hi;
+ uint32_t n;
bool tail;
- // temporary variables (not necessary to preserve across calls)
- size_t isz;
- uint32_t i, ipd;
- symbol_t *sym;
- cons_t *c;
- value_t *pv, v, e;
- function_t *fn;
- int64_t i64;
- int x;
+apply_cl_top:;
+ uint32_t bp = FL(sp)-nargs;
+ function_t *fn = (function_t*)ptr(FL(stack)[bp-1]);
+ const uint8_t *ip = cvalue_data(fn->bcode);
+ assert(!ismanaged((uintptr_t)ip));
- n = 0;
- v = 0;
- USED(n);
- USED(v);
-apply_cl_top:
- i = FL(sp)+5+2;
- while(i >= FL(nstack))
+ if(FL(sp)+5+2 >= FL(nstack))
fl_grow_stack();
- bp = FL(sp)-nargs;
- fn = (function_t*)ptr(FL(stack)[bp-1]);
- ip = cvalue_data(fn->bcode);
- assert(!ismanaged((uintptr_t)ip));
PUSH(fn->env);
PUSH(FL(curr_frame));
PUSH(nargs);
- ipd = FL(sp)++;
+ uint32_t ipd = FL(sp)++;
FL(curr_frame) = FL(sp);
#if defined(COMPUTED_GOTO)
--- a/src/vm.inc
+++ b/src/vm.inc
@@ -9,7 +9,7 @@
PUSH(FL(stack)[bp]);
NEXT_OP;
-OP(OP_TCALLL)
+OP(OP_TCALLL) {
tail = true;
if(0){
OP(OP_CALLL)
@@ -28,12 +28,12 @@
}
LABEL(do_call):
FL(stack)[ipd] = (uintptr_t)ip;
- v = FL(stack)[FL(sp)-n-1];
+ value_t v = FL(stack)[FL(sp)-n-1];
if(tag(v) == TAG_FUNCTION){
if(v > (N_BUILTINS<<3)){
if(tail){
FL(curr_frame) = FL(stack)[FL(curr_frame)-3];
- for(s = -1; s < (fixnum_t)n; s++)
+ for(fixnum_t s = -1; s < (fixnum_t)n; s++)
FL(stack)[bp+s] = FL(stack)[FL(sp)+s-n];
FL(sp) = bp+n;
}
@@ -40,9 +40,9 @@
nargs = n;
goto apply_cl_top;
}
- i = uintval(v);
+ uint32_t i = uintval(v);
assert(isbuiltin(v));
- s = builtins[i].nargs;
+ fixnum_t s = builtins[i].nargs;
if(s >= 0)
argcount(n, (unsigned)s);
else if(s != ANYARGS && (signed)n < -s)
@@ -72,7 +72,7 @@
#endif
}
}else if(fl_likely(iscbuiltin(v))){
- s = FL(sp) - n;
+ fixnum_t s = FL(sp) - n;
v = ((cvalue_t*)ptr(v))->cbuiltin(&FL(stack)[s], n);
FL(sp) = s;
FL(stack)[s-1] = v;
@@ -79,26 +79,28 @@
NEXT_OP;
}
type_error("function", v);
+}
-OP(OP_ARGC)
- n = *ip++;
+OP(OP_ARGC) {
+ uint32_t na = *ip++;
if(0){
OP(OP_ARGCL)
- n = GET_INT32(ip);
+ na = GET_INT32(ip);
ip += 4;
}
- if(fl_unlikely(nargs != n)){
+ if(fl_unlikely(nargs != na)){
FL(stack)[ipd] = (uintptr_t)ip;
- arity_error(nargs, n);
+ arity_error(nargs, na);
}
NEXT_OP;
+}
OP(OP_LOADA1)
PUSH(FL(stack)[bp+1]);
NEXT_OP;
-OP(OP_RET)
- v = POP();
+OP(OP_RET) {
+ value_t v = POP();
FL(sp) = FL(curr_frame);
FL(curr_frame) = FL(stack)[FL(sp)-3];
if(FL(curr_frame) == top_frame)
@@ -110,6 +112,7 @@
bp = FL(curr_frame) - 4 - nargs;
FL(stack)[FL(sp)-1] = v;
NEXT_OP;
+}
OP(OP_LOAD1)
PUSH(fixnum(1));
@@ -116,8 +119,7 @@
NEXT_OP;
OP(OP_LOADA)
- v = FL(stack)[bp + *ip++];
- PUSH(v);
+ PUSH(FL(stack)[bp + *ip++]);
NEXT_OP;
OP(OP_BRN)
@@ -124,8 +126,8 @@
ip += POP() == FL_nil ? GET_INT16(ip) : 2;
NEXT_OP;
-OP(OP_LOADGL)
- v = fn_vals(FL(stack)[bp-1]);
+OP(OP_LOADGL) {
+ value_t v = fn_vals(FL(stack)[bp-1]);
v = vector_elt(v, GET_INT32(ip));
ip += 4;
if(0){
@@ -136,7 +138,7 @@
ip++;
}
assert(issymbol(v));
- sym = (symbol_t*)ptr(v);
+ symbol_t *sym = ptr(v);
if(fl_unlikely(sym->binding == UNBOUND)){
FL(stack)[ipd] = (uintptr_t)ip;
unbound_error(v);
@@ -143,13 +145,14 @@
}
PUSH(sym->binding);
NEXT_OP;
+}
OP(OP_LT)
n = *ip++;
LABEL(apply_lt):
{
- i = n;
- value_t a = FL(stack)[FL(sp)-i], b;
+ uint32_t i = n;
+ value_t a = FL(stack)[FL(sp)-i], b, v;
for(v = FL_t; i > 1; a = b){
i--;
b = FL(stack)[FL(sp)-i];
@@ -159,7 +162,7 @@
break;
}
}else{
- x = numeric_compare(a, b, false, false, false);
+ int x = numeric_compare(a, b, false, false, false);
if(x > 1)
x = numval(fl_compare(a, b, false));
if(x >= 0){
@@ -173,13 +176,15 @@
}
NEXT_OP;
-OP(OP_LOADV)
- v = fn_vals(FL(stack)[bp-1]);
+OP(OP_LOADV) {
+ value_t v = fn_vals(FL(stack)[bp-1]);
assert(*ip < vector_size(v));
PUSH(vector_elt(v, *ip++));
NEXT_OP;
+}
-OP(OP_ADD2)
+OP(OP_ADD2) {
+ value_t v;
LABEL(do_add2):
FL(stack)[ipd] = (uintptr_t)ip;
if(0){
@@ -187,6 +192,7 @@
LABEL(do_sub2):
FL(stack)[ipd] = (uintptr_t)ip;
v = FL(stack)[FL(sp)-1];
+ int64_t i64;
FL(stack)[FL(sp)-1] = isfixnum(v) ? fixnum_neg(v) : fl_neg(v);
}
{
@@ -202,7 +208,7 @@
POPN(1);
FL(stack)[FL(sp)-1] = v;
NEXT_OP;
-
+}
OP(OP_LOADI8)
PUSH(fixnum((int8_t)*ip++));
NEXT_OP;
@@ -224,8 +230,8 @@
PUSH(vector_elt(FL(stack)[bp+nargs], 0));
NEXT_OP;
-OP(OP_CAR)
- v = FL(stack)[FL(sp)-1];
+OP(OP_CAR) {
+ value_t v = FL(stack)[FL(sp)-1];
if(fl_likely(iscons(v)))
v = car_(v);
else if(fl_unlikely(v != FL_nil)){
@@ -234,32 +240,34 @@
}
FL(stack)[FL(sp)-1] = v;
NEXT_OP;
+}
-OP(OP_CLOSURE)
- n = *ip++;
- assert(n > 0);
- pv = alloc_words(1+n + sizeof(function_t)/sizeof(value_t));
- v = tagptr(pv, TAG_VECTOR);
- *pv++ = fixnum(n);
- for(i = 0; i < n; i++)
- *pv++ = FL(stack)[FL(sp)-n+i];
- POPN(n);
+OP(OP_CLOSURE) {
+ uint32_t x = *ip++;
+ assert(x > 0);
+ value_t *pv = alloc_words(1+x + sizeof(function_t)/sizeof(value_t));
+ value_t v = tagptr(pv, TAG_VECTOR);
+ *pv++ = fixnum(x);
+ for(uint32_t i = 0; i < x; i++)
+ *pv++ = FL(stack)[FL(sp)-x+i];
+ POPN(x);
PUSH(v);
- fn = (function_t*)pv;
- e = FL(stack)[FL(sp)-2]; // closure to copy
+ function_t *f = (function_t*)pv;
+ value_t e = FL(stack)[FL(sp)-2]; // closure to copy
assert(isfunction(e));
- fn->bcode = fn_bcode(e);
- fn->vals = fn_vals(e);
- fn->env = FL(stack)[FL(sp)-1];
- fn->name = fn_name(e);
+ f->bcode = fn_bcode(e);
+ f->vals = fn_vals(e);
+ f->env = FL(stack)[FL(sp)-1];
+ f->name = fn_name(e);
POPN(1);
- FL(stack)[FL(sp)-1] = tagptr(fn, TAG_FUNCTION);
+ FL(stack)[FL(sp)-1] = tagptr(f, TAG_FUNCTION);
NEXT_OP;
+}
-OP(OP_CONS)
+OP(OP_CONS) {
if(FL(curheap) > FL(lim))
fl_gc(0);
- c = (cons_t*)FL(curheap);
+ cons_t *c = (cons_t*)FL(curheap);
FL(curheap) += sizeof(cons_t);
c->car = FL(stack)[FL(sp)-2];
c->cdr = FL(stack)[FL(sp)-1];
@@ -266,6 +274,7 @@
FL(stack)[FL(sp)-2] = tagptr(c, TAG_CONS);
POPN(1);
NEXT_OP;
+}
OP(OP_BRNE)
ip += FL(stack)[FL(sp)-2] != FL(stack)[FL(sp)-1] ? GET_INT16(ip) : 2;
@@ -272,8 +281,8 @@
POPN(2);
NEXT_OP;
-OP(OP_CDR)
- v = FL(stack)[FL(sp)-1];
+OP(OP_CDR) {
+ value_t v = FL(stack)[FL(sp)-1];
if(fl_likely(iscons(v)))
v = cdr_(v);
else if(fl_unlikely(v != FL_nil)){
@@ -282,6 +291,7 @@
}
FL(stack)[FL(sp)-1] = v;
NEXT_OP;
+}
OP(OP_LOADVOID)
PUSH(FL_void);
@@ -295,16 +305,16 @@
FL(stack)[bp + *ip++] = FL(stack)[FL(sp)-1];
NEXT_OP;
-OP(OP_VARGC)
- i = *ip++;
+OP(OP_VARGC) {
+ uint32_t i = *ip++;
if(0){
OP(OP_VARGCL)
i = GET_INT32(ip);
ip += 4;
}
- s = (fixnum_t)nargs - (fixnum_t)i;
+ fixnum_t s = (fixnum_t)nargs - (fixnum_t)i;
if(s > 0){
- v = list(&FL(stack)[bp+i], s, 0);
+ value_t v = list(&FL(stack)[bp+i], s, 0);
FL(stack)[bp+i] = v;
if(s > 1){
FL(stack)[bp+i+1] = FL(stack)[bp+nargs+0];
@@ -328,15 +338,17 @@
ipd = FL(sp)-1;
nargs = i+1;
NEXT_OP;
+}
-OP(OP_SHIFT)
- i = *ip++;
+OP(OP_SHIFT) {
+ uint32_t i = *ip++;
FL(stack)[FL(sp)-1-i] = FL(stack)[FL(sp)-1];
FL(sp) -= i;
NEXT_OP;
+}
-OP(OP_SETCAR)
- v = FL(stack)[FL(sp)-2];
+OP(OP_SETCAR) {
+ value_t v = FL(stack)[FL(sp)-2];
if(fl_unlikely(!iscons(v))){
FL(stack)[ipd] = (uintptr_t)ip;
type_error("cons", v);
@@ -344,18 +356,20 @@
car_(v) = FL(stack)[FL(sp)-1];
POPN(1);
NEXT_OP;
+}
OP(OP_LOADNIL)
PUSH(FL_nil);
NEXT_OP;
-OP(OP_BOX)
- i = *ip++;
- v = mk_cons();
+OP(OP_BOX) {
+ uint32_t i = *ip++;
+ value_t v = mk_cons();
car_(v) = FL(stack)[bp+i];
cdr_(v) = FL_nil;
FL(stack)[bp+i] = v;
NEXT_OP;
+}
OP(OP_JMP)
ip += GET_INT16(ip);
@@ -365,7 +379,7 @@
FL(stack)[FL(sp)-1] = iscons(FL(stack)[FL(sp)-1]) ? FL_nil : FL_t;
NEXT_OP;
-OP(OP_AREF2)
+OP(OP_AREF2) {
n = 2;
if(0){
OP(OP_AREF)
@@ -372,16 +386,16 @@
FL(stack)[ipd] = (uintptr_t)ip;
n = 3 + *ip++;
}
-LABEL(apply_aref):
- v = FL(stack)[FL(sp)-n];
- for(i = n-1; i > 0; i--){
+LABEL(apply_aref):;
+ value_t v = FL(stack)[FL(sp)-n];
+ for(uint32_t i = n-1; i > 0; i--){
if(isarray(v)){
FL(stack)[FL(sp)-i-1] = v;
v = cvalue_array_aref(&FL(stack)[FL(sp)-i-1]);
continue;
}
- e = FL(stack)[FL(sp)-i];
- isz = tosize(e);
+ value_t e = FL(stack)[FL(sp)-i];
+ size_t isz = tosize(e);
if(isvector(v)){
if(fl_unlikely(isz >= vector_size(v)))
bounds_error(v, e);
@@ -403,9 +417,10 @@
POPN(n);
PUSH(v);
NEXT_OP;
+}
-OP(OP_NANP)
- v = FL(stack)[FL(sp)-1];
+OP(OP_NANP) {
+ value_t v = FL(stack)[FL(sp)-1];
if(!iscprim(v))
v = FL_nil;
else{
@@ -424,13 +439,14 @@
}
FL(stack)[FL(sp)-1] = v;
NEXT_OP;
+}
OP(OP_LOAD0)
PUSH(fixnum(0));
NEXT_OP;
-OP(OP_SETCDR)
- v = FL(stack)[FL(sp)-2];
+OP(OP_SETCDR) {
+ value_t v = FL(stack)[FL(sp)-2];
if(fl_unlikely(!iscons(v))){
FL(stack)[ipd] = (uintptr_t)ip;
type_error("cons", v);
@@ -438,26 +454,27 @@
cdr_(v) = FL(stack)[FL(sp)-1];
POPN(1);
NEXT_OP;
+}
OP(OP_LOADC1)
PUSH(vector_elt(FL(stack)[bp+nargs], 1));
NEXT_OP;
-OP(OP_ASET)
+OP(OP_ASET) {
FL(stack)[ipd] = (uintptr_t)ip;
- v = FL(stack)[FL(sp)-3];
+ value_t v = FL(stack)[FL(sp)-3];
n = 3;
if(0){
LABEL(apply_aset):
v = FL(stack)[FL(sp)-n];
- for(i = n-1; i >= 3; i--){
+ for(uint32_t i = n-1; i >= 3; i--){
if(isarray(v)){
FL(stack)[FL(sp)-i-1] = v;
v = cvalue_array_aref(&FL(stack)[FL(sp)-i-1]);
continue;
}
- e = FL(stack)[FL(sp)-i];
- isz = tosize(e);
+ value_t e = FL(stack)[FL(sp)-i];
+ size_t isz = tosize(e);
if(isvector(v)){
if(fl_unlikely(isz >= vector_size(v)))
bounds_error(v, e);
@@ -478,8 +495,8 @@
}
FL(stack)[FL(sp)-3] = v;
}
- e = FL(stack)[FL(sp)-2];
- isz = tosize(e);
+ value_t e = FL(stack)[FL(sp)-2];
+ size_t isz = tosize(e);
if(isvector(v)){
if(fl_unlikely(isz >= vector_size(v)))
bounds_error(v, e);
@@ -502,8 +519,10 @@
POPN(n);
PUSH(e);
NEXT_OP;
+}
-OP(OP_EQUAL)
+OP(OP_EQUAL) {
+ value_t v;
if(FL(stack)[FL(sp)-2] == FL(stack)[FL(sp)-1])
v = FL_t;
else
@@ -511,18 +530,20 @@
FL(stack)[FL(sp)-2] = v;
POPN(1);
NEXT_OP;
+}
OP(OP_CONSP)
FL(stack)[FL(sp)-1] = iscons(FL(stack)[FL(sp)-1]) ? FL_t : FL_nil;
NEXT_OP;
-OP(OP_LOADC)
- v = FL(stack)[bp+nargs];
- i = *ip++;
+OP(OP_LOADC) {
+ value_t v = FL(stack)[bp+nargs];
+ uint32_t i = *ip++;
assert(isvector(v));
assert(i < vector_size(v));
PUSH(vector_elt(v, i));
NEXT_OP;
+}
OP(OP_SYMBOLP)
FL(stack)[FL(sp)-1] = issymbol(FL(stack)[FL(sp)-1]) ? FL_t : FL_nil;
@@ -533,41 +554,41 @@
NEXT_OP;
OP(OP_BRBOUND)
- i = GET_INT32(ip);
+ PUSH(FL(stack)[bp+GET_INT32(ip)] != UNBOUND ? FL_t : FL_nil);
ip += 4;
- PUSH(FL(stack)[bp+i] != UNBOUND ? FL_t : FL_nil);
NEXT_OP;
-OP(OP_OPTARGS)
- i = GET_INT32(ip);
+OP(OP_OPTARGS) {
+ uint32_t i = GET_INT32(ip);
ip += 4;
- n = GET_INT32(ip);
+ uint32_t x = GET_INT32(ip);
ip += 4;
if(fl_unlikely(nargs < i)){
FL(stack)[ipd] = (uintptr_t)ip;
lerrorf(FL_ArgError, "too few arguments");
}
- if((int32_t)n > 0){
- if(fl_unlikely(nargs > n)){
+ if((int32_t)x > 0){
+ if(fl_unlikely(nargs > x)){
FL(stack)[ipd] = (uintptr_t)ip;
lerrorf(FL_ArgError, "too many arguments");
}
}else
- n = -n;
- if(fl_likely(n > nargs)){
- n -= nargs;
- FL(sp) += n;
- FL(stack)[FL(sp)-1] = FL(stack)[FL(sp)-n-1];
- FL(stack)[FL(sp)-2] = nargs+n;
- FL(stack)[FL(sp)-3] = FL(stack)[FL(sp)-n-3];
- FL(stack)[FL(sp)-4] = FL(stack)[FL(sp)-n-4];
+ x = -x;
+ if(fl_likely(x > nargs)){
+ x -= nargs;
+ FL(sp) += x;
+ FL(stack)[FL(sp)-1] = FL(stack)[FL(sp)-x-1];
+ FL(stack)[FL(sp)-2] = nargs+x;
+ FL(stack)[FL(sp)-3] = FL(stack)[FL(sp)-x-3];
+ FL(stack)[FL(sp)-4] = FL(stack)[FL(sp)-x-4];
FL(curr_frame) = FL(sp);
ipd = FL(sp)-1;
- for(i = 0; i < n; i++)
+ for(i = 0; i < x; i++)
FL(stack)[bp+nargs+i] = UNBOUND;
- nargs += n;
+ nargs += x;
}
NEXT_OP;
+}
OP(OP_EQ)
FL(stack)[FL(sp)-2] = FL(stack)[FL(sp)-2] == FL(stack)[FL(sp)-1] ? FL_t : FL_nil;
@@ -578,7 +599,7 @@
n = *ip++;
LABEL(apply_list):
if(n > 0){
- v = list(&FL(stack)[FL(sp)-n], n, 0);
+ value_t v = list(&FL(stack)[FL(sp)-n], n, 0);
POPN(n);
PUSH(v);
}else{
@@ -586,18 +607,19 @@
}
NEXT_OP;
-OP(OP_BOUNDP)
+OP(OP_BOUNDP) {
FL(stack)[ipd] = (uintptr_t)ip;
- sym = tosymbol(FL(stack)[FL(sp)-1]);
+ symbol_t *sym = tosymbol(FL(stack)[FL(sp)-1]);
FL(stack)[FL(sp)-1] = sym->binding == UNBOUND ? FL_nil : FL_t;
NEXT_OP;
+}
OP(OP_NUMEQ)
n = *ip++;
LABEL(apply_numeq):
{
- i = n;
- value_t a = FL(stack)[FL(sp)-i], b;
+ uint32_t i = n;
+ value_t a = FL(stack)[FL(sp)-i], b, v;
for(v = FL_t; i > 1; a = b){
i--;
b = FL(stack)[FL(sp)-i];
@@ -616,8 +638,8 @@
}
NEXT_OP;
-OP(OP_CADR)
- v = FL(stack)[FL(sp)-1];
+OP(OP_CADR) {
+ value_t v = FL(stack)[FL(sp)-1];
if(fl_likely(iscons(v))){
v = cdr_(v);
if(fl_likely(iscons(v)))
@@ -633,8 +655,9 @@
}
FL(stack)[FL(sp)-1] = v;
NEXT_OP;
+}
-OP(OP_TAPPLY)
+OP(OP_TAPPLY) {
tail = true;
if(0){
OP(OP_APPLY)
@@ -641,8 +664,8 @@
tail = false;
}
n = *ip++;
-LABEL(apply_apply):
- v = POP(); // arglist
+LABEL(apply_apply):;
+ value_t v = POP(); // arglist
n = FL(sp)-(n-2); // n-2 == # leading arguments not in the list
while(iscons(v)){
PUSHSAFE(car_(v));
@@ -654,60 +677,65 @@
}
n = FL(sp)-n;
goto LABEL(do_call);
+}
OP(OP_LOADT)
PUSH(FL_t);
NEXT_OP;
-OP(OP_BUILTINP)
- v = FL(stack)[FL(sp)-1];
+OP(OP_BUILTINP) {
+ value_t v = FL(stack)[FL(sp)-1];
FL(stack)[FL(sp)-1] = (isbuiltin(v) || iscbuiltin(v)) ? FL_t : FL_nil;
NEXT_OP;
+}
-OP(OP_NEG)
+OP(OP_NEG) {
LABEL(do_neg):
FL(stack)[ipd] = (uintptr_t)ip;
- v = FL(stack)[FL(sp)-1];
+ value_t v = FL(stack)[FL(sp)-1];
+ int64_t i64;
FL(stack)[FL(sp)-1] = isfixnum(v) ? fixnum_neg(v) : fl_neg(v);
NEXT_OP;
+}
OP(OP_FIXNUMP)
FL(stack)[FL(sp)-1] = isfixnum(FL(stack)[FL(sp)-1]) ? FL_t : FL_nil;
NEXT_OP;
-OP(OP_MUL)
+OP(OP_MUL) {
n = *ip++;
LABEL(apply_mul):
FL(stack)[ipd] = (uintptr_t)ip;
- v = fl_mul_any(&FL(stack)[FL(sp)-n], n);
+ value_t v = fl_mul_any(&FL(stack)[FL(sp)-n], n);
POPN(n);
PUSH(v);
NEXT_OP;
+}
-OP(OP_IDIV)
- {
- value_t a = FL(stack)[FL(sp)-2];
- value_t b = FL(stack)[FL(sp)-1];
- if(bothfixnums(a, b)){
- if(b == 0){
- FL(stack)[ipd] = (uintptr_t)ip;
- divide_by_0_error();
- }
- v = fixnum(numval(a) / numval(b));
- }else{
+OP(OP_IDIV) {
+ value_t a = FL(stack)[FL(sp)-2];
+ value_t b = FL(stack)[FL(sp)-1];
+ value_t v;
+ if(bothfixnums(a, b)){
+ if(b == 0){
FL(stack)[ipd] = (uintptr_t)ip;
- v = fl_idiv2(a, b);
+ divide_by_0_error();
}
- POPN(1);
- FL(stack)[FL(sp)-1] = v;
+ v = fixnum(numval(a) / numval(b));
+ }else{
+ FL(stack)[ipd] = (uintptr_t)ip;
+ v = fl_idiv2(a, b);
}
+ POPN(1);
+ FL(stack)[FL(sp)-1] = v;
NEXT_OP;
+}
-OP(OP_DIV)
+OP(OP_DIV) {
n = *ip++;
LABEL(apply_div):
FL(stack)[ipd] = (uintptr_t)ip;
- i = FL(sp)-n;
+ uint32_t i = FL(sp)-n;
if(n == 1){
FL(stack)[FL(sp)-1] = fl_div2(fixnum(1), FL(stack)[i]);
}else{
@@ -717,16 +745,17 @@
FL(stack)[i+1] = fl_mul_any(&FL(stack)[i], n);
FL(stack)[i] = POP();
}
- v = fl_div2(FL(stack)[i], FL(stack)[i+1]);
+ value_t v = fl_div2(FL(stack)[i], FL(stack)[i+1]);
POPN(n);
PUSH(v);
}
NEXT_OP;
+}
-OP(OP_VECTOR)
+OP(OP_VECTOR) {
n = *ip++;
-LABEL(apply_vector):
- v = alloc_vector(n, 0);
+LABEL(apply_vector):;
+ value_t v = alloc_vector(n, 0);
if(n){
memcpy(&vector_elt(v, 0), &FL(stack)[FL(sp)-n], n*sizeof(value_t));
POPN(n);
@@ -733,6 +762,7 @@
}
PUSH(v);
NEXT_OP;
+}
OP(OP_COMPARE)
FL(stack)[FL(sp)-2] = fl_compare(FL(stack)[FL(sp)-2], FL(stack)[FL(sp)-1], false);
@@ -739,11 +769,12 @@
POPN(1);
NEXT_OP;
-OP(OP_FOR)
+OP(OP_FOR) {
FL(stack)[ipd] = (uintptr_t)ip;
- i = FL(sp);
- s = tofixnum(FL(stack)[i-3]);
- hi = tofixnum(FL(stack)[i-2]);
+ uint32_t i = FL(sp);
+ value_t v;
+ fixnum_t s = tofixnum(FL(stack)[i-3]);
+ fixnum_t hi = tofixnum(FL(stack)[i-2]);
FL(sp) += 2;
for(v = FL_void; s <= hi; s++){
FL(stack)[i+0] = FL(stack)[i-1];
@@ -753,9 +784,10 @@
POPN(4);
FL(stack)[i+1] = v;
NEXT_OP;
+}
-OP(OP_SETGL)
- v = fn_vals(FL(stack)[bp-1]);
+OP(OP_SETGL) {
+ value_t v = fn_vals(FL(stack)[bp-1]);
v = vector_elt(v, GET_INT32(ip));
ip += 4;
if(0){
@@ -766,42 +798,45 @@
ip++;
}
assert(issymbol(v));
- sym = (symbol_t*)ptr(v);
+ symbol_t *sym = ptr(v);
v = FL(stack)[FL(sp)-1];
if(!isconstant(sym))
sym->binding = v;
NEXT_OP;
+}
OP(OP_VECTORP)
FL(stack)[FL(sp)-1] = isvector(FL(stack)[FL(sp)-1]) ? FL_t : FL_nil;
NEXT_OP;
-OP(OP_TRYCATCH)
+OP(OP_TRYCATCH) {
FL(stack)[ipd] = (uintptr_t)ip;
- v = do_trycatch();
+ value_t v = do_trycatch();
POPN(1);
FL(stack)[FL(sp)-1] = v;
NEXT_OP;
+}
-OP(OP_ADD)
+OP(OP_ADD) {
n = *ip++;
if(n == 2)
goto LABEL(do_add2);
LABEL(apply_add):
FL(stack)[ipd] = (uintptr_t)ip;
- v = fl_add_any(&FL(stack)[FL(sp)-n], n);
+ value_t v = fl_add_any(&FL(stack)[FL(sp)-n], n);
POPN(n);
PUSH(v);
NEXT_OP;
+}
OP(OP_LOADAL)
assert(nargs > 0);
- i = GET_INT32(ip);
+ PUSH(FL(stack)[bp+GET_INT32(ip)]);
ip += 4;
- PUSH(FL(stack)[bp+i]);
NEXT_OP;
-OP(OP_EQV)
+OP(OP_EQV) {
+ value_t v;
if(FL(stack)[FL(sp)-2] == FL(stack)[FL(sp)-1])
v = FL_t;
else if(!leafp(FL(stack)[FL(sp)-2]) || !leafp(FL(stack)[FL(sp)-1]))
@@ -811,22 +846,24 @@
FL(stack)[FL(sp)-2] = v;
POPN(1);
NEXT_OP;
+}
-OP(OP_KEYARGS)
- v = fn_vals(FL(stack)[bp-1]);
+OP(OP_KEYARGS) {
+ value_t v = fn_vals(FL(stack)[bp-1]);
v = vector_elt(v, 0);
- i = GET_INT32(ip);
+ uint32_t i = GET_INT32(ip);
ip += 4;
- n = GET_INT32(ip);
+ uint32_t x = GET_INT32(ip);
ip += 4;
- s = GET_INT32(ip);
+ fixnum_t s = GET_INT32(ip);
ip += 4;
FL(stack)[ipd] = (uintptr_t)ip;
- nargs = process_keys(v, i, n, labs(s)-(i+n), bp, nargs, s<0);
+ nargs = process_keys(v, i, x, labs(s)-(i+x), bp, nargs, s<0);
ipd = FL(sp)-1;
NEXT_OP;
+}
-OP(OP_SUB)
+OP(OP_SUB) {
n = *ip++;
LABEL(apply_sub):
if(n == 2)
@@ -834,12 +871,13 @@
if(n == 1)
goto LABEL(do_neg);
FL(stack)[ipd] = (uintptr_t)ip;
- i = FL(sp)-n;
+ uint32_t i = FL(sp)-n;
// we need to pass the full arglist on to fl_add_any
// so it can handle rest args properly
PUSH(FL(stack)[i]);
FL(stack)[i] = fixnum(0);
- v = fl_add_any(&FL(stack)[i], n);
+ value_t v = fl_add_any(&FL(stack)[i], n);
+ int64_t i64;
FL(stack)[i+1] = isfixnum(v) ? fixnum_neg(v) : fl_neg(v);
FL(stack)[i] = POP();
v = fl_add_any(&FL(stack)[i], 2);
@@ -846,6 +884,7 @@
POPN(n);
PUSH(v);
NEXT_OP;
+}
OP(OP_BRNL)
ip += POP() == FL_nil ? GET_INT32(ip) : 4;
@@ -852,27 +891,28 @@
NEXT_OP;
OP(OP_SETAL)
- i = GET_INT32(ip);
+ FL(stack)[bp+GET_INT32(ip)] = FL(stack)[FL(sp)-1];
ip += 4;
- FL(stack)[bp+i] = FL(stack)[FL(sp)-1];
NEXT_OP;
-OP(OP_BOXL)
- i = GET_INT32(ip);
+OP(OP_BOXL) {
+ uint32_t i = GET_INT32(ip);
ip += 4;
- v = mk_cons();
+ value_t v = mk_cons();
car_(v) = FL(stack)[bp+i];
cdr_(v) = FL_nil;
FL(stack)[bp+i] = v;
NEXT_OP;
+}
-OP(OP_FUNCTIONP)
- v = FL(stack)[FL(sp)-1];
+OP(OP_FUNCTIONP) {
+ value_t v = FL(stack)[FL(sp)-1];
FL(stack)[FL(sp)-1] =
((tag(v) == TAG_FUNCTION &&
(isbuiltin(v) || v>(N_BUILTINS<<3))) ||
iscbuiltin(v)) ? FL_t : FL_nil;
NEXT_OP;
+}
OP(OP_JMPL)
ip += GET_INT32(ip);
@@ -888,15 +928,15 @@
NEXT_OP;
OP(OP_LOADCL)
- i = GET_INT32(ip);
ip += 4;
- v = FL(stack)[bp+nargs];
- PUSH(vector_elt(v, i));
+ PUSH(vector_elt(FL(stack)[bp+nargs], GET_INT32(ip)));
+ ip += 4;
NEXT_OP;
-OP(OP_LOADVL)
- v = fn_vals(FL(stack)[bp-1]);
+OP(OP_LOADVL) {
+ value_t v = fn_vals(FL(stack)[bp-1]);
v = vector_elt(v, GET_INT32(ip));
ip += 4;
PUSH(v);
NEXT_OP;
+}