SLCompartment.sleela
lib/advantage/integration/SLCompartment.sleela · 201 line(s) · sleela
<< lib/advantage/integration/SLCompartment.sleela
SLeeLa Standard Library Definition.
Definition: The recursive compartment -- the self-similar building block of
a vertical-integration model. >>
#sleela 3.0
material;
artifact;
pure;
gasoline;
< A COMPARTMENT is one unit of the model. It has: a kind (see >
< SLIntegrationKind), a CAPACITIVE SPACE (capacity + used units), MEANING (what >
< it holds / is for) and RELEVANCE (its weight in the chain), and -- crucially >
< -- it can contain CHILD compartments, so a compartment recursively holds its >
< own model(s). A nested-model kind is simply a compartment whose children form >
< a complete lower-tier integration. This self-similarity is the OOD core. >
class SLCompartment {
< ---- 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 = 10541;
String metaAuthor = "Kiro Agent";
String metaDate = "2026-11-08";
String metaCopyright = "SLeeLa project";
String metaTrademark = "none";
String metaCorporation = "none";
< metaOrigin: National | <nation> | International | Galactic >
String metaOrigin = "International";
String metaBirthDate = "2026-11-08";
< metaScienceRating: maturity/robustness on a 1..10 scale >
int metaScienceRating = 8;
< 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; }
< ---- Identity & kind ---- >
String label;
int kind;
String meaning;
int relevance;
< ---- Capacitive space ---- >
int capacity;
int used;
< ---- Recursive children (its own model) ---- >
SLCompartment[] children;
int childCount;
int childCap;
< Configure from a kind, using SLIntegrationKind for defaults. >
void configure(String lbl, int k, SLIntegrationKind cat) {
label = lbl;
kind = k;
meaning = cat.meaningOf(k);
relevance = cat.relevanceOf(k);
capacity = cat.capacityUnits(cat.defaultCapacityClass(k));
used = 0;
childCap = 16;
children = new SLCompartment[childCap];
childCount = 0;
}
String getLabel() { return label; }
int getKind() { return kind; }
String getMeaning() { return meaning; }
int getRelevance() { return relevance; }
int getCapacity() { return capacity; }
int getUsed() { return used; }
void setCapacity(int c) { capacity = c; }
void setMeaning(String m) { meaning = m; }
void setRelevance(int r) { relevance = r; }
< Free space remaining in this compartment's own capacitive space. >
int free() { return capacity - used; }
< Fill `amount` units if they fit; returns the amount actually stored. >
int store(int amount) {
int room = free();
int put = amount;
if (put > room) { put = room; }
if (put < 0) { put = 0; }
used = used + put;
return put;
}
< Release `amount` units; returns the amount actually released. >
int release(int amount) {
int take = amount;
if (take > used) { take = used; }
if (take < 0) { take = 0; }
used = used - take;
return take;
}
< ---- Recursion: nest a child compartment (its own model) ---- >
void addChild(SLCompartment c) {
if (childCount >= childCap) { return; }
children[childCount] = c;
childCount = childCount + 1;
}
int getChildCount() { return childCount; }
SLCompartment childAt(int i) {
if (i < 0) { return null; }
if (i >= childCount) { return null; }
return children[i];
}
< Total compartments in this subtree, including self (recursive count). >
int subtreeSize() {
int total = 1;
int i = 0;
while (i < childCount) {
SLCompartment c = children[i];
total = total + c.subtreeSize();
i = i + 1;
}
return total;
}
< Maximum nesting depth of this subtree (self = depth 1). >
int depth() {
int best = 0;
int i = 0;
while (i < childCount) {
SLCompartment c = children[i];
int d = c.depth();
if (d > best) { best = d; }
i = i + 1;
}
return best + 1;
}
< Aggregate capacity of this subtree (self + all descendants). >
int totalCapacity() {
int sum = capacity;
int i = 0;
while (i < childCount) {
SLCompartment c = children[i];
sum = sum + c.totalCapacity();
i = i + 1;
}
return sum;
}
< Aggregate used units of this subtree. >
int totalUsed() {
int sum = used;
int i = 0;
while (i < childCount) {
SLCompartment c = children[i];
sum = sum + c.totalUsed();
i = i + 1;
}
return sum;
}
< Sum of relevance across this subtree -- a crude "value density". >
int totalRelevance() {
int sum = relevance;
int i = 0;
while (i < childCount) {
SLCompartment c = children[i];
sum = sum + c.totalRelevance();
i = i + 1;
}
return sum;
}
String describe() {
return "compartment '" + label + "' kind=" + kind + " (" + meaning + ")"
+ " cap=" + capacity + " used=" + used
+ " children=" + childCount + " subtree=" + subtreeSize();
}
}