ArkScript
A small, lisp-inspired, functional scripting language
Builtins.hpp
Go to the documentation of this file.
1
/**
2
* @file Builtins.hpp
3
* @author Lexy Plateau (lexplt.dev@gmail.com)
4
* @brief Host the declaration of all the ArkScript builtins
5
* @date 2020-10-27
6
*
7
* @copyright Copyright (c) 2020-2026
8
*
9
*/
10
11
#ifndef ARK_BUILTINS_BUILTINS_HPP
12
#define ARK_BUILTINS_BUILTINS_HPP
13
14
#include <vector>
15
16
#include <
Ark/VM/Value/Value.hpp
>
17
18
namespace
Ark
19
{
20
class
VM
;
21
}
22
23
#define ARK_BUILTIN(name) Value name(std::vector<Value>& n, VM* vm)
24
25
namespace
Ark::internal::Builtins
26
{
27
extern
const
Value
falseSym
;
28
extern
const
Value
trueSym
;
29
extern
const
Value
nil
;
30
extern
const
Value
platform
;
31
extern
const
Value
version
;
32
33
ARK_API
extern
const
std::vector<std::pair<std::string, Value>>
builtins
;
34
35
// ------------------------------
36
// builtins functions: we must use the instruction `BUILTIN index`
37
// ------------------------------
38
namespace
List
39
{
40
ARK_BUILTIN
(reverseList);
41
ARK_BUILTIN
(findInList);
42
ARK_BUILTIN
(sort_);
43
ARK_BUILTIN
(fill);
44
ARK_BUILTIN
(setListAt);
45
}
46
47
namespace
IO
48
{
49
ARK_BUILTIN
(print);
50
ARK_BUILTIN
(puts_);
51
ARK_BUILTIN
(input);
52
ARK_BUILTIN
(writeFile);
53
ARK_BUILTIN
(appendToFile);
54
ARK_BUILTIN
(readFile);
55
ARK_BUILTIN
(readLinesFile);
56
ARK_BUILTIN
(fileExists);
57
ARK_BUILTIN
(listFiles);
58
ARK_BUILTIN
(isDirectory);
59
ARK_BUILTIN
(makeDir);
60
ARK_BUILTIN
(removeFile);
61
}
62
63
namespace
Time
64
{
65
ARK_BUILTIN
(timeSinceEpoch);
66
ARK_BUILTIN
(timestampToDate);
67
ARK_BUILTIN
(parseDate);
68
}
69
70
namespace
System
71
{
72
ARK_BUILTIN
(system_);
73
ARK_BUILTIN
(sleep);
74
ARK_BUILTIN
(exit_);
75
ARK_BUILTIN
(assert_);
76
}
77
78
namespace
String
79
{
80
ARK_BUILTIN
(format);
81
ARK_BUILTIN
(findSubStr);
82
ARK_BUILTIN
(removeAtStr);
83
ARK_BUILTIN
(utf8len);
84
ARK_BUILTIN
(ord);
85
ARK_BUILTIN
(chr);
86
ARK_BUILTIN
(setStringAt);
87
ARK_BUILTIN
(codepoints);
88
ARK_BUILTIN
(bytes);
89
}
90
91
namespace
Mathematics
92
{
93
ARK_BUILTIN
(exponential);
94
ARK_BUILTIN
(logarithm);
95
ARK_BUILTIN
(ceil_);
96
ARK_BUILTIN
(floor_);
97
ARK_BUILTIN
(round_);
98
ARK_BUILTIN
(isnan_);
99
ARK_BUILTIN
(isinf_);
100
101
extern
const
Value
pi_
;
102
extern
const
Value
e_
;
103
extern
const
Value
tau_
;
104
extern
const
Value
inf_
;
105
extern
const
Value
nan_
;
106
107
ARK_BUILTIN
(cos_);
108
ARK_BUILTIN
(sin_);
109
ARK_BUILTIN
(tan_);
110
ARK_BUILTIN
(acos_);
111
ARK_BUILTIN
(asin_);
112
ARK_BUILTIN
(atan_);
113
ARK_BUILTIN
(cosh_);
114
ARK_BUILTIN
(sinh_);
115
ARK_BUILTIN
(tanh_);
116
ARK_BUILTIN
(acosh_);
117
ARK_BUILTIN
(asinh_);
118
ARK_BUILTIN
(atanh_);
119
120
ARK_BUILTIN
(random);
121
122
ARK_BUILTIN
(countOnes);
123
ARK_BUILTIN
(countZeros);
124
ARK_BUILTIN
(bitwiseNot);
125
ARK_BUILTIN
(bitwiseAnd);
126
ARK_BUILTIN
(bitwiseOr);
127
ARK_BUILTIN
(bitwiseXor);
128
ARK_BUILTIN
(bitwiseRshift);
129
ARK_BUILTIN
(bitwiseLshift);
130
ARK_BUILTIN
(bitCeil);
131
ARK_BUILTIN
(bitFloor);
132
ARK_BUILTIN
(bitWidth);
133
ARK_BUILTIN
(countLeftZeros);
134
ARK_BUILTIN
(countLeftOnes);
135
ARK_BUILTIN
(countRightZeros);
136
ARK_BUILTIN
(countRightOnes);
137
}
138
139
namespace
Async
140
{
141
ARK_BUILTIN
(async);
142
ARK_BUILTIN
(await);
143
}
144
145
namespace
Dict
146
{
147
ARK_BUILTIN
(dict);
148
ARK_BUILTIN
(get);
149
ARK_BUILTIN
(add);
150
ARK_BUILTIN
(contains);
151
ARK_BUILTIN
(remove);
152
ARK_BUILTIN
(keys);
153
ARK_BUILTIN
(size);
154
}
155
156
namespace
Bytecode
157
{
158
ARK_BUILTIN
(disassemble);
159
}
160
161
ARK_BUILTIN
(slice);
162
163
namespace
Operators
164
{
165
ARK_BUILTIN
(add);
166
ARK_BUILTIN
(sub);
167
ARK_BUILTIN
(mul);
168
ARK_BUILTIN
(div);
169
ARK_BUILTIN
(mod);
170
ARK_BUILTIN
(toNumber);
171
ARK_BUILTIN
(toString);
172
ARK_BUILTIN
(lessThan);
173
ARK_BUILTIN
(lessOrEq);
174
ARK_BUILTIN
(greaterThan);
175
ARK_BUILTIN
(greaterOrEq);
176
ARK_BUILTIN
(eq);
177
ARK_BUILTIN
(notEq);
178
ARK_BUILTIN
(not_);
179
ARK_BUILTIN
(len);
180
ARK_BUILTIN
(isEmpty);
181
ARK_BUILTIN
(isNil);
182
ARK_BUILTIN
(tail);
183
ARK_BUILTIN
(head);
184
ARK_BUILTIN
(at);
185
ARK_BUILTIN
(atAt);
186
ARK_BUILTIN
(type);
187
ARK_BUILTIN
(append_list);
188
ARK_BUILTIN
(concat_list);
189
ARK_BUILTIN
(pop_list);
190
}
191
}
192
193
#undef ARK_BUILTIN
194
195
#endif
ARK_BUILTIN
#define ARK_BUILTIN(name)
Definition
Builtins.hpp:23
CallKind::List
@ List
ARK_API
#define ARK_API
Definition
Module.hpp:22
Value.hpp
Default value type handled by the virtual machine.
Ark::VM
The ArkScript virtual machine, executing ArkScript bytecode.
Definition
VM.hpp:40
Ark::Value
Definition
Value.hpp:93
Ark::internal::Dict
Definition
Dict.hpp:29
Ark::internal::Builtins::Mathematics::inf_
const Value inf_
Ark::internal::Builtins::Mathematics::nan_
const Value nan_
Ark::internal::Builtins::Mathematics::tau_
const Value tau_
Ark::internal::Builtins::Mathematics::e_
const Value e_
Ark::internal::Builtins::Mathematics::pi_
const Value pi_
Ark::internal::Builtins
Definition
Builtins.hpp:26
Ark::internal::Builtins::platform
const Value platform
Ark::internal::Builtins::nil
const Value nil
Ark::internal::Builtins::version
const Value version
Ark::internal::Builtins::falseSym
const Value falseSym
Ark::internal::Builtins::trueSym
const Value trueSym
Ark::internal::Builtins::builtins
ARK_API const std::vector< std::pair< std::string, Value > > builtins
Ark::internal::NodeType::String
@ String
Ark
Definition
Builtins.hpp:19
include
Ark
Builtins
Builtins.hpp
Generated on Sat Aug 29 2026 18:10:55 for ArkScript by
1.12.0