Skip to content

Latest commit

 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

lib-compile

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.

Exports

Function Description
Compile Compiles a RichTea source string. Returns a CompilationResult.
BuildDistributable Packages a CompilationResult into a standalone executable JAR. Returns a ByteArrayOutputStream.

Compile

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.

Attributes

Attribute Description
source (implicit) The RichTea source code string to compile.

BuildDistributable

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.

Attributes

Attribute Description
compilation (implicit) The CompilationResult returned by Compile.

Examples

Compile and run a source string at runtime

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

Compile source from a file and build a distributable JAR

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")

Self-compiling build script

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 }")
})

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages