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

macos-creator.sleela

lib/operating-system/examples/macos/macos-creator.sleela · 153 line(s) · sleela

#sleela 2.5
material;
< macos-creator.sleela -- a self-contained, COMPILABLE OS Creator example for a >
< macOS-shaped OS. Mirrors the lib/os design classes in one unit (the split >
< provider classes use native string intrinsics that do not compile standalone; >
< see "Issues/notes" at the bottom). >
<  >
< It demonstrates the macOS family defaults the OS Creator applies: the XNU/ >
< Darwin kernel (Darwin 24 / Sequoia), the boot.efi loader, an APFS root, >
< kernel-managed dynamic swap files, launchd as init, Aqua/WindowServer as the >
< session, and the IOKit base-driver families. Built here as arm64 (Apple >
< Silicon); its compat routes run Windows (Wine/CrossOver) and Linux (Lima). >
<  >
< Run:  ./impl/build/sleela run lib/operating-system/examples/macos/macos-creator.sleela >

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 = 10998;
  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 MacosCreator {

  Model macos(String name, String version) {
    Model m = new Model();
    m.name = name; m.version = version; m.arch = "arm64";
    m.triple = "aarch64-apple-darwin";
    < Darwin 24 (Sequoia) >
    m.loader = "boot.efi"; m.kernel = "XNU"; m.kernelVer = "24.0.0";
    m.cmdline = "ro quiet"; m.rootfs = "APFS"; m.init = "launchd";
    m.desktop = "Aqua/WindowServer";
    return m;
  }

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

  boolean readyToCompile(Model m) {
    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 "https://pkgs.local/macos"; }
  String kernelSrc(Model m)   { return "https://opensource.apple.com/source/xnu"; }

  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    \"macOS\"\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 IOPCIFamily/AppleACPIPlatform boot\nstorage IOAHCIFamily/IONVMeFamily boot\n";
    s = s + "display AppleDisplay/framebuffer boot\nkeyboard AppleHIDKeyboard boot\n";
    s = s + "mouse AppleHIDMouse early\nusb IOUSBHostFamily early\naudio AppleHDA 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://uefi.org/firmware\n";
    s = s + "runtime-qemu iso     https://www.qemu.org/download";
    return s;
  }

  String settings(Model m) {
    String s = "swap: dynamic (kernel-managed under /private/var/vm)\n";
    s = s + "filesystem: root=" + m.rootfs + " esp=fat32\n";
    s = s + "cmdline: " + m.cmdline;
    return s;
  }

  < macOS has no FS interpreter; it runs Windows (Wine) and Linux (Lima VM) >
  < guests; Rosetta 2 translates x86-64 within the macOS world. >
  String compat(Model m) {
    return "macOS runs Windows via wine/crossover + win32-libs\n"
         + "macOS runs Linux via lima + linux-userland\n"
         + "(x86-64 within macOS: Rosetta 2)";
  }

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

  void main() {
    Model os = macos("Clarion", "1.0");
    banner("OS Creator example: " + identity(os));
    print("readyToCompile = " + readyToCompile(os));
    if (!readyToCompile(os)) { print("REFUSED: 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");
  }
}