novice-vm.sleela
lib/vm/examples/01-novice/novice-vm.sleela · 92 line(s) · sleela
#sleela 2.5
material;
< 01-novice: the simplest useful SLVM program -- compilable and runnable. >
< >
< A novice learns the VM lifecycle in four calls: configure -> start -> use -> >
< stop. This mirrors lib/vm/SLVM.sleela (name/state/count, start/stop/active, >
< register) in one self-contained file, because `sleela run` compiles one file >
< as a single unit and the split lib/vm classes are not visible to an importing >
< program (see examples/README.md "Issues and notes"). >
< >
< Run: ./impl/build/sleela run lib/vm/examples/01-novice/novice-vm.sleela >
< A minimal VM, exactly the shape of lib/vm/SLVM.sleela. >
class Vm {
< ---- 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 = 11012;
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; }
String name;
< 0 stopped, 1 running >
int state;
int modules;
void configure(String n) { name = n; state = 0; modules = 0; }
void start() { state = 1; }
void stop() { state = 0; }
boolean active() { return state == 1; }
< "register" a module >
void loadModule() { modules = modules + 1; }
int moduleCount() { return modules; }
}
class NoviceVM {
void main() {
print("=== novice: VM lifecycle ===");
Vm vm = new Vm();
vm.configure("hello-vm");
print("configured: " + vm.name + " (active=" + vm.active() + ")");
vm.start();
print("started: active=" + vm.active());
< Load a couple of modules into the running VM. >
vm.loadModule();
vm.loadModule();
print("modules loaded: " + vm.moduleCount());
vm.stop();
print("stopped: active=" + vm.active());
print("done");
}
}