ArkScript
A small, fast, functional and scripting language for video games
Word.hpp
Go to the documentation of this file.
1
/**
2
* @file Word.hpp
3
* @author Alexandre Plateau (
[email protected]
)
4
* @brief Describe an instruction and its immediate argument
5
* @date 2022-07-02
6
*
7
* @copyright Copyright (c) 2022-2025
8
*
9
*/
10
11
#ifndef ARK_COMPILER_WORD_HPP
12
#define ARK_COMPILER_WORD_HPP
13
14
namespace
Ark::internal
15
{
16
struct
Word
17
{
18
uint8_t
opcode
= 0;
///< Instruction opcode
19
uint8_t
byte_1
= 0;
20
uint8_t
byte_2
= 0;
21
uint8_t
byte_3
= 0;
22
23
explicit
Word
(
const
uint8_t inst,
const
uint16_t arg = 0) :
24
opcode
(inst),
byte_2
(static_cast<uint8_t>(arg >> 8)),
byte_3
(static_cast<uint8_t>(arg & 0xff))
25
{}
26
27
/**
28
* @brief Construct a word with two arguments, each on 12 bits. It's up to the caller to ensure that no data is lost
29
* @param inst
30
* @param primary_arg argument on 12 bits, the upper 4 bits are lost
31
* @param secondary_arg 2nd argument on 12 bits, the upper 4 bits are lost
32
*/
33
Word
(
const
uint8_t inst,
const
uint16_t primary_arg,
const
uint16_t secondary_arg) :
34
opcode
(inst)
35
{
36
byte_1
=
static_cast<
uint8_t
>
((secondary_arg & 0xff0) >> 4);
37
byte_2
=
static_cast<
uint8_t
>
((secondary_arg & 0x00f) << 4 | (primary_arg & 0xf00) >> 8);
38
byte_3
=
static_cast<
uint8_t
>
(primary_arg & 0x0ff);
39
}
40
};
41
}
42
43
#endif
Ark::internal
Definition
Builtins.hpp:25
Ark::internal::Word
Definition
Word.hpp:17
Ark::internal::Word::opcode
uint8_t opcode
Instruction opcode.
Definition
Word.hpp:18
Ark::internal::Word::Word
Word(const uint8_t inst, const uint16_t primary_arg, const uint16_t secondary_arg)
Construct a word with two arguments, each on 12 bits. It's up to the caller to ensure that no data is...
Definition
Word.hpp:33
Ark::internal::Word::byte_3
uint8_t byte_3
Definition
Word.hpp:21
Ark::internal::Word::byte_1
uint8_t byte_1
Definition
Word.hpp:19
Ark::internal::Word::byte_2
uint8_t byte_2
Definition
Word.hpp:20
Ark::internal::Word::Word
Word(const uint8_t inst, const uint16_t arg=0)
Definition
Word.hpp:23
include
Ark
Compiler
IntermediateRepresentation
Word.hpp
Generated on Wed May 21 2025 18:40:52 for ArkScript by
1.12.0