changes to pygen

This commit is contained in:
2026-03-25 10:56:26 -06:00
parent c6fdb59791
commit c6c63d6391
4 changed files with 58 additions and 36 deletions

View File

@@ -15,7 +15,7 @@
},
{
"cell_type": "code",
"execution_count": 34,
"execution_count": 1,
"id": "b0fcd533",
"metadata": {},
"outputs": [
@@ -68,7 +68,7 @@
},
{
"cell_type": "code",
"execution_count": 35,
"execution_count": 2,
"id": "b33de8ac",
"metadata": {},
"outputs": [
@@ -144,7 +144,7 @@
},
{
"cell_type": "code",
"execution_count": 36,
"execution_count": 3,
"id": "58645013",
"metadata": {},
"outputs": [
@@ -283,7 +283,7 @@
},
{
"cell_type": "code",
"execution_count": 37,
"execution_count": 4,
"id": "452bc76c",
"metadata": {},
"outputs": [
@@ -357,7 +357,7 @@
},
{
"cell_type": "code",
"execution_count": 38,
"execution_count": 5,
"id": "5aaebef0",
"metadata": {},
"outputs": [
@@ -380,7 +380,7 @@
"\n",
"\n",
"CPU.hpp updated successfully at: .//src//spider/runtime/cpu/CPU.hpp\n",
"Total lines in updated file: 792\n"
"Total lines in updated file: 883\n"
]
}
],
@@ -451,7 +451,7 @@
},
{
"cell_type": "code",
"execution_count": 39,
"execution_count": 8,
"id": "instrmap_gen",
"metadata": {},
"outputs": [
@@ -459,8 +459,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
"InstrMap.cpp written to: .//src//spider/runtime/cpu/InstrMap.cpp\n",
" Size : 34,246 bytes\n",
"InstrMap.cpp written to: .//src//spider/runtime/instr/InstrMap.cpp\n",
" Size : 34,157 bytes\n",
" Array entries : 512 (128 populated, 384 nullptr)\n",
" Switch cases : 128\n",
" Line endings : LF-only verified\n"
@@ -516,8 +516,8 @@
"L.append(' * optimisation can inline the handlers.')\n",
"L.append(' *')\n",
"L.append(' */')\n",
"L.append('')\n",
"L.append('#include \"CPU.hpp\"')\n",
"L.append('') # [CHANGE] Use absolute path to make paths more explicit\n",
"L.append('#include <spider/runtime/cpu/CPU.hpp>')\n",
"L.append('')\n",
"L.append('namespace spider {')\n",
"L.append('')\n",
@@ -527,18 +527,19 @@
"L.append('// Version 1 — Lookup table of member-function pointers')\n",
"L.append('// =============================================================')\n",
"L.append('')\n",
"L.append('/** Pointer-to-member type for a zero-argument CPU instruction. */')\n",
"L.append('using CPUInstr = void (CPU::*)();')\n",
"# [CHANGE] Use CPU::Fn Instead\n",
"#L.append('/** Pointer-to-member type for a zero-argument CPU instruction. */')\n",
"#L.append('using CPUInstr = void (CPU::*)();')\n",
"L.append('')\n",
"L.append('/**')\n",
"L.append(f' * Instruction dispatch table ({TABLE_SIZE} entries, 9-bit opcode space).')\n",
"L.append(' *')\n",
"L.append(' * Usage:')\n",
"L.append(' * u16 opcode = fetch();')\n",
"L.append(' * CPUInstr fn = InstrMap[opcode];')\n",
"L.append(' * CPU::Fn fn = InstrMap[opcode];')\n",
"L.append(' * if (fn) (cpu.*fn)();')\n",
"L.append(' */')\n",
"L.append(f'CPUInstr InstrMap[{TABLE_SIZE}] = {{')\n",
"L.append(' */') # [CHANGE] Made it part of the CPU & avoided explicit size.\n",
"L.append(f'CPU::Fn CPU::instrMap[] = {{')\n",
"\n",
"for opc in range(TABLE_SIZE):\n",
" mnem = opcode_to_mnem.get(opc)\n",
@@ -567,10 +568,10 @@
"L.append(' * but expressed as a switch so the compiler can choose the best')\n",
"L.append(' * lowering strategy (jump table, binary search, etc.).')\n",
"L.append(' *')\n",
"L.append(' * @param opcode 9-bit instruction opcode (0x000 0x1FF).')\n",
"L.append(' * @param opcode 9-bit instruction opcode (0x000 - 0x1FF).')\n",
"L.append(' */')\n",
"L.append('void CPU::execute(u16 opcode) {')\n",
"L.append(' switch (opcode) {')\n",
"L.append('void CPU::executeSwLk() {')\n",
"L.append(' switch (_opcode) {')\n",
"\n",
"last_group = None\n",
"for opc in sorted(opcode_to_mnem.keys()):\n",
@@ -594,7 +595,8 @@
"INSTRMAP_SRC = '\\n'.join(L)\n",
"\n",
"# ── Write to file ───────────────────────────────────────────────────────────\n",
"INSTRMAP_PATH = f'{SRC_ROOT}/spider/runtime/cpu/InstrMap.cpp'\n",
"# [CHANGE] Write this in the instructions folder to avoid CPU file bloat\n",
"INSTRMAP_PATH = f'{SRC_ROOT}/spider/runtime/instr/InstrMap.cpp'\n",
"\n",
"with open(INSTRMAP_PATH, 'wb') as f:\n",
" f.write(INSTRMAP_SRC.encode('utf-8'))\n",
@@ -631,7 +633,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.5"
"version": "3.13.7"
}
},
"nbformat": 4,