Home /Modules/vm/SLVmCapability.sleela

SLVmCapability.sleela

lib/vm/src/sleela/SLVmCapability.sleela · 100 line(s) · sleela

<< lib/vm/src/sleela/SLVmCapability.sleela
   SLeeLa Standard Library Definition.
   Definition: Defines SLVmCapability — the OOD equivalent of the native
     capability-enforcement choke point (virtual-machine/vm-version/007/
     vm_capability.{h,c}, v007). It turns the SLVmConfig capability mask into
     real decisions: a bridge asks `check` before acting; a disabled capability
     yields a typed DENIED result (reported, counted) and refuses the op. This
     closes the gap v001 noted (the mask was recorded but not enforced).
   
   Mirrors: vm_cap_allowed/check/denials/reset, vm_cap_name.
   
   Family: vm. Composes SLVmConfig, SLVmResult, SLVmReport, SLVmTelemetry. >>
#sleela 2.5
material;
class SLVmCapability {
  < ---- 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 = 11283;
  String metaAuthor = "unknown";
  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 = "unknown";
  < 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; }
  SLVmConfig config;
  int denials;

  void bind(SLVmConfig cfg) { config = cfg; denials = 0; }
  void reset() { denials = 0; }
  int denialCount() { return denials; }

  boolean allowed(int cap) {
    < unconfigured -> permissive >
    if (config == null) { return true; }
    return config.has(cap);
  }

  < Guard a bridge op. Returns true to proceed; on denial fills `out` with a >
  < DENIED result, reports+counts it, returns false. >
  boolean check(int cap, String subsystem, String operation,
                SLVmResult out, SLVmReport rep, SLVmTelemetry tel) {
    if (allowed(cap)) { return true; }
    denials = denials + 1;
    if (tel != null) { tel.addErrors(1); }
    if (out != null) {
      < 7 = 7 (literal: a sibling class static cannot be read through an instance) >
      out.fail(7, subsystem,
               "capability '" + capName(cap) + "' denied for operation '" + operation + "'");
      out.report(rep);
    }
    return false;
  }

  String capName(int cap) {
    if (cap == 1)   { return "memory"; }
    if (cap == 2)  { return "file-io"; }
    if (cap == 4)  { return "network"; }
    if (cap == 8)  { return "threads"; }
    if (cap == 16)   { return "dynlib"; }
    if (cap == 32) { return "terminal"; }
    if (cap == 64)    { return "paths"; }
    if (cap == 128)  { return "process"; }
    if (cap == 256)      { return "ipc"; }
    if (cap == 512)     { return "time"; }
    return "capability";
  }
}