Catálogo de opcodes BasicPlus VM

Bytecode .mod — vista navegable PARCIAL: los 110 opcodes de V1 (0x00..0x70). Los 65 aditivos de V2–V6 (0x6F, 0x71..0xB0: long, double, potencia, CHECKCAST, sentinelas) y los 14 de V7 (0xB1..0xBE: los _REF del enlace tardío, LEA_FIELD, LEA_FIELD_REF e INVOKE_SLOT) no están aquí: el catálogo completo (189) es docs/OPCODES.md; la fuente, bpgenvm-c/include/bpvm_opcodes.h. La columna «AOT C» es el diseño de H3 (V3), no lo que hace el AOT de hoy (ver su convención, abajo).

Convención de la columna "AOT C"

Ojo: es el boceto de H3 (V3), no el AOT de hoy. El AOT que se hizo no traduce el bytecode opcode a opcode: traduce a C el árbol de cada función native (AotCEmitter, en el compilador), con sus locales como variables de C, y los vm_op_* de esta columna no existen en el código. Se queda como referencia de lo que hace cada opcode visto desde C. Lo que hace el AOT de verdad, y lo que no traduce, en el manual §8.3 y en docs/AOT_LIMITES.md.

Cada opcode incluye su traducción a C para el generador AOT (H3). Las categorías visualmente marcadas:

Variables en scope de la función AOT

uint8_t* mem;          // memory[] de la VM
uint32_t sp, bp, cs;   // registros BP del frame actual
bpvm_t*  vm;           // contexto VM (para helpers / GC / sink)

Helpers asumidos

static inline int32_t  rd32(uint8_t* p);                  // read i32 BE
static inline void     wr32(uint8_t* p, int32_t v);       // write i32 BE
static inline int16_t  rd16s(uint8_t* p);                 // read i16 BE sign-ext
static inline uint16_t rd16u(uint8_t* p);                 // read u16 BE
static inline float    i2f(int32_t b);                    // bitcast i32→f32
static inline int32_t  f2i(float f);                      // bitcast f32→i32

Los vm_op_* son funciones del runtime VM-C extraídas del switch del intérprete; cada una replica un bloque case OP_X: de interp.c. El refactor a static inline compartido entre intérprete y AOT es el primer paso de #157.

Sin resultados para el filtro actual.

Núcleo 0x00..0x0F

CodeOpOperandoStackSemánticaAOT C
0x00HALT—( -- )Termina la VM entera. Sólo legal en thread main.
// n/a — AOT no emite HALT.
// Aparece en el entry point del módulo,
// que sigue siendo bytecode interpretado.
0x01PUSHi32 value( -- v )Empuja value al stack.
wr32(mem+sp, value); sp += 4;
0x02ADD—( a b -- a+b )Suma entera (i32 con wrap).
sp -= 4; int32_t b = rd32(mem+sp);
sp -= 4; int32_t a = rd32(mem+sp);
wr32(mem+sp, a + b); sp += 4;
0x03PRINT—( v -- )Imprime int + newline al OutputSink.
→ vm_op_print_i32(vm, &sp);
0x04GET_GLOBALi16 soff( -- v )Push mem[cs + soff] i32.
wr32(mem+sp, rd32(mem+cs+soff));
sp += 4;
0x05SET_GLOBALi16 soff( v -- )Escribe i32 en mem[cs + soff].
sp -= 4;
wr32(mem+cs+soff, rd32(mem+sp));
0x06CALL_EXTu16 idx( -- )Llama función importada en ext-table[idx].
// Si target AOT'd → C call directa
//   tgt(vm, &sp, &bp);
// Si no → vm_op_call_ext(vm, &sp, &bp, &cs, idx);
0x07CALLi32 relAddr( -- )Llama función local. Push saved pc/bp/cs; bp ← sp.
// Self-call (recursión) o intra-módulo:
//   tgt(vm, &sp, &bp);   // si AOT'd
// Si no → vm_op_call(vm, &sp, &bp, relAddr);
0x08RETu8 k( retVal -- )Restaura cs/bp/pc; sp ← bp-12-k*4; push retVal.
// Final de función AOT:
sp -= 4; int32_t r = rd32(mem+sp);
sp = bp - 12 - k*4;
bp = rd32(mem+bp-8);
return r;   // C return — caller pushea
0x09GET_LOCALi16 soff( -- v )Push mem[bp + soff] i32.
wr32(mem+sp, rd32(mem+bp+soff));
sp += 4;
0x0ASET_LOCALi16 soff( v -- )Escribe i32 en mem[bp + soff].
sp -= 4;
wr32(mem+bp+soff, rd32(mem+sp));
0x0BEQ—( a b -- a==b )Comparación entera. Resultado 1 / 0.
sp -= 4; int32_t b = rd32(mem+sp);
sp -= 4; int32_t a = rd32(mem+sp);
wr32(mem+sp, a == b ? 1 : 0); sp += 4;
0x0CLT—( a b -- a<b )Comparación entera signed.
sp -= 4; int32_t b = rd32(mem+sp);
sp -= 4; int32_t a = rd32(mem+sp);
wr32(mem+sp, a < b ? 1 : 0); sp += 4;
0x0DJUMPi32 rel( -- )Salto incondicional.
goto label_X;   // X = pc destino,
                // emitido como label por
                // el AOT al hacer CFG pass
