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 ([email protected])
4 * @brief Common code for the compiler
5 * @version 0.5
6 * @date 2021-10-02
7 *
8 * @copyright Copyright (c) 2021-2024
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
20namespace Ark
21{
22 using bytecode_t = std::vector<uint8_t>;
23}
24
25namespace Ark::internal
26{
27 /// The different node types available
28 enum class NodeType
29 {
30 Symbol,
31 Capture,
32 Keyword,
33 String,
34 Number,
35 List,
36 Spread,
37 Field,
38 Macro,
40 Unused
41 };
42
43 /// Node types as string, in the same order as the enum NodeType
44 constexpr std::array<std::string_view, 11> nodeTypes = {
45 "Symbol",
46 "Capture",
47 "Keyword",
48 "String",
49 "Number",
50 "List",
51 "Spread",
52 "Field",
53 "Macro",
54 "Namespace",
55 "Unused"
56 };
57
58 /// The different keywords available
59 enum class Keyword
60 {
61 Fun,
62 Let,
63 Mut,
64 Set,
65 If,
66 While,
67 Begin,
68 Import,
69 Del
70 };
71
72 /// List of available keywords in ArkScript
73 constexpr std::array<std::string_view, 9> keywords = {
74 "fun",
75 "let",
76 "mut",
77 "set",
78 "if",
79 "while",
80 "begin",
81 "import",
82 "del"
83 };
84
85 namespace Language
86 {
87 constexpr std::string_view AppendInPlace = "append!";
88 constexpr std::string_view ConcatInPlace = "concat!";
89 constexpr std::string_view PopInPlace = "pop!";
90 constexpr std::string_view SetAtInPlace = "@=";
91 constexpr std::string_view SetAt2InPlace = "@@=";
92 /// All the builtins that modify in place a variable
97
98 // This list is related to include/Ark/Compiler/Instructions.hpp
99 // The order is very important
100 constexpr std::array<std::string_view, 9> listInstructions = {
101 "list",
102 "append",
103 "concat",
106 "pop",
110 };
111
112 constexpr std::string_view SysArgs = "sys:args";
113 constexpr std::string_view SysPlatform = "sys:platform";
114
115 constexpr std::string_view And = "and";
116 constexpr std::string_view Or = "or";
117
118 constexpr std::string_view Undef = "$undef";
119 constexpr std::string_view Symcat = "$symcat";
120 constexpr std::string_view Argcount = "$argcount";
121 constexpr std::string_view Repr = "$repr";
122 constexpr std::string_view Paste = "$paste";
123
124 constexpr std::array macros = {
125 Undef,
126 Symcat,
127 Argcount,
128 Repr,
129 Paste
130 };
131
132 // This list is related to include/Ark/Compiler/Instructions.hpp
133 // from FIRST_OPERATOR, to LAST_OPERATOR
134 // The order is very important
135 constexpr std::array<std::string_view, 24> operators = {
136 "+", "-", "*", "/",
137 ">", "<", "<=", ">=", "!=", "=",
138 "len", "empty?", "tail", "head",
139 "nil?", "assert",
140 "toNumber", "toString",
141 "@", "@@", "mod",
142 "type", "hasField",
143 "not"
144 };
145 }
146}
147
148#endif
constexpr std::array< std::string_view, 9 > listInstructions
Definition Common.hpp:100
constexpr std::string_view AppendInPlace
Definition Common.hpp:87
constexpr std::string_view Argcount
Definition Common.hpp:120
constexpr std::array< std::string_view, 24 > operators
Definition Common.hpp:135
constexpr std::string_view ConcatInPlace
Definition Common.hpp:88
constexpr std::string_view SysPlatform
Definition Common.hpp:113
constexpr std::string_view PopInPlace
Definition Common.hpp:89
constexpr std::array macros
Definition Common.hpp:124
constexpr std::string_view Paste
Definition Common.hpp:122
constexpr std::string_view SetAt2InPlace
Definition Common.hpp:91
constexpr std::string_view SysArgs
Definition Common.hpp:112
constexpr std::string_view And
Definition Common.hpp:115
constexpr std::string_view Repr
Definition Common.hpp:121
constexpr std::array UpdateRef
All the builtins that modify in place a variable.
Definition Common.hpp:93
constexpr std::string_view Or
Definition Common.hpp:116
constexpr std::string_view Symcat
Definition Common.hpp:119
constexpr std::string_view Undef
Definition Common.hpp:118
constexpr std::string_view SetAtInPlace
Definition Common.hpp:90
constexpr std::array< std::string_view, 11 > nodeTypes
Node types as string, in the same order as the enum NodeType.
Definition Common.hpp:44
NodeType
The different node types available.
Definition Common.hpp:29
Keyword
The different keywords available.
Definition Common.hpp:60
constexpr std::array< std::string_view, 9 > keywords
List of available keywords in ArkScript.
Definition Common.hpp:73
std::vector< uint8_t > bytecode_t
Definition Common.hpp:22