diff options
author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-05-13 15:03:12 +0200 |
---|---|---|
committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-05-13 18:15:46 +0200 |
commit | c46869699aa3ae477516fba0043c2cfd8cda822a (patch) | |
tree | 2a63c9302f530a4da5ee3121eb2a545c39e0fe20 /src/tools.h | |
parent | 13f7f505375f7c1afd3a7e479a64cc147501b01d (diff) | |
download | lanes-c46869699aa3ae477516fba0043c2cfd8cda822a.tar.gz lanes-c46869699aa3ae477516fba0043c2cfd8cda822a.tar.bz2 lanes-c46869699aa3ae477516fba0043c2cfd8cda822a.zip |
Move InterCopyContext implementation in a separate file
Diffstat (limited to 'src/tools.h')
-rw-r--r-- | src/tools.h | 78 |
1 files changed, 10 insertions, 68 deletions
diff --git a/src/tools.h b/src/tools.h index 53d3a99..be76fd9 100644 --- a/src/tools.h +++ b/src/tools.h | |||
@@ -1,88 +1,30 @@ | |||
1 | #pragma once | 1 | #pragma once |
2 | 2 | ||
3 | #include "deep.h" | 3 | #include "uniquekey.h" |
4 | #include "macros_and_utils.h" | ||
5 | 4 | ||
6 | // forwards | ||
7 | class Universe; | 5 | class Universe; |
8 | 6 | ||
9 | // ################################################################################################# | 7 | enum class LookupMode |
10 | |||
11 | enum class VT | ||
12 | { | 8 | { |
13 | NORMAL, // keep this one first so that it's the value we get when we default-construct | 9 | LaneBody, // send the lane body directly from the source to the destination lane. keep this one first so that it's the value we get when we default-construct |
14 | KEY, | 10 | ToKeeper, // send a function from a lane to a keeper state |
15 | METATABLE | 11 | FromKeeper // send a function from a keeper state to a lane |
16 | }; | 12 | }; |
17 | 13 | ||
18 | enum class InterCopyResult | 14 | enum class FuncSubType |
19 | { | 15 | { |
20 | Success, | 16 | Bytecode, |
21 | NotEnoughValues, | 17 | Native, |
22 | Error | 18 | FastJIT |
23 | }; | 19 | }; |
24 | 20 | ||
25 | // ################################################################################################# | 21 | [[nodiscard]] FuncSubType luaG_getfuncsubtype(lua_State* L_, int _i); |
26 | |||
27 | using CacheIndex = Unique<int>; | ||
28 | using SourceIndex = Unique<int>; | ||
29 | class InterCopyContext | ||
30 | { | ||
31 | public: | ||
32 | Universe* const U; | ||
33 | DestState const L2; | ||
34 | SourceState const L1; | ||
35 | CacheIndex const L2_cache_i; | ||
36 | SourceIndex L1_i; // that one can change when we reuse the context | ||
37 | VT vt; // that one can change when we reuse the context | ||
38 | LookupMode const mode; | ||
39 | char const* name; // that one can change when we reuse the context | ||
40 | |||
41 | private: | ||
42 | // when mode == LookupMode::FromKeeper, L1 is a keeper state and L2 is not, therefore L2 is the state where we want to raise the error | ||
43 | // whon mode != LookupMode::FromKeeper, L1 is not a keeper state, therefore L1 is the state where we want to raise the error | ||
44 | lua_State* getErrL() const { return (mode == LookupMode::FromKeeper) ? L2 : L1; } | ||
45 | |||
46 | // for use in copy_cached_func | ||
47 | void copy_func() const; | ||
48 | void lookup_native_func() const; | ||
49 | |||
50 | // for use in inter_copy_function | ||
51 | void copy_cached_func() const; | ||
52 | [[nodiscard]] bool lookup_table() const; | ||
53 | |||
54 | // for use in inter_copy_table | ||
55 | void inter_copy_keyvaluepair() const; | ||
56 | [[nodiscard]] bool push_cached_metatable() const; | ||
57 | [[nodiscard]] bool push_cached_table() const; | ||
58 | |||
59 | // for use in inter_copy_userdata | ||
60 | [[nodiscard]] bool tryCopyClonable() const; | ||
61 | [[nodiscard]] bool tryCopyDeep() const; | ||
62 | |||
63 | // copying a single Lua stack item | ||
64 | [[nodiscard]] bool inter_copy_boolean() const; | ||
65 | [[nodiscard]] bool inter_copy_function() const; | ||
66 | [[nodiscard]] bool inter_copy_lightuserdata() const; | ||
67 | [[nodiscard]] bool inter_copy_nil() const; | ||
68 | [[nodiscard]] bool inter_copy_number() const; | ||
69 | [[nodiscard]] bool inter_copy_string() const; | ||
70 | [[nodiscard]] bool inter_copy_table() const; | ||
71 | [[nodiscard]] bool inter_copy_userdata() const; | ||
72 | |||
73 | public: | ||
74 | [[nodiscard]] bool inter_copy_one() const; | ||
75 | [[nodiscard]] InterCopyResult inter_copy_package() const; | ||
76 | [[nodiscard]] InterCopyResult inter_copy(int n_) const; | ||
77 | [[nodiscard]] InterCopyResult inter_move(int n_) const; | ||
78 | }; | ||
79 | 22 | ||
80 | // ################################################################################################# | 23 | // ################################################################################################# |
81 | 24 | ||
82 | [[nodiscard]] int luaG_nameof(lua_State* L_); | 25 | [[nodiscard]] int luaG_nameof(lua_State* L_); |
83 | 26 | ||
84 | void populate_func_lookup_table(lua_State* L_, int i_, char const* name_); | 27 | void populate_func_lookup_table(lua_State* L_, int i_, char const* name_); |
85 | void initialize_allocator_function(Universe* U_, lua_State* L_); | ||
86 | 28 | ||
87 | // ################################################################################################# | 29 | // ################################################################################################# |
88 | 30 | ||