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
* @version 1.0
6
* @date 2022-07-02
7
*
8
* @copyright Copyright (c) 2022-2024
9
*
10
*/
11
12
#ifndef ARK_COMPILER_WORD_HPP
13
#define ARK_COMPILER_WORD_HPP
14
15
namespace
Ark::internal
16
{
17
struct
Word
18
{
19
uint8_t
opcode
= 0;
///< Instruction opcode
20
uint8_t
byte_1
= 0;
21
uint8_t
byte_2
= 0;
22
uint8_t
byte_3
= 0;
23
24
explicit
Word
(
const
uint8_t inst,
const
uint16_t arg = 0) :
25
opcode
(inst),
byte_2
(static_cast<uint8_t>(arg >> 8)),
byte_3
(static_cast<uint8_t>(arg & 0xff))
26
{}
27
28
/**
29
* @brief Construct a word with two arguments, each on 12 bits. It's up to the caller to ensure that no data is lost
30
* @param inst
31
* @param primary_arg argument on 12 bits, the upper 4 bits are lost
32
* @param secondary_arg 2nd argument on 12 bits, the upper 4 bits are lost
33
*/
34
Word
(
const
uint8_t inst,
const
uint16_t primary_arg,
const
uint16_t secondary_arg) :
35
opcode
(inst)
36
{
37
byte_1
=
static_cast<
uint8_t
>
((secondary_arg & 0xff0) >> 4);
38
byte_2
=
static_cast<
uint8_t
>
((secondary_arg & 0x00f) << 4 | (primary_arg & 0xf00) >> 8);
39
byte_3
=
static_cast<
uint8_t
>
(primary_arg & 0x0ff);
40
}
41
};
42
}
43
44
#endif
Ark::internal
Definition
Builtins.hpp:26
Ark::internal::Word
Definition
Word.hpp:18
Ark::internal::Word::opcode
uint8_t opcode
Instruction opcode.
Definition
Word.hpp:19
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:34
Ark::internal::Word::byte_3
uint8_t byte_3
Definition
Word.hpp:22
Ark::internal::Word::byte_1
uint8_t byte_1
Definition
Word.hpp:20
Ark::internal::Word::byte_2
uint8_t byte_2
Definition
Word.hpp:21
Ark::internal::Word::Word
Word(const uint8_t inst, const uint16_t arg=0)
Definition
Word.hpp:24
include
Ark
Compiler
Word.hpp
Generated on Wed Jan 15 2025 19:51:44 for ArkScript by
1.12.0