Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions stack-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ fn main() {
if cli.enable_all || cli.enable_scope {
engine.add_module(stack_std::scope::module());
}

if cli.enable_all || cli.enable_tag {
engine.add_module(stack_std::tag::module());
}
}

match cli.subcommand {
Expand Down Expand Up @@ -307,6 +311,10 @@ struct Cli {
#[arg(long)]
#[cfg(feature = "stack-std")]
enable_scope: bool,
/// Enable the tag standard module.
#[arg(long)]
#[cfg(feature = "stack-std")]
enable_tag: bool,
}

#[derive(Debug, Clone, PartialEq, Eq, Default, clap::Subcommand)]
Expand Down
7 changes: 3 additions & 4 deletions stack-core/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,9 @@ impl Engine {
}
Ok(context)
} else {
context.stack_push(Expr {
kind: ExprKind::Error(Error::new("unknown function".into())),
info: None,
})?;
context.stack_push(
ExprKind::Error(Error::new("unknown function".into())).into(),
)?;

Ok(context)
}
Expand Down
28 changes: 28 additions & 0 deletions stack-core/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,29 @@ use crate::{lexer::Span, scope::Scope, source::Source, symbol::Symbol};
pub struct Expr {
pub kind: ExprKind,
pub info: Option<ExprInfo>,
pub tags: HashMap<Symbol, Expr>,
}

impl Expr {
pub fn with_tags(mut self, tags: HashMap<Symbol, Expr>) -> Self {
self.tags = tags;
self
}

pub fn with_info(mut self, info: Option<ExprInfo>) -> Self {
self.info = info;
self
}
}

impl From<ExprKind> for Expr {
fn from(value: ExprKind) -> Self {
Self {
info: None,
kind: value,
tags: HashMap::new(),
}
}
}

impl PartialEq for Expr {
Expand Down Expand Up @@ -57,6 +80,11 @@ pub enum ExprKind {
}

impl ExprKind {
#[inline]
pub fn into_expr(self) -> Expr {
self.into()
}

#[inline]
pub const fn is_nil(&self) -> bool {
matches!(self, Self::Nil)
Expand Down
Loading