2021-03-24 20:33:20 +01:00
|
|
|
#ifndef LIBCUBESCRIPT_THREAD_HH
|
|
|
|
#define LIBCUBESCRIPT_THREAD_HH
|
|
|
|
|
|
|
|
#include <cubescript/cubescript.hh>
|
|
|
|
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
#include "cs_std.hh"
|
|
|
|
#include "cs_state.hh"
|
2021-03-30 00:31:11 +02:00
|
|
|
#include "cs_ident.hh"
|
2021-03-24 20:33:20 +01:00
|
|
|
|
|
|
|
namespace cubescript {
|
|
|
|
|
|
|
|
struct thread_state {
|
2021-04-02 19:12:46 +02:00
|
|
|
using astack_allocator = std_allocator<std::pair<int const, alias_stack>>;
|
2021-03-24 20:33:20 +01:00
|
|
|
/* thread call stack */
|
|
|
|
ident_link *callstack{};
|
2021-03-25 01:37:13 +01:00
|
|
|
/* the shared state pointer */
|
|
|
|
internal_state *istate{};
|
|
|
|
/* the public state interface */
|
|
|
|
state *pstate{};
|
2021-03-30 00:28:06 +02:00
|
|
|
/* VM stack */
|
2021-03-24 22:37:53 +01:00
|
|
|
valbuf<any_value> vmstack;
|
2021-04-02 19:12:46 +02:00
|
|
|
/* ident stack */
|
2021-03-30 00:28:06 +02:00
|
|
|
valbuf<ident_stack> idstack;
|
2021-04-02 19:12:46 +02:00
|
|
|
/* per-alias stack pointer */
|
|
|
|
std::unordered_map<
|
|
|
|
int, alias_stack, std::hash<int>, std::equal_to<int>, astack_allocator
|
|
|
|
> astacks;
|
2021-03-24 20:33:20 +01:00
|
|
|
/* per-thread storage buffer for error messages */
|
|
|
|
charbuf errbuf;
|
|
|
|
/* we can attach a hook to vm events */
|
|
|
|
hook_func call_hook{};
|
2021-03-25 01:55:47 +01:00
|
|
|
/* whether we own the internal state (i.e. not a side thread */
|
|
|
|
bool owner = false;
|
2021-04-04 19:31:29 +02:00
|
|
|
/* thread ident flags */
|
|
|
|
int ident_flags = 0;
|
|
|
|
/* run depth limit */
|
|
|
|
std::size_t max_run_depth = 0;
|
|
|
|
/* current run depth */
|
|
|
|
std::size_t run_depth = 0;
|
|
|
|
/* loop nesting level */
|
|
|
|
std::size_t loop_level = 0;
|
2021-04-10 03:50:05 +02:00
|
|
|
/* debug info */
|
|
|
|
std::string_view source{};
|
|
|
|
std::size_t *current_line = nullptr;
|
2021-03-24 20:33:20 +01:00
|
|
|
|
2021-03-24 22:37:53 +01:00
|
|
|
thread_state(internal_state *cs);
|
2021-03-24 20:33:20 +01:00
|
|
|
|
2021-03-24 22:37:53 +01:00
|
|
|
hook_func set_hook(hook_func f);
|
2021-03-24 20:33:20 +01:00
|
|
|
|
|
|
|
hook_func &get_hook() { return call_hook; }
|
|
|
|
hook_func const &get_hook() const { return call_hook; }
|
2021-04-02 05:47:49 +02:00
|
|
|
|
|
|
|
alias_stack &get_astack(alias *a);
|
2021-04-04 01:08:30 +02:00
|
|
|
alias_stack const &get_astack(alias const *a);
|
2021-03-24 20:33:20 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} /* namespace cubescript */
|
|
|
|
|
|
|
|
#endif /* LIBCUBESCRIPT_THREAD_HH */
|