Home /Modules/vm/SleelaVMSystemCallBridge.sleela

SleelaVMSystemCallBridge.sleela

lib/vm/SleelaVMSystemCallBridge.sleela · 180 line(s) · sleela

<< lib/vm/SleelaVMSystemCallBridge.sleela
   SLeeLa Standard Library Definition.
   Definition: Defines SleelaVMSystemCallBridge โ€” the VM-family face of the
     operating-system System Call API. Where SLVMNativeBinding is the lifecycle
     anchor for "the VM reaches native code," this class is the concrete bridge
     that exposes the host System API to a running VM through the os* built-ins
     (OP_OS_* opcodes), serviced by impl/core/sleela_os.c on Windows, Linux, and
     macOS. Every SLeeLa VM โ€” the base SLVM and generations SLVM/1..11 โ€” shares
     one ISA, so if the base VM can issue these system calls, every generation
     can too; this class is how a VM advertises and performs them.
   
   Capability: pairs with SleelaVMFeatureBits.PROCESS and .OS_SYSCALLS. A VM that
   sets those bits is declaring it supports this bridge. A spawned process is a
   VM-local bounded handle (the sockets/files discipline), never a raw PID.
   
   Family: vm. Native VM/OS work crosses the explicit os* SLVM bridge. >>
#sleela 2.5
material;
class SleelaVMSystemCallBridge {
  < ---- 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 = 10289;
  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-06";
  < 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 name;
  int state;
  int calls;

  void configure(String n) { name = n; state = 0; calls = 0; }
  void start() { state = 1; }
  void stop() { state = 0; }
  boolean active() { return state == 1; }

  < ---- Host identity ------------------------------------------------------ >
  String platform() { calls = calls + 1; return osPlatform(); }
  String hostName() { calls = calls + 1; return osHostName(); }
  String userName() { calls = calls + 1; return osUserName(); }
  int processId()   { calls = calls + 1; return osProcessId(); }
  boolean supports(int capability) { calls = calls + 1; return osCapability(capability) == 1; }

  < ---- Environment -------------------------------------------------------- >
  String getEnv(String key) { calls = calls + 1; return osGetEnv(key); }
  boolean setEnv(String key, String value) { calls = calls + 1; return osSetEnv(key, value) == 0; }

  < ---- Working directory -------------------------------------------------- >
  String currentDir() { calls = calls + 1; return osCurrentDir(); }
  boolean changeDir(String path) { calls = calls + 1; return osChangeDir(path) == 0; }
  String tempDir() { calls = calls + 1; return osTempDir(); }

  < ---- Filesystem metadata ------------------------------------------------ >
  boolean exists(String path) { calls = calls + 1; return osExists(path) == 1; }
  boolean isDir(String path) { calls = calls + 1; return osIsDir(path) == 1; }
  int fileSize(String path) { calls = calls + 1; return osFileSize(path); }
  boolean makeDir(String path) { calls = calls + 1; return osMakeDir(path) == 0; }
  boolean remove(String path) { calls = calls + 1; return osRemove(path) == 0; }
  boolean rename(String from, String to) { calls = calls + 1; return osRename(from, to) == 0; }

  < ---- Process execution (bounded VM-local handles) ----------------------- >
  < Synchronous run; returns the command's exit code. >
  int run(String command) { calls = calls + 1; return osRun(command); }
  < Background start; returns a VM-local process handle (-1 on failure). >
  int spawn(String command) { calls = calls + 1; return osSpawn(command); }
  < Wait for a spawned process; returns its exit code and frees the handle. >
  int waitFor(int processHandle) { calls = calls + 1; return osWait(processHandle); }
  < Terminate a spawned process. >
  boolean kill(int processHandle) { calls = calls + 1; return osKill(processHandle) == 0; }
  < Release a spawned process without waiting. >
  void closeProcess(int processHandle) { calls = calls + 1; osProcessClose(processHandle); }

