ArkScript
A small, fast, functional and scripting language for video games
Entity.cpp
Go to the documentation of this file.
2
3namespace Ark::internal::IR
4{
5 Entity::Entity(const Kind kind) :
6 m_kind(kind),
7 m_inst(NOP)
8 {}
9
10 Entity::Entity(const Instruction inst, const uint16_t arg) :
11 m_kind(Kind::Opcode),
12 m_inst(inst), m_primary_arg(arg)
13 {}
14
15 Entity::Entity(const Instruction inst, const uint16_t primary_arg, const uint16_t secondary_arg) :
16 m_kind(Kind::Opcode2Args),
17 m_inst(inst), m_primary_arg(primary_arg), m_secondary_arg(secondary_arg)
18 {}
19
21 {
22 auto label = Entity(Kind::Label);
23 label.m_label = value;
24
25 return label;
26 }
27
29 {
30 auto jump = Entity(Kind::Goto);
31 jump.m_label = label.m_label;
32
33 return jump;
34 }
35
36 Entity Entity::GotoIf(const Entity& label, const bool cond)
37 {
38 auto jump = Entity(cond ? Kind::GotoIfTrue : Kind::GotoIfFalse);
39 jump.m_label = label.m_label;
40
41 return jump;
42 }
43
45 {
46 if (m_kind == Kind::Opcode)
47 return Word(m_inst, m_primary_arg);
50 return Word(0, 0);
51 }
52}
An entity in the IR is a bundle of information.
static Entity Label(label_t value)
Definition Entity.cpp:20
label_t label() const
Definition Entity.hpp:55
static Entity GotoIf(const Entity &label, bool cond)
Definition Entity.cpp:36
static Entity Goto(const Entity &label)
Definition Entity.cpp:28
Word bytecode() const
Definition Entity.cpp:44
std::size_t label_t
Definition Entity.hpp:33
Instruction
The different bytecodes are stored here.