Home /Modules/operating-system/linux-creator.sleela

linux-creator.sleela

lib/operating-system/examples/linux/linux-creator.sleela · 161 line(s) · sleela

#sleela 2.5
material;
< linux-creator.sleela -- a self-contained, COMPILABLE OS Creator example for a >
< Linux-shaped OS. It mirrors the lib/os design classes (SLOSModel + its layers, >
< SLOSCreator) in one compilation unit, because `sleela run` compiles one file >
< as a single unit and the split lib/os provider classes use native string >
< intrinsics that do not compile standalone (see "Issues/notes" at the bottom). >
<  >
< What it demonstrates, end to end: >
< 1. shape a Linux OS (kernel, rootfs, swap, base drivers, compat, downloads), >
< 2. check the pre-build readiness gate (downloads + settings in place), >
< 3. "create" the OS by printing the key artifacts the OS Creator would write: >
< os_config.h, the base-driver table, swap/filesystems/downloads settings, >
< and the compat (Linux-runs-Windows) route. >
<  >
< Run:   ./impl/build/sleela run lib/operating-system/examples/linux/linux-creator.sleela >

< ---- A compact Linux OS model (the OOD aggregate) ----------------------- >
struct Model {
  < ---- 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 = 10997;
  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-11";
  < metaScienceRating: maturity/robustness on a 1..10 scale >
  int metaScienceRating = 7;
  < 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; String version; String arch; String triple;
  String loader; String kernel; String kernelVer; String cmdline;
  String rootfs; String init; String desktop;
}

class LinuxCreator {

  Model linux(String name, String version) {
    Model m = new Model();
    m.name = name; m.version = version; m.arch = "amd64";
    m.triple = "x86_64-unknown-linux-gnu";
    m.loader = "GRUB"; m.kernel = "Linux"; m.kernelVer = "6.12.0";
    m.cmdline = "ro quiet splash"; m.rootfs = "ext4"; m.init = "systemd";
    m.desktop = "GNOME Shell";
    return m;
  }

  String identity(Model m) { return m.name + " " + m.version + " (Linux, " + m.arch + ")"; }

  < ---- readiness gate: URLs + settings present before compile --------- >
  boolean readyToCompile(Model m) {
    < A Linux build needs a package repo + kernel source resolved, and the >
    < irreducible settings (os.conf, cmdline, filesystems, base-drivers). >
    boolean downloads = packageRepo(m) != "" && kernelSrc(m) != "";
    boolean settings = m.rootfs != "" && m.cmdline != "";
    boolean bootable = m.loader != "" && m.kernel != "";
    return downloads && settings && bootable;
  }
  String packageRepo(Model m) { return "http://archive.ubuntu.com/ubuntu"; }
  String kernelSrc(Model m)   { return "https://cdn.kernel.org/pub/linux/kernel"; }

  < ---- emitted artifacts (what the OS Creator writes) ----------------- >
  String configHeader(Model m) {
    String h = "/* os_config.h - generated by SLeeLa OS Creator for " + identity(m) + " */\n";
    h = h + "#define OS_NAME     \"" + m.name + "\"\n";
    h = h + "#define OS_SHAPE    \"Linux\"\n";
    h = h + "#define OS_ARCH     \"" + m.arch + "\"\n";
    h = h + "#define OS_TRIPLE   \"" + m.triple + "\"\n";
    h = h + "#define OS_LOADER   \"" + m.loader + "\"\n";
    h = h + "#define OS_KERNEL   \"" + m.kernel + "\"\n";
    h = h + "#define OS_KERNEL_VER \"" + m.kernelVer + "\"\n";
    h = h + "#define OS_ROOTFS   \"" + m.rootfs + "\"\n";
    h = h + "#define OS_INIT     \"" + m.init + "\"\n";
    h = h + "#define OS_DESKTOP  \"" + m.desktop + "\"\n";
    return h;
  }

  String baseDrivers(Model m) {
    String s = "bus pci+acpi boot\nstorage ahci+nvme boot\ndisplay efifb boot\n";
    s = s + "keyboard atkbd+usbhid boot\nmouse usbhid early\nusb xhci_hcd early\naudio snd_hda_intel early";
    return s;
  }

  String downloads(Model m) {
    String s = "package-repo compile " + packageRepo(m) + "\n";
    s = s + "kernel-src   compile " + kernelSrc(m) + "\n";
    s = s + "firmware-src iso     https://git.kernel.org/.../linux-firmware.git\n";
    s = s + "runtime-wine iso     https://dl.winehq.org/wine-builds";
    return s;
  }

  String settings(Model m) {
    String s = "swap: file 1.0x RAM, swappiness 60\n";
    s = s + "filesystem: root=" + m.rootfs + " esp=fat32\n";
    s = s + "cmdline: " + m.cmdline;
    return s;
  }

  String compat(Model m) {
    return "Linux runs Windows via wine + binfmt_misc + win32-libs\n"
         + "Linux runs macOS via darling + binfmt_misc + darwin-libs";
  }

  void banner(String t) {
    print("================================================================");
    print("  " + t);
    print("================================================================");
  }

  void main() {
    Model os = linux("Determinant", "1.0");
    banner("OS Creator example: " + identity(os));

    print("readyToCompile = " + readyToCompile(os));
    if (!readyToCompile(os)) {
      print("REFUSED: downloads/settings not in place; not emitting.");
      return;
    }
    print("");

    banner("os/os_config.h");           print(configHeader(os));
    banner("kernel/base-drivers (series)"); print(baseDrivers(os));
    banner("config/downloads.conf");    print(downloads(os));
    banner("config settings");          print(settings(os));
    banner("userspace/compat-loader");  print(compat(os));

    banner("done");
    print("Next: the OS Creator writes these under /os-development, then: sh build.sh");
  }
}