ArkScript
A small, lisp-inspired, functional scripting language
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 entity = Entity(Kind::Label);
23 entity.m_label = value;
24
25 return entity;
26 }
27
28 Entity Entity::Goto(const Entity& label, const Instruction inst)
29 {
30 auto jump = Entity(Kind::Goto);
31 jump.m_label = label.m_label;
32 jump.m_inst = inst;
33
34 return jump;
35 }
36
37 Entity Entity::GotoWithArg(const Entity& label, const Instruction inst, const uint16_t primary_arg)
38 {
39 auto jump = Entity(Kind::GotoWithArg);
40 jump.m_label = label.m_label;
41 jump.m_inst = inst;
42 jump.m_primary_arg = primary_arg;
43
44 return jump;
45 }
46
47 Entity Entity::GotoIf(const Entity& label, const bool cond)
48 {
50 }
51
53 {
54 if (m_kind == Kind::Opcode)
55 return Word(m_inst, m_primary_arg);
58 return Word(0, 0);
59 }
60
61 void Entity::setSourceLocation(const std::string& filename, std::size_t line)
62 {
64 m_source_line = line;
65 }
66}
An entity in the IR is a bundle of information.
static Entity Goto(const Entity &label, Instruction inst=Instruction::JUMP)
Definition Entity.cpp:28
static Entity Label(label_t value)
Definition Entity.cpp:20
label_t label() const
Definition Entity.hpp:56
Instruction inst() const
Definition Entity.hpp:60
static Entity GotoIf(const Entity &label, bool cond)
Definition Entity.cpp:47
static Entity GotoWithArg(const Entity &label, Instruction inst, uint16_t primary_arg)
Definition Entity.cpp:37
std::size_t m_source_line
Definition Entity.hpp:81
void setSourceLocation(const std::string &filename, std::size_t line)
Definition Entity.cpp:61
Word bytecode() const
Definition Entity.cpp:52
const std::string & filename() const
Definition Entity.hpp:70
std::string m_source_file
Definition Entity.hpp:80
std::size_t label_t
Definition Entity.hpp:32
Instruction
The different bytecodes are stored here.