pub struct GlobalEnv {
pub namespaces: RwLock<HashMap<Arc<str>, GcPtr<Namespace>>>,
pub source_paths: RwLock<Vec<PathBuf>>,
pub loaded: Mutex<HashSet<Arc<str>>>,
pub loading: Mutex<HashSet<Arc<str>>>,
pub builtin_sources: RwLock<HashMap<Arc<str>, &'static str>>,
pub gc_config: RwLock<Option<Arc<GcConfig>>>,
pub compiler_ready: Atomic<bool>,
pub eval_fn: fn(&Form, &mut Env) -> Result<Value, EvalError>,
pub call_cljrs_fn: fn(&CljxFn, &[Value], &mut Env) -> Result<Value, EvalError>,
/* private fields */
}Expand description
The global mutable store of all namespaces.
Fields§
§namespaces: RwLock<HashMap<Arc<str>, GcPtr<Namespace>>>§source_paths: RwLock<Vec<PathBuf>>Directories to search when resolving namespace names to files.
loaded: Mutex<HashSet<Arc<str>>>Namespaces that have been fully loaded from a file (idempotent guard).
loading: Mutex<HashSet<Arc<str>>>Namespaces currently being loaded (cycle detection).
builtin_sources: RwLock<HashMap<Arc<str>, &'static str>>Built-in namespace sources embedded in the binary.
Checked by load_ns before falling back to source-path search.
gc_config: RwLock<Option<Arc<GcConfig>>>GC configuration for automatic collection based on memory pressure.
compiler_ready: Atomic<bool>True once the Clojure compiler namespaces have been loaded and IR lowering is available. Before this, all functions use tree-walking.
eval_fn: fn(&Form, &mut Env) -> Result<Value, EvalError>Evaluator function. Evaluates form given env, produces an EvalResult.
call_cljrs_fn: fn(&CljxFn, &[Value], &mut Env) -> Result<Value, EvalError>Call a cljrs function.
Implementations§
Source§impl GlobalEnv
impl GlobalEnv
pub fn new( eval_fn: fn(&Form, &mut Env) -> Result<Value, EvalError>, call_cljrs_fn: fn(&CljxFn, &[Value], &mut Env) -> Result<Value, EvalError>, on_fn_defined: Option<fn(&CljxFn, &mut Env)>, ) -> Arc<GlobalEnv>
Sourcepub fn set_source_paths(&self, paths: Vec<PathBuf>)
pub fn set_source_paths(&self, paths: Vec<PathBuf>)
Replace the source path list.
Sourcepub fn register_builtin_source(&self, ns: &str, src: &'static str)
pub fn register_builtin_source(&self, ns: &str, src: &'static str)
Register an embedded namespace source (called by cljrs-stdlib at startup).
Sourcepub fn builtin_source(&self, ns: &str) -> Option<&'static str>
pub fn builtin_source(&self, ns: &str) -> Option<&'static str>
Look up an embedded source for a namespace, if one has been registered.
Sourcepub fn mark_loaded(&self, ns: &str)
pub fn mark_loaded(&self, ns: &str)
Mark a namespace as fully loaded from a file.
Sourcepub fn is_loaded(&self, ns: &str) -> bool
pub fn is_loaded(&self, ns: &str) -> bool
True if the namespace has already been loaded from a file.
Sourcepub fn set_gc_config(&self, config: Arc<GcConfig>)
pub fn set_gc_config(&self, config: Arc<GcConfig>)
Set the GC configuration for automatic memory pressure management.
Sourcepub fn gc_config(&self) -> Option<Arc<GcConfig>>
pub fn gc_config(&self) -> Option<Arc<GcConfig>>
Get the GC configuration, if one has been set.
Sourcepub fn resolve_alias(&self, current_ns: &str, alias: &str) -> Option<Arc<str>>
pub fn resolve_alias(&self, current_ns: &str, alias: &str) -> Option<Arc<str>>
Resolve a short alias to a full namespace name in current_ns.
Sourcepub fn get_or_create_ns(&self, name: &str) -> GcPtr<Namespace>
pub fn get_or_create_ns(&self, name: &str) -> GcPtr<Namespace>
Return the namespace with this name, creating it if it doesn’t exist.
Sourcepub fn intern(&self, ns_name: &str, name: Arc<str>, val: Value) -> GcPtr<Var>
pub fn intern(&self, ns_name: &str, name: Arc<str>, val: Value) -> GcPtr<Var>
Intern name with val in the given namespace, returning the Var.
Sourcepub fn lookup_var(&self, ns_name: &str, sym_name: &str) -> Option<GcPtr<Var>>
pub fn lookup_var(&self, ns_name: &str, sym_name: &str) -> Option<GcPtr<Var>>
Look up a Var in the named namespace (interns only).
Sourcepub fn lookup_in_ns(&self, ns_name: &str, sym_name: &str) -> Option<Value>
pub fn lookup_in_ns(&self, ns_name: &str, sym_name: &str) -> Option<Value>
Look up a value in ns_name: checks interns then refers.
Routes through the dynamic binding stack so binding overrides work.
Sourcepub fn lookup_var_in_ns(
&self,
ns_name: &str,
sym_name: &str,
) -> Option<GcPtr<Var>>
pub fn lookup_var_in_ns( &self, ns_name: &str, sym_name: &str, ) -> Option<GcPtr<Var>>
Look up the raw Var (not its value) in ns_name: interns then refers.
Sourcepub fn refer_all(&self, dst_ns: &str, src_ns: &str)
pub fn refer_all(&self, dst_ns: &str, src_ns: &str)
Copy all interns from src_ns into dst_ns as refers.
Sourcepub fn refer_named(&self, dst_ns: &str, src_ns: &str, names: &[Arc<str>])
pub fn refer_named(&self, dst_ns: &str, src_ns: &str, names: &[Arc<str>])
Copy selected interns from src_ns into dst_ns as refers.
Sourcepub fn add_alias(&self, current_ns: &str, alias: &str, full_ns: &str)
pub fn add_alias(&self, current_ns: &str, alias: &str, full_ns: &str)
Register alias → full_ns in current_ns’s alias table.
Sourcepub fn eval(&self, form: &Form, env: &mut Env) -> Result<Value, EvalError>
pub fn eval(&self, form: &Form, env: &mut Env) -> Result<Value, EvalError>
Evaluate form given env.
Sourcepub fn call_cljrs_fn(
&self,
func: &CljxFn,
args: &[Value],
env: &mut Env,
) -> Result<Value, EvalError>
pub fn call_cljrs_fn( &self, func: &CljxFn, args: &[Value], env: &mut Env, ) -> Result<Value, EvalError>
Call the given cljrs function.
Sourcepub fn on_fn_defined(&self, f: &CljxFn, env: &mut Env)
pub fn on_fn_defined(&self, f: &CljxFn, env: &mut Env)
Callback hook for new functions defined.
Sourcepub fn set_on_fn_defined(&mut self, hook: fn(&CljxFn, &mut Env))
pub fn set_on_fn_defined(&mut self, hook: fn(&CljxFn, &mut Env))
Sets the on-new-function-defined hook.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for GlobalEnv
impl RefUnwindSafe for GlobalEnv
impl Send for GlobalEnv
impl Sync for GlobalEnv
impl Unpin for GlobalEnv
impl UnsafeUnpin for GlobalEnv
impl UnwindSafe for GlobalEnv
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more