0x0EJUMP_IF_FALSEi32 rel( v -- )Si v == 0, salta.
sp -= 4;
if (rd32(mem+sp) == 0) goto label_X;
0x0FENTERu16 bytes( -- )Reserva bytes en stack para locales.
sp += bytes;

Aritmética + arrays 0x10..0x1F

CodeOpOperandoStackSemánticaAOT C
0x10SUB—( a b -- a-b )Resta entera.
sp -= 4; int32_t b = rd32(mem+sp);
sp -= 4; int32_t a = rd32(mem+sp);
wr32(mem+sp, a - b); sp += 4;
0x11MUL—( a b -- a*b )Mul con wrap.
sp -= 4; int32_t b = rd32(mem+sp);
sp -= 4; int32_t a = rd32(mem+sp);
wr32(mem+sp, a * b); sp += 4;
0x12DIV—( a b -- a/b )RuntimeError si b==0.
sp -= 4; int32_t b = rd32(mem+sp);
sp -= 4; int32_t a = rd32(mem+sp);
if (b == 0) return bpvm_throw(vm,"div0");
wr32(mem+sp, a / b); sp += 4;
0x13MOD—( a b -- a%b )Signo del dividendo. RuntimeError si b==0.
sp -= 4; int32_t b = rd32(mem+sp);
sp -= 4; int32_t a = rd32(mem+sp);
if (b == 0) return bpvm_throw(vm,"mod0");
wr32(mem+sp, a % b); sp += 4;
0x14NEG—( a -- -a )i32 negate.
sp -= 4; int32_t a = rd32(mem+sp);
wr32(mem+sp, -a); sp += 4;
0x15AND—( a b -- a&&b )Lógico boolean.
sp -= 4; int32_t b = rd32(mem+sp);
sp -= 4; int32_t a = rd32(mem+sp);
wr32(mem+sp, (a&&b)?1:0); sp += 4;
0x16OR—( a b -- a||b )Lógico boolean.
sp -= 4; int32_t b = rd32(mem+sp);
sp -= 4; int32_t a = rd32(mem+sp);
wr32(mem+sp, (a||b)?1:0); sp += 4;
0x17NOT—( a -- !a )Lógico boolean.
sp -= 4; int32_t a = rd32(mem+sp);
wr32(mem+sp, !a?1:0); sp += 4;
0x18GT—( a b -- a>b )Compara signed.
sp -= 4; int32_t b = rd32(mem+sp);
sp -= 4; int32_t a = rd32(mem+sp);
wr32(mem+sp, a > b ? 1 : 0); sp += 4;
0x19GE—( a b -- a>=b )Compara signed.
sp -= 4; int32_t b = rd32(mem+sp);
sp -= 4; int32_t a = rd32(mem+sp);
wr32(mem+sp, a >= b ? 1 : 0); sp += 4;
0x1ALE—( a b -- a<=b )Compara signed.
sp -= 4; int32_t b = rd32(mem+sp);
sp -= 4; int32_t a = rd32(mem+sp);
wr32(mem+sp, a <= b ? 1 : 0); sp += 4;
0x1BNEQ—( a b -- a!=b )Compara entera.
sp -= 4; int32_t b = rd32(mem+sp);
sp -= 4; int32_t a = rd32(mem+sp);
wr32(mem+sp, a != b ? 1 : 0); sp += 4;
0x1CLEA_GLOBALi16 soff( -- addr )Push cs + soff.
wr32(mem+sp, (int32_t)(cs+soff));
sp += 4;
0x1DNEWARRAY—( size -- ref )Aloca TYPE_ARRAY_I32. RuntimeError si size<0.
→ vm_op_newarray_i32(vm, &sp);
// heap alloc + GC barrier — siempre helper
0x1EALOAD—( ref idx -- v )v = mem[ref+4+idx*4]. RuntimeError out-of-range.
→ vm_op_aload_i32(vm, &sp);
// bounds check obliga a helper
0x1FASTORE—( ref idx v -- )RuntimeError out-of-range.
→ vm_op_astore_i32(vm, &sp);

