<< lib/operating-system/SLCppEmitter.sleela SLeeLa Standard Library Definition. Definition: Defines SLCppEmitter — the C++ backend of the OS-construction family. Given a configured SLOSModel, it emits C++ source text that models the designed OS as objects: an OsImage class whose constructor records the model's identity, shape, kernel and boot parameters, and whose assemble() method composes the boot chain (bootloader -> kernel -> rootfs -> drivers -> services -> optional desktop) in the firmware->boot->kernel->userspace-> desktop order. The C++ output pairs with SLCEmitter's C output; a build can use whichever surface the native toolchain prefers. This is the "compiling the Sleela produces C++" half of the pipeline. All output is ordinary String concatenation on OP_ADD; no new VM opcode is used. Family: operating-system. Consumes SLOSModel and its composed specs. >> #sleela 2.5 material; class SLCppEmitter { < ---- 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 = 10882; String metaAuthor = "Kiro Agent"; String metaDate = "2026-10-16"; String metaCopyright = "SLeeLa project"; String metaTrademark = "none"; String metaCorporation = "none"; < metaOrigin: National | | International | Galactic > String metaOrigin = "International"; String metaBirthDate = "2026-10-10"; < 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 intToStr(int v) { return "" + v; } < Emit the OsImage C++ translation unit for the model. > String emitOsImage(SLOSModel m) { String s = "// os_image.cpp - generated by SLeeLa lib/os from " + m.identity() + "\n"; s = s + "#include \n#include \n\n"; s = s + "namespace sleela_os {\n\n"; s = s + "class OsImage {\n"; s = s + "public:\n"; s = s + " std::string name = \"" + m.name() + "\";\n"; s = s + " std::string version = \"" + m.osVersion() + "\";\n"; s = s + " std::string edition = \"" + m.osEdition() + "\";\n"; s = s + " std::string shape = \"" + m.osShape().name() + "\";\n"; s = s + " std::string arch = \"" + m.architectures().primaryArch().arch() + "\";\n"; s = s + " std::string triple = \"" + m.architectures().primaryArch().targetTriple() + "\";\n"; s = s + " std::string loader = \"" + m.bootloader().loaderName() + "\";\n"; s = s + " std::string kernel = \"" + m.kernelSpec().name() + "\";\n"; s = s + " std::string cmdline = \"" + m.kernelSpec().commandLine() + "\";\n"; s = s + " std::string rootfs = \"" + m.layout().fsFormat() + "\";\n"; s = s + " std::string init = \"" + m.serviceSet().serviceManager() + "\";\n"; if (m.desktopSpec().hasDesktop()) { s = s + " std::string desktop = \"" + m.desktopSpec().shell() + "\";\n"; } else { s = s + " bool headless = true;\n"; } s = s + "\n"; < Build the services vector from the model's unit manifest. > s = s + emitServiceVector(m); s = s + "\n"; s = s + " // Compose the boot chain in firmware->desktop order.\n"; s = s + " int assemble() {\n"; s = s + " if (!firmwareHandoff(loader)) return 1;\n"; s = s + " if (!kernelStart(cmdline)) return 2;\n"; s = s + " if (!mountRootfs(rootfs)) return 3;\n"; s = s + " if (!loadDrivers()) return 4;\n"; s = s + " for (auto &svc : services) startService(svc);\n"; if (m.desktopSpec().hasDesktop()) { s = s + " startSession(desktop);\n"; } s = s + " return 0;\n"; s = s + " }\n\n"; s = s + "private:\n"; s = s + " bool firmwareHandoff(const std::string&);\n"; s = s + " bool kernelStart(const std::string&);\n"; s = s + " bool mountRootfs(const std::string&);\n"; s = s + " bool loadDrivers();\n"; s = s + " void startService(const std::string&);\n"; if (m.desktopSpec().hasDesktop()) { s = s + " void startSession(const std::string&);\n"; } s = s + "};\n\n"; s = s + "} // namespace sleela_os\n"; return s; } < Emit the service vector initialiser from the model's unit manifest. > String emitServiceVector(SLOSModel m) { String units = m.serviceSet().unitManifest(); String out = " std::vector services = {"; String line = ""; int i = 0; int n = strLen(units); int first = 1; while (i <= n) { String ch = charAt(units, i); if (ch == "\n" || i == n) { if (strLen(line) > 0) { String nm = firstToken(line); if (first == 1) { out = out + "\"" + nm + "\""; first = 0; } else { out = out + ", \"" + nm + "\""; } } line = ""; } else { line = line + ch; } i = i + 1; } out = out + "};\n"; return out; } < The token before the first space on a "name mode" line. > String firstToken(String line) { int i = 0; int n = strLen(line); while (i < n) { if (charAt(line, i) == " ") { return substr(line, 0, i); } i = i + 1; } return line; } < String primitives wrap the shared native text intrinsics. > int strLen(String s) { return native sleela_str_length(s); } String substr(String s, int a, int b) { return native sleela_str_substring(s, a, b); } String charAt(String s, int i) { return substr(s, i, i + 1); } }