Home /Modules/cpu/SLGuestProgram.sleela

SLGuestProgram.sleela

lib/cpu/SLGuestProgram.sleela · 104 line(s) · sleela

<< lib/cpu/SLGuestProgram.sleela
   SLeeLa Standard Library Definition.
   Definition: Defines SLGuestProgram — a loadable guest *user* program: a
     compiled opcode image (like SLGuestKernelImage) plus the base address at
     which it is loaded into the guest substrate's code store. Where
     SLGuestKernelImage is the kernel, SLGuestProgram is an application the guest
     kernel loads as a task and the scheduler runs. Programs are built from
     source in any supported language through the same toolchain, so a guest
     user program can be C/C++/Java/Sleela.
   
   loadInto() appends the program's opcodes to the guest substrate and returns
   the entry index (its base), which becomes the task's entry point.
   
   Family: cpu. Composes SLSleelaVM, SLGuestKernelBuilder (shared compile path). >>
#sleela 2.5
material;
class SLGuestProgram {
  < ---- 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 = 10236;
  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; }
  String name;
  SLRAM ops;
  SLRAM args;
  int length;
  < substrate code index where this program was loaded >
  int base;

  void configure(String programName, int capacity) {
    name = programName;
    ops = new SLRAM(); ops.configure(capacity, 32); ops.allocate();
    args = new SLRAM(); args.configure(capacity, 32); args.allocate();
    length = 0; base = 0;
  }

  int append(int opcode, int arg) {
    ops.writeWord(length, opcode); args.writeWord(length, arg);
    int at = length; length = length + 1; return at;
  }

  < Build a guest program from source via the shared toolchain, copying the >
  < compiled opcode image out of a scratch kernel-image build. >
  void buildFrom(String sourcePath, int langId) {
    SLGuestKernelBuilder builder = new SLGuestKernelBuilder(); builder.configure();
    SLGuestKernelImage img = builder.build(sourcePath, langId, name, "task");
    int i = 0;
    while (i < img.size()) { append(img.opcodeAt(i), img.argAt(i)); i = i + 1; }
  }

  < Load the program into the guest substrate at the current end of its code >
  < store; returns the entry index (base) for the task. >
  int loadInto(SLSleelaVM vm) {
    base = vm.programLength();
    int i = 0;
    while (i < length) { vm.loadOpcode(ops.readWord(i), args.readWord(i)); i = i + 1; }
    return base;
  }

  < Op/arg accessors so a program can be serialized to an on-disk executable. >
  int opcodeAt(int i) { return ops.readWord(i); }
  int argAt(int i) { return args.readWord(i); }

  int entryBase() { return base; }
  int size() { return length; }
  String programName() { return name; }
}