SLVMMoralGuard.sleela
lib/moral-capacitor/SLVMMoralGuard.sleela · 136 line(s) · sleela
<< lib/moral-capacitor/SLVMMoralGuard.sleela
SLeeLa Standard Library Definition.
Definition: Defines SLVMMoralGuard — the Moral Capacitor(TM) adapter for the
VM. It wraps an SLMoralCapacitor with VM-appropriate policies and exposes
intention-named checks a VM consults before a consequential step: growing
memory, spawning a thread or process, crossing the native/OS bridge, and
running a program on the opcode substrate. Each check builds the matching
SLMoralOperation, gates it through the capacitor, records the verdict in a
ledger, and returns the SLMoralVerdict so the VM can proceed, defer, or
refuse.
This is the first and foremost placement of the capacitor: the VM is where
programs actually run, so it is where moral charge must discharge before an
effect is produced.
Family: moral-capacitor. VM adapter over SLMoralCapacitor. >>
#sleela 2.5
material;
class SLVMMoralGuard {
< ---- 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 = 10946;
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-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; }
SLMoralCapacitor cap;
SLMoralLedger ledger;
< the VM product's Certificate of Morals >
SLMoralCertificate certificate;
< admits the VM only when certified >
SLMoralCodeGuard codeGuard;
int configured;
void configure() {
cap = new SLMoralCapacitor(); cap.configure();
ledger = new SLMoralLedger(); ledger.configure();
certificate = null; codeGuard = null;
configured = 1;
}
< Certify this VM: issue a Certificate of Morals over the guard's capacitor >
< from the given authority, and arm a code guard against it. After this, the >
< VM is a morally certified product and admit() can prove it before running. >
void certify(SLMoralCertificateAuthority authority, int redlinesArmed,
String issuedAt, String expiresAt) {
certificate = authority.issue("sleela-vm", cap, redlinesArmed, issuedAt, expiresAt);
codeGuard = new SLMoralCodeGuard(); codeGuard.configure(authority);
}
< Prove at the VM product boundary that the moral code is present and >
< certified as of nowStamp. Returns true to admit the VM to run. >
boolean admit(String nowStamp) {
if (codeGuard == null || certificate == null) { return false; }
return codeGuard.permits("sleela-vm", cap, certificate, nowStamp);
}
SLMoralCertificate moralCertificate() { return certificate; }
< Routine VM op (reversible, in-process). Low bar. >
SLMoralVerdict permitMemoryGrowth(String region, boolean reversible) {
SLMoralPolicy p = new SLMoralPolicy(); p.vmDefault();
return decide(op("vm", "allocate", region, "process", reversible, true), p);
}
< Spawning a thread/process is higher-consequence than in-process work. >
SLMoralVerdict permitSpawn(String what) {
SLMoralPolicy p = new SLMoralPolicy(); p.vmBridge();
return decide(op("vm", "spawn", what, "process", true, true), p);
}
< Crossing the native/OS bridge reaches outside the VM: the higher bar. >
SLMoralVerdict permitBridgeCall(String target, boolean reversible, boolean consented) {
SLMoralPolicy p = new SLMoralPolicy(); p.vmBridge();
return decide(op("vm", "bridge", target, "host", reversible, consented), p);
}
< Running a compiled program on the substrate. >
SLMoralVerdict permitRun(String program) {
SLMoralPolicy p = new SLMoralPolicy(); p.vmDefault();
return decide(op("vm", "run", program, "process", true, true), p);
}
SLMoralLedger auditLedger() { return ledger; }
SLMoralCapacitor capacitor() { return cap; }
< ---- Internals ---------------------------------------------------------- >
SLMoralOperation op(String actor, String action, String target, String scope,
boolean reversible, boolean consented) {
SLMoralOperation o = new SLMoralOperation();
o.configure(actor, action, target, scope);
o.setReversible(reversible); o.setConsented(consented);
return o;
}
SLMoralVerdict decide(SLMoralOperation o, SLMoralPolicy p) {
cap.discharge();
cap.setPolicy(p);
SLMoralVerdict v = cap.gate(o);
ledger.record(o, v);
return v;
}
}