u3: unify interpreter opcode information using X macro

This commit is contained in:
Peter McEvoy 2022-05-03 21:40:46 +00:00
parent 1c6feb7b0f
commit 5cd72d7052

View File

@ -382,125 +382,130 @@ _n_nock_on(u3_noun bus, u3_noun fol)
} }
#endif #endif
/* These must match the order in the section marked OPCODE TABLE, // Several opcodes "overflow" (from byte to short index) to their successor, so
* and several opcodes "overflow" (from byte to short index) to // order can matter here.
* their successor, so order can matter here. */ #define OPCODES \
// general purpose /* general purpose */ \
#define HALT 0 X(HALT, "halt", &&do_halt), /* 0 */ \
#define BAIL 1 X(BAIL, "bail", &&do_bail), /* 1 */ \
#define COPY 2 X(COPY, "copy", &&do_copy), /* 2 */ \
#define SWAP 3 X(SWAP, "swap", &&do_swap), /* 3 */ \
#define TOSS 4 X(TOSS, "toss", &&do_toss), /* 4 */ \
#define AUTO 5 X(AUTO, "auto", &&do_auto), /* 5 */ \
#define AULT 6 X(AULT, "ault", &&do_ault), /* 6 */ \
#define SNOC 7 X(SNOC, "snoc", &&do_snoc), /* 7 */ \
#define SNOL 8 X(SNOL, "snol", &&do_snol), /* 8 */ \
#define HEAD 9 X(HEAD, "head", &&do_head), /* 9 */ \
#define HELD 10 X(HELD, "held", &&do_held), /* 10 */ \
#define TAIL 11 X(TAIL, "tail", &&do_tail), /* 11 */ \
#define TALL 12 X(TALL, "tall", &&do_tall), /* 12 */ \
// fragment (keep) /* fragment (keep) */ \
#define FABK 13 X(FABK, "fabk", &&do_fabk), /* 13 */ \
#define FASK 14 X(FASK, "fask", &&do_fask), /* 14 */ \
#define FIBK 15 X(FIBK, "fibk", &&do_fibk), /* 15 */ \
#define FISK 16 X(FISK, "fisk", &&do_fisk), /* 16 */ \
// fragment (lose) /* fragment (lose) */ \
#define FABL 17 X(FABL, "fabl", &&do_fabl), /* 17 */ \
#define FASL 18 X(FASL, "fasl", &&do_fasl), /* 18 */ \
#define FIBL 19 X(FIBL, "fibl", &&do_fibl), /* 19 */ \
#define FISL 20 X(FISL, "fisl", &&do_fisl), /* 20 */ \
// literal (keep) /* literal (keep) */ \
#define LIT0 21 X(LIT0, "lit0", &&do_lit0), /* 21 */ \
#define LIT1 22 X(LIT1, "lit1", &&do_lit1), /* 22 */ \
#define LITB 23 X(LITB, "litb", &&do_litb), /* 23 */ \
#define LITS 24 X(LITS, "lits", &&do_lits), /* 24 */ \
#define LIBK 25 X(LIBK, "libk", &&do_libk), /* 25 */ \
#define LISK 26 X(LISK, "lisk", &&do_lisk), /* 26 */ \
// literal (lose) /* literal (lose) */ \
#define LIL0 27 X(LIL0, "lil0", &&do_lil0), /* 27 */ \
#define LIL1 28 X(LIL1, "lil1", &&do_lil1), /* 28 */ \
#define LILB 29 X(LILB, "lilb", &&do_lilb), /* 29 */ \
#define LILS 30 X(LILS, "lils", &&do_lils), /* 30 */ \
#define LIBL 31 X(LIBL, "libl", &&do_libl), /* 31 */ \
#define LISL 32 X(LISL, "lisl", &&do_lisl), /* 32 */ \
// nock /* nock */ \
#define NOLK 33 X(NOLK, "nolk", &&do_nolk), /* 33 */ \
#define NOCT 34 X(NOCT, "noct", &&do_noct), /* 34 */ \
#define NOCK 35 X(NOCK, "nock", &&do_nock), /* 35 */ \
// 3 & 4 /* 3 & 4 */ \
#define DEEP 36 X(DEEP, "deep", &&do_deep), /* 36 */ \
#define BUMP 37 X(BUMP, "bump", &&do_bump), /* 37 */ \
// equality /* equality */ \
#define SAM0 38 X(SAM0, "sam0", &&do_sam0), /* 38 */ \
#define SAM1 39 X(SAM1, "sam1", &&do_sam1), /* 39 */ \
#define SAMB 40 X(SAMB, "samb", &&do_samb), /* 40 */ \
#define SAMS 41 X(SAMS, "sams", &&do_sams), /* 41 */ \
#define SANB 42 X(SANB, "sanb", &&do_sanb), /* 42 */ \
#define SANS 43 X(SANS, "sans", &&do_sans), /* 43 */ \
#define SAME 44 X(SAME, "same", &&do_same), /* 44 */ \
#define SALM 45 X(SALM, "salm", &&do_salm), /* 45 */ \
#define SAMC 46 X(SAMC, "samc", &&do_samc), /* 46 */ \
// unconditional skips /* unconditional skips */ \
#define SBIP 47 X(SBIP, "sbip", &&do_sbip), /* 47 */ \
#define SIPS 48 X(SIPS, "sips", &&do_sips), /* 48 */ \
#define SWIP 49 X(SWIP, "swip", &&do_swip), /* 49 */ \
// conditional skips /* conditional skips */ \
#define SBIN 50 X(SBIN, "sbin", &&do_sbin), /* 50 */ \
#define SINS 51 X(SINS, "sins", &&do_sins), /* 51 */ \
#define SWIN 52 X(SWIN, "swin", &&do_swin), /* 52 */ \
// nock 9 /* nock 9 */ \
#define KICB 53 X(KICB, "kicb", &&do_kicb), /* 53 */ \
#define KICS 54 X(KICS, "kics", &&do_kics), /* 54 */ \
#define TICB 55 X(TICB, "ticb", &&do_ticb), /* 55 */ \
#define TICS 56 X(TICS, "tics", &&do_tics), /* 56 */ \
// nock 12 /* nock 12 */ \
#define WILS 57 X(WILS, "wils", &&do_wils), /* 57 */ \
#define WISH 58 X(WISH, "wish", &&do_wish), /* 58 */ \
// hint processing /* hint processing */ \
#define BUSH 59 X(BUSH, "bush", &&do_bush), /* 59 */ \
#define SUSH 60 X(SUSH, "sush", &&do_sush), /* 60 */ \
#define DROP 61 X(DROP, "drop", &&do_drop), /* 61 */ \
#define HECK 62 X(HECK, "heck", &&do_heck), /* 62 */ \
#define SLOG 63 X(SLOG, "slog", &&do_slog), /* 63 */ \
// fast (keep) /* fast (keep) */ \
#define BAST 64 X(BAST, "bast", &&do_bast), /* 64 */ \
#define SAST 65 X(SAST, "sast", &&do_sast), /* 65 */ \
// fast (lose) /* fast (lose) */ \
#define BALT 66 X(BALT, "balt", &&do_balt), /* 66 */ \
#define SALT 67 X(SALT, "salt", &&do_salt), /* 67 */ \
// memo (keep) /* memo (keep) */ \
#define SKIB 68 X(SKIB, "skib", &&do_skib), /* 68 */ \
#define SKIS 69 X(SKIS, "skis", &&do_skis), /* 69 */ \
// memo (lose) /* memo (lose) */ \
#define SLIB 70 X(SLIB, "slib", &&do_slib), /* 70 */ \
#define SLIS 71 X(SLIS, "slis", &&do_slis), /* 71 */ \
#define SAVE 72 X(SAVE, "save", &&do_save), /* 72 */ \
// before formula /* before formula */ \
#define HILB 73 // atomic, byte X(HILB, "hilb", &&do_hilb), /* 73: atomic, byte */ \
#define HILS 74 // atomic, short X(HILS, "hils", &&do_hils), /* 74: atomic, short */ \
#define HINB 75 // arbitrary, byte X(HINB, "hinb", &&do_hinb), /* 75: arbitrary, byte */ \
#define HINS 76 // arbitrary, short X(HINS, "hins", &&do_hins), /* 76: arbitrary, short */ \
// after formula /* after formula */ \
#define HILK 77 // atomic, keep X(HILK, "hilk", &&do_hilk), /* 77: atomic, keep */ \
#define HILL 78 // atomic, lose X(HILL, "hill", &&do_hill), /* 78: atomic, lose */ \
#define HINK 79 // arbitrary, keep X(HINK, "hink", &&do_hink), /* 79: arbitrary, keep */ \
#define HINL 80 // arbitrary, lose X(HINL, "hinl", &&do_hinl), /* 80: arbitrary, lose */ \
// nock 10 /* nock 10 */ \
#define MUTH 81 X(MUTH, "muth", &&do_muth), /* 81 */ \
#define KUTH 82 X(KUTH, "kuth", &&do_kuth), /* 82 */ \
#define MUTT 83 X(MUTT, "mutt", &&do_mutt), /* 83 */ \
#define KUTT 84 X(KUTT, "kutt", &&do_kutt), /* 84 */ \
#define MUSM 85 X(MUSM, "musm", &&do_musm), /* 85 */ \
#define KUSM 86 X(KUSM, "kusm", &&do_kusm), /* 86 */ \
#define MUTB 87 X(MUTB, "mutb", &&do_mutb), /* 87 */ \
#define MUTS 88 X(MUTS, "muts", &&do_muts), /* 88 */ \
#define MITB 89 X(MITB, "mitb", &&do_mitb), /* 89 */ \
#define MITS 90 X(MITS, "mits", &&do_mits), /* 90 */ \
#define KUTB 91 X(KUTB, "kutb", &&do_kutb), /* 91 */ \
#define KUTS 92 X(KUTS, "kuts", &&do_kuts), /* 92 */ \
#define KITB 93 X(KITB, "kitb", &&do_kitb), /* 93 */ \
#define KITS 94 X(KITS, "kits", &&do_kits), /* 94 */ \
#define LAST 95 X(LAST, NULL, NULL), /* 95 */
// Opcodes.
#define X(opcode, name, indirect_jump) opcode
enum { OPCODES };
#undef X
/* _n_arg(): return the size (in bytes) of an opcode's argument /* _n_arg(): return the size (in bytes) of an opcode's argument
*/ */
@ -949,40 +954,9 @@ static void _n_print_stack(u3p(u3_noun) empty) {
#endif #endif
#ifdef VERBOSE_BYTECODE #ifdef VERBOSE_BYTECODE
// match to OPCODE TABLE # define X(opcode, name, indirect_jump) name
static char* opcode_names[] = { static c3_c* opcode_names[] = { OPCODES };
"halt", "bail", # undef X
"copy", "swap", "toss",
"auto", "ault", "snoc", "snol",
"head", "held", "tail", "tall",
"fabk", "fask", "fibk", "fisk",
"fabl", "fasl", "fibl", "fisl",
"lit0", "lit1", "litb", "lits",
"libk", "lisk",
"lil0", "lil1", "lilb", "lils",
"libl", "lisl",
"nolk", "noct", "nock",
"deep", "bump",
"sam0", "sam1", "samb", "sams",
"sanb", "sans",
"same", "salm", "samc",
"sbip", "sips", "swip",
"sbin", "sins", "swin",
"kicb", "kics", "ticb", "tics",
"wils", "wish",
"bush", "sush",
"drop", "heck", "slog",
"bast", "sast",
"balt", "salt",
"skib", "skis", "slib", "slis",
"save",
"hilb", "hils", "hinb", "hins"
"hilk", "hill", "hink", "hinl"
"muth", "kuth", "mutt", "kutt",
"musm", "kusm",
"mutb", "muts", "mitb", "mits",
"kutb", "kuts", "kitb", "kits",
};
#endif #endif
/* _n_apen(): emit the instructions contained in src to dst /* _n_apen(): emit the instructions contained in src to dst
@ -1873,40 +1847,11 @@ typedef struct {
static u3_noun static u3_noun
_n_burn(u3n_prog* pog_u, u3_noun bus, c3_ys mov, c3_ys off) _n_burn(u3n_prog* pog_u, u3_noun bus, c3_ys mov, c3_ys off)
{ {
/* OPCODE TABLE */
static void* lab[] = { // Opcode jump table.
&&do_halt, &&do_bail, # define X(opcode, name, indirect_jump) indirect_jump
&&do_copy, &&do_swap, &&do_toss, static void* lab[] = { OPCODES };
&&do_auto, &&do_ault, &&do_snoc, &&do_snol, # undef X
&&do_head, &&do_held, &&do_tail, &&do_tall,
&&do_fabk, &&do_fask, &&do_fibk, &&do_fisk,
&&do_fabl, &&do_fasl, &&do_fibl, &&do_fisl,
&&do_lit0, &&do_lit1, &&do_litb, &&do_lits,
&&do_libk, &&do_lisk,
&&do_lil0, &&do_lil1, &&do_lilb, &&do_lils,
&&do_libl, &&do_lisl,
&&do_nolk, &&do_noct, &&do_nock,
&&do_deep, &&do_bump,
&&do_sam0, &&do_sam1, &&do_samb, &&do_sams,
&&do_sanb, &&do_sans,
&&do_same, &&do_salm, &&do_samc,
&&do_sbip, &&do_sips, &&do_swip,
&&do_sbin, &&do_sins, &&do_swin,
&&do_kicb, &&do_kics, &&do_ticb, &&do_tics,
&&do_wils, &&do_wish,
&&do_bush, &&do_sush,
&&do_drop, &&do_heck, &&do_slog,
&&do_bast, &&do_sast,
&&do_balt, &&do_salt,
&&do_skib, &&do_skis, &&do_slib, &&do_slis,
&&do_save,
&&do_hilb, &&do_hils, &&do_hinb, &&do_hins,
&&do_hilk, &&do_hill, &&do_hink, &&do_hinl,
&&do_muth, &&do_kuth, &&do_mutt, &&do_kutt,
&&do_musm, &&do_kusm,
&&do_mutb, &&do_muts, &&do_mitb, &&do_mits,
&&do_kutb, &&do_kuts, &&do_kitb, &&do_kits,
};
u3j_site* sit_u; u3j_site* sit_u;
u3j_rite* rit_u; u3j_rite* rit_u;