An embeddable, thread-safe implementation of the cubescript language
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

60 lines
1.6 KiB

#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 thread_state {
using astack_allocator = std_allocator<std::pair<int const, alias_stack>>;
/* thread call stack */
ident_link *callstack{};
/* 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;
/* 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{};
/* whether we own the internal state (i.e. not a side thread */
bool owner = false;
/* thread ident flags */
int ident_flags = 0;
/* call depth limit */
std::size_t max_call_depth = 0;
/* current call depth */
std::size_t call_depth = 0;
/* loop nesting level */
std::size_t loop_level = 0;
/* 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; }
alias_stack &get_astack(alias const *a);
};
} /* namespace cubescript */
#endif /* LIBCUBESCRIPT_THREAD_HH */