ArkScript
A small, lisp-inspired, functional scripting language
Builtins.hpp
Go to the documentation of this file.
1/**
2 * @file Builtins.hpp
3 * @author Lex 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-2025
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.hpp>
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 }
74
75 namespace String
76 {
77 ARK_BUILTIN(format);
78 ARK_BUILTIN(findSubStr);
79 ARK_BUILTIN(removeAtStr);
82 ARK_BUILTIN(setStringAt);
83 }
84
85 namespace Mathematics
86 {
87 ARK_BUILTIN(exponential);
88 ARK_BUILTIN(logarithm);
90 ARK_BUILTIN(floor_);
91 ARK_BUILTIN(round_);
92 ARK_BUILTIN(isnan_);
93 ARK_BUILTIN(isinf_);
94
95 extern const Value pi_;
96 extern const Value e_;
97 extern const Value tau_;
98 extern const Value inf_;
99 extern const Value nan_;
100
110 ARK_BUILTIN(acosh_);
111 ARK_BUILTIN(asinh_);
112 ARK_BUILTIN(atanh_);
113
114 ARK_BUILTIN(random);
115 }
116
117 namespace Async
118 {
121 }
122
123 namespace Dict
124 {
128 ARK_BUILTIN(contains);
129 ARK_BUILTIN(remove);
132 }
133
134 namespace Bytecode
135 {
136 ARK_BUILTIN(disassemble);
137 }
138}
139
140#undef ARK_BUILTIN
141
142#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:47
ARK_API const std::vector< std::pair< std::string, Value > > builtins