Output, jumps compactos, float push 0x20..0x2F

CodeOpOperandoStackSemánticaAOT C
0x20ALEN—( ref -- length )Push mem[ref+0]. 0 si ref==0.
sp -= 4; uint32_t r = (uint32_t)rd32(mem+sp);
wr32(mem+sp, r ? rd32(mem+r) : 0);
sp += 4;
0x21PRINT_CHAR—( ch -- )Codepoint al output sin newline.
→ vm_op_print_char(vm, &sp);
0x22PRINT_STRING—( ref -- )Imprime string + newline.
→ vm_op_print_string(vm, &sp, /*nl=*/1);
0x23LEA_LOCALi16 soff( -- addr )Push bp + soff.
wr32(mem+sp, (int32_t)(bp+soff));
sp += 4;
0x24JUMP8i8 rel( -- )Salto corto.
goto label_X;   // X = pc destino
0x25JUMP16i16 rel( -- )Salto medio.
goto label_X;
0x26JUMP_IF_FALSE8i8 rel( v -- )Salto condicional corto.
sp -= 4;
if (rd32(mem+sp) == 0) goto label_X;
0x27JUMP_IF_FALSE16i16 rel( v -- )Salto condicional medio.
sp -= 4;
if (rd32(mem+sp) == 0) goto label_X;
0x28FPUSHf32 v( -- v )Push float como i32 raw-bits.
wr32(mem+sp, f2i(value)); sp += 4;
0x29FADD—( a b -- a+b )Float add.
sp -= 4; float b = i2f(rd32(mem+sp));
sp -= 4; float a = i2f(rd32(mem+sp));
wr32(mem+sp, f2i(a + b)); sp += 4;
0x2AFSUB—( a b -- a-b )Float sub.
sp -= 4; float b = i2f(rd32(mem+sp));
sp -= 4; float a = i2f(rd32(mem+sp));
wr32(mem+sp, f2i(a - b)); sp += 4;
0x2BFMUL—( a b -- a*b )Float mul.
sp -= 4; float b = i2f(rd32(mem+sp));
sp -= 4; float a = i2f(rd32(mem+sp));
wr32(mem+sp, f2i(a * b)); sp += 4;
0x2CFDIV—( a b -- a/b )RuntimeError si b==0.0.
sp -= 4; float b = i2f(rd32(mem+sp));
sp -= 4; float a = i2f(rd32(mem+sp));
if (b == 0.0f) return bpvm_throw(vm,"fdiv0");
wr32(mem+sp, f2i(a / b)); sp += 4;
0x2DFMOD—( a b -- a%b )IEEE remainder.
→ vm_op_fmod(vm, &sp);
// fmodf() / IEEEremainder dependiente
// de implementación — helper centraliza
0x2EFNEG—( a -- -a )Float negate.
sp -= 4; float a = i2f(rd32(mem+sp));
wr32(mem+sp, f2i(-a)); sp += 4;
0x2FFEQ—( a b -- a==b )Float equal estricto.
sp -= 4; float b = i2f(rd32(mem+sp));
sp -= 4; float a = i2f(rd32(mem+sp));
wr32(mem+sp, a == b ? 1 : 0); sp += 4;

Float comparisons + arrays narrow 0x30..0x3F

