#ifndef LIBCUBESCRIPT_THREAD_HH #define LIBCUBESCRIPT_THREAD_HH #include #include #include "cs_std.hh" #include "cs_state.hh" #include "cs_ident.hh" namespace cubescript { struct ident_level { ident &id; argset usedargs{}; ident_level(ident &i): id{i} {}; }; struct thread_state { using astack_allocator = std_allocator>; /* the shared state pointer */ internal_state *istate{}; /* the public state interface */ state *pstate{}; /* VM stack */ valbuf vmstack; /* ident stack */ valbuf idstack; /* call stack */ valbuf callstack; /* per-alias stack pointer */ std::unordered_map< int, alias_stack, std::hash, std::equal_to, 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 = 1024; /* 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); char *request_errbuf(std::size_t bufs, char *&sp); }; } /* namespace cubescript */ #endif /* LIBCUBESCRIPT_THREAD_HH */