Home /Modules/cpu/SLExecutorBuild.sleela

SLExecutorBuild.sleela

lib/cpu/components/SLExecutorBuild.sleela · 197 line(s) · sleela

<< lib/cpu/components/SLExecutorBuild.sleela
   SLeeLa Standard Library Definition.
   Definition: Defines SLExecutorBuild — a user-assembled Sleela executor: a CPU
     model (SLCPURuntime / SL<ARCH>CPU) running at its spec clock (or overclocked)
     plus the components the user picked from SLComponentCatalog — a motherboard,
     a memory module, a primary storage device, an optional optical drive, and a
     system bus. It wires the memory module's backing store into the CPU and
     exposes the assembled machine so the Creator/SLVM can host it and run
     C/C++/Java/Sleela workloads on it.
   
   This is the "build your own machine" surface: pick a CPU, set its clock,
   choose RAM/storage/optical/bus, and get a configured executor whose
   performance reflects every choice.
   
   Family: cpu.components. Composes SLCPURuntime, SLMotherboard, SLMemoryModule,
     SLMemoryInterface, SLStorageDevice, SLOpticalDrive, SLSystemBus. >>
#sleela 2.5
material;
class SLExecutorBuild {
  < ---- 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 = 10500;
  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-09";
  < 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 buildName;
  SLCPURuntime cpu;
  SLMotherboard board;
  SLMemoryModule memory;
  < optional OOD cadence-overlay over `memory` >
  SLMemoryInterface memInterface;
  < optional two-tier (usual/accurate) router >
  SLMemoryTierRouter tiers;
  SLStorageDevice storage;
  SLOpticalDrive optical;
  SLSystemBus bus;
  int assembled;

  void configure(String name) { buildName = name; assembled = 0; }

  < Pick parts (any may be omitted; CPU and memory are required to assemble). >
  void installCpu(SLCPURuntime chosenCpu)        { cpu = chosenCpu; }
  void installBoard(SLMotherboard motherboard)   { board = motherboard; }
  void installMemory(SLMemoryModule module)      { memory = module; }
  void installStorage(SLStorageDevice device)    { storage = device; }
  void installOptical(SLOpticalDrive drive)      { optical = drive; }
  void installBus(SLSystemBus systemBus)         { bus = systemBus; }

  < The OOD slot for a memory interface/adapter layer: a Sleela-level overlay >
  < that imposes a target-tech refresh duty cycle on the real module (e.g. run >
  < the DDR5 so it refreshes as though it were DDR2). Composed WITH the module: >
  < install a module first, then install an interface that wraps it. The real >
  < backing store is never replaced — only the observed availability changes. >
  void installMemoryInterface(SLMemoryInterface iface) { memInterface = iface; }

  < Designate PHYSICAL memory tiers: a usual-activities module and an >
  < accuracy/competency module, plus which is the main (document default). A >
  < function marked usualmem/accuratemem binds to the matching module; the rest >
  < inherit the main tier. The accurate tier doubles as the base `memory` the >
  < CPU mounts, so single-tier builds are unaffected. >
  void installUsualTier(SLMemoryModule m) {
    if (tiers == null) { tiers = new SLMemoryTierRouter(); tiers.configure(); }
    tiers.installUsual(m);
  }
  void installAccurateTier(SLMemoryModule m) {
    if (tiers == null) { tiers = new SLMemoryTierRouter(); tiers.configure(); }
    tiers.installAccurate(m);
    < the accurate tier is the base store >
    if (memory == null) { memory = m; }
  }
  void setMainTier(int tier) {
    if (tiers == null) { tiers = new SLMemoryTierRouter(); tiers.configure(); }
    tiers.setMainTier(tier);
  }

  < Optional accelerators: give the build's CPU direct DMA and/or native GPU >
  < access, so a program on this executor can use them at any point. >
  void enableDMA() { if (cpu != null) { cpu.enableDMA(); } }
  void enableGPU() { if (cpu != null) { cpu.enableGPU(); } }
  boolean dmaEnabled() { return cpu != null && cpu.dmaEnabled(); }
  boolean gpuEnabled() { return cpu != null && cpu.gpuEnabled(); }

