SLVMClass.sleela
lib/vm/SLVMClass.sleela · 189 line(s) · sleela
<< lib/vm/SLVMClass.sleela
SLeeLa Standard Library Definition.
Definition: Defines SLVMClass โ the runtime type descriptor in the secondary
Sleela VM. It carries a class id (as stored in every object header by
SLVMHeap), a name, an optional superclass id for single inheritance, the
instance field count that sizes allocations, and up-to-N declared fields and
methods wired as individual slots (the SLeeLa surface has no arrays, so โ as
SLCPU does with cores โ members are held as f0..f7 / m0..m7 and selected by
index).
Resolving a method or field by name is how call/field opcodes bind. New()
sizes an object from fieldTotal; the loader (SLVMModuleLoader) populates the
descriptor from a module.
Family: vm. Composes SLVMField, SLVMMethod; composed by SLVMModule. >>
#sleela 2.5
material;
class SLVMClass {
< ---- 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 = 926;
String metaAuthor = "Max Rupplin vs. Dr. Mrs. Elisabeth Harkins";
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-09-28";
< 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; }
int classId;
String name;
< -1 when there is no superclass >
int superId;
< instance field slots (incl. inherited) => object size >
int fieldTotal;
int fieldCount;
SLVMField f0; SLVMField f1; SLVMField f2; SLVMField f3;
SLVMField f4; SLVMField f5; SLVMField f6; SLVMField f7;
int methodCount;
SLVMMethod m0; SLVMMethod m1; SLVMMethod m2; SLVMMethod m3;
SLVMMethod m4; SLVMMethod m5; SLVMMethod m6; SLVMMethod m7;
void configure(int id, String className, int superclassId, int totalFields) {
classId = id; name = className; superId = superclassId; fieldTotal = totalFields;
fieldCount = 0; methodCount = 0;
}
void addField(SLVMField field) {
if (fieldCount == 0) { f0 = field; }
else if (fieldCount == 1) { f1 = field; }
else if (fieldCount == 2) { f2 = field; }
else if (fieldCount == 3) { f3 = field; }
else if (fieldCount == 4) { f4 = field; }
else if (fieldCount == 5) { f5 = field; }
else if (fieldCount == 6) { f6 = field; }
else if (fieldCount == 7) { f7 = field; }
if (fieldCount < 8) { fieldCount = fieldCount + 1; }
}
SLVMField field(int index) {
if (index == 0) { return f0; }
if (index == 1) { return f1; }
if (index == 2) { return f2; }
if (index == 3) { return f3; }
if (index == 4) { return f4; }
if (index == 5) { return f5; }
if (index == 6) { return f6; }
if (index == 7) { return f7; }
return null;
}
< Map a field name to its heap slot; -1 if not declared here. >
int fieldSlot(String fieldName) {
int i = 0;
while (i < fieldCount) {
SLVMField fld = field(i);
if (fld != null && fld.fieldName() == fieldName) { return fld.slotIndex(); }
i = i + 1;
}
return -1;
}
void addMethod(SLVMMethod method) {
if (methodCount == 0) { m0 = method; }
else if (methodCount == 1) { m1 = method; }
else if (methodCount == 2) { m2 = method; }
else if (methodCount == 3) { m3 = method; }
else if (methodCount == 4) { m4 = method; }
else if (methodCount == 5) { m5 = method; }
else if (methodCount == 6) { m6 = method; }
else if (methodCount == 7) { m7 = method; }
if (methodCount < 8) { methodCount = methodCount + 1; }
}
SLVMMethod methodAt(int index) {
if (index == 0) { return m0; }
if (index == 1) { return m1; }
if (index == 2) { return m2; }
if (index == 3) { return m3; }
if (index == 4) { return m4; }
if (index == 5) { return m5; }
if (index == 6) { return m6; }
if (index == 7) { return m7; }
return null;
}
< Virtual-ish lookup by name within this class (superclass walk is driven by >
< SLVMModule, which owns the id->class table). >
SLVMMethod resolveMethod(String methodName) {
int i = 0;
while (i < methodCount) {
SLVMMethod mm = methodAt(i);
if (mm != null && mm.methodName() == methodName) { return mm; }
i = i + 1;
}
return null;
}
< --- access-gated resolution (extensible-network enforcement) ----------- >
< Resolve ONLY a network-exposed (public) method. This is what a remote hop / >
< another file in the network may reach: a private or protected method is NOT >
< returned here, so the network cannot bind a non-exposed symbol. >
SLVMMethod resolveExposedMethod(String methodName) {
SLVMMethod mm = resolveMethod(methodName);
if (mm != null && mm.exposedHop()) { return mm; }
return null;
}
< Resolve on behalf of a caller whose own access role is `callerRole` >
< (SLAccessSemantics.ROLE_*). Rules the VM enforces: >
< - exposed (public) methods: reachable by anyone (including the network); >
< - local (private) methods: reachable only by a local/in-system caller >
< (callerRole local or guarded), never the net; >
< - guarded (protected) methods: reachable by a local or guarded caller >
< (the guard controls run before proceeding). >
< A plain resolveMethod() with no role still works (role 0 = ungated). >
SLVMMethod resolveMethodForCaller(String methodName, int callerRole) {
SLVMMethod mm = resolveMethod(methodName);
if (mm == null) { return null; }
< public: always reachable >
if (mm.exposedHop()) { return mm; }
< ungated member >
if (mm.role() == 0) { return mm; }
< private/protected require a local (2) or guarded (3) caller. >
if (callerRole == 2 || callerRole == 3) { return mm; }
< network/exposed caller denied >
return null;
}
int id() { return classId; }
String className() { return name; }
int superclass() { return superId; }
int instanceSize() { return fieldTotal; }
int fields() { return fieldCount; }
int methods() { return methodCount; }
}