ArkScript
A small, fast, functional and scripting language for video games
Common.hpp
Go to the documentation of this file.
1 /**
2  * @file Common.hpp
3  * @author Alexandre Plateau (lexplt.dev@gmail.com)
4  * @brief Common code for the compiler
5  * @version 0.3
6  * @date 2021-10-02
7  *
8  * @copyright Copyright (c) 2021
9  *
10  */
11 
12 #ifndef ARK_COMPILER_COMMON_HPP
13 #define ARK_COMPILER_COMMON_HPP
14 
15 #include <array>
16 #include <string_view>
17 #include <vector>
18 #include <cinttypes>
19 
20 namespace Ark
21 {
22  using bytecode_t = std::vector<uint8_t>;
23 }
24 
25 namespace Ark::internal
26 {
27  /// The different node types available
28  enum class NodeType
29  {
30  Symbol,
31  Capture,
32  GetField,
33  Keyword,
34  String,
35  Number,
36  List,
37  Closure,
38  Macro,
39  Spread,
40  Unused
41  };
42 
43  constexpr std::array<std::string_view, 11> nodeTypes = {
44  "Symbol",
45  "Capture",
46  "GetField",
47  "Keyword",
48  "String",
49  "Number",
50  "List",
51  "Closure",
52  "Macro",
53  "Spread",
54  "Unused"
55  };
56 
57  /// The different keywords available
58  enum class Keyword
59  {
60  Fun,
61  Let,
62  Mut,
63  Set,
64  If,
65  While,
66  Begin,
67  Import,
68  Quote,
69  Del
70  };
71 
72  /// List of available keywords in ArkScript
73  constexpr std::array<std::string_view, 10> keywords = {
74  "fun",
75  "let",
76  "mut",
77  "set",
78  "if",
79  "while",
80  "begin",
81  "import",
82  "quote",
83  "del"
84  };
85 
86  // This list is related to include/Ark/Compiler/Instructions.hpp
87  // from FIRST_OPERATOR, to LAST_OPERATOR
88  // The order is very important
89  constexpr std::array<std::string_view, 25> operators = {
90  "+", "-", "*", "/",
91  ">", "<", "<=", ">=", "!=", "=",
92  "len", "empty?", "tail", "head",
93  "nil?", "assert",
94  "toNumber", "toString",
95  "@", "and", "or", "mod",
96  "type", "hasField",
97  "not"
98  };
99 }
100 
101 #endif
constexpr std::array< std::string_view, 11 > nodeTypes
Definition: Common.hpp:43
NodeType
The different node types available.
Definition: Common.hpp:29
constexpr std::array< std::string_view, 25 > operators
Definition: Common.hpp:89
Keyword
The different keywords available.
Definition: Common.hpp:59
constexpr std::array< std::string_view, 10 > keywords
List of available keywords in ArkScript.
Definition: Common.hpp:73
Definition: Builtins.hpp:21
std::vector< uint8_t > bytecode_t
Definition: Common.hpp:22