very-senior-vm.sleela
lib/vm/examples/04-very-senior/very-senior-vm.sleela · 195 line(s) · sleela
#sleela 2.5
material;
< 04-very-senior: a production-grade VM assembly, end to end -- compilable. >
< >
< A very-senior user drives the whole VM lifecycle with the advanced >
< subsystems: a resilient component fetcher (the SLVMComponentFetcher + >
< SLSupportDownloader fallback: primary -> official -> college/edu -> archive), >
< an OS system-call bridge gated by feature bits, a dynamic memory guard with a >
< quality/aggressiveness setting, a challenge/report manager that verifies the >
< assembly, and a build plan that emits the C/C++ the VM compiles toward. It >
< mirrors lib/vm's advanced tiers (SLVMComponentFetcher, SleelaVMSystemCall >
< Bridge, SleelaVMDynamicMemoryGuard, SleelaVMChallengeManagerAdvanced, >
< SleelaVMReportsManager, SleelaVMBuildPlan) as composed, running objects. >
< >
< New ideas over senior: resilient acquisition with ranked fallback, a >
< capability bridge gated by features, a self-verifying challenge pass with a >
< report, and emitted build artifacts -- the full "assemble, verify, emit" arc. >
< >
< Run: ./impl/build/sleela run lib/vm/examples/04-very-senior/very-senior-vm.sleela >
< ---- Resilient component fetcher (mirrors SLVMComponentFetcher) -------- >
< Ranked support tiers by likelihood of a final/college reference. >
class ComponentFetcher {
< ---- 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 = 10994;
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-11";
< metaScienceRating: maturity/robustness on a 1..10 scale >
int metaScienceRating = 7;
< 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; }
< tier 0 authoritative, 1 official-mirror, 2 college/edu, 3 archive >
String url(String kind, int tier) {
if (kind == "runtime") {
if (tier == 0) { return "https://dl.sleela.vm/runtime"; }
if (tier == 1) { return "https://mirrors.kernel.org/sleela/runtime"; }
if (tier == 2) { return "https://mirror.cs.mit.edu/sleela/runtime"; }
return "https://web.archive.org/web/2id_/https://dl.sleela.vm/runtime";
}
if (kind == "stdlib") {
if (tier == 0) { return "https://dl.sleela.vm/stdlib"; }
if (tier == 1) { return "https://mirrors.kernel.org/sleela/stdlib"; }
if (tier == 2) { return "https://mirror.cs.princeton.edu/sleela/stdlib"; }
return "https://web.archive.org/web/2id_/https://dl.sleela.vm/stdlib";
}
return "";
}
String tierName(int t) {
if (t == 0) { return "authoritative"; }
if (t == 1) { return "official-mirror"; }
if (t == 2) { return "college"; }
return "archive";
}
< Simulate acquisition: the primary (tier 0) is "down" here, so the fetcher >
< falls through to the first working tier. Returns the tier that succeeded. >
int acquire(String kind, int primaryDown) {
int t = 0;
while (t <= 3) {
< tier 0 fails when primaryDown==1; every later tier succeeds. >
if (!(t == 0 && primaryDown == 1)) { return t; }
t = t + 1;
}
return -1;
}
}
< ---- OS system-call bridge, gated by a feature bit --------------------- >
class SyscallBridge {
boolean enabled;
void configure(boolean processFeature) { enabled = processFeature; }
< A guarded syscall: only answers when the PROCESS/OS_SYSCALLS feature is on. >
String platform() { if (!enabled) { return "(syscalls disabled)"; } return "host-os"; }
boolean up() { return enabled; }
}
< ---- Dynamic memory guard with a quality/aggressiveness knob ----------- >
class MemoryGuard {
< "slow-careful" / "balanced" / "fast" >
String mode;
< 0..100 >
int aggressiveness;
void configure(String m, int a) {
mode = m;
aggressiveness = a; if (a < 0) { aggressiveness = 0; } if (a > 100) { aggressiveness = 100; }
}
boolean valid() { return mode == "slow-careful" || mode == "balanced" || mode == "fast"; }
String summary() { return "guard mode=" + mode + " aggressiveness=" + aggressiveness; }
}
< ---- Challenge/report manager: verify the assembly, emit a verdict ----- >
class ChallengeManager {
int checks; int passed;
void configure() { checks = 0; passed = 0; }
void require(boolean cond) { checks = checks + 1; if (cond) { passed = passed + 1; } }
boolean allPassed() { return checks > 0 && passed == checks; }
String report() { return "challenge: " + passed + "/" + checks + " passed -> "
+ verdict(); }
String verdict() { if (allPassed()) { return "VERIFIED"; } return "FAILED"; }
}
< ---- Build plan: emit the C the VM compiles toward --------------------- >
class BuildPlan {
String emitVmConfigC(String name, boolean syscalls, String guardMode) {
String c = "/* sleela_vm_config.h - generated by the very-senior VM example */\n";
c = c + "#define VM_NAME \"" + name + "\"\n";
c = c + "#define VM_OS_SYSCALLS " + bit(syscalls) + "\n";
c = c + "#define VM_MEM_GUARD \"" + guardMode + "\"\n";
return c;
}
String bit(boolean b) { if (b) { return "1"; } return "0"; }
}
class VerySeniorVM {
void banner(String t) { print("---- " + t + " ----"); }
void main() {
print("=== very-senior: assemble -> verify -> emit ===");
< enable OS syscalls >
boolean processFeature = true;
< 1. Resiliently acquire components (primary is down -> fall through). >
banner("resilient acquisition (primary down -> fallback)");
ComponentFetcher fetch = new ComponentFetcher();
int rt = fetch.acquire("runtime", 1);
int sl = fetch.acquire("stdlib", 1);
print("runtime via " + fetch.tierName(rt) + " -> " + fetch.url("runtime", rt));
print("stdlib via " + fetch.tierName(sl) + " -> " + fetch.url("stdlib", sl));
print("");
< 2. Bring up the bridge + guard. >
banner("subsystems");
SyscallBridge bridge = new SyscallBridge(); bridge.configure(processFeature);
MemoryGuard guard = new MemoryGuard(); guard.configure("slow-careful", 25);
print("syscall bridge: platform() = " + bridge.platform());
print(guard.summary() + " valid=" + guard.valid());
print("");
< 3. Verify the assembly with the challenge manager. >
banner("verification");
ChallengeManager chal = new ChallengeManager(); chal.configure();
< runtime acquired >
chal.require(rt >= 0);
< stdlib acquired >
chal.require(sl >= 0);
< syscalls available >
chal.require(bridge.up());
< guard configured correctly >
chal.require(guard.valid());
print(chal.report());
if (!chal.allPassed()) { print("REFUSED: assembly not verified"); return; }
print("");
< 4. Emit the build artifact only once verified. >
banner("emit sleela_vm_config.h");
BuildPlan plan = new BuildPlan();
print(plan.emitVmConfigC("determinant-vm", bridge.up(), guard.mode));
print("done");
}
}