Skip to content

Commit 488e2ca

Browse files
committed
Add more fields to API
1 parent e8ed87a commit 488e2ca

3 files changed

Lines changed: 45 additions & 34 deletions

File tree

src/eval/eval_context.rs

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,24 @@ impl<'a, 's, 'ps, 'g, 'c, 't> EvalContext<'a, 's, 'ps, 'g, 'c, 't> {
152152
pub const fn call_level(&self) -> usize {
153153
self.global.level
154154
}
155+
/// _(internals, debugging)_ Debugging interface.
156+
/// Exported under the `debugging` and `internals` features only.
157+
#[cfg(feature = "debugging")]
158+
#[cfg(feature = "internals")]
159+
#[inline(always)]
160+
#[must_use]
161+
pub fn debugger(&self) -> Option<&crate::debugger::Debugger> {
162+
self.global.debugger.as_deref()
163+
}
164+
/// _(internals, debugging)_ Mutable reference to the debugging interface.
165+
/// Exported under the `debugging` and `internals` features only.
166+
#[cfg(feature = "debugging")]
167+
#[cfg(feature = "internals")]
168+
#[inline(always)]
169+
#[must_use]
170+
pub fn debugger_mut(&mut self) -> Option<&mut crate::debugger::Debugger> {
171+
self.global.debugger.as_deref_mut()
172+
}
155173

156174
/// Evaluate an [expression tree][crate::Expression] within this [evaluation context][`EvalContext`].
157175
///
@@ -383,12 +401,16 @@ impl<'a, 's, 'ps, 'g, 'c, 't> EvalContext<'a, 's, 'ps, 'g, 'c, 't> {
383401
/// # Examples
384402
///
385403
/// ```rust,ignore
386-
/// // The following disables caching of function resolution results for this frame
387-
/// // by pushing a new, empty, caching layer. This is useful if the resolution will be volatile.
404+
/// // The following pushes a new, empty, caching layer to make sure that new function resolutions
405+
/// // do not persist. This is useful if the resolution will be volatile.
388406
/// let result: i64 = context.new_frame()
389407
/// .with_new_caching_layer()
390408
/// .call_fn("foo", (0_i64,))?;
391409
///
410+
/// // In the above example, the resolution to function 'foo' will not be cached outside the frame.
411+
/// // The next call to 'foo' will be resolved again instead of using the cached resolution,
412+
/// // even if 'foo' is redefined.
413+
///
392414
/// // The following modifies the [`EvalContext`] before using, restoring its state afterwards.
393415
/// {
394416
/// // Modify the context before using...
@@ -415,7 +437,6 @@ impl<'a, 's, 'ps, 'g, 'c, 't> EvalContext<'a, 's, 'ps, 'g, 'c, 't> {
415437
/// * the original [scope][EvalContext::scope] will be rewound if [`EvalContextFrameGuard::rewind_scope`] was set to `true`.
416438
/// * the [source][GlobalRuntimeState::source] will be restored if a new source was set via [`EvalContextFrameGuard::with_source`] or cleared via [`EvalContextFrameGuard::clear_source`].
417439
/// * the current [nesting level][GlobalRuntimeState::level] of function calls will be restored if modified via [`EvalContextFrameGuard::up_call_level`].
418-
/// * the current [scope level][GlobalRuntimeState::scope_level] will be restored if modified via [`EvalContextFrameGuard::up_scope_level`].
419440
/// * the current [`tag`][GlobalRuntimeState::tag] will be restored if modified via [`EvalContextFrameGuard::with_tag`] or [`EvalContextFrameGuard::clear_tag`].
420441
pub fn new_frame<'f>(&'f mut self) -> EvalContextFrameGuard<'f, 'a, 's, 'ps, 'g, 'c, 't> {
421442
EvalContextFrameGuard {
@@ -430,8 +451,6 @@ impl<'a, 's, 'ps, 'g, 'c, 't> EvalContext<'a, 's, 'ps, 'g, 'c, 't> {
430451
source: None,
431452
#[cfg(feature = "internals")]
432453
level: None,
433-
#[cfg(feature = "internals")]
434-
scope_level: None,
435454
tag: None,
436455

437456
context: self,
@@ -520,8 +539,6 @@ pub struct EvalContextFrameGuard<'f, 'a, 's, 'ps, 'g, 'c, 't> {
520539
source: Option<Option<ImmutableString>>,
521540
#[cfg(feature = "internals")]
522541
level: Option<usize>,
523-
#[cfg(feature = "internals")]
524-
scope_level: Option<usize>,
525542
tag: Option<Dynamic>,
526543
}
527544

@@ -551,10 +568,6 @@ impl Drop for EvalContextFrameGuard<'_, '_, '_, '_, '_, '_, '_> {
551568
if let Some(level) = self.level {
552569
self.context.global.level = level;
553570
}
554-
#[cfg(feature = "internals")]
555-
if let Some(scope_level) = self.scope_level {
556-
self.context.global.scope_level = scope_level;
557-
}
558571
if let Some(tag) = self.tag.take() {
559572
*self.context.tag_mut() = tag;
560573
}
@@ -659,13 +672,4 @@ impl<'t> EvalContextFrameGuard<'_, '_, '_, '_, '_, '_, 't> {
659672
self.context.global.level += 1;
660673
self
661674
}
662-
/// _(internals)_ Increment the current scope level.
663-
/// Exported under the `internals` feature only.
664-
#[cfg(feature = "internals")]
665-
#[inline(always)]
666-
pub fn up_scope_level(mut self) -> Self {
667-
self.scope_level = Some(self.context.global.scope_level);
668-
self.context.global.scope_level += 1;
669-
self
670-
}
671675
}

src/func/native.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -265,16 +265,6 @@ impl<'a> NativeCallContext<'a> {
265265
pub fn iter_imports(&self) -> impl Iterator<Item = (&str, &crate::Module)> {
266266
self.global.iter_imports()
267267
}
268-
/// _(internals)_ The current [`GlobalRuntimeState`], if any.
269-
/// Exported under the `internals` feature only.
270-
///
271-
/// Not available under `no_module`.
272-
#[expose_under_internals]
273-
#[inline(always)]
274-
#[must_use]
275-
const fn global_runtime_state(&self) -> &GlobalRuntimeState {
276-
self.global
277-
}
278268
/// Get an iterator over the namespaces containing definitions of all script-defined functions
279269
/// in reverse order (i.e. parent namespaces are iterated after child namespaces).
280270
///
@@ -295,6 +285,25 @@ impl<'a> NativeCallContext<'a> {
295285
pub fn namespaces(&self) -> &[crate::SharedModule] {
296286
&self.global.lib
297287
}
288+
/// _(internals)_ The current [`GlobalRuntimeState`], if any.
289+
/// Exported under the `internals` feature only.
290+
///
291+
/// Not available under `no_module`.
292+
#[expose_under_internals]
293+
#[inline(always)]
294+
#[must_use]
295+
const fn global_runtime_state(&self) -> &GlobalRuntimeState {
296+
self.global
297+
}
298+
/// _(internals, debugging)_ Debugging interface.
299+
/// Exported under the `debugging` and `internals` features only.
300+
#[cfg(feature = "debugging")]
301+
#[cfg(feature = "internals")]
302+
#[inline(always)]
303+
#[must_use]
304+
pub fn debugger(&self) -> Option<&crate::debugger::Debugger> {
305+
self.global.debugger.as_deref()
306+
}
298307

299308
/// Call a function inside the call context with the provided arguments.
300309
#[inline]

tests/functions.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -626,9 +626,8 @@ fn test_missing_function_receives_args() {
626626
#[cfg(not(feature = "no_object"))]
627627
fn test_missing_function_not_called_for_existing() {
628628
use std::sync::atomic::{AtomicBool, Ordering};
629-
use std::sync::Arc;
630629

631-
let called = Arc::new(AtomicBool::new(false));
630+
let called = Shared::new(AtomicBool::new(false));
632631
let called_clone = called.clone();
633632

634633
let mut engine = Engine::new();
@@ -708,9 +707,8 @@ fn test_missing_function_multiple_arities() {
708707
#[cfg(not(feature = "no_object"))]
709708
fn test_missing_function_is_method_call_flag() {
710709
use std::sync::atomic::{AtomicBool, Ordering};
711-
use std::sync::Arc;
712710

713-
let saw_method = Arc::new(AtomicBool::new(false));
711+
let saw_method = Shared::new(AtomicBool::new(false));
714712
let saw_method_clone = saw_method.clone();
715713

716714
let mut engine = Engine::new();

0 commit comments

Comments
 (0)