shithub: femtolisp

Download patch

ref: 0f3c051904ead079fa2f2457d86623283e5f2ecb
parent: 0769956a24915cb1f30f6e720e2f2051e755d0e0
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Tue Nov 12 20:59:17 EST 2024

make computed goto table a bit more readable

--- a/flisp.c
+++ b/flisp.c
@@ -900,99 +900,100 @@
 #pragma GCC diagnostic ignored "-Wpedantic"
 #define OP(x) op_##x:
 #define NEXT_OP goto *((uint8_t*)&&op_OP_LOADA0 + ops[op = *ip++])
-	static const intptr_t ops[] = {
-		[OP_LOADA0] = (uint8_t*)&&op_OP_LOADA0 - (uint8_t*)&&op_OP_LOADA0,
-		[OP_LOADA1] = (uint8_t*)&&op_OP_LOADA1 - (uint8_t*)&&op_OP_LOADA0,
-		[OP_LOADV] = (uint8_t*)&&op_OP_LOADV - (uint8_t*)&&op_OP_LOADA0,
-		[OP_BRF] = (uint8_t*)&&op_OP_BRF - (uint8_t*)&&op_OP_LOADA0,
-		[OP_POP] = (uint8_t*)&&op_OP_POP - (uint8_t*)&&op_OP_LOADA0,
-		[OP_CALL] = (uint8_t*)&&op_OP_CALL - (uint8_t*)&&op_OP_LOADA0,
-		[OP_TCALL] = (uint8_t*)&&op_OP_TCALL - (uint8_t*)&&op_OP_LOADA0,
-		[OP_LOADG] = (uint8_t*)&&op_OP_LOADG - (uint8_t*)&&op_OP_LOADA0,
-		[OP_LOADA] = (uint8_t*)&&op_OP_LOADA - (uint8_t*)&&op_OP_LOADA0,
-		[OP_LOADC] = (uint8_t*)&&op_OP_LOADC - (uint8_t*)&&op_OP_LOADA0,
-		[OP_RET] = (uint8_t*)&&op_OP_RET - (uint8_t*)&&op_OP_LOADA0,
-		[OP_DUP] = (uint8_t*)&&op_OP_DUP - (uint8_t*)&&op_OP_LOADA0,
-		[OP_CAR] = (uint8_t*)&&op_OP_CAR - (uint8_t*)&&op_OP_LOADA0,
-		[OP_CDR] = (uint8_t*)&&op_OP_CDR - (uint8_t*)&&op_OP_LOADA0,
-		[OP_CLOSURE] = (uint8_t*)&&op_OP_CLOSURE - (uint8_t*)&&op_OP_LOADA0,
-		[OP_SETA] = (uint8_t*)&&op_OP_SETA - (uint8_t*)&&op_OP_LOADA0,
-		[OP_JMP] = (uint8_t*)&&op_OP_JMP - (uint8_t*)&&op_OP_LOADA0,
-		[OP_LOADC00] = (uint8_t*)&&op_OP_LOADC00 - (uint8_t*)&&op_OP_LOADA0,
-		[OP_PAIRP] = (uint8_t*)&&op_OP_PAIRP - (uint8_t*)&&op_OP_LOADA0,
-		[OP_BRNE] = (uint8_t*)&&op_OP_BRNE - (uint8_t*)&&op_OP_LOADA0,
-		[OP_LOADT] = (uint8_t*)&&op_OP_LOADT - (uint8_t*)&&op_OP_LOADA0,
-		[OP_LOAD0] = (uint8_t*)&&op_OP_LOAD0 - (uint8_t*)&&op_OP_LOADA0,
-		[OP_LOADC01] = (uint8_t*)&&op_OP_LOADC01 - (uint8_t*)&&op_OP_LOADA0,
-		[OP_AREF] = (uint8_t*)&&op_OP_AREF - (uint8_t*)&&op_OP_LOADA0,
-		[OP_ATOMP] = (uint8_t*)&&op_OP_ATOMP - (uint8_t*)&&op_OP_LOADA0,
-		[OP_BRT] = (uint8_t*)&&op_OP_BRT - (uint8_t*)&&op_OP_LOADA0,
-		[OP_BRNN] = (uint8_t*)&&op_OP_BRNN - (uint8_t*)&&op_OP_LOADA0,
-		[OP_LOAD1] = (uint8_t*)&&op_OP_LOAD1 - (uint8_t*)&&op_OP_LOADA0,
-		[OP_LT] = (uint8_t*)&&op_OP_LT - (uint8_t*)&&op_OP_LOADA0,
-		[OP_ADD2] = (uint8_t*)&&op_OP_ADD2 - (uint8_t*)&&op_OP_LOADA0,
-		[OP_SETCDR] = (uint8_t*)&&op_OP_SETCDR - (uint8_t*)&&op_OP_LOADA0,
-		[OP_LOADF] = (uint8_t*)&&op_OP_LOADF - (uint8_t*)&&op_OP_LOADA0,
-		[OP_CONS] = (uint8_t*)&&op_OP_CONS - (uint8_t*)&&op_OP_LOADA0,
-		[OP_EQ] = (uint8_t*)&&op_OP_EQ - (uint8_t*)&&op_OP_LOADA0,
-		[OP_SYMBOLP] = (uint8_t*)&&op_OP_SYMBOLP - (uint8_t*)&&op_OP_LOADA0,
-		[OP_NOT] = (uint8_t*)&&op_OP_NOT - (uint8_t*)&&op_OP_LOADA0,
-		[OP_CADR] = (uint8_t*)&&op_OP_CADR - (uint8_t*)&&op_OP_LOADA0,
-		[OP_NEG] = (uint8_t*)&&op_OP_NEG - (uint8_t*)&&op_OP_LOADA0,
-		[OP_NULLP] = (uint8_t*)&&op_OP_NULLP - (uint8_t*)&&op_OP_LOADA0,
-		[OP_BOOLEANP] = (uint8_t*)&&op_OP_BOOLEANP - (uint8_t*)&&op_OP_LOADA0,
-		[OP_NUMBERP] = (uint8_t*)&&op_OP_NUMBERP - (uint8_t*)&&op_OP_LOADA0,
-		[OP_FIXNUMP] = (uint8_t*)&&op_OP_FIXNUMP - (uint8_t*)&&op_OP_LOADA0,
-		[OP_BOUNDP] = (uint8_t*)&&op_OP_BOUNDP - (uint8_t*)&&op_OP_LOADA0,
-		[OP_BUILTINP] = (uint8_t*)&&op_OP_BUILTINP - (uint8_t*)&&op_OP_LOADA0,
-		[OP_FUNCTIONP] = (uint8_t*)&&op_OP_FUNCTIONP - (uint8_t*)&&op_OP_LOADA0,
-		[OP_VECTORP] = (uint8_t*)&&op_OP_VECTORP - (uint8_t*)&&op_OP_LOADA0,
-		[OP_NOP] = (uint8_t*)&&op_OP_NOP - (uint8_t*)&&op_OP_LOADA0,
-		[OP_SETCAR] = (uint8_t*)&&op_OP_SETCAR - (uint8_t*)&&op_OP_LOADA0,
-		[OP_JMPL] = (uint8_t*)&&op_OP_JMPL - (uint8_t*)&&op_OP_LOADA0,
-		[OP_BRFL] = (uint8_t*)&&op_OP_BRFL - (uint8_t*)&&op_OP_LOADA0,
-		[OP_BRTL] = (uint8_t*)&&op_OP_BRTL - (uint8_t*)&&op_OP_LOADA0,
-		[OP_EQV] = (uint8_t*)&&op_OP_EQV - (uint8_t*)&&op_OP_LOADA0,
-		[OP_EQUAL] = (uint8_t*)&&op_OP_EQUAL - (uint8_t*)&&op_OP_LOADA0,
-		[OP_LIST] = (uint8_t*)&&op_OP_LIST - (uint8_t*)&&op_OP_LOADA0,
-		[OP_APPLY] = (uint8_t*)&&op_OP_APPLY - (uint8_t*)&&op_OP_LOADA0,
-		[OP_ADD] = (uint8_t*)&&op_OP_ADD - (uint8_t*)&&op_OP_LOADA0,
-		[OP_SUB] = (uint8_t*)&&op_OP_SUB - (uint8_t*)&&op_OP_LOADA0,
-		[OP_MUL] = (uint8_t*)&&op_OP_MUL - (uint8_t*)&&op_OP_LOADA0,
-		[OP_DIV] = (uint8_t*)&&op_OP_DIV - (uint8_t*)&&op_OP_LOADA0,
-		[OP_IDIV] = (uint8_t*)&&op_OP_IDIV - (uint8_t*)&&op_OP_LOADA0,
-		[OP_NUMEQ] = (uint8_t*)&&op_OP_NUMEQ - (uint8_t*)&&op_OP_LOADA0,
-		[OP_COMPARE] = (uint8_t*)&&op_OP_COMPARE - (uint8_t*)&&op_OP_LOADA0,
-		[OP_ARGC] = (uint8_t*)&&op_OP_ARGC - (uint8_t*)&&op_OP_LOADA0,
-		[OP_VECTOR] = (uint8_t*)&&op_OP_VECTOR - (uint8_t*)&&op_OP_LOADA0,
-		[OP_ASET] = (uint8_t*)&&op_OP_ASET - (uint8_t*)&&op_OP_LOADA0,
-		[OP_LOADNIL] = (uint8_t*)&&op_OP_LOADNIL - (uint8_t*)&&op_OP_LOADA0,
-		[OP_LOADI8] = (uint8_t*)&&op_OP_LOADI8 - (uint8_t*)&&op_OP_LOADA0,
-		[OP_LOADVL] = (uint8_t*)&&op_OP_LOADVL - (uint8_t*)&&op_OP_LOADA0,
-		[OP_LOADGL] = (uint8_t*)&&op_OP_LOADGL - (uint8_t*)&&op_OP_LOADA0,
-		[OP_LOADAL] = (uint8_t*)&&op_OP_LOADAL - (uint8_t*)&&op_OP_LOADA0,
-		[OP_LOADCL] = (uint8_t*)&&op_OP_LOADCL - (uint8_t*)&&op_OP_LOADA0,
-		[OP_SETG] = (uint8_t*)&&op_OP_SETG - (uint8_t*)&&op_OP_LOADA0,
-		[OP_SETGL] = (uint8_t*)&&op_OP_SETGL - (uint8_t*)&&op_OP_LOADA0,
-		[OP_SETAL] = (uint8_t*)&&op_OP_SETAL - (uint8_t*)&&op_OP_LOADA0,
-		[OP_SETC] = (uint8_t*)&&op_OP_SETC - (uint8_t*)&&op_OP_LOADA0,
-		[OP_SETCL] = (uint8_t*)&&op_OP_SETCL - (uint8_t*)&&op_OP_LOADA0,
-		[OP_VARGC] = (uint8_t*)&&op_OP_VARGC - (uint8_t*)&&op_OP_LOADA0,
-		[OP_TRYCATCH] = (uint8_t*)&&op_OP_TRYCATCH - (uint8_t*)&&op_OP_LOADA0,
-		[OP_FOR] = (uint8_t*)&&op_OP_FOR - (uint8_t*)&&op_OP_LOADA0,
-		[OP_TAPPLY] = (uint8_t*)&&op_OP_TAPPLY - (uint8_t*)&&op_OP_LOADA0,
-		[OP_SUB2] = (uint8_t*)&&op_OP_SUB2 - (uint8_t*)&&op_OP_LOADA0,
-		[OP_LARGC] = (uint8_t*)&&op_OP_LARGC - (uint8_t*)&&op_OP_LOADA0,
-		[OP_LVARGC] = (uint8_t*)&&op_OP_LVARGC - (uint8_t*)&&op_OP_LOADA0,
-		[OP_CALLL] = (uint8_t*)&&op_OP_CALLL - (uint8_t*)&&op_OP_LOADA0,
-		[OP_TCALLL] = (uint8_t*)&&op_OP_TCALLL - (uint8_t*)&&op_OP_LOADA0,
-		[OP_BRNEL] = (uint8_t*)&&op_OP_BRNEL - (uint8_t*)&&op_OP_LOADA0,
-		[OP_BRNNL] = (uint8_t*)&&op_OP_BRNNL - (uint8_t*)&&op_OP_LOADA0,
-		[OP_BRN] = (uint8_t*)&&op_OP_BRN - (uint8_t*)&&op_OP_LOADA0,
-		[OP_BRNL] = (uint8_t*)&&op_OP_BRNL - (uint8_t*)&&op_OP_LOADA0,
-		[OP_OPTARGS] = (uint8_t*)&&op_OP_OPTARGS - (uint8_t*)&&op_OP_LOADA0,
-		[OP_BRBOUND] = (uint8_t*)&&op_OP_BRBOUND - (uint8_t*)&&op_OP_LOADA0,
-		[OP_KEYARGS] = (uint8_t*)&&op_OP_KEYARGS - (uint8_t*)&&op_OP_LOADA0,
+#define GOTO_OP_OFFSET(op) [op] = (int)((uint8_t*)&&op_##op - (uint8_t*)&&op_OP_LOADA0)
+	static const int ops[] = {
+		GOTO_OP_OFFSET(OP_LOADA0),
+		GOTO_OP_OFFSET(OP_LOADA1),
+		GOTO_OP_OFFSET(OP_LOADV),
+		GOTO_OP_OFFSET(OP_BRF),
+		GOTO_OP_OFFSET(OP_POP),
+		GOTO_OP_OFFSET(OP_CALL),
+		GOTO_OP_OFFSET(OP_TCALL),
+		GOTO_OP_OFFSET(OP_LOADG),
+		GOTO_OP_OFFSET(OP_LOADA),
+		GOTO_OP_OFFSET(OP_LOADC),
+		GOTO_OP_OFFSET(OP_RET),
+		GOTO_OP_OFFSET(OP_DUP),
+		GOTO_OP_OFFSET(OP_CAR),
+		GOTO_OP_OFFSET(OP_CDR),
+		GOTO_OP_OFFSET(OP_CLOSURE),
+		GOTO_OP_OFFSET(OP_SETA),
+		GOTO_OP_OFFSET(OP_JMP),
+		GOTO_OP_OFFSET(OP_LOADC00),
+		GOTO_OP_OFFSET(OP_PAIRP),
+		GOTO_OP_OFFSET(OP_BRNE),
+		GOTO_OP_OFFSET(OP_LOADT),
+		GOTO_OP_OFFSET(OP_LOAD0),
+		GOTO_OP_OFFSET(OP_LOADC01),
+		GOTO_OP_OFFSET(OP_AREF),
+		GOTO_OP_OFFSET(OP_ATOMP),
+		GOTO_OP_OFFSET(OP_BRT),
+		GOTO_OP_OFFSET(OP_BRNN),
+		GOTO_OP_OFFSET(OP_LOAD1),
+		GOTO_OP_OFFSET(OP_LT),
+		GOTO_OP_OFFSET(OP_ADD2),
+		GOTO_OP_OFFSET(OP_SETCDR),
+		GOTO_OP_OFFSET(OP_LOADF),
+		GOTO_OP_OFFSET(OP_CONS),
+		GOTO_OP_OFFSET(OP_EQ),
+		GOTO_OP_OFFSET(OP_SYMBOLP),
+		GOTO_OP_OFFSET(OP_NOT),
+		GOTO_OP_OFFSET(OP_CADR),
+		GOTO_OP_OFFSET(OP_NEG),
+		GOTO_OP_OFFSET(OP_NULLP),
+		GOTO_OP_OFFSET(OP_BOOLEANP),
+		GOTO_OP_OFFSET(OP_NUMBERP),
+		GOTO_OP_OFFSET(OP_FIXNUMP),
+		GOTO_OP_OFFSET(OP_BOUNDP),
+		GOTO_OP_OFFSET(OP_BUILTINP),
+		GOTO_OP_OFFSET(OP_FUNCTIONP),
+		GOTO_OP_OFFSET(OP_VECTORP),
+		GOTO_OP_OFFSET(OP_NOP),
+		GOTO_OP_OFFSET(OP_SETCAR),
+		GOTO_OP_OFFSET(OP_JMPL),
+		GOTO_OP_OFFSET(OP_BRFL),
+		GOTO_OP_OFFSET(OP_BRTL),
+		GOTO_OP_OFFSET(OP_EQV),
+		GOTO_OP_OFFSET(OP_EQUAL),
+		GOTO_OP_OFFSET(OP_LIST),
+		GOTO_OP_OFFSET(OP_APPLY),
+		GOTO_OP_OFFSET(OP_ADD),
+		GOTO_OP_OFFSET(OP_SUB),
+		GOTO_OP_OFFSET(OP_MUL),
+		GOTO_OP_OFFSET(OP_DIV),
+		GOTO_OP_OFFSET(OP_IDIV),
+		GOTO_OP_OFFSET(OP_NUMEQ),
+		GOTO_OP_OFFSET(OP_COMPARE),
+		GOTO_OP_OFFSET(OP_ARGC),
+		GOTO_OP_OFFSET(OP_VECTOR),
+		GOTO_OP_OFFSET(OP_ASET),
+		GOTO_OP_OFFSET(OP_LOADNIL),
+		GOTO_OP_OFFSET(OP_LOADI8),
+		GOTO_OP_OFFSET(OP_LOADVL),
+		GOTO_OP_OFFSET(OP_LOADGL),
+		GOTO_OP_OFFSET(OP_LOADAL),
+		GOTO_OP_OFFSET(OP_LOADCL),
+		GOTO_OP_OFFSET(OP_SETG),
+		GOTO_OP_OFFSET(OP_SETGL),
+		GOTO_OP_OFFSET(OP_SETAL),
+		GOTO_OP_OFFSET(OP_SETC),
+		GOTO_OP_OFFSET(OP_SETCL),
+		GOTO_OP_OFFSET(OP_VARGC),
+		GOTO_OP_OFFSET(OP_TRYCATCH),
+		GOTO_OP_OFFSET(OP_FOR),
+		GOTO_OP_OFFSET(OP_TAPPLY),
+		GOTO_OP_OFFSET(OP_SUB2),
+		GOTO_OP_OFFSET(OP_LARGC),
+		GOTO_OP_OFFSET(OP_LVARGC),
+		GOTO_OP_OFFSET(OP_CALLL),
+		GOTO_OP_OFFSET(OP_TCALLL),
+		GOTO_OP_OFFSET(OP_BRNEL),
+		GOTO_OP_OFFSET(OP_BRNNL),
+		GOTO_OP_OFFSET(OP_BRN),
+		GOTO_OP_OFFSET(OP_BRNL),
+		GOTO_OP_OFFSET(OP_OPTARGS),
+		GOTO_OP_OFFSET(OP_BRBOUND),
+		GOTO_OP_OFFSET(OP_KEYARGS),
 	};
 	NEXT_OP;
 #else