CodeOpOperandoStackSemánticaAOT C
0x30FNEQ—( a b -- a!=b )Float not-equal.
sp -= 4; float b = i2f(rd32(mem+sp));
sp -= 4; float a = i2f(rd32(mem+sp));
wr32(mem+sp, a != b ? 1 : 0); sp += 4;
0x31FLT—( a b -- a<b )Float less-than.
sp -= 4; float b = i2f(rd32(mem+sp));
sp -= 4; float a = i2f(rd32(mem+sp));
wr32(mem+sp, a < b ? 1 : 0); sp += 4;
0x32FLE—( a b -- a<=b )Float less-or-equal.
sp -= 4; float b = i2f(rd32(mem+sp));
sp -= 4; float a = i2f(rd32(mem+sp));
wr32(mem+sp, a <= b ? 1 : 0); sp += 4;
0x33FGT—( a b -- a>b )Float greater-than.
sp -= 4; float b = i2f(rd32(mem+sp));
sp -= 4; float a = i2f(rd32(mem+sp));
wr32(mem+sp, a > b ? 1 : 0); sp += 4;
0x34FGE—( a b -- a>=b )Float greater-or-equal.
sp -= 4; float b = i2f(rd32(mem+sp));
sp -= 4; float a = i2f(rd32(mem+sp));
wr32(mem+sp, a >= b ? 1 : 0); sp += 4;
0x35FPRINT—( f -- )Imprime float + newline.
→ vm_op_print_f32(vm, &sp, /*nl=*/1);
0x36I2F—( i -- f )i32 → f32.
sp -= 4; int32_t i = rd32(mem+sp);
wr32(mem+sp, f2i((float)i)); sp += 4;
0x37F2I—( f -- i )f32 → i32 (truncar).
sp -= 4; float f = i2f(rd32(mem+sp));
wr32(mem+sp, (int32_t)f); sp += 4;
0x38NEWARRAY_I8—( size -- ref )Aloca TYPE_ARRAY_I8.
→ vm_op_newarray_i8(vm, &sp);
0x39NEWARRAY_I16—( size -- ref )Aloca TYPE_ARRAY_I16.
→ vm_op_newarray_i16(vm, &sp);
0x3AALOAD_I8—( ref idx -- v )i8 sign-ext.
→ vm_op_aload_i8(vm, &sp);
// bounds check + sign-extend
0x3BALOAD_U8—( ref idx -- v )u8 zero-ext.
→ vm_op_aload_u8(vm, &sp);
0x3CALOAD_I16—( ref idx -- v )i16 BE sign-ext.
→ vm_op_aload_i16(vm, &sp);
0x3DALOAD_U16—( ref idx -- v )u16 zero-ext.
→ vm_op_aload_u16(vm, &sp);
0x3EASTORE_I8—( ref idx v -- )mem[ref+4+idx] = v & 0xFF.
→ vm_op_astore_i8(vm, &sp);
0x3FASTORE_I16—( ref idx v -- )2 bytes BE.
→ vm_op_astore_i16(vm, &sp);

Globals narrow + bitwise + casts 0x40..0x4F

