Support call stack and FunctionExit for native functions.
This commit is contained in:
@@ -70,6 +70,8 @@ pub struct NativeCallContext<'a> {
|
||||
lib: &'a [&'a Module],
|
||||
/// [Position] of the function call.
|
||||
pos: Position,
|
||||
/// The current nesting level of function calls.
|
||||
level: usize,
|
||||
}
|
||||
|
||||
impl<'a, M: AsRef<[&'a Module]> + ?Sized, S: AsRef<str> + 'a + ?Sized>
|
||||
@@ -80,6 +82,7 @@ impl<'a, M: AsRef<[&'a Module]> + ?Sized, S: AsRef<str> + 'a + ?Sized>
|
||||
&'a GlobalRuntimeState<'a>,
|
||||
&'a M,
|
||||
Position,
|
||||
usize,
|
||||
)> for NativeCallContext<'a>
|
||||
{
|
||||
#[inline(always)]
|
||||
@@ -91,6 +94,7 @@ impl<'a, M: AsRef<[&'a Module]> + ?Sized, S: AsRef<str> + 'a + ?Sized>
|
||||
&'a GlobalRuntimeState,
|
||||
&'a M,
|
||||
Position,
|
||||
usize,
|
||||
),
|
||||
) -> Self {
|
||||
Self {
|
||||
@@ -100,6 +104,7 @@ impl<'a, M: AsRef<[&'a Module]> + ?Sized, S: AsRef<str> + 'a + ?Sized>
|
||||
global: Some(value.3),
|
||||
lib: value.4.as_ref(),
|
||||
pos: value.5,
|
||||
level: value.6,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -116,6 +121,7 @@ impl<'a, M: AsRef<[&'a Module]> + ?Sized, S: AsRef<str> + 'a + ?Sized>
|
||||
global: None,
|
||||
lib: value.2.as_ref(),
|
||||
pos: Position::NONE,
|
||||
level: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -141,6 +147,7 @@ impl<'a> NativeCallContext<'a> {
|
||||
global: None,
|
||||
lib,
|
||||
pos: Position::NONE,
|
||||
level: 0,
|
||||
}
|
||||
}
|
||||
/// _(internals)_ Create a new [`NativeCallContext`].
|
||||
@@ -158,6 +165,7 @@ impl<'a> NativeCallContext<'a> {
|
||||
global: &'a GlobalRuntimeState,
|
||||
lib: &'a [&Module],
|
||||
pos: Position,
|
||||
level: usize,
|
||||
) -> Self {
|
||||
Self {
|
||||
engine,
|
||||
@@ -166,6 +174,7 @@ impl<'a> NativeCallContext<'a> {
|
||||
global: Some(global),
|
||||
lib,
|
||||
pos,
|
||||
level,
|
||||
}
|
||||
}
|
||||
/// The current [`Engine`].
|
||||
@@ -186,6 +195,12 @@ impl<'a> NativeCallContext<'a> {
|
||||
pub const fn position(&self) -> Position {
|
||||
self.pos
|
||||
}
|
||||
/// Current nesting level of function calls.
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
pub const fn call_level(&self) -> usize {
|
||||
self.level
|
||||
}
|
||||
/// The current source.
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
@@ -316,7 +331,7 @@ impl<'a> NativeCallContext<'a> {
|
||||
is_method_call,
|
||||
Position::NONE,
|
||||
None,
|
||||
0,
|
||||
self.level + 1,
|
||||
)
|
||||
.map(|(r, _)| r)
|
||||
}
|
||||
|
Reference in New Issue
Block a user