Skip to content

Commit

Permalink
fastn_package stuff: not compiling
Browse files Browse the repository at this point in the history
  • Loading branch information
amitu committed Dec 19, 2024
1 parent 0bde415 commit 57654b6
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 8 deletions.
2 changes: 2 additions & 0 deletions v0.5/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions v0.5/fastn-compiler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 7 additions & 3 deletions v0.5/fastn-compiler/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -37,6 +40,7 @@ impl Compiler {
document.content = vec![];

Self {
package,
arena,
definitions: std::collections::HashMap::new(),
modules: std::collections::HashMap::new(),
Expand Down Expand Up @@ -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<Compiler> {
use fastn_continuation::Continuation;
Expand Down
8 changes: 4 additions & 4 deletions v0.5/fastn-package/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ pub type UR<U, R> = fastn_continuation::UR<U, R, fastn_section::Error>;

#[derive(Debug)]
pub struct Package {
name: String,
systems: Vec<System>,
dependencies: Vec<Dependency>,
pub name: String,
pub systems: Vec<System>,
pub dependencies: Vec<Dependency>,
pub auto_imports: Vec<AutoImport>,
apps: Vec<App>,
pub apps: Vec<App>,
}

#[derive(Clone, Debug)]
Expand Down
1 change: 1 addition & 0 deletions v0.5/fastn-unresolved/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion v0.5/fastn-unresolved/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,16 @@ pub enum SoMBase<S, M> {
Module(M),
}

#[derive(Debug, Clone)]
pub struct Package {
inner: std::sync::Arc<fastn_section::Package>,
}

#[derive(Debug, Clone)]
pub struct Document {
pub aliases: Option<AliasesID>,
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<fastn_section::Span>,
pub definitions: Vec<URD>,
pub content: Vec<URCI>,
Expand All @@ -76,6 +81,7 @@ pub struct Document {
#[derive(Debug, Clone)]
pub struct Definition {
pub aliases: AliasesID,
pub module: fastn_unresolved::Module,
pub symbol: Option<fastn_unresolved::Symbol>, // <package-name>/<module-name>#<definition-name>
/// 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
Expand Down
1 change: 1 addition & 0 deletions v0.5/fastn-unresolved/src/parser/function_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
4 changes: 4 additions & 0 deletions v0.5/fastn-unresolved/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ mod function_definition;
mod import;

pub fn parse(
package: fastn_unresolved::Package,
module: fastn_unresolved::Module,
source: &str,
arena: &mut fastn_unresolved::Arena,
// global_aliases: &fastn_unresolved::AliasesSimple,
) -> fastn_unresolved::Document {
let (mut document, sections) = fastn_unresolved::Document::new(
module,
package,
fastn_section::Document::parse(&arcstr::ArcStr::from(source)),
arena,
);
Expand Down Expand Up @@ -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,
);
Expand Down
10 changes: 10 additions & 0 deletions v0.5/fastn-unresolved/src/utils.rs
Original file line number Diff line number Diff line change
@@ -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_section::Section>) {
(
fastn_unresolved::Document {
package,
module,
aliases: Some(arena.new_aliases()),
module_doc: document.module_doc,
Expand Down Expand Up @@ -268,3 +270,11 @@ impl fastn_unresolved::Arena {
.map(|v| v.to_owned())
}
}

impl From<fastn_package::Package> for fastn_unresolved::Package {
fn from(value: fastn_package::Package) -> Self {
Self {
inner: std::sync::Arc::new(value),
}
}
}

0 comments on commit 57654b6

Please sign in to comment.