ArkScript
A small, lisp-inspired, functional scripting language
Entity.cpp
Go to the documentation of this file.
1
#include <
Ark/Compiler/IntermediateRepresentation/Entity.hpp
>
2
3
namespace
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
20
Entity::Entity
(
const
Instruction
inst,
const
uint8_t inst2,
const
uint8_t inst3,
const
uint8_t inst4) :
21
m_kind(
Kind
::
Opcode3Args
),
22
m_inst(inst), m_primary_arg(inst2), m_secondary_arg(inst3), m_tertiary_arg(inst4)
23
{}
24
25
Entity
Entity::Label
(
const
label_t
value)
26
{
27
auto
entity =
Entity
(
Kind::Label
);
28
entity.m_label = value;
29
30
return
entity;
31
}
32
33
Entity
Entity::Goto
(
const
Entity
& label,
const
Instruction
inst)
34
{
35
auto
jump =
Entity
(
Kind::Goto
);
36
jump.m_label =
label
.m_label;
37
jump.m_inst =
inst
;
38
39
return
jump;
40
}
41
42
Entity
Entity::GotoWithArg
(
const
Entity
& label,
const
Instruction
inst,
const
uint16_t primary_arg)
43
{
44
auto
jump =
Entity
(
Kind::GotoWithArg
);
45
jump.m_label =
label
.m_label;
46
jump.m_inst =
inst
;
47
jump.m_primary_arg = primary_arg;
48
49
return
jump;
50
}
51
52
Entity
Entity::GotoIf
(
const
Entity
& label,
const
bool
cond)
53
{
54
return
Goto
(
label
, cond ?
POP_JUMP_IF_TRUE
:
POP_JUMP_IF_FALSE
);
55
}
56
57
Word
Entity::bytecode
()
const
58
{
59
if
(
m_kind
==
Kind::Opcode
)
60
return
Word
(
m_inst
,
m_primary_arg
);
61
if
(
m_kind
==
Kind::Opcode2Args
)
62
return
Word
(
m_inst
,
m_primary_arg
,
m_secondary_arg
);
63
if
(
m_kind
==
Kind::Opcode3Args
)
64
return
Word
(
65
m_inst
,
66
static_cast<
uint8_t
>
(
m_primary_arg
),
67
static_cast<
uint8_t
>
(
m_secondary_arg
),
68
static_cast<
uint8_t
>
(
m_tertiary_arg
));
69
return
Word
(0, 0);
70
}
71
72
void
Entity::setSourceLocation
(
const
std::string& filename, std::size_t line)
73
{
74
m_source_file
=
filename
;
75
m_source_line
= line;
76
}
77
}
Entity.hpp
An entity in the IR is a bundle of information.
Ark::internal::IR::Entity
Definition
Entity.hpp:41
Ark::internal::IR::Entity::m_tertiary_arg
uint16_t m_tertiary_arg
Definition
Entity.hpp:87
Ark::internal::IR::Entity::m_kind
Kind m_kind
Definition
Entity.hpp:82
Ark::internal::IR::Entity::Goto
static Entity Goto(const Entity &label, Instruction inst=Instruction::JUMP)
Definition
Entity.cpp:33
Ark::internal::IR::Entity::Label
static Entity Label(label_t value)
Definition
Entity.cpp:25
Ark::internal::IR::Entity::m_primary_arg
uint16_t m_primary_arg
Definition
Entity.hpp:85
Ark::internal::IR::Entity::label
label_t label() const
Definition
Entity.hpp:61
Ark::internal::IR::Entity::m_secondary_arg
uint16_t m_secondary_arg
Definition
Entity.hpp:86
Ark::internal::IR::Entity::Entity
Entity(Kind kind)
Definition
Entity.cpp:5
Ark::internal::IR::Entity::inst
Instruction inst() const
Definition
Entity.hpp:65
Ark::internal::IR::Entity::GotoIf
static Entity GotoIf(const Entity &label, bool cond)
Definition
Entity.cpp:52
Ark::internal::IR::Entity::GotoWithArg
static Entity GotoWithArg(const Entity &label, Instruction inst, uint16_t primary_arg)
Definition
Entity.cpp:42
Ark::internal::IR::Entity::m_source_line
std::size_t m_source_line
Definition
Entity.hpp:89
Ark::internal::IR::Entity::setSourceLocation
void setSourceLocation(const std::string &filename, std::size_t line)
Definition
Entity.cpp:72
Ark::internal::IR::Entity::bytecode
Word bytecode() const
Definition
Entity.cpp:57
Ark::internal::IR::Entity::m_inst
Instruction m_inst
Definition
Entity.hpp:84
Ark::internal::IR::Entity::filename
const std::string & filename() const
Definition
Entity.hpp:77
Ark::internal::IR::Entity::m_source_file
std::string m_source_file
Definition
Entity.hpp:88
Ark::internal::IR
Definition
Entity.hpp:22
Ark::internal::IR::Kind
Kind
Definition
Entity.hpp:24
Ark::internal::IR::Kind::GotoWithArg
@ GotoWithArg
Ark::internal::IR::Kind::Opcode
@ Opcode
Ark::internal::IR::Kind::Goto
@ Goto
Ark::internal::IR::Kind::Label
@ Label
Ark::internal::IR::Kind::Opcode3Args
@ Opcode3Args
Ark::internal::IR::Kind::Opcode2Args
@ Opcode2Args
Ark::internal::IR::label_t
std::size_t label_t
Definition
Entity.hpp:33
Ark::internal::Instruction
Instruction
The different bytecodes are stored here.
Definition
Instructions.hpp:27
Ark::internal::POP_JUMP_IF_FALSE
@ POP_JUMP_IF_FALSE
Definition
Instructions.hpp:69
Ark::internal::NOP
@ NOP
Definition
Instructions.hpp:29
Ark::internal::POP_JUMP_IF_TRUE
@ POP_JUMP_IF_TRUE
Definition
Instructions.hpp:53
Ark::internal::Word
Definition
Word.hpp:19
src
arkreactor
Compiler
IntermediateRepresentation
Entity.cpp
Generated on Sat Jan 3 2026 17:22:02 for ArkScript by
1.12.0