  < ---- OS-level-support catalogue integration --------------------------- >
  < The existing OP_OS_* bridge is the VM execution path. This list records
    the OSLS taxonomy groups that have a corresponding current VM built-in. >
  SLList osSupportVMGroups() {
    SLList out = new SLList();
    out.add("HostIdentity");
    out.add("Environment");
    out.add("PathManagement");
    out.add("FileSystem");
    out.add("ProcessInspection");
    out.add("ProcessControl");
    out.add("CapabilityDiscovery");
    out.add("OSLSInspection");
    out.add("CPUArchitecture");
    out.add("TimeZoneCalendar");
    out.add("NetworkInterfaces");
    out.add("Scheduling");
    return out;
  }

  < Canonical current OS service opcodes; codes are append-only in the VM ISA. >
  SLList osSupportVMOpcodes() {
    SLList out = new SLList();
    out.add("OP_OS_PLATFORM=103");
    out.add("OP_OS_CAPABILITY=104");
    out.add("OP_OS_GETENV=105");
    out.add("OP_OS_SETENV=106");
    out.add("OP_OS_CWD=107");
    out.add("OP_OS_CHDIR=108");
    out.add("OP_OS_HOSTNAME=109");
    out.add("OP_OS_USERNAME=110");
    out.add("OP_OS_TEMPDIR=111");
    out.add("OP_OS_PID=112");
    out.add("OP_OS_EXISTS=113");
    out.add("OP_OS_ISDIR=114");
    out.add("OP_OS_FILESIZE=115");
    out.add("OP_OS_MKDIR=116");
    out.add("OP_OS_REMOVE=117");
    out.add("OP_OS_RENAME=118");
    out.add("OP_OS_RUN=119");
    out.add("OP_OS_SPAWN=120");
    out.add("OP_OS_WAIT=121");
    out.add("OP_OS_KILL=122");
    out.add("OP_OS_PCLOSE=123");
    out.add("OP_OSLS_CALL=155");
    return out;
  }

  < These methods identify which layer is present. The OP_OS_* host bridge is
    implemented in impl/core/sleela_os.c. The richer osls_* metadata ABI remains
    a separate C library and is not claimed as VM-registered until a host
    adapter registers and tests its symbols. >
  boolean coreOSOpcodeBridgeImplemented() { return true; }
  boolean oslsCAbiAdapterRegistered() { return false; }

  < OSLS read-only host inspection: the VM returns status-bearing JSON Strings,
    never raw native pointers or C record layouts. >
  String oslsSystemInfoJSON() { calls = calls + 1; return oslsSystemInfo(); }
  String oslsProcessInfoJSON(int pid) { calls = calls + 1; return oslsProcessInfo(pid); }
  String oslsEnumerateProcessesJSON() { calls = calls + 1; return oslsEnumerateProcesses(); }
  String oslsGetEnvironmentValueJSON(String name) { calls = calls + 1; return oslsGetEnvironmentValue(name); }
  String oslsEnumerateEnvironmentJSON() { calls = calls + 1; return oslsEnumerateEnvironment(); }
  String oslsGetFileInfoJSON(String path) { calls = calls + 1; return oslsGetFileInfo(path); }
  String oslsListDirectoryJSON(String path) { calls = calls + 1; return oslsListDirectory(path); }
  String oslsGetCPUInfoJSON() { calls = calls + 1; return oslsGetCPUInfo(); }
  String oslsGetTimezoneInfoJSON() { calls = calls + 1; return oslsGetTimezoneInfo(); }
  String oslsGetNetworkInterfacesJSON() { calls = calls + 1; return oslsGetNetworkInterfaces(); }
  String oslsCronValidateJSON(String expression) { calls = calls + 1; return oslsCronValidate(expression); }
  String oslsCronNextAfterJSON(String expression, int epochSeconds) {
    calls = calls + 1; return oslsCronNextAfter(expression, epochSeconds);
  }

  int callCount() { return calls; }
}