CodeOpOperandoStackSemánticaAOT C
0x40GET_GLOBAL_I8i16 soff( -- v )i8 sign-ext.
int32_t v = (int8_t)mem[cs+soff];
wr32(mem+sp, v); sp += 4;
0x41GET_GLOBAL_U8i16 soff( -- v )u8 zero-ext.
wr32(mem+sp, (int32_t)mem[cs+soff]);
sp += 4;
0x42GET_GLOBAL_I16i16 soff( -- v )i16 BE sign-ext.
wr32(mem+sp, (int32_t)rd16s(mem+cs+soff));
sp += 4;
0x43GET_GLOBAL_U16i16 soff( -- v )u16 zero-ext.
wr32(mem+sp, (int32_t)rd16u(mem+cs+soff));
sp += 4;
0x44SET_GLOBAL_I8i16 soff( v -- )mem[cs+soff] = v & 0xFF.
sp -= 4;
mem[cs+soff] = (uint8_t)rd32(mem+sp);
0x45SET_GLOBAL_I16i16 soff( v -- )2 bytes BE.
sp -= 4; int32_t v = rd32(mem+sp);
mem[cs+soff]   = (v >> 8) & 0xFF;
mem[cs+soff+1] =  v       & 0xFF;
0x46BAND—( a b -- a&b )Bitwise AND.
sp -= 4; int32_t b = rd32(mem+sp);
sp -= 4; int32_t a = rd32(mem+sp);
wr32(mem+sp, a & b); sp += 4;
0x47BOR—( a b -- a|b )Bitwise OR.
sp -= 4; int32_t b = rd32(mem+sp);
sp -= 4; int32_t a = rd32(mem+sp);
wr32(mem+sp, a | b); sp += 4;
0x48BXOR—( a b -- a^b )Bitwise XOR.
sp -= 4; int32_t b = rd32(mem+sp);
sp -= 4; int32_t a = rd32(mem+sp);
wr32(mem+sp, a ^ b); sp += 4;
0x49BNOT—( a -- ~a )Bitwise NOT.
sp -= 4; int32_t a = rd32(mem+sp);
wr32(mem+sp, ~a); sp += 4;
0x4ASHL—( a b -- a<<b )b & 31.
sp -= 4; int32_t b = rd32(mem+sp);
sp -= 4; int32_t a = rd32(mem+sp);
wr32(mem+sp, a << (b & 31)); sp += 4;
0x4BSHR_S—( a b -- a>>b )Aritmético (sign-fill).
sp -= 4; int32_t b = rd32(mem+sp);
sp -= 4; int32_t a = rd32(mem+sp);
wr32(mem+sp, a >> (b & 31)); sp += 4;
0x4CSHR_U—( a b -- a>>>b )Lógico (zero-fill).
sp -= 4; uint32_t b = (uint32_t)rd32(mem+sp);
sp -= 4; uint32_t a = (uint32_t)rd32(mem+sp);
wr32(mem+sp, (int32_t)(a >> (b & 31)));
sp += 4;
0x4DI32_TO_I8—( v -- v8s )Rango -128..127. RuntimeError si fuera.
→ vm_op_i32_to_i8(vm, &sp);
// range check obliga a helper
0x4EI32_TO_U8—( v -- v8u )Rango 0..255.
→ vm_op_i32_to_u8(vm, &sp);
0x4FI32_TO_I16—( v -- v16s )Rango -32768..32767.
→ vm_op_i32_to_i16(vm, &sp);

Clases, builtins, excepciones 0x50..0x5F

CodeOpOperandoStackSemánticaAOT C
0x50I32_TO_U16—( v -- v16u )Rango 0..65535.
→ vm_op_i32_to_u16(vm, &sp);
0x51GC_COLLECT—( -- )Dispara GC manual.
→ vm_op_gc_collect(vm);
0x52NEW_OBJECTi16 csOff( -- ref )Aloca objeto, escribe classPtr.
→ vm_op_new_object(vm, &sp, cs+csOff);
// heapAlloc + GC barrier — siempre helper
0x53GET_FIELDu8 slot( ref -- v )v = mem[ref+4+slot*4].
sp -= 4; uint32_t r = (uint32_t)rd32(mem+sp);
wr32(mem+sp, rd32(mem+r+4+slot*4));
sp += 4;
0x54SET_FIELDu8 slot( ref v -- )mem[ref+4+slot*4] = v.
sp -= 4; int32_t v = rd32(mem+sp);
sp -= 4; uint32_t r = (uint32_t)rd32(mem+sp);
wr32(mem+r+4+slot*4, v);
0x55INVOKE_VIRTUALu8 slot, u8 numArgs( ...args this -- )Despacho con fall-back al parent.
→ vm_op_invoke_virtual(
    vm, &sp, &bp, &cs,
    slot, numArgs);
