Home /Modules/compiler/SLCompileChoice.sleela

SLCompileChoice.sleela

lib/compiler/SLCompileChoice.sleela · 110 line(s) · sleela

<< lib/compiler/SLCompileChoice.sleela
   SLeeLa Standard Library Definition.
   Definition: Defines SLCompileChoice, the compiler's decision about which
     source form to compile, making .sldocument a selectable compile choice.
   
   A developer tells the compiler "compile this as a program" or "compile this as
   an ordered document". SLCompileChoice records that selection, resolves it from
   a file name when not stated explicitly, and routes to the right front end:
     - a .sleela program compiles through the ordinary SLeeLa Compiler path;
     - a .sldocument compiles through the document-aware path (which still uses
       the SLeeLa Compiler for the step methods and any companion .sleela source).
   
   The choice is explicit and fail-closed: an unknown form is not guessed; it is
   surfaced as a diagnostic.
   
   Family: compiler. Native VM/OS work crosses an explicit bridge. >>
#sleela 2.5
material;
< Unified SLeeLa SDK front-end object. >
class SLCompileChoice {
  < ---- 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 = 10067;
  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-05";
  < 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; }
  SLSourceForm sourceForm;
  String inputPath;
  int state;
  String diagnostic;

  < Choose explicitly by form. >
  void choose(String path, int form) {
    inputPath = path;
    sourceForm = new SLSourceForm();
    sourceForm.configure(form);
    state = sourceForm.ext().length() > 0 ? 1 : 0;
    diagnostic = state == 1 ? "" : "unknown source form chosen";
  }

  < Choose by inferring the form from the input file's extension. >
  void chooseFromPath(String path) {
    inputPath = path;
    sourceForm = new SLSourceForm();
    int f = sourceForm.fromExtension(path);
    if (f == 0) {
      state = 0;
      diagnostic = "unrecognised source extension; compile form unresolved";
    } else {
      state = 1;
      diagnostic = "";
    }
  }

  boolean resolved() { return state == 1; }
  String diagnostics() { return diagnostic; }
  int form() { return sourceForm == null ? 0 : sourceForm.value(); }
  boolean compilesAsDocument() { return sourceForm != null && sourceForm.isDocument(); }
  boolean compilesAsProgram() { return sourceForm != null && sourceForm.isProgram(); }

  < Compile through the selected front end. Returns a VM frame handle (>= 0) on >
  < success, or -1 with a diagnostic. The document path is routed to the >
  < document-aware native compile; the program path to the ordinary one. >
  int compile() {
    if (!resolved()) { diagnostic = "cannot compile: form unresolved"; return -1; }
    if (compilesAsDocument()) {
      return native sleela_compile_choice(inputPath, SLSourceForm.SLDOCUMENT);
    }
    if (compilesAsProgram()) {
      return native sleela_compile_choice(inputPath, SLSourceForm.SLEELA);
    }
    return native sleela_compile_choice(inputPath, sourceForm.value());
  }
}