lib-compile is a RichTea library that exposes the RichTea compiler from within a running RichTea program. It lets you compile RichTea source code at runtime and package the result as a standalone executable JAR — enabling self-hosting and meta-programming workflows.
| Function | Description |
|---|---|
Compile |
Compiles a RichTea source string. Returns a CompilationResult. |
BuildDistributable |
Packages a CompilationResult into a standalone executable JAR. Returns a ByteArrayOutputStream. |
Compiles a string of RichTea source code using the built-in Compiler. Returns a CompilationResult object that can be executed directly or passed to BuildDistributable.
| Attribute | Description |
|---|---|
source (implicit) |
The RichTea source code string to compile. |
Takes a CompilationResult (from Compile) and packages it into a self-contained, executable JAR file. Returns a ByteArrayOutputStream containing the JAR bytes, which can be written to disk with WriteFile.
| Attribute | Description |
|---|---|
compilation (implicit) |
The CompilationResult returned by Compile. |
Import("*" from:"modules/std")
Import("*" from:"modules/compile")
Let(source:"Import(\"*\" from:\"modules/std\") Print(\"Hello from compiled code!\")")
Compile(source)
// _ is now a CompilationResult — it can be executed directly by the runtime
Import("*" from:"modules/std")
Import("*" from:"modules/compile")
// Read the source program
ReadFile(path:"src/myprogram.tea")
Let(source:_)
// Compile it
Compile(source)
Let(compilation:_)
// Package into a standalone JAR
BuildDistributable(compilation)
// Write the JAR to disk
WriteFile(path:"dist/myprogram.jar" contents:_)
Print("Build complete: dist/myprogram.jar")
Import("*" from:"modules/std")
Import("*" from:"modules/compile")
Let(files:["src/main.tea", "src/utils.tea"])
ForEach(in:files as:"file" :{
ReadFile(path:file)
Compile(_)
Let(result:_)
BuildDistributable(result)
// Derive output path: src/main.tea -> dist/main.jar
Let(outPath:"dist/{ file.replaceAll(\"src/\", \"\").replaceAll(\".tea\", \".jar\") }")
WriteFile(path:outPath contents:_)
Print("Built: { outPath }")
})