Adobe Source Libraries 2.0.2
A collection of C++ libraries.
Loading...
Searching...
No Matches
virtual_machine.hpp
Go to the documentation of this file.
1/*
2 Copyright 2013 Adobe
3 Distributed under the Boost Software License, Version 1.0.
4 (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5*/
6/**************************************************************************************************/
7
8#ifndef ADOBE_VIRTUAL_MACHINE_HPP
9#define ADOBE_VIRTUAL_MACHINE_HPP
10
11#include <adobe/config.hpp>
12
13#include <functional>
14#include <stdexcept>
15#include <string>
16
17#define BOOST_FUNCTION_NO_DEPRECATED
18#include <boost/operators.hpp>
19
20#include <adobe/any_regular.hpp>
21#include <adobe/array_fwd.hpp>
23#include <adobe/name.hpp>
24
25/**************************************************************************************************/
26
27namespace adobe {
28
29/**************************************************************************************************/
30
32const char* type_name(const std::type_info& type);
33
34/**************************************************************************************************/
35
37template <class T>
38auto cast(adobe::any_regular_t& x) -> decltype(x.cast<T>()) {
39 if constexpr (!std::is_same_v<T, adobe::any_regular_t>) {
40 if (x.type_info() != typeid(promote_t<T>))
41 throw std::runtime_error(std::string{"expected `"} + type_name(typeid(promote_t<T>)) +
42 "` found `" + type_name(x.type_info()) + "`");
43 }
44 return x.cast<T>();
45}
46
48template <class T>
49auto cast(const adobe::any_regular_t& x) -> decltype(x.cast<T>()) {
50 if constexpr (!std::is_same_v<T, adobe::any_regular_t>) {
51 if (x.type_info() != typeid(promote_t<T>))
52 throw std::runtime_error(std::string{"expected `"} + type_name(typeid(promote_t<T>)) +
53 "` found `" + type_name(x.type_info()) + "`");
54 }
55 return x.cast<T>();
56}
57
58/**************************************************************************************************/
59/*
60 Note: For all bitwise operators the numeric data type (double) will be cast down to a
61 std::uint32_t for the operation.
62*/
64public:
66
72 std::size_t index);
73
74 using variable_lookup_t = std::function<variable_lookup_signature_t>;
75 using dictionary_function_lookup_t = std::function<dictionary_function_lookup_signature_t>;
76 using array_function_lookup_t = std::function<array_function_lookup_signature_t>;
77 using named_index_lookup_t = std::function<named_index_lookup_signature_t>;
78 using numeric_index_lookup_t = std::function<numeric_index_lookup_signature_t>;
79
81 const any_regular_t&);
82
83 using binary_op_override_t = std::function<binary_op_override_signature_t>;
84
85#if !defined(ADOBE_NO_DOCUMENTATION)
88
90
92#endif
93
94 void evaluate(const expression_t& expression);
95#if 0
96 void evaluate_named_arguments(const dictionary_t&);
97#endif
98
99 const any_regular_t& back() const;
101 void pop_back();
102
108
110
111 class implementation_t;
112
113private:
114 implementation_t* object_m;
115};
116
117/**************************************************************************************************/
118
119} // namespace adobe
120
121/**************************************************************************************************/
122
123#endif
124
125/**************************************************************************************************/
A runtime polymorphic type similar to std::any which can hold any type which models Regular.
void set_variable_lookup(const variable_lookup_t &)
void override_operator(name_t, const binary_op_override_t &)
std::function< dictionary_function_lookup_signature_t > dictionary_function_lookup_t
any_regular_t & back()
any_regular_t numeric_index_lookup_signature_t(const any_regular_t &, std::size_t index)
std::function< array_function_lookup_signature_t > array_function_lookup_t
virtual_machine_t(const virtual_machine_t &)
any_regular_t binary_op_override_signature_t(const any_regular_t &, const any_regular_t &)
void set_dictionary_function_lookup(const dictionary_function_lookup_t &)
const any_regular_t & back() const
void set_numeric_index_lookup(const numeric_index_lookup_t &)
virtual_machine_t & operator=(const virtual_machine_t &rhs)
std::function< binary_op_override_signature_t > binary_op_override_t
std::function< numeric_index_lookup_signature_t > numeric_index_lookup_t
std::function< variable_lookup_signature_t > variable_lookup_t
any_regular_t dictionary_function_lookup_signature_t(name_t, const dictionary_t &)
std::function< named_index_lookup_signature_t > named_index_lookup_t
any_regular_t array_function_lookup_signature_t(name_t, const array_t &)
any_regular_t named_index_lookup_signature_t(const any_regular_t &, name_t index)
any_regular_t variable_lookup_signature_t(name_t)
void set_named_index_lookup(const named_index_lookup_t &)
void set_array_function_lookup(const array_function_lookup_t &)
void evaluate(const expression_t &expression)
closed_hash_map< name_t, any_regular_t > dictionary_t
const char * type_name(const std::type_info &type)
Returns a simple name for the core types used by the virtual machine.
auto cast(adobe::any_regular_t &x) -> decltype(x.cast< T >())
Does a runtime cast on an any_regular_t with better error reporting.
std::vector< any_regular_t > array_t
Definition array_fwd.hpp:23
typename promote< T >::type promote_t
A character string class for immutable strings.
Definition name.hpp:220