From 57654b6e04f5ce8114bc02a4f0579bb3b804671f Mon Sep 17 00:00:00 2001 From: Amit Upadhyay Date: Fri, 20 Dec 2024 00:27:00 +0530 Subject: [PATCH] fastn_package stuff: not compiling --- v0.5/Cargo.lock | 2 ++ v0.5/fastn-compiler/Cargo.toml | 1 + v0.5/fastn-compiler/src/compiler.rs | 10 +++++++--- v0.5/fastn-package/src/lib.rs | 8 ++++---- v0.5/fastn-unresolved/Cargo.toml | 1 + v0.5/fastn-unresolved/src/lib.rs | 8 +++++++- .../fastn-unresolved/src/parser/function_definition.rs | 1 + v0.5/fastn-unresolved/src/parser/mod.rs | 4 ++++ v0.5/fastn-unresolved/src/utils.rs | 10 ++++++++++ 9 files changed, 37 insertions(+), 8 deletions(-) diff --git a/v0.5/Cargo.lock b/v0.5/Cargo.lock index 2ca563273..45fabe54b 100644 --- a/v0.5/Cargo.lock +++ b/v0.5/Cargo.lock @@ -189,6 +189,7 @@ version = "0.1.0" dependencies = [ "fastn-builtins", "fastn-continuation", + "fastn-package", "fastn-resolved", "fastn-section", "fastn-unresolved", @@ -277,6 +278,7 @@ dependencies = [ "arcstr", "fastn-builtins", "fastn-continuation", + "fastn-package", "fastn-resolved", "fastn-section", "id-arena", diff --git a/v0.5/fastn-compiler/Cargo.toml b/v0.5/fastn-compiler/Cargo.toml index 4e49c66e2..8c493d2a2 100644 --- a/v0.5/fastn-compiler/Cargo.toml +++ b/v0.5/fastn-compiler/Cargo.toml @@ -12,6 +12,7 @@ homepage.workspace = true fastn-builtins.workspace = true fastn-resolved.workspace = true fastn-continuation.workspace = true +fastn-package.workspace = true fastn-section.workspace = true fastn-unresolved.workspace = true indexmap.workspace = true diff --git a/v0.5/fastn-compiler/src/compiler.rs b/v0.5/fastn-compiler/src/compiler.rs index 003fae370..af6327d63 100644 --- a/v0.5/fastn-compiler/src/compiler.rs +++ b/v0.5/fastn-compiler/src/compiler.rs @@ -17,18 +17,21 @@ pub struct Compiler { pub(crate) document: fastn_unresolved::Document, // pub global_aliases: fastn_unresolved::AliasesSimple, iterations: usize, + package: fastn_package::Package, } impl Compiler { fn new( source: &str, - package: &str, + package: fastn_package::Package, module: Option<&str>, // global_aliases: fastn_unresolved::AliasesSimple, ) -> Self { let mut arena = fastn_unresolved::Arena::default(); + let mut document = fastn_unresolved::parse( - fastn_unresolved::Module::new(package, module, &mut arena), + &package, + fastn_unresolved::Module::new(package.name.as_str(), module, &mut arena), source, &mut arena, // &global_aliases, @@ -37,6 +40,7 @@ impl Compiler { document.content = vec![]; Self { + package, arena, definitions: std::collections::HashMap::new(), modules: std::collections::HashMap::new(), @@ -182,7 +186,7 @@ impl Compiler { /// warnings from OK part as error, and discard the generated JS. pub fn compile( source: &str, - package: &str, + package: fastn_package::Package, module: Option<&str>, ) -> fastn_continuation::Result { use fastn_continuation::Continuation; diff --git a/v0.5/fastn-package/src/lib.rs b/v0.5/fastn-package/src/lib.rs index 5afbd91bc..9309bee37 100644 --- a/v0.5/fastn-package/src/lib.rs +++ b/v0.5/fastn-package/src/lib.rs @@ -11,11 +11,11 @@ pub type UR = fastn_continuation::UR; #[derive(Debug)] pub struct Package { - name: String, - systems: Vec, - dependencies: Vec, + pub name: String, + pub systems: Vec, + pub dependencies: Vec, pub auto_imports: Vec, - apps: Vec, + pub apps: Vec, } #[derive(Clone, Debug)] diff --git a/v0.5/fastn-unresolved/Cargo.toml b/v0.5/fastn-unresolved/Cargo.toml index 70095f241..fab10e2c0 100644 --- a/v0.5/fastn-unresolved/Cargo.toml +++ b/v0.5/fastn-unresolved/Cargo.toml @@ -11,6 +11,7 @@ homepage.workspace = true [dependencies] arcstr.workspace = true fastn-builtins.workspace = true +fastn-package.workspace = true fastn-continuation.workspace = true fastn-resolved.workspace = true fastn-section.workspace = true diff --git a/v0.5/fastn-unresolved/src/lib.rs b/v0.5/fastn-unresolved/src/lib.rs index 297e989e4..5972c57f1 100644 --- a/v0.5/fastn-unresolved/src/lib.rs +++ b/v0.5/fastn-unresolved/src/lib.rs @@ -59,11 +59,16 @@ pub enum SoMBase { Module(M), } +#[derive(Debug, Clone)] +pub struct Package { + inner: std::sync::Arc, +} + #[derive(Debug, Clone)] pub struct Document { pub aliases: Option, pub module: fastn_unresolved::Module, - // pub package: fastn_unresolved::Package, // auto import, dependencies + pub package: fastn_unresolved::Package, // auto import, dependencies pub module_doc: Option, pub definitions: Vec, pub content: Vec, @@ -76,6 +81,7 @@ pub struct Document { #[derive(Debug, Clone)] pub struct Definition { pub aliases: AliasesID, + pub module: fastn_unresolved::Module, pub symbol: Option, // /# /// we will keep the builtins not as ScopeFrame, but as plain hashmap. /// we have two scopes at this level, the auto-imports, and scope of all symbols explicitly diff --git a/v0.5/fastn-unresolved/src/parser/function_definition.rs b/v0.5/fastn-unresolved/src/parser/function_definition.rs index 92a76a6aa..b608a58e8 100644 --- a/v0.5/fastn-unresolved/src/parser/function_definition.rs +++ b/v0.5/fastn-unresolved/src/parser/function_definition.rs @@ -43,6 +43,7 @@ pub(super) fn function_definition( // TODO: get rid of all the Default::default below document.definitions.push( fastn_unresolved::Definition { + module: document.module.clone(), symbol: Default::default(), doc: Default::default(), aliases: document.aliases.unwrap(), diff --git a/v0.5/fastn-unresolved/src/parser/mod.rs b/v0.5/fastn-unresolved/src/parser/mod.rs index 053b8dfff..b74e787bc 100644 --- a/v0.5/fastn-unresolved/src/parser/mod.rs +++ b/v0.5/fastn-unresolved/src/parser/mod.rs @@ -3,6 +3,7 @@ mod function_definition; mod import; pub fn parse( + package: fastn_unresolved::Package, module: fastn_unresolved::Module, source: &str, arena: &mut fastn_unresolved::Arena, @@ -10,6 +11,7 @@ pub fn parse( ) -> fastn_unresolved::Document { let (mut document, sections) = fastn_unresolved::Document::new( module, + package, fastn_section::Document::parse(&arcstr::ArcStr::from(source)), arena, ); @@ -68,9 +70,11 @@ where let mut arena = fastn_unresolved::Arena::default(); let module = fastn_unresolved::Module::new("main", None, &mut arena); + // let package = fastn_unresolved::Package::new(); let (mut document, sections) = fastn_unresolved::Document::new( module, + package, fastn_section::Document::parse(&arcstr::ArcStr::from(source)), &mut arena, ); diff --git a/v0.5/fastn-unresolved/src/utils.rs b/v0.5/fastn-unresolved/src/utils.rs index 0f53d8c22..5a21cca40 100644 --- a/v0.5/fastn-unresolved/src/utils.rs +++ b/v0.5/fastn-unresolved/src/utils.rs @@ -1,11 +1,13 @@ impl fastn_unresolved::Document { pub(crate) fn new( module: fastn_unresolved::Module, + package: fastn_unresolved::Package, document: fastn_section::Document, arena: &mut fastn_unresolved::Arena, ) -> (fastn_unresolved::Document, Vec) { ( fastn_unresolved::Document { + package, module, aliases: Some(arena.new_aliases()), module_doc: document.module_doc, @@ -268,3 +270,11 @@ impl fastn_unresolved::Arena { .map(|v| v.to_owned()) } } + +impl From for fastn_unresolved::Package { + fn from(value: fastn_package::Package) -> Self { + Self { + inner: std::sync::Arc::new(value), + } + } +}