Home /Modules/cpu/SLProgramLoader.sleela

SLProgramLoader.sleela

lib/cpu/SLProgramLoader.sleela · 98 line(s) · sleela

<< lib/cpu/SLProgramLoader.sleela
   SLeeLa Standard Library Definition.
   Definition: Defines SLProgramLoader — the OS loader that copies an SLProgram
     image into main memory at a chosen load address, registers the entry point,
     and asks the OS to spawn it as a process. This is the final link: it takes
     an assembled Sleela program and makes it a running process on the Sleela
     CPU under the Sleela OS.
   
   Family: cpu. Composes SLOperatingSystem, SLRAM, SLProgram, SLProcess. >>
#sleela 2.5
material;
class SLProgramLoader {
  < ---- 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 = 10274;
  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; }
  SLOperatingSystem os;
  SLRAM memory;
  < multi-language front-end driver >
  SLCompilerDriver compiler;
  int loaded;

  void configure(SLOperatingSystem operatingSystem, SLRAM ram) {
    os = operatingSystem; memory = ram; loaded = 0;
    compiler = new SLCompilerDriver();
  }

  < Attach the ISA so the loader can compile source in any supported language. >
  void attachCompiler(SLInstructionSet isa) { compiler.configure(isa); }

  < Copy an already-compiled program image into memory starting at loadAddr, >
  < then spawn it. Returns the created process. >
  SLProcess load(SLProgram program, int loadAddr) {
    int i = 0;
    while (i < program.size()) {
      memory.writeWord(loadAddr + i, program.wordAt(i));
      i = i + 1;
    }
    program.setEntryPoint(loadAddr);
    loaded = loaded + 1;
    return os.spawn(program.programName(), loadAddr);
  }

  < Compile a source file in ANY supported language (C, C++, Java, Sleela) to a >
  < program image via the shared frontend/IR/backend pipeline, then load it. >
  < This is the multi-language loader entry point. >
  SLProcess loadSource(String path, int langId, String programName, int loadAddr) {
    SLProgram prog = compiler.compile(path, langId, programName);
    return load(prog, loadAddr);
  }

  < Convenience: infer the language from the file extension. >
  SLProcess loadFile(String path, String programName, int loadAddr) {
    SLProgram prog = compiler.compileFile(path, programName);
    return load(prog, loadAddr);
  }

  SLCompilerDriver compilerDriver() { return compiler; }
  int programsLoaded() { return loaded; }
}