2021-03-24 19:33:20 +00: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-29 22:31:11 +00:00
|
|
|
#include "cs_ident.hh"
|
2021-03-24 19:33:20 +00:00
|
|
|
|
|
|
|
namespace cubescript {
|
|
|
|
|
2021-04-08 21:33:00 +00:00
|
|
|
struct parser_state;
|
2021-03-24 19:33:20 +00:00
|
|
|
|
|
|
|
struct thread_state {
|
2021-04-02 17:12:46 +00:00
|
|
|
using astack_allocator = std_allocator<std::pair<int const, alias_stack>>;
|
2021-03-24 19:33:20 +00:00
|
|
|
/* thread call stack */
|
|
|
|
ident_link *callstack{};
|
2021-03-25 00:37:13 +00:00
|
|
|
/* the shared state pointer */
|
|
|
|
internal_state *istate{};
|
|
|
|
/* the public state interface */
|
|
|
|
state *pstate{};
|
2021-03-24 19:33:20 +00:00
|
|
|
/* current codegen state for diagnostics */
|
2021-04-08 21:33:00 +00:00
|
|
|
parser_state *cstate{};
|
2021-03-29 22:28:06 +00:00
|
|
|
/* VM stack */
|
2021-03-24 21:37:53 +00:00
|
|
|
valbuf<any_value> vmstack;
|
2021-04-02 17:12:46 +00:00
|
|
|
/* ident stack */
|
2021-03-29 22:28:06 +00:00
|
|
|
valbuf<ident_stack> idstack;
|
2021-04-02 17:12:46 +00:00
|
|
|
/* per-alias stack pointer */
|
|
|
|
std::unordered_map<
|
|
|
|
int, alias_stack, std::hash<int>, std::equal_to<int>, astack_allocator
|
|
|
|
> astacks;
|
2021-03-24 19:33:20 +00: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 00:55:47 +00:00
|
|
|
/* whether we own the internal state (i.e. not a side thread */
|
|
|
|
bool owner = false;
|
2021-04-04 17:31:29 +00: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-03-24 19:33:20 +00:00
|
|
|
|
2021-03-24 21:37:53 +00:00
|
|
|
thread_state(internal_state *cs);
|
2021-03-24 19:33:20 +00:00
|
|
|
|
2021-03-24 21:37:53 +00:00
|
|
|
hook_func set_hook(hook_func f);
|
2021-03-24 19:33:20 +00:00
|
|
|
|
|
|
|
hook_func &get_hook() { return call_hook; }
|
|
|
|
hook_func const &get_hook() const { return call_hook; }
|
2021-04-02 03:47:49 +00:00
|
|
|
|
|
|
|
alias_stack &get_astack(alias *a);
|
2021-04-03 23:08:30 +00:00
|
|
|
alias_stack const &get_astack(alias const *a);
|
2021-03-24 19:33:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} /* namespace cubescript */
|
|
|
|
|
|
|
|
#endif /* LIBCUBESCRIPT_THREAD_HH */
|