// vtable walk — siempre helper
0x56PRINT_NONL—( v -- )Int sin newline.
→ vm_op_print_i32(vm, &sp, /*nl=*/0);
0x57FPRINT_NONL—( f -- )Float sin newline.
→ vm_op_print_f32(vm, &sp, /*nl=*/0);
0x58PRINT_STR_NONL—( ref -- )String sin newline.
→ vm_op_print_string(vm, &sp, /*nl=*/0);
0x59PRINT_NL—( -- )Newline: desde V7 (#600) saca la línea del hilo entera, de una vez.
→ vm_op_print_nl(vm);
0x5ACALL_BUILTINu16 id( args -- result )Despacha al builtin id.
→ vm_op_call_builtin(vm, &sp, &bp, id);
// AOT puede inlinear builtins concretos
// si los conoce (Math.sqrt → sqrtf, etc.)
0x5BTRY_BEGINi32 handlerRel, i16 clsOff( -- )Push handler al stack de excepciones.
→ vm_op_try_begin(vm, sp, bp, cs,
                  handler_pc, clsOff);
// AOT v1 puede no soportar try — emit fail
0x5CTRY_END—( -- )Pop top del handler stack.
→ vm_op_try_end(vm);
0x5DTHROW—( ref -- )Busca handler o BpThreadFault.
→ vm_op_throw(vm, &sp);
// puede no retornar — el AOT debe asumir
// "tail call" o usar setjmp/longjmp
0x5EINSTANCEOFi16 csOff( ref -- 1|0 )Sube por parent_offset buscando match.
→ vm_op_instanceof(vm, &sp, cs+csOff);
// class hierarchy walk — siempre helper
0x5FFREE_REF—( ref -- )Liberación determinista. Desde V7 (#668) el compilador lo emite sólo para lo que no puede tener destructor; lo demás muere por Core.__destruye (ver OPCODES.md).
→ vm_op_free_ref(vm, &sp);
// recorre owner_bitmap recursivo

Owner, compactos, threading 0x60..0x70

CodeOpOperandoStackSemánticaAOT C
0x60SET_FIELD_OWNERu8 slot( ref v -- )SET_FIELD + FREE_REF del previo. Desde V7 (#668), sólo para un campo owner que no puede tener destructor.
→ vm_op_set_field_owner(vm, &sp, slot);
0x61PUSH_0—( -- 0 )Push literal 0.
wr32(mem+sp, 0); sp += 4;
0x62PUSH_1—( -- 1 )Push literal 1.
wr32(mem+sp, 1); sp += 4;
0x63PUSH_2—( -- 2 )Push literal 2.
wr32(mem+sp, 2); sp += 4;
0x64PUSH_3—( -- 3 )Push literal 3.
wr32(mem+sp, 3); sp += 4;
0x65PUSH_4—( -- 4 )Push literal 4.
wr32(mem+sp, 4); sp += 4;
0x66PUSH_NEG1—( -- -1 )Push literal -1.
wr32(mem+sp, -1); sp += 4;
0x67GET_LOCAL_S8i8 soff( -- v )Igual GET_LOCAL, offset i8.
wr32(mem+sp, rd32(mem+bp+soff));
sp += 4;
0x68SET_LOCAL_S8i8 soff( v -- )Igual SET_LOCAL, offset i8.
sp -= 4;
wr32(mem+bp+soff, rd32(mem+sp));
0x69LEA_LOCAL_S8i8 soff( -- addr )Igual LEA_LOCAL, offset i8.
wr32(mem+sp, (int32_t)(bp+soff));
sp += 4;
0x6AGET_GLOBAL_S8i8 soff( -- v )i32 read; offset i8 sign-ext.
wr32(mem+sp, rd32(mem+cs+soff));
sp += 4;
0x6BSET_GLOBAL_S8i8 soff( v -- )i32 write; offset i8 sign-ext.
sp -= 4;
wr32(mem+cs+soff, rd32(mem+sp));
0x6CLEA_GLOBAL_S8i8 soff( -- addr )Igual LEA_GLOBAL, offset i8.
wr32(mem+sp, (int32_t)(cs+soff));
sp += 4;
0x70THREAD_EXIT—( -- )Termina thread actual. Sentinela en mem[0].
// n/a — sólo aparece como sentinela
// en mem[0], que el AOT no toca.

Convenciones de notación (bytecode)

i32, u32, i16, u16, i8, u8, f32
Enteros y float big-endian.
soff
Signed offset al bp (positivo = arg/var arriba; negativo = saved regs / args debajo).
rel
Relativo al instruction address (byte del opcode, NO al pc post-operando). Difiere del estilo JVM.

instruction_addr = pc - 1  # ya consumimos el byte de opcode
rel = read_immediate(pc)
pc = instruction_addr + rel

Aplica a JUMP, JUMP_IF_FALSE y sus variantes compactas.
csOff
Relativo al cs (= codeStart) del módulo actual.
Stack effect
Notación ( a b -- c ) = pop b, pop a, push c. La cima a la derecha.

Tras ejecutar un opcode, pc apunta al siguiente, salvo control flow.