Home /Modules/cpu/SLFrontendSleela.sleela

SLFrontendSleela.sleela

lib/cpu/SLFrontendSleela.sleela · 85 line(s) · sleela

<< lib/cpu/SLFrontendSleela.sleela
   SLeeLa Standard Library Definition.
   Definition: Defines SLFrontendSleela — the SLeeLa-language frontend. It
     lowers a SLeeLa method body into the common SLIR. This is the reference
     frontend of the family: because SLeeLa is the system's native language and
     its ISA aligns with the VM ISA, this path is the most direct and is modeled
     end to end (expression trees -> IR temporaries -> IR ops).
   
   The method lowerArithmetic() demonstrates a complete lowering: it builds IR
   for an arithmetic+syscall program (compute, print, exit) that the shared
   backend turns into runnable machine code.
   
   Family: cpu. Extends SLFrontend. >>
#sleela 2.5
material;
class SLFrontendSleela extends SLFrontend {
  < ---- 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 = 10222;
  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; }

  void init(String path) { configure("sleela", LANG_SLEELA, path); }

  < Lower a canonical demo: t0 = 2; t1 = 3; t2 = t0 + t1; syscall WRITE t2; halt. >
  SLIR lower() {
    SLIR m = intermediate();
    < for constant access >
    SLIRInstruction k = new SLIRInstruction();

    int t0 = m.allocTemp();
    int t1 = m.allocTemp();
    int t2 = m.allocTemp();

    < t0 = 2 >
    m.emit(k.IR_CONST, t0, -1, -1, 2);
    < t1 = 3 >
    m.emit(k.IR_CONST, t1, -1, -1, 3);
    < t2 = t0 + t1 >
    m.emit(k.IR_ADD,   t2, t0, t1, 0);
    < SYS_WRITE(t2) >
    m.emit(k.IR_SYSCALL, -1, t2, -1, 0);
    < SYS_EXIT >
    m.emit(k.IR_SYSCALL, -1, -1, -1, 4);
    m.emit(k.IR_HALT, -1, -1, -1, 0);
    return m;
  }
}