mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-08-03 05:10:55 +00:00
imports are now python style with a twist: forms! import std ffi and import local myfile
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
package gay.pizza.pork.frontend
|
||||
|
||||
class StandardImportSource(override val fileContentSource: ContentSource) : ImportSource {
|
||||
class DynamicImportSource : ImportSource {
|
||||
private val providers = mutableMapOf<String,ContentSource>()
|
||||
|
||||
override fun provideContentSource(form: String): ContentSource {
|
@ -1,3 +1,3 @@
|
||||
package gay.pizza.pork.frontend
|
||||
|
||||
data class ImportLocator(val path: String, val form: String? = null)
|
||||
data class ImportLocator(val form: String, val path: String)
|
||||
|
@ -1,7 +1,5 @@
|
||||
package gay.pizza.pork.frontend
|
||||
|
||||
interface ImportSource {
|
||||
val fileContentSource: ContentSource
|
||||
|
||||
fun provideContentSource(form: String): ContentSource
|
||||
}
|
||||
|
@ -32,7 +32,8 @@ class World(val importSource: ImportSource) {
|
||||
private fun resolveAllImports(unit: CompilationUnit): Set<CompilationUnit> {
|
||||
val units = mutableSetOf<CompilationUnit>()
|
||||
for (declaration in unit.declarations.filterIsInstance<ImportDeclaration>()) {
|
||||
val importLocator = ImportLocator(declaration.path.text, form = declaration.form?.id)
|
||||
val importPath = declaration.components.joinToString("/") { it.id } + ".pork"
|
||||
val importLocator = ImportLocator(declaration.form.id, importPath)
|
||||
val importedUnit = loadOneUnit(importLocator)
|
||||
units.add(importedUnit)
|
||||
}
|
||||
@ -45,18 +46,14 @@ class World(val importSource: ImportSource) {
|
||||
return unit
|
||||
}
|
||||
|
||||
private fun pickContentSource(form: String? = null): ContentSource {
|
||||
if (form != null) {
|
||||
return importSource.provideContentSource(form)
|
||||
}
|
||||
return importSource.fileContentSource
|
||||
}
|
||||
private fun pickContentSource(form: String): ContentSource =
|
||||
importSource.provideContentSource(form)
|
||||
|
||||
fun stableIdentity(
|
||||
importLocator: ImportLocator,
|
||||
contentSource: ContentSource = pickContentSource(importLocator.form)
|
||||
): String {
|
||||
val formKey = importLocator.form ?: "file"
|
||||
val formKey = importLocator.form
|
||||
val stableIdentity = contentSource.stableContentIdentity(importLocator.path)
|
||||
return "[${formKey}][${stableIdentity}]"
|
||||
}
|
||||
|
Reference in New Issue
Block a user