SLClock.sleela
lib/cpu/SLClock.sleela · 75 line(s) · sleela
<< lib/cpu/SLClock.sleela
SLeeLa Standard Library Definition.
Definition: Defines SLClock — the oscillator that drives synchronous logic.
It produces alternating low/high levels (ticks); every rising edge advances
the CPU by one cycle. Frequency is modeled in MHz, and the clock counts the
cycles it has issued (the basis for performance accounting).
Family: cpu. Pure Sleela timing source. >>
#sleela 2.5
material;
class SLClock {
< ---- 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 = 10207;
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; }
int frequencyMHz;
< current clock level, 0 or 1 >
int level;
< completed cycles (rising edges issued) >
int cycles;
void configure(int mhz) { frequencyMHz = mhz; level = 0; cycles = 0; }
< One half-step: toggle the level. A full cycle is two toggles; a rising >
< edge (0 -> 1) increments the cycle counter. >
int toggle() {
if (level == 0) { level = 1; cycles = cycles + 1; } else { level = 0; }
return level;
}
< Issue a full cycle (low then high) and return the new cycle count. >
int tick() { toggle(); toggle(); return cycles; }
int currentLevel() { return level; }
int cycleCount() { return cycles; }
int frequency() { return frequencyMHz; }
}