-
Notifications
You must be signed in to change notification settings - Fork 43
/
bytecode_compiler.hpp
85 lines (71 loc) · 2.15 KB
/
bytecode_compiler.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#ifndef __SDK_BYTECODE_COMPILER_HPP__
#define __SDK_BYTECODE_COMPILER_HPP__
/**
* @brief A factory class for creating bytecode compilers.
*/
#include <BytecodeCompileRecipe.hpp>
#include <memory>
#include <string>
#include <vector>
namespace VMPilot::SDK::BytecodeCompiler {
// Defined the base class for a bytecode compiler.
class CompilerBase {
std::string name;
public:
/**
* @brief Compile a script into bytecode.
*
* @param script The script to compile.
* @return std::vector<uint8_t> The compiled bytecode.
*/
virtual std::vector<uint8_t> Compile(const BytecodeCompileRecipe& script) = 0;
/**
* @brief Get the name of the compiler.
* This is used to identify the compiler in the configuration file.
*/
inline std::string GetName() const noexcept { return name; }
/**
* @brief Construct a new Compiler Base object
*
* @param name The name of the compiler.
*/
CompilerBase(std::string name) : name(name) {}
/**
* @brief Destroy the Compiler Base object
*/
virtual ~CompilerBase() = default;
};
// Define the factory class for creating bytecode compilers.
class CompilerFactory {
public:
/**
* @brief Create a new compiler.
*
* @param name The name of the compiler to create.
* @return std::unique_ptr<CompilerBase> The created compiler.
*/
static std::unique_ptr<CompilerBase> CreateCompiler(
const std::string& name) noexcept;
};
class _NotImplementedYet : public CompilerBase {
public:
/**
* @brief Compile a script into bytecode.
*
* @param script The script to compile.
* @return std::vector<uint8_t> The compiled bytecode.
*/
std::vector<uint8_t> Compile(const BytecodeCompileRecipe& script) override;
/**
* @brief Construct a new _NotImplementedYet object
*/
_NotImplementedYet() : CompilerBase("not_implemented") {}
/**
* @brief Construct a new _NotImplementedYet object
*
* @param name The name of the compiler.
*/
_NotImplementedYet(std::string name) : CompilerBase(name) {}
};
} // namespace VMPilot::SDK::BytecodeCompiler
#endif