-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathProgram.hpp
More file actions
97 lines (75 loc) · 2.09 KB
/
Copy pathProgram.hpp
File metadata and controls
97 lines (75 loc) · 2.09 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
#pragma once
#include "common.hpp"
#include "forward.hpp"
#include "memory/GarbageCollector.hpp"
#include "runtime/forward.hpp"
#include "utilities.hpp"
#include <bitset>
class Function;
class VirtualMachine;
class CodeFlags
{
public:
enum class Flag {
OPTIMIZED = 0,
NEWLOCALS = 1,
VARARGS = 2,
VARKEYWORDS = 3,
NESTED = 4,
GENERATOR = 5,
COROUTINE = 6,
CLASS = 7,
};
private:
std::bitset<8> m_flags;
CodeFlags() = default;
public:
template<typename... Args>
// requires std::conjunction_v<std::is_same<Flag, Args>...>
static CodeFlags create(Args... args)
{
CodeFlags f;
(f.m_flags.set(static_cast<uint8_t>(args)), ...);
return f;
}
static CodeFlags from_byte(uint8_t b)
{
auto f = CodeFlags();
f.m_flags = std::bitset<8>(b);
return f;
}
void set(Flag f) { m_flags.set(static_cast<uint8_t>(f)); }
void reset(Flag f) { m_flags.reset(static_cast<uint8_t>(f)); }
bool is_set(Flag f) const { return m_flags[static_cast<uint8_t>(f)]; }
std::bitset<8> bits() const { return m_flags; }
};
class Program
: NonCopyable
, public std::enable_shared_from_this<Program>
{
std::string m_filename;
std::vector<std::string> m_argv;
protected:
Program() {}
public:
Program(std::string &&filename, std::vector<std::string> &&argv);
virtual ~Program() {}
virtual int execute(VirtualMachine *) = 0;
const std::string &filename() const { return m_filename; }
const std::vector<std::string> &argv() const { return m_argv; }
void set_filename(std::string filename) { m_filename = std::move(filename); }
virtual std::string to_string() const = 0;
virtual py::PyObject *as_pyfunction(const std::string &function_name,
const std::vector<py::Value> &default_values,
const std::vector<py::Value> &kw_default_values,
py::PyTuple *closure) const = 0;
virtual py::PyObject *main_function() = 0;
virtual void visit_functions(Cell::Visitor &) const = 0;
virtual std::vector<uint8_t> serialize() const = 0;
};
namespace compiler {
std::shared_ptr<Program> compile(std::shared_ptr<ast::Module> node,
std::vector<std::string> argv,
Backend backend,
OptimizationLevel lvl);
}