Skip to content

Commit

Permalink
add scope:is-loaded method (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vandesm14 authored Jun 13, 2024
1 parent c862a60 commit a81ef9c
Showing 1 changed file with 32 additions and 7 deletions.
39 changes: 32 additions & 7 deletions stack-std/src/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,29 @@ pub fn module() -> Module {
ExprKind::Symbol(ref x) => {
if Intrinsic::from_str(x.as_str()).is_ok() {
context.stack_push(ExprKind::String("intrinsic".into()).into())
} else if engine
.module(&Symbol::new(
x.as_str().split(':').next().unwrap_or_default().into(),
))
.is_some()
{
context.stack_push(ExprKind::String("module".into()).into())
} else if context.let_get(*x).is_some() {
context.stack_push(ExprKind::String("let".into()).into())
} else if context.scope_item(*x).is_some() {
context.stack_push(ExprKind::String("scope".into()).into())
} else if engine.module(x).is_some() {
context.stack_push(ExprKind::String("module".into()).into())
} else if x.as_str().contains(':') {
if let Some(module) = engine.module(&Symbol::new(
x.as_str().split(':').next().unwrap_or_default().into(),
)) {
if module
.func(Symbol::new(
x.as_str().split(':').nth(1).unwrap_or_default().into(),
))
.is_some()
{
context.stack_push(ExprKind::String("module".into()).into())
} else {
context.stack_push(ExprKind::Nil.into())
}
} else {
context.stack_push(ExprKind::Nil.into())
}
} else {
context.stack_push(ExprKind::Nil.into())
}
Expand Down Expand Up @@ -60,6 +72,19 @@ pub fn module() -> Module {
.stack_push(ExprKind::List(items).into())
.map(|_| context)
}),
)
.add_func(
Symbol::from_ref("is-loaded"),
Arc::new(|engine, mut context, expr| {
let symbol = context.stack_pop(&expr)?;

match symbol.kind {
ExprKind::Symbol(ref x) => context
.stack_push(ExprKind::Boolean(engine.module(x).is_some()).into()),
_ => context.stack_push(ExprKind::Nil.into()),
}
.map(|_| context)
}),
);

module
Expand Down

0 comments on commit a81ef9c

Please sign in to comment.