Home /Modules/cpu/SLIRInstruction.sleela

SLIRInstruction.sleela

lib/cpu/SLIRInstruction.sleela · 120 line(s) · sleela

<< lib/cpu/SLIRInstruction.sleela
   SLeeLa Standard Library Definition.
   Definition: Defines SLIRInstruction — one instruction of the common
     intermediate representation (IR) that every language frontend lowers to.
     The IR is a small, language-neutral three-address form: an operation plus a
     destination temporary and up to two source operands (temporaries or
     immediates). SLLowering turns a stream of these into real machine code for
     the SLInstructionSet.
   
   A single IR shared by C, C++, Java, and Sleela is exactly how real multi-
   language toolchains work (e.g. LLVM IR behind clang/clang++/other frontends;
   a bytecode IR behind javac). This models that convergence point.
   
   Family: cpu. Pure Sleela IR node. >>
#sleela 2.5
material;
class SLIRInstruction {
  < ---- 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 = 10251;
  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; }
  < Language-neutral IR operations. >
  < dst = imm >
  static final int IR_CONST  = 0;
  < dst = a >
  static final int IR_MOVE   = 1;
  < dst = a + b >
  static final int IR_ADD    = 2;
  static final int IR_SUB    = 3;
  static final int IR_MUL    = 4;
  static final int IR_DIV    = 5;
  static final int IR_MOD    = 6;
  static final int IR_AND    = 7;
  static final int IR_OR     = 8;
  static final int IR_XOR    = 9;
  < compare a, b (sets condition) >
  static final int IR_CMP    = 10;
  < branch target marker (imm = label id) >
  static final int IR_LABEL  = 11;
  < goto label imm >
  static final int IR_JUMP   = 12;
  < if last compare == 0 goto label imm >
  static final int IR_JZ     = 13;
  static final int IR_JNZ    = 14;
  < dst = mem[a] >
  static final int IR_LOAD   = 15;
  < mem[a] = b >
  static final int IR_STORE  = 16;
  < stage argument a for the next call >
  static final int IR_PARAM  = 17;
  < dst = call label imm (function entry) >
  static final int IR_CALL   = 18;
  < return a >
  static final int IR_RET    = 19;
  < dst = syscall imm with arg a >
  static final int IR_SYSCALL= 20;
  static final int IR_HALT   = 21;

  int op;
  < destination temporary id (-1 if none) >
  int dst;
  < first source temporary id (-1 if none) >
  int a;
  < second source temporary id (-1 if none) >
  int b;
  < immediate / label id / syscall number >
  int imm;
  < when true, `a` carries an immediate value, not a temp id >
  boolean aIsImm;

  void configure(int operation, int dstTemp, int srcA, int srcB, int immediate) {
    op = operation; dst = dstTemp; a = srcA; b = srcB; imm = immediate; aIsImm = false;
  }
  void markImmediateA() { aIsImm = true; }

  int operation() { return op; }
  int destination() { return dst; }
  int sourceA() { return a; }
  int sourceB() { return b; }
  int immediate() { return imm; }
  boolean immediateA() { return aIsImm; }
}