Skip to content

Commit 754bc1e

Browse files
committed
wip: add import processing infrastructure for traits
- Added process_imports_for_traits() to resolve and parse stdlib modules - Imports now properly appear in TypedAST as Import declarations - Discovered that trait/impl declarations are not yet supported in TypedAST - Need to implement: trait/impl TypedAST types, builder methods, and lowering Next steps: 1. Add Trait and Impl variants to TypedDeclaration 2. Create builder methods in TypedASTBuilder 3. Add AstHostFunctions handlers 4. Implement lowering to register in TypeRegistry
1 parent 6c9b91c commit 754bc1e

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

crates/zyntax_embed/src/runtime.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,9 @@ impl ZyntaxRuntime {
811811
let module_name = InternedString::new_global("main");
812812
let type_registry = std::sync::Arc::new(TypeRegistry::new());
813813

814+
// Process imports to load stdlib traits and impls before lowering
815+
self.process_imports_for_traits(&program, &type_registry)?;
816+
814817
let mut lowering_ctx = LoweringContext::new(
815818
module_name,
816819
type_registry.clone(),
@@ -832,6 +835,45 @@ impl ZyntaxRuntime {
832835
Ok(hir_module)
833836
}
834837

838+
/// Process import declarations to load stdlib traits and implementations
839+
///
840+
/// This scans the TypedProgram for Import declarations, resolves them using
841+
/// the registered import resolvers, parses the imported modules, and registers
842+
/// their trait definitions and implementations in the TypeRegistry.
843+
fn process_imports_for_traits(
844+
&self,
845+
program: &zyntax_typed_ast::TypedProgram,
846+
type_registry: &std::sync::Arc<zyntax_typed_ast::TypeRegistry>,
847+
) -> RuntimeResult<()> {
848+
use zyntax_typed_ast::typed_ast::TypedDeclaration;
849+
850+
// Collect all import declarations
851+
for decl in &program.declarations {
852+
if let TypedDeclaration::Import(import) = &decl.node {
853+
// Get module name (for simple imports like "import prelude", it's a single identifier)
854+
let module_name = import.module_path
855+
.first()
856+
.and_then(|s| s.resolve_global())
857+
.unwrap_or_else(|| "unknown".to_string());
858+
859+
log::debug!("Processing import: {}", module_name);
860+
861+
// Try to resolve the import using our import resolvers
862+
if let Ok(Some(source)) = self.resolve_import(&module_name) {
863+
log::debug!("Resolved import '{}', parsing module...", module_name);
864+
865+
// TODO: Parse the imported module and extract traits/impls
866+
// For now, just log that we found it
867+
log::info!("Found stdlib module '{}' ({} bytes)", module_name, source.len());
868+
} else {
869+
log::warn!("Could not resolve import: {}", module_name);
870+
}
871+
}
872+
}
873+
874+
Ok(())
875+
}
876+
835877
/// Get a function pointer by name
836878
pub fn get_function_ptr(&self, name: &str) -> Option<*const u8> {
837879
self.function_ids.get(name)

0 commit comments

Comments
 (0)