ArkScript
A small, fast, functional and scripting language for video games
Builtins.hpp
Go to the documentation of this file.
1/**
2 * @file Builtins.hpp
3 * @author Alexandre Plateau ([email protected])
4 * @brief Host the declaration of all the ArkScript builtins
5 * @version 0.1
6 * @date 2020-10-27
7 *
8 * @copyright Copyright (c) 2020-2021
9 *
10 */
11
12#ifndef ARK_BUILTINS_BUILTINS_HPP
13#define ARK_BUILTINS_BUILTINS_HPP
14
15#include <vector>
16
17#include <Ark/VM/Value.hpp>
18#include <Ark/Exceptions.hpp>
19
20namespace Ark
21{
22 class VM;
23}
24
26{
27 extern const Value falseSym;
28 extern const Value trueSym;
29 extern const Value nil;
30
31 extern const std::vector<std::pair<std::string, Value>> builtins;
32
33 // ------------------------------
34 // builtins functions: we must use the instruction `BUILTIN index`
35 // ------------------------------
36 namespace List
37 {
38 Value reverseList(std::vector<Value>& n, VM* vm); // list:reverse, single arg
39 Value findInList(std::vector<Value>& n, VM* vm); // list:find, 2 arguments
40 Value sliceList(std::vector<Value>& n, VM* vm); // list:slice, 4 arguments
41 Value sort_(std::vector<Value>& n, VM* vm); // list:sort, 1 argument
42 Value fill(std::vector<Value>& n, VM* vm); // list:fill, 2 arguments
43 Value setListAt(std::vector<Value>& n, VM* vm); // list:setAt, 3 arguments
44 }
45
46 namespace IO
47 {
48 Value print(std::vector<Value>& n, VM* vm); // print, multiple arguments
49 Value puts_(std::vector<Value>& n, VM* vm); // puts, multiple arguments
50 Value input(std::vector<Value>& n, VM* vm); // input, 0 or 1 argument
51 Value writeFile(std::vector<Value>& n, VM* vm); // io:writeFile, 2 or 3 arguments
52 Value readFile(std::vector<Value>& n, VM* vm); // io:readFile, 1 argument
53 Value fileExists(std::vector<Value>& n, VM* vm); // io:fileExists?, 1 argument
54 Value listFiles(std::vector<Value>& n, VM* vm); // io:listFiles, 1 argument
55 Value isDirectory(std::vector<Value>& n, VM* vm); // io:isDir?, 1 argument
56 Value makeDir(std::vector<Value>& n, VM* vm); // io:makeDir, 1 argument
57 Value removeFiles(std::vector<Value>& n, VM* vm); // io:removeFiles, multiple arguments
58 }
59
60 namespace Time
61 {
62 Value timeSinceEpoch(std::vector<Value>& n, VM* vm); // time, 0 argument
63 }
64
65 namespace System
66 {
67 Value system_(std::vector<Value>& n, VM* vm); // sys:exec, 1 argument
68 Value sleep(std::vector<Value>& n, VM* vm); // sleep, 1 argument
69 Value exit_(std::vector<Value>& n, VM* vm); // sys:exit, 1 argument
70 }
71
72 namespace String
73 {
74 Value format(std::vector<Value>& n, VM* vm); // str:format, multiple arguments
75 Value findSubStr(std::vector<Value>& n, VM* vm); // str:find, 2 arguments
76 Value removeAtStr(std::vector<Value>& n, VM* vm); // str:removeAt, 2 arguments
77 Value ord(std::vector<Value>& n, VM* vm); // str:ord, 1 arguments
78 Value chr(std::vector<Value>& n, VM* vm); // str:chr, 1 arguments
79 }
80
81 namespace Mathematics
82 {
83 Value exponential(std::vector<Value>& n, VM* vm); // math:exp, 1 argument
84 Value logarithm(std::vector<Value>& n, VM* vm); // math:ln, 1 argument
85 Value ceil_(std::vector<Value>& n, VM* vm); // math:ceil, 1 argument
86 Value floor_(std::vector<Value>& n, VM* vm); // math:floor, 1 argument
87 Value round_(std::vector<Value>& n, VM* vm); // math:round, 1 argument
88 Value isnan_(std::vector<Value>& n, VM* vm); // math:NaN?, 1 argument
89 Value isinf_(std::vector<Value>& n, VM* vm); // math:Inf?, 1 argument
90
91 extern const Value pi_;
92 extern const Value e_;
93 extern const Value tau_;
94 extern const Value inf_;
95 extern const Value nan_;
96
97 Value cos_(std::vector<Value>& n, VM* vm); // math:cos, 1 argument
98 Value sin_(std::vector<Value>& n, VM* vm); // math:sin, 1 argument
99 Value tan_(std::vector<Value>& n, VM* vm); // math:tan, 1 argument
100 Value acos_(std::vector<Value>& n, VM* vm); // math:arccos, 1 argument
101 Value asin_(std::vector<Value>& n, VM* vm); // math:arcsin, 1 argument
102 Value atan_(std::vector<Value>& n, VM* vm); // math:arctan, 1 argument
103 Value cosh_(std::vector<Value>& n, VM* vm); // math:cosh, 1 argument
104 Value sinh_(std::vector<Value>& n, VM* vm); // math:sinh, 1 argument
105 Value tanh_(std::vector<Value>& n, VM* vm); // math:tanh, 1 argument
106 Value acosh_(std::vector<Value>& n, VM* vm); // math:acosh, 1 argument
107 Value asinh_(std::vector<Value>& n, VM* vm); // math:asinh, 1 argument
108 Value atanh_(std::vector<Value>& n, VM* vm); // math:atanh, 1 argument
109 }
110
111 namespace Async
112 {
113 Value async(std::vector<Value>& n, VM* vm); // async, 1+ arguments
114 Value await(std::vector<Value>& n, VM* vm); // await, 1 argument
115 }
116}
117
118#endif
ArkScript homemade exceptions.
The ArkScript virtual machine, executing ArkScript bytecode.
Definition: VM.hpp:41
Value async(std::vector< Value > &n, VM *vm)
Value await(std::vector< Value > &n, VM *vm)
Value makeDir(std::vector< Value > &n, VM *vm)
Value input(std::vector< Value > &n, VM *vm)
Value readFile(std::vector< Value > &n, VM *vm)
Value puts_(std::vector< Value > &n, VM *vm)
Value print(std::vector< Value > &n, VM *vm)
Value writeFile(std::vector< Value > &n, VM *vm)
Value fileExists(std::vector< Value > &n, VM *vm)
Value listFiles(std::vector< Value > &n, VM *vm)
Value removeFiles(std::vector< Value > &n, VM *vm)
Value isDirectory(std::vector< Value > &n, VM *vm)
Value sort_(std::vector< Value > &n, VM *vm)
Value fill(std::vector< Value > &n, VM *vm)
Value reverseList(std::vector< Value > &n, VM *vm)
Value setListAt(std::vector< Value > &n, VM *vm)
Value findInList(std::vector< Value > &n, VM *vm)
Value sliceList(std::vector< Value > &n, VM *vm)
Value atan_(std::vector< Value > &n, VM *vm)
Value isinf_(std::vector< Value > &n, VM *vm)
Value atanh_(std::vector< Value > &n, VM *vm)
Value acos_(std::vector< Value > &n, VM *vm)
Value asin_(std::vector< Value > &n, VM *vm)
Value cosh_(std::vector< Value > &n, VM *vm)
Value logarithm(std::vector< Value > &n, VM *vm)
Value tan_(std::vector< Value > &n, VM *vm)
Value ceil_(std::vector< Value > &n, VM *vm)
Value cos_(std::vector< Value > &n, VM *vm)
Value floor_(std::vector< Value > &n, VM *vm)
Value tanh_(std::vector< Value > &n, VM *vm)
Value acosh_(std::vector< Value > &n, VM *vm)
Value sinh_(std::vector< Value > &n, VM *vm)
Value isnan_(std::vector< Value > &n, VM *vm)
Value exponential(std::vector< Value > &n, VM *vm)
Value asinh_(std::vector< Value > &n, VM *vm)
Value round_(std::vector< Value > &n, VM *vm)
Value sin_(std::vector< Value > &n, VM *vm)
Value ord(std::vector< Value > &n, VM *vm)
Value findSubStr(std::vector< Value > &n, VM *vm)
Value removeAtStr(std::vector< Value > &n, VM *vm)
Value format(std::vector< Value > &n, VM *vm)
Value chr(std::vector< Value > &n, VM *vm)
Value system_(std::vector< Value > &n, VM *vm)
Value sleep(std::vector< Value > &n, VM *vm)
Value exit_(std::vector< Value > &n, VM *vm)
Value timeSinceEpoch(std::vector< Value > &n, VM *vm)
const std::vector< std::pair< std::string, Value > > builtins
Definition: Builtins.hpp:21