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:
- inline C directo, 1-5 líneas. El AOT lo emite literal.
- helper Llamada a una función
vm_op_*del runtime. Usado cuando la lógica es compleja (GC, dispatch virtual, excepciones, range checks). - ctrl Control flow — el AOT lo traduce a estructuras C nativas (
goto,return, llamada directa). - n/a No aplica al cuerpo de funciones AOT (HALT, THREAD_EXIT).
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.
Núcleo 0x00..0x0F
| Code | Op | Operando | Stack | Semántica | AOT C |
|---|---|---|---|---|---|
| 0x00 | HALT | — | ( -- ) | 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. |
| 0x01 | PUSH | i32 value | ( -- v ) | Empuja value al stack. | wr32(mem+sp, value); sp += 4; |
| 0x02 | ADD | — | ( 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; |
| 0x03 | — | ( v -- ) | Imprime int + newline al OutputSink. | → vm_op_print_i32(vm, &sp); | |
| 0x04 | GET_GLOBAL | i16 soff | ( -- v ) | Push mem[cs + soff] i32. | wr32(mem+sp, rd32(mem+cs+soff)); sp += 4; |
| 0x05 | SET_GLOBAL | i16 soff | ( v -- ) | Escribe i32 en mem[cs + soff]. | sp -= 4; wr32(mem+cs+soff, rd32(mem+sp)); |
| 0x06 | CALL_EXT | u16 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); |
| 0x07 | CALL | i32 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); |
| 0x08 | RET | u8 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 |
| 0x09 | GET_LOCAL | i16 soff | ( -- v ) | Push mem[bp + soff] i32. | wr32(mem+sp, rd32(mem+bp+soff)); sp += 4; |
| 0x0A | SET_LOCAL | i16 soff | ( v -- ) | Escribe i32 en mem[bp + soff]. | sp -= 4; wr32(mem+bp+soff, rd32(mem+sp)); |
| 0x0B | EQ | — | ( 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; |
| 0x0C | LT | — | ( 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; |
| 0x0D | JUMP | i32 rel | ( -- ) | Salto incondicional. | goto label_X; // X = pc destino,
// emitido como label por
// el AOT al hacer CFG pass |
| 0x0E | JUMP_IF_FALSE | i32 rel | ( v -- ) | Si v == 0, salta. | sp -= 4; if (rd32(mem+sp) == 0) goto label_X; |
| 0x0F | ENTER | u16 bytes | ( -- ) | Reserva bytes en stack para locales. | sp += bytes; |
Aritmética + arrays 0x10..0x1F
| Code | Op | Operando | Stack | Semántica | AOT C |
|---|---|---|---|---|---|
| 0x10 | SUB | — | ( 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; |
| 0x11 | MUL | — | ( 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; |
| 0x12 | DIV | — | ( 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; |
| 0x13 | MOD | — | ( 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; |
| 0x14 | NEG | — | ( a -- -a ) | i32 negate. | sp -= 4; int32_t a = rd32(mem+sp); wr32(mem+sp, -a); sp += 4; |
| 0x15 | AND | — | ( 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; |
| 0x16 | OR | — | ( 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; |
| 0x17 | NOT | — | ( a -- !a ) | Lógico boolean. | sp -= 4; int32_t a = rd32(mem+sp); wr32(mem+sp, !a?1:0); sp += 4; |
| 0x18 | GT | — | ( 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; |
| 0x19 | GE | — | ( 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; |
| 0x1A | LE | — | ( 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; |
| 0x1B | NEQ | — | ( 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; |
| 0x1C | LEA_GLOBAL | i16 soff | ( -- addr ) | Push cs + soff. | wr32(mem+sp, (int32_t)(cs+soff)); sp += 4; |
| 0x1D | NEWARRAY | — | ( size -- ref ) | Aloca TYPE_ARRAY_I32. RuntimeError si size<0. | → vm_op_newarray_i32(vm, &sp); // heap alloc + GC barrier — siempre helper |
| 0x1E | ALOAD | — | ( ref idx -- v ) | v = mem[ref+4+idx*4]. RuntimeError out-of-range. | → vm_op_aload_i32(vm, &sp); // bounds check obliga a helper |
| 0x1F | ASTORE | — | ( ref idx v -- ) | RuntimeError out-of-range. | → vm_op_astore_i32(vm, &sp); |
Output, jumps compactos, float push 0x20..0x2F
| Code | Op | Operando | Stack | Semántica | AOT C |
|---|---|---|---|---|---|
| 0x20 | ALEN | — | ( 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; |
| 0x21 | PRINT_CHAR | — | ( ch -- ) | Codepoint al output sin newline. | → vm_op_print_char(vm, &sp); |
| 0x22 | PRINT_STRING | — | ( ref -- ) | Imprime string + newline. | → vm_op_print_string(vm, &sp, /*nl=*/1); |
| 0x23 | LEA_LOCAL | i16 soff | ( -- addr ) | Push bp + soff. | wr32(mem+sp, (int32_t)(bp+soff)); sp += 4; |
| 0x24 | JUMP8 | i8 rel | ( -- ) | Salto corto. | goto label_X; // X = pc destino |
| 0x25 | JUMP16 | i16 rel | ( -- ) | Salto medio. | goto label_X; |
| 0x26 | JUMP_IF_FALSE8 | i8 rel | ( v -- ) | Salto condicional corto. | sp -= 4; if (rd32(mem+sp) == 0) goto label_X; |
| 0x27 | JUMP_IF_FALSE16 | i16 rel | ( v -- ) | Salto condicional medio. | sp -= 4; if (rd32(mem+sp) == 0) goto label_X; |
| 0x28 | FPUSH | f32 v | ( -- v ) | Push float como i32 raw-bits. | wr32(mem+sp, f2i(value)); sp += 4; |
| 0x29 | FADD | — | ( 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; |
| 0x2A | FSUB | — | ( 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; |
| 0x2B | FMUL | — | ( 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; |
| 0x2C | FDIV | — | ( 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; |
| 0x2D | FMOD | — | ( a b -- a%b ) | IEEE remainder. | → vm_op_fmod(vm, &sp); // fmodf() / IEEEremainder dependiente // de implementación — helper centraliza |
| 0x2E | FNEG | — | ( a -- -a ) | Float negate. | sp -= 4; float a = i2f(rd32(mem+sp)); wr32(mem+sp, f2i(-a)); sp += 4; |
| 0x2F | FEQ | — | ( 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
| Code | Op | Operando | Stack | Semántica | AOT C |
|---|---|---|---|---|---|
| 0x30 | FNEQ | — | ( 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; |
| 0x31 | FLT | — | ( 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; |
| 0x32 | FLE | — | ( 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; |
| 0x33 | FGT | — | ( 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; |
| 0x34 | FGE | — | ( 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; |
| 0x35 | FPRINT | — | ( f -- ) | Imprime float + newline. | → vm_op_print_f32(vm, &sp, /*nl=*/1); |
| 0x36 | I2F | — | ( i -- f ) | i32 → f32. | sp -= 4; int32_t i = rd32(mem+sp); wr32(mem+sp, f2i((float)i)); sp += 4; |
| 0x37 | F2I | — | ( f -- i ) | f32 → i32 (truncar). | sp -= 4; float f = i2f(rd32(mem+sp)); wr32(mem+sp, (int32_t)f); sp += 4; |
| 0x38 | NEWARRAY_I8 | — | ( size -- ref ) | Aloca TYPE_ARRAY_I8. | → vm_op_newarray_i8(vm, &sp); |
| 0x39 | NEWARRAY_I16 | — | ( size -- ref ) | Aloca TYPE_ARRAY_I16. | → vm_op_newarray_i16(vm, &sp); |
| 0x3A | ALOAD_I8 | — | ( ref idx -- v ) | i8 sign-ext. | → vm_op_aload_i8(vm, &sp); // bounds check + sign-extend |
| 0x3B | ALOAD_U8 | — | ( ref idx -- v ) | u8 zero-ext. | → vm_op_aload_u8(vm, &sp); |
| 0x3C | ALOAD_I16 | — | ( ref idx -- v ) | i16 BE sign-ext. | → vm_op_aload_i16(vm, &sp); |
| 0x3D | ALOAD_U16 | — | ( ref idx -- v ) | u16 zero-ext. | → vm_op_aload_u16(vm, &sp); |
| 0x3E | ASTORE_I8 | — | ( ref idx v -- ) | mem[ref+4+idx] = v & 0xFF. | → vm_op_astore_i8(vm, &sp); |
| 0x3F | ASTORE_I16 | — | ( ref idx v -- ) | 2 bytes BE. | → vm_op_astore_i16(vm, &sp); |
Globals narrow + bitwise + casts 0x40..0x4F
| Code | Op | Operando | Stack | Semántica | AOT C |
|---|---|---|---|---|---|
| 0x40 | GET_GLOBAL_I8 | i16 soff | ( -- v ) | i8 sign-ext. | int32_t v = (int8_t)mem[cs+soff]; wr32(mem+sp, v); sp += 4; |
| 0x41 | GET_GLOBAL_U8 | i16 soff | ( -- v ) | u8 zero-ext. | wr32(mem+sp, (int32_t)mem[cs+soff]); sp += 4; |
| 0x42 | GET_GLOBAL_I16 | i16 soff | ( -- v ) | i16 BE sign-ext. | wr32(mem+sp, (int32_t)rd16s(mem+cs+soff)); sp += 4; |
| 0x43 | GET_GLOBAL_U16 | i16 soff | ( -- v ) | u16 zero-ext. | wr32(mem+sp, (int32_t)rd16u(mem+cs+soff)); sp += 4; |
| 0x44 | SET_GLOBAL_I8 | i16 soff | ( v -- ) | mem[cs+soff] = v & 0xFF. | sp -= 4; mem[cs+soff] = (uint8_t)rd32(mem+sp); |
| 0x45 | SET_GLOBAL_I16 | i16 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; |
| 0x46 | BAND | — | ( 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; |
| 0x47 | BOR | — | ( 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; |
| 0x48 | BXOR | — | ( 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; |
| 0x49 | BNOT | — | ( a -- ~a ) | Bitwise NOT. | sp -= 4; int32_t a = rd32(mem+sp); wr32(mem+sp, ~a); sp += 4; |
| 0x4A | SHL | — | ( 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; |
| 0x4B | SHR_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; |
| 0x4C | SHR_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; |
| 0x4D | I32_TO_I8 | — | ( v -- v8s ) | Rango -128..127. RuntimeError si fuera. | → vm_op_i32_to_i8(vm, &sp); // range check obliga a helper |
| 0x4E | I32_TO_U8 | — | ( v -- v8u ) | Rango 0..255. | → vm_op_i32_to_u8(vm, &sp); |
| 0x4F | I32_TO_I16 | — | ( v -- v16s ) | Rango -32768..32767. | → vm_op_i32_to_i16(vm, &sp); |
Clases, builtins, excepciones 0x50..0x5F
| Code | Op | Operando | Stack | Semántica | AOT C |
|---|---|---|---|---|---|
| 0x50 | I32_TO_U16 | — | ( v -- v16u ) | Rango 0..65535. | → vm_op_i32_to_u16(vm, &sp); |
| 0x51 | GC_COLLECT | — | ( -- ) | Dispara GC manual. | → vm_op_gc_collect(vm); |
| 0x52 | NEW_OBJECT | i16 csOff | ( -- ref ) | Aloca objeto, escribe classPtr. | → vm_op_new_object(vm, &sp, cs+csOff); // heapAlloc + GC barrier — siempre helper |
| 0x53 | GET_FIELD | u8 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; |
| 0x54 | SET_FIELD | u8 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); |
| 0x55 | INVOKE_VIRTUAL | u8 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 |
| 0x56 | PRINT_NONL | — | ( v -- ) | Int sin newline. | → vm_op_print_i32(vm, &sp, /*nl=*/0); |
| 0x57 | FPRINT_NONL | — | ( f -- ) | Float sin newline. | → vm_op_print_f32(vm, &sp, /*nl=*/0); |
| 0x58 | PRINT_STR_NONL | — | ( ref -- ) | String sin newline. | → vm_op_print_string(vm, &sp, /*nl=*/0); |
| 0x59 | PRINT_NL | — | ( -- ) | Newline: desde V7 (#600) saca la línea del hilo entera, de una vez. | → vm_op_print_nl(vm); |
| 0x5A | CALL_BUILTIN | u16 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.) |
| 0x5B | TRY_BEGIN | i32 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 |
| 0x5C | TRY_END | — | ( -- ) | Pop top del handler stack. | → vm_op_try_end(vm); |
| 0x5D | THROW | — | ( ref -- ) | Busca handler o BpThreadFault. | → vm_op_throw(vm, &sp); // puede no retornar — el AOT debe asumir // "tail call" o usar setjmp/longjmp |
| 0x5E | INSTANCEOF | i16 csOff | ( ref -- 1|0 ) | Sube por parent_offset buscando match. | → vm_op_instanceof(vm, &sp, cs+csOff); // class hierarchy walk — siempre helper |
| 0x5F | FREE_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
| Code | Op | Operando | Stack | Semántica | AOT C |
|---|---|---|---|---|---|
| 0x60 | SET_FIELD_OWNER | u8 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); |
| 0x61 | PUSH_0 | — | ( -- 0 ) | Push literal 0. | wr32(mem+sp, 0); sp += 4; |
| 0x62 | PUSH_1 | — | ( -- 1 ) | Push literal 1. | wr32(mem+sp, 1); sp += 4; |
| 0x63 | PUSH_2 | — | ( -- 2 ) | Push literal 2. | wr32(mem+sp, 2); sp += 4; |
| 0x64 | PUSH_3 | — | ( -- 3 ) | Push literal 3. | wr32(mem+sp, 3); sp += 4; |
| 0x65 | PUSH_4 | — | ( -- 4 ) | Push literal 4. | wr32(mem+sp, 4); sp += 4; |
| 0x66 | PUSH_NEG1 | — | ( -- -1 ) | Push literal -1. | wr32(mem+sp, -1); sp += 4; |
| 0x67 | GET_LOCAL_S8 | i8 soff | ( -- v ) | Igual GET_LOCAL, offset i8. | wr32(mem+sp, rd32(mem+bp+soff)); sp += 4; |
| 0x68 | SET_LOCAL_S8 | i8 soff | ( v -- ) | Igual SET_LOCAL, offset i8. | sp -= 4; wr32(mem+bp+soff, rd32(mem+sp)); |
| 0x69 | LEA_LOCAL_S8 | i8 soff | ( -- addr ) | Igual LEA_LOCAL, offset i8. | wr32(mem+sp, (int32_t)(bp+soff)); sp += 4; |
| 0x6A | GET_GLOBAL_S8 | i8 soff | ( -- v ) | i32 read; offset i8 sign-ext. | wr32(mem+sp, rd32(mem+cs+soff)); sp += 4; |
| 0x6B | SET_GLOBAL_S8 | i8 soff | ( v -- ) | i32 write; offset i8 sign-ext. | sp -= 4; wr32(mem+cs+soff, rd32(mem+sp)); |
| 0x6C | LEA_GLOBAL_S8 | i8 soff | ( -- addr ) | Igual LEA_GLOBAL, offset i8. | wr32(mem+sp, (int32_t)(cs+soff)); sp += 4; |
| 0x70 | THREAD_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 aJUMP,JUMP_IF_FALSEy 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.