SLSleelaOpcode.sleela
lib/cpu/SLSleelaOpcode.sleela · 217 line(s) · sleela
<< lib/cpu/SLSleelaOpcode.sleela
SLeeLa Standard Library Definition.
Definition: Defines SLSleelaOpcode โ the canonical SLeeLa VM opcode registry,
the Turing-complete substrate that the whole CPU model reduces to. The
codes and mnemonics mirror the native enum exactly (impl/core/sleela_core.h
`SLOp` and lib/vm/InstructionSet.sleela). The native enum currently defines
156 opcodes (codes 0..155), dispatched one-at-a-time by the native VM, and
organized here as a DOUBLE SHELF of three contiguous tiers:
- shelf 1, base computational/service core (codes 0..48): arithmetic,
control flow, call/return, threads, sockets, pipes, files;
- shelf 2, substrate extensions (codes 49..97): time services, structs,
Synchro / Munction / Best-of;
- shelf 3, host-facing services (codes 98..155): arrays, OS syscalls, GC
hint, `ran::`, Idea realtime canvas, VM-select / Modium, UI bridge,
structural send, runtime type checks, stack duplication, and the typed OSLS native binding.
All three shelves are acceptable opcodes; the tiers (BASE_COUNT /
SUBSTRATE_COUNT / NATIVE_COUNT and the TIER_* flags) do not gate execution,
they let the professional monitoring/storage layer tag and iterate each
shelf under its own flag. Every CPU instruction and OS syscall lowers onto
shelf 1 (plus structs on shelf 2).
Codes are conservative: they match the native numbering exactly rather than
inventing a parallel set.
This is the ground truth. The register-style SLInstructionSet, the OS system
calls, and every language frontend ultimately map onto THESE opcodes. Because
the native VM already executes them and they are Turing complete, any program
expressed as a stream of these opcodes has a well-defined, machine-realizable
meaning โ which is what lets C, C++, Java, and Sleela be 1:1 in Turing effect
(SLTuringBridge).
Family: cpu. Pure Sleela opcode registry; the canonical substrate. >>
#sleela 2.5
material;
class SLSleelaOpcode {
< ---- Descriptive metadata (version 1.11 nested-friendly accessors) ---- >
<< Eleven catalogued attributes with getter/setter pairs, so a GUI, loader,
or catalog can read and (where appropriate) override this record.
Values are faithful to the subject's real origin where publicly known. >>
String metaVersion = "1.0.0";
int metaId = 10282;
String metaAuthor = "Kiro Agent";
String metaDate = "2026-10-16";
String metaCopyright = "SLeeLa project";
String metaTrademark = "none";
String metaCorporation = "none";
< metaOrigin: National | <nation> | International | Galactic >
String metaOrigin = "International";
String metaBirthDate = "2026-10-06";
< metaScienceRating: maturity/robustness on a 1..10 scale >
int metaScienceRating = 9;
< metaNationalSchedule: a real, citable instrument or "none" >
String metaNationalSchedule = "none";
String getMetaVersion() { return metaVersion; }
void setMetaVersion(String v) { metaVersion = v; }
int getMetaId() { return metaId; }
void setMetaId(int v) { metaId = v; }
String getAuthor() { return metaAuthor; }
void setAuthor(String v) { metaAuthor = v; }
String getDate() { return metaDate; }
void setDate(String v) { metaDate = v; }
String getCopyright() { return metaCopyright; }
void setCopyright(String v) { metaCopyright = v; }
String getTrademark() { return metaTrademark; }
void setTrademark(String v) { metaTrademark = v; }
String getCorporation() { return metaCorporation; }
void setCorporation(String v) { metaCorporation = v; }
String getOrigin() { return metaOrigin; }
void setOrigin(String v) { metaOrigin = v; }
String getBirthDate() { return metaBirthDate; }
void setBirthDate(String v) { metaBirthDate = v; }
int getScienceRating() { return metaScienceRating; }
void setScienceRating(int v) { metaScienceRating = v; }
String getNationalSchedule() { return metaNationalSchedule; }
void setNationalSchedule(String v) { metaNationalSchedule = v; }
< Base computational/service core, in exact native numeric order. These are >
< the Turing-complete subset the CPU ISA and OS syscalls lower onto; the >
< native enum continues past them with extended host-facing opcodes. >
static final int OP_NOP=0; static final int OP_CONST=1; static final int OP_POP=2; static final int OP_DUP=3;
static final int OP_LOADG=4; static final int OP_STOREG=5; static final int OP_LOADL=6; static final int OP_STOREL=7;
static final int OP_ADD=8; static final int OP_SUB=9; static final int OP_MUL=10; static final int OP_DIV=11;
static final int OP_MOD=12; static final int OP_NEG=13; static final int OP_EQ=14; static final int OP_NE=15;
static final int OP_LT=16; static final int OP_LE=17; static final int OP_GT=18; static final int OP_GE=19;
static final int OP_AND=20; static final int OP_OR=21; static final int OP_NOT=22; static final int OP_JMP=23;
static final int OP_JMPF=24; static final int OP_CALL=25; static final int OP_RET=26; static final int OP_PRINT=27;
static final int OP_SPAWN=28; static final int OP_JOINALL=29; static final int OP_LOCK=30; static final int OP_UNLOCK=31;
static final int OP_SEND=32; static final int OP_RECV=33; static final int OP_LISTEN=34; static final int OP_ACCEPT=35;
static final int OP_CONNECT=36; static final int OP_SOCKREAD=37; static final int OP_SOCKWRITE=38; static final int OP_SOCKCLOSE=39;
static final int OP_PIPE=40; static final int OP_PIPEPEER=41; static final int OP_FIFO_MK=42; static final int OP_FILEOPEN=43;
static final int OP_FILEREAD=44; static final int OP_FILEWRITE=45; static final int OP_FILECLOSE=46; static final int OP_FILEUNLINK=47;
static final int OP_HALT=48;
< Time services 49..57, structs 58..62 (available to the substrate). >
static final int OP_NEWSTRUCT=58; static final int OP_GETFIELD=59; static final int OP_SETFIELD=60;
< --- Double-shelf opcode tiers -------------------------------------------- >
< The native substrate (impl/core/sleela_core.h `SLOp`) defines 156 opcodes >
< (codes 0..154). All are acceptable; the tiers below do not gate execution, >
< they let the professional monitoring/storage layer tag each opcode by the >
< SHELF it belongs to and iterate each shelf under its own flag. >
< >
< The three shelves are contiguous half-open ranges [prev, COUNT): >
< Shelf 1 codes 0..48 base computational/service core (through OP_HALT): >
< arithmetic, control flow, call/return, threads, sockets, pipes, >
< files. The Turing-complete subset the CPU ISA + syscalls lower onto. >
< Shelf 2 codes 49..97 substrate extensions: time services, structs, >
< Synchro / Munction / Best-of. Part of the canonical substrate. >
< Shelf 3 codes 98..154 host-facing services: arrays, OS syscalls, GC >
< hint, `ran::`, Idea realtime canvas, VM-select / Modium, UI bridge, >
< structural send, runtime type checks, and two-entry stack duplication. >
< end of shelf 1 (base core), exclusive >
static final int BASE_COUNT = 49;
< end of shelf 2 (substrate), exclusive >
static final int SUBSTRATE_COUNT = 98;
< end of shelf 3 (full native enum), exclusive. Includes host-facing services through OP_OSLS_CALL (155) >
< OP_UI_CALL (150), OP_SSEND (151), OP_CHECKCAST (152), OP_INSTANCEOF (153), >
< OP_DUP2 (154), and OP_OSLS_CALL (155): the real opcodes are 0..155, so the count is 156. >
static final int NATIVE_COUNT = 156;
< OP_SSEND (151): the ::: structural-offload send. A host-shelf service opcode >
< that frames a String source element-by-element into a receiver reach. >
static final int OP_UI_CALL = 150;
static final int OP_SSEND = 151;
static final int OP_CHECKCAST = 152;
static final int OP_INSTANCEOF = 153;
static final int OP_DUP2 = 154;
static final int OP_OSLS_CALL = 155;
< Tier ids the monitoring/storage layer pivots on (the "iteration flags"). >
< not a native opcode (out of range) >
static final int TIER_NONE = 0;
< shelf 1: base computational/service core >
static final int TIER_BASE = 1;
< shelf 2: substrate extensions >
static final int TIER_SUBSTRATE = 2;
< shelf 3: host-facing services >
static final int TIER_HOST = 3;
int code;
String mnemonic;
void configure(int opcode, String name) { code = opcode; mnemonic = name; }
< Any native opcode is acceptable; validity is the full 0..NATIVE_COUNT range. >
boolean valid(int opcode) { return opcode >= 0 && opcode < NATIVE_COUNT; }
< Per-shelf acceptance checks (all acceptable; these name WHICH shelf). >
boolean isBase(int opcode) { return opcode >= 0 && opcode < BASE_COUNT; }
boolean isSubstrate(int opcode) { return opcode >= BASE_COUNT && opcode < SUBSTRATE_COUNT; }
boolean isHost(int opcode) { return opcode >= SUBSTRATE_COUNT && opcode < NATIVE_COUNT; }
< The shelf an opcode sits on, as a TIER_* flag โ the value the professional >
< monitoring/storage layer records per opcode and iterates each shelf under. >
int tier(int opcode) {
if (isBase(opcode)) { return TIER_BASE; }
if (isSubstrate(opcode)) { return TIER_SUBSTRATE; }
if (isHost(opcode)) { return TIER_HOST; }
return TIER_NONE;
}
String tierName(int opcode) {
int t = tier(opcode);
if (t == TIER_BASE) { return "base-core"; }
if (t == TIER_SUBSTRATE) { return "substrate-ext"; }
if (t == TIER_HOST) { return "host-service"; }
return "none";
}
< Count of opcodes on each shelf, for sizing per-shelf monitoring/storage. >
< 49 >
int baseShelfCount() { return BASE_COUNT; }
< 49 >
int substrateShelfCount() { return SUBSTRATE_COUNT - BASE_COUNT; }
< 58 >
int hostShelfCount() { return NATIVE_COUNT - SUBSTRATE_COUNT; }
< Classification used by the mapping/equivalence layers. >
boolean isStackPush(int op) { return op == OP_CONST || op == OP_DUP || op == OP_LOADG || op == OP_LOADL; }
boolean isArithmetic(int op) { return op >= OP_ADD && op <= OP_NEG; }
boolean isComparison(int op) { return op >= OP_EQ && op <= OP_GE; }
boolean isLogic(int op) { return op == OP_AND || op == OP_OR || op == OP_NOT; }
boolean isControl(int op) { return op == OP_JMP || op == OP_JMPF || op == OP_CALL || op == OP_RET || op == OP_HALT; }
< The I/O + OS-service opcodes a system-call layer maps onto. >
boolean isService(int op) { return (op >= OP_PRINT && op <= OP_FILEUNLINK) && op != OP_HALT; }
String nameOf(int op) {
if (op==OP_NOP){return "OP_NOP";} if (op==OP_CONST){return "OP_CONST";}
if (op==OP_POP){return "OP_POP";} if (op==OP_DUP){return "OP_DUP";}
if (op==OP_LOADG){return "OP_LOADG";} if (op==OP_STOREG){return "OP_STOREG";}
if (op==OP_LOADL){return "OP_LOADL";} if (op==OP_STOREL){return "OP_STOREL";}
if (op==OP_ADD){return "OP_ADD";} if (op==OP_SUB){return "OP_SUB";}
if (op==OP_MUL){return "OP_MUL";} if (op==OP_DIV){return "OP_DIV";}
if (op==OP_MOD){return "OP_MOD";} if (op==OP_NEG){return "OP_NEG";}
if (op==OP_EQ){return "OP_EQ";} if (op==OP_NE){return "OP_NE";}
if (op==OP_LT){return "OP_LT";} if (op==OP_LE){return "OP_LE";}
if (op==OP_GT){return "OP_GT";} if (op==OP_GE){return "OP_GE";}
if (op==OP_AND){return "OP_AND";} if (op==OP_OR){return "OP_OR";}
if (op==OP_NOT){return "OP_NOT";} if (op==OP_JMP){return "OP_JMP";}
if (op==OP_JMPF){return "OP_JMPF";} if (op==OP_CALL){return "OP_CALL";}
if (op==OP_RET){return "OP_RET";} if (op==OP_PRINT){return "OP_PRINT";}
if (op==OP_HALT){return "OP_HALT";}
if (op==OP_FILEOPEN){return "OP_FILEOPEN";} if (op==OP_FILEREAD){return "OP_FILEREAD";}
if (op==OP_FILEWRITE){return "OP_FILEWRITE";} if (op==OP_FILECLOSE){return "OP_FILECLOSE";}
if (op==OP_NEWSTRUCT){return "OP_NEWSTRUCT";} if (op==OP_GETFIELD){return "OP_GETFIELD";}
if (op==OP_SETFIELD){return "OP_SETFIELD";}
return "OP_?";
}
< Shelf-boundary reporters (exclusive upper bounds). >
< base core: 0..48 >
int baseCount() { return BASE_COUNT; }
< + substrate: 0..97 >
int substrateCount() { return SUBSTRATE_COUNT; }
< full native set: 0..149 >
int nativeCount() { return NATIVE_COUNT; }
}