Line | Branch | Exec | Source |
---|---|---|---|
1 | #pragma once | ||
2 | #include "script.h" | ||
3 | #include <map> | ||
4 | |||
5 | namespace script | ||
6 | { | ||
7 | |||
8 | struct language_token | ||
9 | { | ||
10 | command ID; | ||
11 | bool has_operand; | ||
12 | std::string token; | ||
13 | char byte_code; | ||
14 | }; | ||
15 | |||
16 | static const std::vector<language_token> language_tokens = { | ||
17 | |||
18 | {command::TEXT, true, "text", 0}, | ||
19 | {command::PROCESS, false, "process", 1}, | ||
20 | {command::PRINT, false, "print", 2}, | ||
21 | {command::LOAD, true, "load", 3}, | ||
22 | {command::SAVE, true, "save", 4}}; | ||
23 | |||
24 | 136 | inline bool get_from_token(const std::string& token, language_token& res) | |
25 | { | ||
26 |
2/2✓ Branch 5 taken 327 times.
✓ Branch 6 taken 2 times.
|
329 | for (const auto& t : language_tokens) |
27 |
2/2✓ Branch 1 taken 134 times.
✓ Branch 2 taken 193 times.
|
327 | if (t.token == token) |
28 | { | ||
29 |
1/2✓ Branch 1 taken 134 times.
✗ Branch 2 not taken.
|
134 | res = t; |
30 | 134 | return true; | |
31 | } | ||
32 | |||
33 | 2 | return false; | |
34 | } | ||
35 | |||
36 | 12 | inline bool get_from_ID(command ID, language_token& res) | |
37 | { | ||
38 |
1/2✓ Branch 5 taken 24 times.
✗ Branch 6 not taken.
|
24 | for (const auto& t : language_tokens) |
39 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 12 times.
|
24 | if (t.ID == ID) |
40 | { | ||
41 |
1/2✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
|
12 | res = t; |
42 | 12 | return true; | |
43 | } | ||
44 | |||
45 | ✗ | return false; | |
46 | } | ||
47 | |||
48 | 9 | inline bool get_from_byte_code(char byte_code, language_token& res) | |
49 | { | ||
50 |
1/2✓ Branch 5 taken 18 times.
✗ Branch 6 not taken.
|
18 | for (const auto& t : language_tokens) |
51 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
|
18 | if (t.byte_code == byte_code) |
52 | { | ||
53 |
1/2✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
|
9 | res = t; |
54 | 9 | return true; | |
55 | } | ||
56 | |||
57 | ✗ | return false; | |
58 | } | ||
59 | |||
60 | static const std::vector<char> secret_key = { | ||
61 | static_cast<char>(0x6c), static_cast<char>(0x24), static_cast<char>(0x05), | ||
62 | static_cast<char>(0x67), static_cast<char>(0x0f), static_cast<char>(0xd8), | ||
63 | static_cast<char>(0x21), static_cast<char>(0xb1), static_cast<char>(0xf1), | ||
64 | static_cast<char>(0x0a), static_cast<char>(0x14), static_cast<char>(0x53), | ||
65 | static_cast<char>(0xe3), static_cast<char>(0x44), static_cast<char>(0x11), | ||
66 | static_cast<char>(0x87)}; | ||
67 | |||
68 | |||
69 | struct vector_hash | ||
70 | { | ||
71 | 5 | std::size_t operator()(const std::vector<char>& v) const | |
72 | { | ||
73 | std::hash<char> hasher; | ||
74 | 5 | std::size_t seed = 0; | |
75 |
2/2✓ Branch 4 taken 405 times.
✓ Branch 5 taken 5 times.
|
410 | for (char i : v) |
76 | { | ||
77 | 405 | seed ^= hasher(i) + 0x9e3779b9 + (seed << 6) + (seed >> 2); | |
78 | } | ||
79 | 5 | return seed; | |
80 | } | ||
81 | }; | ||
82 | |||
83 | } // namespace script | ||
84 |