Skip to content

Commit

Permalink
default prelude macros
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwparas committed Nov 2, 2024
1 parent 743f05b commit 0e1dab1
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions crates/steel-core/src/steel_vm/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,21 @@ macro_rules! time {
static STATIC_DEFAULT_PRELUDE_MACROS: OnceCell<FxHashMap<InternedString, SteelMacro>> =
OnceCell::new();

pub(crate) fn set_default_prelude_macros(prelude_macros: FxHashMap<InternedString, SteelMacro>) {
static STATIC_DEFAULT_PRELUDE_MACROS_SANDBOX: OnceCell<FxHashMap<InternedString, SteelMacro>> =
OnceCell::new();

pub(crate) fn set_default_prelude_macros(
prelude_macros: FxHashMap<InternedString, SteelMacro>,
sandbox: bool,
) {
if cfg!(feature = "sync") {
STATIC_DEFAULT_PRELUDE_MACROS.set(prelude_macros).unwrap();
if sandbox {
STATIC_DEFAULT_PRELUDE_MACROS_SANDBOX
.set(prelude_macros)
.unwrap();
} else {
STATIC_DEFAULT_PRELUDE_MACROS.set(prelude_macros).unwrap();
}
} else {
DEFAULT_PRELUDE_MACROS.with(|x| {
let mut guard = x.borrow_mut();
Expand All @@ -392,10 +404,12 @@ pub(crate) fn set_default_prelude_macros(prelude_macros: FxHashMap<InternedStrin

pub(crate) fn default_prelude_macros() -> FxHashMap<InternedString, SteelMacro> {
if cfg!(feature = "sync") {
STATIC_DEFAULT_PRELUDE_MACROS
.get()
.cloned()
.unwrap_or_default()
STATIC_DEFAULT_PRELUDE_MACROS.get().cloned().unwrap_or(
STATIC_DEFAULT_PRELUDE_MACROS_SANDBOX
.get()
.cloned()
.unwrap_or_default(),
)
} else {
DEFAULT_PRELUDE_MACROS.with(|x| x.borrow().clone())
}
Expand Down Expand Up @@ -558,7 +572,7 @@ impl Engine {
// values won't leak when top level macros are defined - and modules can clone from
// this to begin seeding their environment.

set_default_prelude_macros(vm.in_scope_macros().clone());
set_default_prelude_macros(vm.in_scope_macros().clone(), sandbox);

#[cfg(feature = "profiling")]
log::debug!(target: "kernel", "Loaded prelude in the kernel!: {:?}", now.elapsed());
Expand Down

0 comments on commit 0e1dab1

Please sign in to comment.