-
Notifications
You must be signed in to change notification settings - Fork 39
Introduce ThreadContext instead of execution depth #726
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7f25e52
2f5c0f8
58bea12
04ac27b
dee285e
415afb6
e0a6dfd
62cfb87
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,28 @@ constexpr ExecutionResult Void{true}; | |
/// Shortcut for execution that resulted in a trap. | ||
constexpr ExecutionResult Trap{false}; | ||
|
||
|
||
class ThreadContext | ||
{ | ||
class [[nodiscard]] Guard | ||
{ | ||
ThreadContext& m_thread_context; | ||
|
||
public: | ||
explicit Guard(ThreadContext& ctx) noexcept : m_thread_context{ctx} {} | ||
~Guard() noexcept { --m_thread_context.depth; } | ||
}; | ||
|
||
public: | ||
int depth = 0; | ||
|
||
Guard bump_call_depth() noexcept | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, this returns private class, I wouldn't think it's possible... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe call it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just an idea: it could be execute member function of ExecutionResult execute(Instance& instance, FuncIdx func_idx, const Value* args) noexcept; then But maybe confusingly too many execute variants then. |
||
{ | ||
++depth; | ||
return Guard{*this}; | ||
} | ||
}; | ||
|
||
/// Execute a function from an instance. | ||
/// | ||
/// @param instance The instance. | ||
|
@@ -49,7 +71,15 @@ constexpr ExecutionResult Trap{false}; | |
/// @param args The pointer to the arguments. The number of items and their types must match | ||
/// the expected number of input parameters of the function, otherwise undefined | ||
/// behaviour (including crash) happens. | ||
/// @param depth The call depth (indexing starts at 0). Can be left at the default setting. | ||
/// @param ctx The thread context. | ||
/// @return The result of the execution. | ||
ExecutionResult execute(Instance& instance, FuncIdx func_idx, const Value* args, int depth = 0); | ||
ExecutionResult execute( | ||
Instance& instance, FuncIdx func_idx, const Value* args, ThreadContext& ctx); | ||
|
||
/// Execute a function from an instance starting at default depth of 0. | ||
inline ExecutionResult execute(Instance& instance, FuncIdx func_idx, const Value* args) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this version used heavily in the tests? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. |
||
{ | ||
ThreadContext ctx; | ||
return execute(instance, func_idx, args, ctx); | ||
} | ||
} // namespace fizzy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should have a comment, see FizzyInstance above.