ArkScript
A small, lisp-inspired, functional scripting language
Procedure.hpp
Go to the documentation of this file.
1/**
2 * @file Procedure.hpp
3 * @author Justin Andreas Lacoste (me@justin.cx)
4 * @brief Wrapper object for user-defined functions
5 * @date 2025-06-09
6 *
7 * @copyright Copyright (c) 2025
8 *
9 */
10
11#ifndef ARK_VM_PROCEDURE_HPP
12#define ARK_VM_PROCEDURE_HPP
13
14#include <functional>
15#include <vector>
16
17namespace Ark
18{
19 class Value;
20 class VM;
21
22 /**
23 * @brief Storage class to hold custom functions
24 */
26 {
27 public:
28 using PointerType = Value (*)(std::vector<Value>&, VM*);
29 using CallbackType = std::function<Value(std::vector<Value>&, VM*)>;
30
31 ///
32 /// Due to clang (sometimes) rejecting forward declared types
33 /// in templates (`Value` causes issues), we have to implement
34 /// the constructor for the actual `CallbackType` using SFINAE
35 /// and a templated constructor, such that when clang
36 /// encounters the constructor, it knows the actual
37 /// declaration of `Value`.
38 ///
39 /**
40 * @brief Create a new procedure.
41 */
42 template <typename T>
43 Procedure(T&& cb) :
44 m_procedure(cb)
45 {
46 }
47
48 /**
49 * @brief Create a new procedure from a stateless C function pointer.
50 */
51 Procedure(PointerType c_ptr);
52
53 Value operator()(std::vector<Value>&, VM*) const;
54
55 bool operator<(const Procedure& other) const noexcept;
56 bool operator==(const Procedure& other) const noexcept;
57
58 private:
60 };
61}
62
63#endif
#define ARK_API
Definition Module.hpp:28
Storage class to hold custom functions.
Definition Procedure.hpp:26
CallbackType m_procedure
Definition Procedure.hpp:59
std::function< Value(std::vector< Value > &, VM *)> CallbackType
Definition Procedure.hpp:29
Value(*)(std::vector< Value > &, VM *) PointerType
Definition Procedure.hpp:28
Procedure(T &&cb)
Create a new procedure.
Definition Procedure.hpp:43
The ArkScript virtual machine, executing ArkScript bytecode.
Definition VM.hpp:46
bool operator<(const Namespace &, const Namespace &)
Definition Namespace.hpp:27
bool operator==(const Namespace &A, const Namespace &B)
Definition Namespace.hpp:21