  < Run the CPU at a chosen frequency (0 = leave at spec). Overclocking returns >
  < false if the target is above the model's stability ceiling. >
  boolean setClock(int targetMHz) {
    if (cpu == null) { return false; }
    if (targetMHz <= 0) { cpu.resetClock(); return true; }
    return cpu.overclock(targetMHz);
  }

  < Assemble the machine: mount the chosen RAM module as the CPU's main memory. >
  < Returns true when the required parts (CPU + memory) are present. >
  boolean assemble() {
    if (cpu == null || memory == null) { return false; }
    < allocate RAM backing at the CPU word width >
    memory.mount(cpu.dataWidth());
    < Mount the usual tier too, when a two-tier router is present, so both >
    < physical modules have backing a dispatched function can bind to. (The >
    < accurate tier is `memory`, already mounted above.) >
    if (tiers != null && tiers.hasUsual()) {
      SLMemoryModule u = tiers.moduleFor(tiers.TIER_USUAL);
      if (u != null && u != memory) { u.mount(cpu.dataWidth()); }
    }
    assembled = 1;
    return true;
  }

  < The effective memory bandwidth available to the CPU is the smaller of the >
  < RAM module's effective peak and (when present) the system bus's peak — the >
  < bus can bottleneck fast RAM. When a memory interface is installed, the RAM >
  < figure is the interface's duty-scaled bandwidth (the refresh cadence >
  < overlay), not the module's raw peak. >
  int effectiveMemoryBandwidthMBs() {
    int ram = memoryBandwidthMBs();
    if (bus == null) { return ram; }
    int b = bus.peakBandwidthMBs();
    return (b < ram) ? b : ram;
  }

  < RAM bandwidth as the system sees it: the interface's duty-scaled figure >
  < when a cadence overlay is installed, otherwise the module's raw peak. >
  int memoryBandwidthMBs() {
    if (memInterface != null) { return memInterface.effectiveBandwidthMBs(); }
    return (memory != null) ? memory.peakBandwidthMBs() : 0;
  }

  < When a motherboard is installed, the memory module's channel count must fit >
  < the board's routed channels (an 8-channel module can't run on a 4-channel >
  < board). No board installed = no constraint. Returns true when the build's >
  < memory topology is seatable on the board. >
  boolean boardFits() {
    if (board == null) { return true; }
    if (memory == null) { return true; }
    return board.supportsChannels(memory.channelCount());
  }

  SLCPURuntime processor()         { return cpu; }
  SLMotherboard motherboard()      { return board; }
  SLMemoryModule ram()             { return memory; }
  SLMemoryInterface ramInterface() { return memInterface; }
  boolean hasMemoryInterface()     { return memInterface != null && memInterface.active(); }

  < Two-tier memory access. memoryForTier(t) returns the physical module a >
  < function with declared tier t (SLMemoryTierRouter.TIER_*) binds to; the VM >
  < dispatcher calls this per function so usualmem/accuratemem actually route. >
  SLMemoryTierRouter tierRouter() { return tiers; }
  boolean twoTierMemory()         { return tiers != null && tiers.twoTier(); }
  SLMemoryModule memoryForTier(int declaredTier) {
    if (tiers == null) { return memory; }
    return tiers.moduleFor(declaredTier);
  }
  SLStorageDevice disk()      { return storage; }
  SLOpticalDrive opticalDrive(){ return optical; }
  SLSystemBus systemBus()     { return bus; }
  boolean ready()             { return assembled == 1; }
  String name()               { return buildName; }
  int cpuSpecMHz()            { return (cpu != null) ? cpu.specClockMHz() : 0; }
  int cpuEffectiveMHz()       { return (cpu != null) ? cpu.effectiveMHz() : 0; }
  boolean cpuOverclocked()    { return cpu != null && cpu.overclocked(); }
  boolean cpuStable()         { return cpu == null || cpu.clockStable(); }
}