SLProcess.sleela
lib/cpu/SLProcess.sleela · 110 line(s) · sleela
<< lib/cpu/SLProcess.sleela
SLeeLa Standard Library Definition.
Definition: Defines SLProcess — a unit of execution the OS schedules: a
process control block (PCB). It records the process id, its state (new,
ready, running, blocked, terminated), its saved program counter and a few
saved registers (its context), its memory base, and accounting. The
scheduler switches the CPU between processes by saving/restoring this.
Family: cpu. Pure Sleela OS data structure. >>
#sleela 2.5
material;
class SLProcess {
< ---- 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 = 10271;
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; }
static final int NEW = 0;
static final int READY = 1;
static final int RUNNING = 2;
static final int BLOCKED = 3;
static final int TERMINATED = 4;
int pid;
String name;
int state;
int priority;
< Saved context (restored on dispatch). >
int savedPC;
int savedR1; int savedR2; int savedR3;
int memoryBase;
int entryPoint;
< scheduler accounting >
int quantaUsed;
void configure(int id, String procName, int entry, int base, int prio) {
pid = id; name = procName; entryPoint = entry; memoryBase = base; priority = prio;
state = NEW; savedPC = entry; savedR1 = 0; savedR2 = 0; savedR3 = 0; quantaUsed = 0;
}
void markReady() { state = READY; }
void markRunning() { state = RUNNING; }
void markBlocked() { state = BLOCKED; }
void terminate() { state = TERMINATED; }
< Save the live core state into the PCB (context switch out). >
void saveContext(SLCore core) {
< modeled resume marker >
savedPC = core.controlUnit().instructionsRetired();
savedR1 = core.registers().read(1);
savedR2 = core.registers().read(2);
savedR3 = core.registers().read(3);
}
< Restore this PCB into the live core (context switch in). >
void restoreContext(SLCore core) {
core.registers().write(1, savedR1);
core.registers().write(2, savedR2);
core.registers().write(3, savedR3);
}
void chargeQuantum() { quantaUsed = quantaUsed + 1; }
int processId() { return pid; }
String processName() { return name; }
int processState() { return state; }
int entry() { return entryPoint; }
int base() { return memoryBase; }
boolean runnable() { return state == READY || state == RUNNING; }
boolean alive() { return state != TERMINATED; }
}