Various progress, doesnt compile

Added prelude, made lambdas a single-token prefix like NS, made progress on implementations, removed const line type
This commit is contained in:
2025-07-31 00:30:41 +02:00
parent 19f2c6426a
commit 769c6cfc9f
31 changed files with 450 additions and 250 deletions

View File

@@ -9,12 +9,11 @@ use futures::{FutureExt, StreamExt, stream};
use hashbrown::HashMap;
use hashbrown::hash_map::Entry;
use itertools::Itertools;
use orchid_api::FetchParsedConst;
use orchid_base::clone;
use orchid_base::error::{OrcRes, Reporter, mk_err, mk_errv};
use orchid_base::interner::Tok;
use orchid_base::location::{Pos, SrcRange};
use orchid_base::name::{Sym, VPath};
use orchid_base::location::{CodeGenInfo, Pos};
use orchid_base::name::{NameLike, Sym, VPath};
use orchid_base::reqnot::Requester;
use crate::api;
@@ -60,11 +59,12 @@ impl Root {
let mut ref_this = self.0.write().await;
let this = &mut *ref_this;
let mut deferred_consts = HashMap::new();
let mut consts = this.consts.clone();
let mut tfpctx = FromParsedCtx {
pars_root: parsed,
deferred_consts: &mut deferred_consts,
consts: &mut consts,
pars_prefix: pars_prefix.clone(),
consts: &mut this.consts,
root: &this.root,
ctx: &this.ctx,
rep,
@@ -78,14 +78,13 @@ impl Root {
)]);
module = Module { imports: HashMap::new(), members }
}
let mut consts = this.consts.clone();
let root = (this.root.merge(&module, this.ctx.clone(), &mut consts).await)
.expect("Merge conflict between parsed and existing module");
let new = Root(Rc::new(RwLock::new(RootData { root, consts, ctx: this.ctx.clone() })));
*this.ctx.root.write().await = new.downgrade();
for (path, (sys_id, pc_id)) in deferred_consts {
let sys = this.ctx.system_inst(sys_id).await.expect("System dropped since parsing");
let api_expr = sys.reqnot().request(FetchParsedConst { id: pc_id, sys: sys.id() }).await;
let api_expr = sys.reqnot().request(api::FetchParsedConst { id: pc_id, sys: sys.id() }).await;
let mut xp_ctx = ExprParseCtx { ctx: &this.ctx, exprs: sys.ext().exprs() };
let expr = Expr::from_api(&api_expr, PathSetBuilder::new(), &mut xp_ctx).await;
new.0.write().await.consts.insert(path, expr);
@@ -154,7 +153,7 @@ impl<'a> TreeFromApiCtx<'a> {
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ResolvedImport {
target: Sym,
sr: SrcRange,
pos: Pos,
}
#[derive(Clone, Default)]
@@ -234,6 +233,22 @@ impl Module {
}
}
let mut imports = HashMap::new();
if parsed.use_prelude {
let systems = ctx.ctx.systems.read().await;
for sys in systems.values().flat_map(|weak| weak.upgrade()) {
for prelude_item in sys.prelude() {
imports.insert(
prelude_item.last_seg(),
Ok(ResolvedImport {
target: prelude_item,
pos: CodeGenInfo::new_details(sys.ctor().name_tok().await, "In prelude", &ctx.ctx.i)
.await
.pos(),
}),
);
}
}
}
let conflicting_imports_msg = ctx.ctx.i.i("Conflicting imports").await;
for (key, values) in imports_by_name {
if values.len() == 1 {
@@ -243,8 +258,10 @@ impl Module {
match abs_path_res {
Err(e) => ctx.rep.report(e.err_obj(&ctx.ctx.i, sr.pos(), &import.to_string()).await),
Ok(abs_path) => {
imports
.insert(key, Ok(ResolvedImport { target: abs_path.to_sym(&ctx.ctx.i).await, sr }));
imports.insert(
key,
Ok(ResolvedImport { target: abs_path.to_sym(&ctx.ctx.i).await, pos: sr.pos() }),
);
},
}
} else {
@@ -263,7 +280,10 @@ impl Module {
let values = stream::iter(values)
.then(|(n, sr)| {
clone!(key; async move {
ResolvedImport { target: n.to_vname().suffix([key.clone()]).to_sym(i).await, sr }
ResolvedImport {
target: n.to_vname().suffix([key.clone()]).to_sym(i).await,
pos: sr.pos(),
}
})
})
.collect::<Vec<_>>()
@@ -278,7 +298,7 @@ impl Module {
ctx.rep.report(mk_err(
self_referential_msg.clone(),
format!("import {} points to itself or a path within itself", &import.target),
[import.sr.pos().into()],
[import.pos.clone().into()],
));
}
}
@@ -363,9 +383,9 @@ pub struct FromParsedCtx<'a> {
pars_prefix: Sym,
pars_root: &'a ParsedModule,
root: &'a Module,
consts: &'a mut HashMap<Sym, Expr>,
rep: &'a Reporter,
ctx: &'a Ctx,
consts: &'a mut HashMap<Sym, Expr>,
deferred_consts: &'a mut HashMap<Sym, (api::SysId, api::ParsedConstId)>,
}
@@ -417,10 +437,6 @@ impl MemberKind {
#[must_use]
async fn from_parsed(parsed: &ParsedMemberKind, path: Sym, ctx: &mut FromParsedCtx<'_>) -> Self {
match parsed {
ParsedMemberKind::ParsedConst(expr) => {
ctx.consts.insert(path, expr.clone());
MemberKind::Const
},
ParsedMemberKind::DeferredConst(id, sys) => {
ctx.deferred_consts.insert(path, (sys.id(), *id));
MemberKind::Const