New macro system and stdlib additions

This commit is contained in:
2025-11-21 14:25:03 +01:00
parent b77653f841
commit 603efef28e
230 changed files with 3033 additions and 16640 deletions

View File

@@ -145,16 +145,6 @@ impl Request for ExtAtomPrint {
type Response = FormattingUnit;
}
/// Can specify the recipient of an atom as well. The main use case for this is
/// to be able to return an atom to other extensions, so it can be combined with
/// a [crate::Move].
#[derive(Clone, Debug, Coding, Hierarchy)]
#[extends(ExtHostReq)]
pub struct CreateAtom(pub Atom, pub SysId);
impl Request for CreateAtom {
type Response = ExprTicket;
}
/// Requests that apply to an existing atom instance
#[derive(Clone, Debug, Coding, Hierarchy)]
#[extends(HostExtReq)]

View File

@@ -43,17 +43,6 @@ pub struct Acquire(pub SysId, pub ExprTicket);
#[extends(ExprNotif, ExtHostNotif)]
pub struct Release(pub SysId, pub ExprTicket);
/// Decrement the reference count for one system and increment it for another,
/// to indicate passing an owned reference. Equivalent to [Acquire] followed by
/// [Release].
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, Coding, Hierarchy)]
#[extends(ExprNotif, ExtHostNotif)]
pub struct Move {
pub dec: SysId,
pub inc: SysId,
pub expr: ExprTicket,
}
/// A description of a new expression. It is used as the return value of
/// [crate::atom::Call] or [crate::atom::CallRef], or a constant in the
/// [crate::tree::Tree].
@@ -67,8 +56,9 @@ pub enum ExpressionKind {
/// template
Arg(u64),
/// Insert the specified host-expression in the template here. When the clause
/// is used in the const tree, this variant is forbidden.
Slot { tk: ExprTicket, by_value: bool },
/// is used in the const tree, this variant is forbidden. The ticket held
/// within is always owning. To avoid a leak, it must be deserialized.
Slot(ExprTicket),
/// The lhs must be fully processed before the rhs can be processed.
/// Equivalent to Haskell's function of the same name
Seq(Box<Expression>, Box<Expression>),
@@ -115,11 +105,12 @@ impl Request for Inspect {
type Response = Inspected;
}
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, Coding, Hierarchy)]
#[derive(Clone, Debug, Coding, Hierarchy)]
#[extends(ExtHostReq)]
#[extendable]
pub enum ExprReq {
Inspect(Inspect),
Create(Create),
}
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, Coding, Hierarchy)]
@@ -128,5 +119,11 @@ pub enum ExprReq {
pub enum ExprNotif {
Acquire(Acquire),
Release(Release),
Move(Move),
}
#[derive(Clone, Debug, Coding, Hierarchy)]
#[extends(ExprReq, ExtHostReq)]
pub struct Create(pub Expression);
impl Request for Create {
type Response = ExprTicket;
}

View File

@@ -17,6 +17,8 @@ pub enum Location {
Gen(CodeGenInfo),
/// Range and file
SourceRange(SourceRange),
/// Multiple locations
Multi(Vec<Location>),
}
#[derive(Clone, Debug, Coding)]

View File

@@ -85,7 +85,6 @@ pub enum ExtHostReq {
IntReq(interner::IntReq),
Fwd(atom::Fwd),
ExtAtomPrint(atom::ExtAtomPrint),
CreateAtom(atom::CreateAtom),
SysFwd(system::SysFwd),
ExprReq(expr::ExprReq),
SubLex(lexer::SubLex),

View File

@@ -1,4 +1,5 @@
use std::collections::HashMap;
use std::fmt;
use std::num::NonZeroU64;
use std::ops::Range;
use std::rc::Rc;
@@ -56,6 +57,15 @@ pub enum Paren {
Square,
Curly,
}
impl fmt::Display for Paren {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", match self {
Self::Round => "()",
Self::Curly => "{}",
Self::Square => "[]",
})
}
}
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Coding)]
pub struct TreeId(pub NonZeroU64);