SLLanguageCompiler.sleela
lib/compiler/SLLanguageCompiler.sleela · 167 line(s) · sleela
<< lib/compiler/SLLanguageCompiler.sleela
SLeeLa Standard Library Definition.
Definition: Defines SLLanguageCompiler, the language-neutral base contract a
developer extends to build a compiler for any publicly known programming
language (C, C++, Java, Python, JavaScript, Rust, Go, ...).
This is the heart of the modular compiler framework. A new language front end
is created by subclassing SLLanguageCompiler and overriding the pipeline
phases it provides. Every front end lowers its own language toward the common
SLeeLa IR and, from there, a VM-ready artifact — so the authoritative path
stays:
<language> source -> front end -> SLeeLa IR -> VM lowering -> SLVM/SLJVM
The framework does not create a parallel language and does not grant itself
VM, capability, security, resolver, memory, or certificate authority. A
produced artifact is only ever executed later, across an explicit SLeeLa
VM/OS and security boundary. Compilation is not execution.
Family: compiler. Native VM/OS work crosses an explicit bridge. >>
#sleela 2.5
material;
< Unified SLeeLa SDK front-end object. >
class SLLanguageCompiler {
< ---- 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 = 10374;
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-07";
< 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; }
< --- Canonical pipeline phases, in order. Mirrors sleela_langc.h. --- >
< load/normalize source units >
static final int PHASE_SOURCE = 1;
< tokenize >
static final int PHASE_LEX = 2;
< build the language syntax tree >
static final int PHASE_PARSE = 3;
< names, scopes, imports, symbols >
static final int PHASE_RESOLVE = 4;
< types, capabilities, dependencies >
static final int PHASE_SEMANTIC = 5;
< lower to target-neutral SLeeLa IR >
static final int PHASE_IR = 6;
< lower IR to VM-ready operations >
static final int PHASE_LOWER = 7;
< emit artifact >
static final int PHASE_CODEGEN = 8;
< --- Lowering targets. Mirrors sleela_langc.h. --- >
static final int TARGET_SLVM = 1;
static final int TARGET_SLJVM = 2;
static final int TARGET_SLIR = 3;
static final int TARGET_NATIVE = 4;
< Identity a concrete front end declares. >
< e.g. "C", "C++", "Java", "Python" >
String languageName;
< e.g. "C-family", "JVM", "scripting" >
String languageFamily;
< the accepted language version >
String languageVersion;
< comma list, e.g. ".c" or ".cc,.cpp,.cxx" >
String sourceExtensions;
< one of TARGET_* >
int defaultTarget;
< true => identify/plan only, never emit >
boolean referenceOnly;
< Which phases this front end provides, as a bitmask of (1 << (phase-1)). >
int phaseMask;
String diagnostic;
< A subclass calls this from its own configure() to declare identity. >
void declare(String name, String family, String version, String exts, int target) {
languageName = name;
languageFamily = family;
languageVersion = version;
sourceExtensions = exts;
defaultTarget = target;
referenceOnly = false;
phaseMask = 0;
diagnostic = "";
}
< Mark a provided phase. A front end calls this once per phase it implements. >
void provide(int phase) {
if (phase >= PHASE_SOURCE && phase <= PHASE_CODEGEN) {
phaseMask = phaseMask | (1 << (phase - 1));
}
}
boolean provides(int phase) {
if (phase < PHASE_SOURCE || phase > PHASE_CODEGEN) { return false; }
return (phaseMask & (1 << (phase - 1))) != 0;
}
< --- Pipeline phase hooks. The base implementations are no-ops that report >
< "absent"; a concrete front end overrides the phases it actually provides. >
< Each returns true when the phase completed, false when refused/incomplete. >
boolean runSource(SLCompileRequest request) { return provides(PHASE_SOURCE); }
boolean runLex(SLCompileRequest request) { return provides(PHASE_LEX); }
boolean runParse(SLCompileRequest request) { return provides(PHASE_PARSE); }
boolean runResolve(SLCompileRequest request) { return provides(PHASE_RESOLVE); }
boolean runSemantic(SLCompileRequest request) { return provides(PHASE_SEMANTIC); }
boolean runIR(SLCompileRequest request) { return provides(PHASE_IR); }
boolean runLower(SLCompileRequest request) { return provides(PHASE_LOWER); }
boolean runCodegen(SLCompileRequest request) { return provides(PHASE_CODEGEN); }
< Register this front end with the native, language-neutral registry so it can >
< be found by name or by source extension alongside every other language. >
int register() {
return native sleela_lang_register_module(
languageName, languageFamily, languageVersion,
sourceExtensions, phaseMask, defaultTarget, referenceOnly);
}
< Produce a compile plan for `request` against this front end. The native >
< framework walks the required phases for the requested target and reports the >
< first missing one (fail-closed; nothing is guessed or silently added). >
SLCompilePlan planCompile(SLCompileRequest request) {
SLCompilePlan plan = new SLCompilePlan();
plan.buildFor(this, request);
return plan;
}
String name() { return languageName; }
int target() { return defaultTarget; }
boolean isReferenceOnly() { return referenceOnly; }
String diagnostics() { return diagnostic; }
}