stdlib: generate stdlib.manifest

This commit is contained in:
2023-09-10 20:47:50 -04:00
parent e8c984f2dc
commit 033da5b2ea
9 changed files with 87 additions and 14 deletions

View File

@ -1,11 +1,19 @@
plugins {
id("gay.pizza.pork.module")
id("gay.pizza.pork.stdlib")
}
tasks.processResources {
dependsOn(tasks.generateStdlibManifest)
inputs.file(tasks.generateStdlibManifest.get().stdlibManifestFile)
from("src/main/pork") {
into("pork/stdlib")
}
from(tasks.generateStdlibManifest.get().outputs) {
into("pork")
}
}
dependencies {

View File

@ -8,7 +8,7 @@ object PorkStdlib : ContentSource {
private val stdlibClass = PorkStdlib::class.java
private fun readManifestFiles(): List<String> {
val manifestContent = read("stdlib.manifest", check = false)
val manifestContent = read("stdlib.manifest")
return manifestContent.split("\n").filter { line ->
val trimmed = line.trim()
trimmed.isNotEmpty() && !trimmed.startsWith("#")
@ -17,17 +17,21 @@ object PorkStdlib : ContentSource {
val files: List<String> = readManifestFiles()
private fun read(path: String, check: Boolean = true): String {
if (check && !files.contains(path)) {
private fun readPorkFile(path: String): String {
if (!files.contains(path)) {
throw RuntimeException("Stdlib does not contain file '${path}'")
}
val stream = stdlibClass.getResourceAsStream("/pork/stdlib/${path}")
?: throw RuntimeException("Stdlib does not contain file '${path}'")
return read("stdlib/${path}")
}
private fun read(path: String): String {
val stream = stdlibClass.getResourceAsStream("/pork/${path}")
?: throw RuntimeException("Unable to find file '${path}'")
return String(stream.readAllBytes())
}
override fun loadAsCharSource(path: String): CharSource {
return StringCharSource(read(path))
return StringCharSource(readPorkFile(path))
}
override fun stableContentIdentity(path: String): String {

View File

@ -1,3 +0,0 @@
lang/prelude.pork
ffi/malloc.pork
numerics/operator.pork