shithub: femtolisp

Download patch

ref: 588c432ea9d25fb5b6820c10580f5364f8dbc9c1
parent: d60399e18345e69419489f201f27f19f1a5616b2
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Wed Dec 25 02:02:03 EST 2024

compute_maxstack: compare maxsp with sp less often

--- a/maxstack.inc
+++ b/maxstack.inc
@@ -5,8 +5,6 @@
 	int i, n, sp = 0, maxsp = 0;
 
 	while(ip < end){
-		if((int32_t)sp > (int32_t)maxsp)
-			maxsp = sp;
 		opcode_t op = *ip++;
 		if(op >= N_OPCODES)
 			return -1;
@@ -42,7 +40,7 @@
 
 		case OP_ARGC: case OP_SETG: case OP_SETA: case OP_BOX:
 			ip++;
-			break;
+			continue;
 
 		case OP_TCALL: case OP_CALL: case OP_CLOSURE: case OP_SHIFT:
 			n = *ip++;  // nargs
@@ -98,10 +96,12 @@
 			break;
 		case OP_JMP:
 			SWAP_INT16(ip);
-			ip += 2; break;
+			ip += 2;
+			continue;
 		case OP_JMPL:
 			SWAP_INT32(ip);
-			ip += 4; break;
+			ip += 4;
+			continue;
 		case OP_BRFL: case OP_BRTL:
 			SWAP_INT32(ip);
 			ip += 4;
@@ -125,7 +125,6 @@
 		case OP_BRNNL: case OP_BRNL:
 			SWAP_INT32(ip);
 			ip += 4; // fallthrough
-
 		case OP_TAPPLY: case OP_APPLY:
 		case OP_LIST: case OP_ADD: case OP_SUB: case OP_MUL: case OP_DIV:
 		case OP_VECTOR:
@@ -152,11 +151,13 @@
 		case OP_NULLP: case OP_BOOLEANP: case OP_NUMBERP:
 		case OP_FIXNUMP: case OP_BOUNDP: case OP_BUILTINP:
 		case OP_FUNCTIONP: case OP_VECTORP:
-			break;
+			continue;
 
 		case OP_EOF_OBJECT: case N_OPCODES:
 			return -1;
 		}
+		if((int32_t)sp > (int32_t)maxsp)
+			maxsp = sp;
 	}
 	assert(ip == end);
 	assert(maxsp >= 0);