ref: 17213e7981553c07bd779712ec2c74b4812d4487
parent: 38d1cabc4f92e3d5f5c1009376bbf130f13e7267
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Mon Mar 27 12:22:48 EDT 2023
restyle apply_cl a bit
--- a/flisp.c
+++ b/flisp.c
@@ -914,18 +914,12 @@
while(1){
switch (op) {
OP(OP_LOADA0)
- if (captured)
- v = vector_elt(Stack[bp], 0);
- else
- v = Stack[bp];
+ v = captured ? vector_elt(Stack[bp], 0) : Stack[bp];
PUSH(v);
NEXT_OP;
OP(OP_LOADA1)
- if (captured)
- v = vector_elt(Stack[bp], 1);
- else
- v = Stack[bp+1];
+ v = captured ? vector_elt(Stack[bp], 1) : Stack[bp+1];
PUSH(v);
NEXT_OP;
@@ -932,15 +926,14 @@
OP(OP_LOADV)
v = fn_vals(Stack[bp-1]);
assert(*ip < vector_size(v));
- v = vector_elt(v, *ip); ip++;
+ v = vector_elt(v, *ip);
+ ip++;
PUSH(v);
NEXT_OP;
OP(OP_BRF)
v = POP();
- if (v == FL_F)
- ip += GET_INT16(ip);
- else ip += 2;
+ ip += v == FL_F ? GET_INT16(ip) : 2;
NEXT_OP;
OP(OP_POP)
@@ -954,7 +947,7 @@
tail = 0;
}
n = GET_INT32(ip);
- ip+=4;
+ ip += 4;
if (0) {
OP(OP_TCALL)
tail = 1;
@@ -1022,7 +1015,8 @@
OP(OP_LOADG)
v = fn_vals(Stack[bp-1]);
assert(*ip < vector_size(v));
- v = vector_elt(v, *ip); ip++;
+ v = vector_elt(v, *ip);
+ ip++;
}
assert(issymbol(v));
sym = (symbol_t*)ptr(v);
@@ -1153,10 +1147,7 @@
NEXT_OP;
OP(OP_BRNE)
- if (Stack[SP-2] != Stack[SP-1])
- ip += GET_INT16(ip);
- else
- ip += 2;
+ ip += Stack[SP-2] != Stack[SP-1] ? GET_INT16(ip) : 2;
POPN(2);
NEXT_OP;
@@ -1176,10 +1167,7 @@
v = Stack[SP-2];
if (isvector(v)) {
e = Stack[SP-1];
- if (isfixnum(e))
- i = numval(e);
- else
- i = (uint32_t)toulong(e, "aref");
+ i = isfixnum(e) ? numval(e) : (uint32_t)toulong(e, "aref");
if ((unsigned)i >= vector_size(v))
bounds_error("aref", v, e);
v = vector_elt(v, i);
@@ -1200,16 +1188,12 @@
OP(OP_BRT)
v = POP();
- if (v != FL_F)
- ip += GET_INT16(ip);
- else ip += 2;
+ ip += v != FL_F ? GET_INT16(ip) : 2;
NEXT_OP;
OP(OP_BRNN)
v = POP();
- if (v != NIL)
- ip += GET_INT16(ip);
- else ip += 2;
+ ip += v != NIL ? GET_INT16(ip) : 2;
NEXT_OP;
OP(OP_LOAD1)
@@ -1228,10 +1212,7 @@
OP(OP_ADD2)
if (bothfixnums(Stack[SP-1], Stack[SP-2])) {
s = numval(Stack[SP-1]) + numval(Stack[SP-2]);
- if (fits_fixnum(s))
- v = fixnum(s);
- else
- v = mk_xlong(s);
+ v = fits_fixnum(s) ? fixnum(s) : mk_xlong(s);
}
else {
v = fl_add_any(&Stack[SP-2], 2, 0);
@@ -1274,9 +1255,11 @@
OP(OP_CADR)
v = Stack[SP-1];
- if (!iscons(v)) type_error("cdr", "cons", v);
+ if (!iscons(v))
+ type_error("cdr", "cons", v);
v = cdr_(v);
- if (!iscons(v)) type_error("car", "cons", v);
+ if (!iscons(v))
+ type_error("car", "cons", v);
Stack[SP-1] = car_(v);
NEXT_OP;
@@ -1438,8 +1421,10 @@
OP(OP_SUB)
n = *ip++;
apply_sub:
- if (n == 2) goto do_sub2;
- if (n == 1) goto do_neg;
+ if (n == 2)
+ goto do_sub2;
+ if (n == 1)
+ goto do_neg;
i = SP-n;
// we need to pass the full arglist on to fl_add_any
// so it can handle rest args properly
@@ -1456,10 +1441,7 @@
do_sub2:
if (bothfixnums(Stack[SP-2], Stack[SP-1])) {
s = numval(Stack[SP-2]) - numval(Stack[SP-1]);
- if (fits_fixnum(s))
- v = fixnum(s);
- else
- v = mk_xlong(s);
+ v = fits_fixnum(s) ? fixnum(s) : mk_xlong(s);
}
else {
Stack[SP-1] = fl_neg(Stack[SP-1]);
@@ -1483,12 +1465,8 @@
break;
}
}
- if (i == SP) {
- if (fits_fixnum(accum))
- v = fixnum(accum);
- else
- v = return_from_int64(accum);
- }
+ if (i == SP)
+ v = fits_fixnum(accum) ? fixnum(accum) : return_from_int64(accum);
POPN(n);
PUSH(v);
NEXT_OP;
@@ -1528,9 +1506,9 @@
OP(OP_NUMEQ)
v = Stack[SP-2]; e = Stack[SP-1];
if (bothfixnums(v, e))
- v = (v == e) ? FL_T : FL_F;
+ v = v == e ? FL_T : FL_F;
else
- v = (!numeric_compare(v,e,1,0,"=")) ? FL_T : FL_F;
+ v = !numeric_compare(v,e,1,0,"=") ? FL_T : FL_F;
POPN(1);
Stack[SP-1] = v;
NEXT_OP;
@@ -1545,7 +1523,7 @@
if (0) {
OP(OP_LARGC)
n = GET_INT32(ip);
- ip+=4;
+ ip += 4;
}
if (nargs != n)
lerrorf(ArgError, "apply: too %s arguments", nargs > n ? "many" : "few");
@@ -1608,18 +1586,21 @@
OP(OP_LOADVL)
v = fn_vals(Stack[bp-1]);
- v = vector_elt(v, GET_INT32(ip)); ip+=4;
+ v = vector_elt(v, GET_INT32(ip));
+ ip += 4;
PUSH(v);
NEXT_OP;
OP(OP_SETGL)
v = fn_vals(Stack[bp-1]);
- v = vector_elt(v, GET_INT32(ip)); ip+=4;
+ v = vector_elt(v, GET_INT32(ip));
+ ip += 4;
if (0) {
OP(OP_SETG)
v = fn_vals(Stack[bp-1]);
assert(*ip < vector_size(v));
- v = vector_elt(v, *ip); ip++;
+ v = vector_elt(v, *ip);
+ ip++;
}
assert(issymbol(v));
sym = (symbol_t*)ptr(v);
@@ -1630,11 +1611,9 @@
OP(OP_LOADAL)
assert(nargs > 0);
- i = GET_INT32(ip); ip+=4;
- if (captured)
- v = vector_elt(Stack[bp], i);
- else
- v = Stack[bp+i];
+ i = GET_INT32(ip);
+ ip += 4;
+ v = captured ? vector_elt(Stack[bp], i) : Stack[bp+i];
PUSH(v);
NEXT_OP;
@@ -1669,8 +1648,10 @@
NEXT_OP;
OP(OP_SETCL)
- s = GET_INT32(ip); ip+=4;
- i = GET_INT32(ip); ip+=4;
+ s = GET_INT32(ip);
+ ip += 4;
+ i = GET_INT32(ip);
+ ip += 4;
v = Stack[bp+nargs];
while (s--)
v = vector_elt(v, vector_size(v)-1);
@@ -1683,7 +1664,7 @@
if (0) {
OP(OP_LVARGC)
i = GET_INT32(ip);
- ip+=4;
+ ip += 4;
}
s = (fixnum_t)nargs - (fixnum_t)i;
if (s > 0) {
@@ -1747,12 +1728,8 @@
OP(OP_BRBOUND)
i = GET_INT32(ip); ip+=4;
- if (captured)
- v = vector_elt(Stack[bp], i);
- else
- v = Stack[bp+i];
- if (v != UNBOUND) PUSH(FL_T);
- else PUSH(FL_F);
+ v = captured ? vector_elt(Stack[bp], i) : Stack[bp+i];
+ PUSH(v != UNBOUND ? FL_T : FL_F);
NEXT_OP;
OP(OP_KEYARGS)