SLOpcodeCondition.sleela
lib/opcodes/running/SLOpcodeCondition.sleela · 130 line(s) · sleela
<< lib/opcodes/running/SLOpcodeCondition.sleela
SLeeLa Standard Library Definition.
Definition: Defines SLOpcodeCondition, a named predicate over VM/program state
that a conditional-reactive construct evaluates to decide whether to react.
Role: a condition answers a yes/no question about the running program without
itself being an opcode — e.g. "is a LOCK currently held?", "has the stream
reached index N?", "did the last opcode warn?". Conditions are the triggers
the reactive layer listens on. The actual state read crosses the VM bridge;
the comparison and threshold logic live here in SLeeLa.
Comparators: a condition compares an observed signal value against a target
using one of the operators below.
Family: opcodes.running. Native VM/OS work crosses an explicit bridge. >>
#sleela 2.5
material;
< Unified SLeeLa standard-library front-end object. >
class SLOpcodeCondition {
< ---- 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 = 10184;
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-05";
< 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; }
< observed == target >
static final int EQ = 0;
< observed != target >
static final int NE = 1;
< observed < target >
static final int LT = 2;
< observed <= target >
static final int LE = 3;
< observed > target >
static final int GT = 4;
< observed >= target >
static final int GE = 5;
< Well-known signals the condition may read from the VM frame. >
< the live instruction pointer >
static final int SIG_IP = 1;
< locks currently held >
static final int SIG_LOCK_DEPTH = 2;
< open call frames >
static final int SIG_CALL_DEPTH = 3;
< open sockets >
static final int SIG_OPEN_SOCKETS = 4;
< governance warnings so far >
static final int SIG_WARN_COUNT = 5;
< current stream index >
static final int SIG_INDEX = 6;
String label;
< which SIG_* to observe >
int signal;
< one of EQ..GE >
int op;
< the value to compare against >
int target;
int state;
void configure(String name, int whichSignal, int comparator, int targetValue) {
label = name;
signal = whichSignal;
op = comparator;
target = targetValue;
state = 1;
}
void enable() { state = 1; }
void disable() { state = 0; }
boolean active() { return state == 1; }
String name() { return label; }
< Read the configured signal from the VM frame across the bridge. `index` is >
< the current stream position, supplied by the reactive driver. >
int observe(int frame, int index) {
if (signal == SIG_INDEX) { return index; }
return native sleela_opcode_signal(frame, signal, index);
}
< Evaluate the predicate against the observed signal. >
boolean holds(int frame, int index) {
if (!active()) { return false; }
int observed = observe(frame, index);
if (op == EQ) { return observed == target; }
if (op == NE) { return observed != target; }
if (op == LT) { return observed < target; }
if (op == LE) { return observed <= target; }
if (op == GT) { return observed > target; }
if (op == GE) { return observed >= target; }
return false;
}
}