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
17
18namespace Ark
19{
20 class VM;
21}
22
23#define ARK_BUILTIN(name) Value name(std::vector<Value>& n, VM* vm)
24
26{
27 extern const Value falseSym;
28 extern const Value trueSym;
29 extern const Value nil;
30 extern const Value platform;
31
32 ARK_API extern const std::vector<std::pair<std::string, Value>> builtins;
33
34 // ------------------------------
35 // builtins functions: we must use the instruction `BUILTIN index`
36 // ------------------------------
37 namespace List
38 {
39 ARK_BUILTIN(reverseList);
40 ARK_BUILTIN(findInList);
41 ARK_BUILTIN(sliceList);
44 ARK_BUILTIN(setListAt);
45 }
46
47 namespace IO
48 {
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 }
67
68 namespace System
69 {
70 ARK_BUILTIN(system_);
73 ARK_BUILTIN(assert_);
74 }
75
76 namespace String
77 {
78 ARK_BUILTIN(format);
79 ARK_BUILTIN(findSubStr);
80 ARK_BUILTIN(removeAtStr);
83 ARK_BUILTIN(setStringAt);
84 }
85
86 namespace Mathematics
87 {
88 ARK_BUILTIN(exponential);
89 ARK_BUILTIN(logarithm);
91 ARK_BUILTIN(floor_);
92 ARK_BUILTIN(round_);
93 ARK_BUILTIN(isnan_);
94 ARK_BUILTIN(isinf_);
95
96 extern const Value pi_;
97 extern const Value e_;
98 extern const Value tau_;
99 extern const Value inf_;
100 extern const Value nan_;
101
111 ARK_BUILTIN(acosh_);
112 ARK_BUILTIN(asinh_);
113 ARK_BUILTIN(atanh_);
114
115 ARK_BUILTIN(random);
116 }
117
118 namespace Async
119 {
122 }
123
124 namespace Dict
125 {
129 ARK_BUILTIN(contains);
130 ARK_BUILTIN(remove);
133 }
134
135 namespace Bytecode
136 {
137 ARK_BUILTIN(disassemble);
138 }
139
141
142 namespace Operators
143 {
149 ARK_BUILTIN(toNumber);
150 ARK_BUILTIN(toString);
151 ARK_BUILTIN(lessThan);
152 ARK_BUILTIN(lessOrEq);
153 ARK_BUILTIN(greaterThan);
154 ARK_BUILTIN(greaterOrEq);
159 ARK_BUILTIN(isEmpty);
166 }
167}
168
169#undef ARK_BUILTIN
170
171#endif
#define ARK_BUILTIN(name)
Definition Builtins.hpp:23
#define ARK_API
Definition Module.hpp:22
Default value type handled by the virtual machine.
The ArkScript virtual machine, executing ArkScript bytecode.
Definition VM.hpp:48
ARK_API const std::vector< std::pair< std::string, Value > > builtins