Replace upvalue-based shell dispatch with OP_LUSH opcode

Add a dedicated OP_LUSH A B instruction that loads shell C functions
directly from the registry, eliminating the need for upvalue allocation
in mainfunc(), upvalue population in lua_load(), and the fragile
LUSH_NUM_UPVALS heuristic. Every chunk no longer carries 4 extra
upvalues.
This commit is contained in:
Cormac Shannon
2026-03-12 22:47:25 +00:00
parent f88b17959f
commit f09a033160
9 changed files with 46 additions and 78 deletions

13
lcmd.h
View File

@@ -9,13 +9,12 @@
#include "lua.h"
/* Upvalue indices for shell functions on the main chunk.
** Index 0 is _ENV (standard). Indices 1-4 are lush shell functions. */
#define LUSH_UPVAL_COMMAND 1
#define LUSH_UPVAL_INTERACTIVE 2
#define LUSH_UPVAL_GETENV 3
#define LUSH_UPVAL_SETENV 4
#define LUSH_NUM_UPVALS 5 /* total: _ENV(0) + 4 shell functions */
/* OP_LUSH sub-operation indices (B operand selects which function) */
#define LUSH_OP_COMMAND 0
#define LUSH_OP_INTERACTIVE 1
#define LUSH_OP_GETENV 2
#define LUSH_OP_SETENV 3
#define LUSH_OP_COUNT 4
int lushCmd_command (lua_State *L);
int lushCmd_interactive (lua_State *L);