Home /Modules/cpu/SLWorkload.sleela

SLWorkload.sleela

lib/cpu/SLWorkload.sleela · 123 line(s) · sleela

<< lib/cpu/SLWorkload.sleela
   SLeeLa Standard Library Definition.
   Definition: Defines SLWorkload — a unit of work to run on a CPU, written in
     C, C++, or Sleela (and Java, which shares the same frontend path). A
     workload names its source, its language, and the SLCPUResource grant it
     needs. compile() drives the shared multi-language pipeline
     (SLCompilerDriver -> SLProgram, the register-ISA image); the CPU then maps
     that image onto its own canonical-opcode substrate and runs it inside the
     grant. The SAME workload therefore runs identically whether its source was
     C, C++, or Sleela — the 1:1 Turing-effect guarantee (SLTuringBridge).
   
   Family: cpu. Composes SLCPUResource, SLCompilerDriver, SLProgram; consumed by
     SLCPURuntime.runWorkload(). >>
#sleela 2.5
material;
class SLWorkload {
  < ---- 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 = 10542;
  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-09";
  < 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 ids (match SLCompilerDriver / SLFrontend). >
  static final int LANG_SLEELA = 0;
  static final int LANG_C      = 1;
  static final int LANG_CPP    = 2;
  static final int LANG_JAVA   = 3;

  < Lifecycle states. >
  static final int STATE_NEW      = 0;
  static final int STATE_COMPILED = 1;
  static final int STATE_ADMITTED = 2;
  static final int STATE_RUNNING  = 3;
  static final int STATE_DONE     = 4;
  static final int STATE_REJECTED = 5;

  String name;
  String sourcePath;
  int language;
  int state;

  < the grant this workload runs within >
  SLCPUResource resource;
  < compiled register-ISA image (language-independent) >
  SLProgram program;
  < last observable output (printed value) >
  int result;

  void configure(String workloadName, String path, int langId, SLCPUResource grant) {
    name = workloadName; sourcePath = path; language = langId;
    resource = grant; state = STATE_NEW; result = 0;
  }

  < Compile the source (any supported language) to the shared register-ISA >
  < image via the multi-language driver. After this the image is language- >
  < independent, so the CPU runs it the same regardless of source language. >
  SLProgram compile(SLInstructionSet isa) {
    SLCompilerDriver driver = new SLCompilerDriver();
    driver.configure(isa);
    program = driver.compile(sourcePath, language, name);
    state = STATE_COMPILED;
    return program;
  }

  void markAdmitted() { state = STATE_ADMITTED; }
  void markRejected() { state = STATE_REJECTED; }
  void markRunning()  { state = STATE_RUNNING; }
  void markDone(int observable) { result = observable; state = STATE_DONE; }

  SLProgram image()        { return program; }
  SLCPUResource grant()    { return resource; }
  int languageId()         { return language; }
  String workloadName()    { return name; }
  String source()          { return sourcePath; }
  int runState()           { return state; }
  int output()             { return result; }
  boolean compiled()       { return state >= STATE_COMPILED; }
  boolean finished()       { return state == STATE_DONE; }
  boolean rejected()       { return state == STATE_REJECTED; }

  String languageName() {
    if (language == LANG_C) { return "C"; }
    if (language == LANG_CPP) { return "C++"; }
    if (language == LANG_JAVA) { return "Java"; }
    return "Sleela";
  }
}