libcubescript/src/cs_thread.hh

70 lines
1.7 KiB
C++
Raw Permalink Normal View History

#ifndef LIBCUBESCRIPT_THREAD_HH
#define LIBCUBESCRIPT_THREAD_HH
#include <cubescript/cubescript.hh>
#include <utility>
#include "cs_std.hh"
#include "cs_state.hh"
#include "cs_ident.hh"
namespace cubescript {
struct ident_level {
ident &id;
2021-05-14 23:31:27 +02:00
argset usedargs{};
ident_level(ident &i): id{i} {};
};
struct thread_state {
using astack_allocator = std_allocator<std::pair<int const, alias_stack>>;
/* the shared state pointer */
internal_state *istate{};
/* the public state interface */
state *pstate{};
/* VM stack */
valbuf<any_value> vmstack;
/* ident stack */
valbuf<ident_stack> idstack;
/* call stack */
valbuf<ident_level> callstack;
/* per-alias stack pointer */
std::unordered_map<
int, alias_stack, std::hash<int>, std::equal_to<int>, astack_allocator
> astacks;
/* 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;
/* thread ident flags */
int ident_flags = 0;
2021-04-30 02:55:20 +02:00
/* call depth limit */
2021-05-08 21:41:13 +02:00
std::size_t max_call_depth = 1024;
2021-04-30 02:55:20 +02:00
/* current call depth */
std::size_t call_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;
thread_state(internal_state *cs);
hook_func set_hook(hook_func f);
hook_func &get_hook() { return call_hook; }
hook_func const &get_hook() const { return call_hook; }
2021-05-02 22:44:38 +02:00
alias_stack &get_astack(alias const *a);
char *request_errbuf(std::size_t bufs, char *&sp);
};
} /* namespace cubescript */
#endif /* LIBCUBESCRIPT_THREAD_HH */