/
builtin_function.hpp
167 lines (139 loc) · 2.57 KB
/
builtin_function.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#ifndef BUILTIN_FUNCTION_HPP_
#define BUILTIN_FUNCTION_HPP_
#include "modelica_function.hpp"
#include "modelica_type.hpp"
#include "runtime/modelica_runtime_error.hpp"
#include "value.hpp"
#include <string>
#include <set>
class builtin_function : public modelica_function
{
public:
virtual ~builtin_function();
protected:
// typedef std::set<value::type_en> type_s;
typedef std::set<modelica_type> type_s;
typedef std::vector<type_s>::iterator formal_parameter_iterator;
protected:
builtin_function();
virtual value do_apply(value args) = 0;
virtual bool match_formal_parameters(value args);
std::vector<type_s> m_formal_parameters;
};
class abs_t : public builtin_function
{
public:
abs_t();
virtual ~abs_t();
protected:
value do_apply(value args);
};
class bt_div_t : public builtin_function
{
public:
bt_div_t();
virtual ~bt_div_t();
protected:
value do_apply(value args);
};
class mod_t : public builtin_function
{
public:
mod_t();
virtual ~mod_t();
protected:
value do_apply(value args);
};
class rem_t : public builtin_function
{
public:
rem_t();
virtual ~rem_t();
protected:
value do_apply(value args);
};
class sqrt_t : public builtin_function
{
public:
sqrt_t();
virtual ~sqrt_t();
protected:
value do_apply(value args);
};
class sign_t : public builtin_function
{
public:
sign_t();
virtual ~sign_t();
protected:
value do_apply(value args);
};
class ceil_t : public builtin_function
{
public:
ceil_t();
virtual ~ceil_t();
protected:
value do_apply(value args);
};
class floor_t : public builtin_function
{
public:
floor_t();
virtual ~floor_t();
protected:
value do_apply(value args);
};
class integer_t : public builtin_function
{
public:
integer_t();
virtual ~integer_t();
protected:
value do_apply(value args);
};
template <class Fn>
class unary_fcn : public builtin_function
{
public:
unary_fcn(Fn fn) : m_fn(fn) {}
virtual ~unary_fcn() {}
value do_apply(value args)
{
if (args.is_function_argument())
{
if (args.array_size() != 1)
{
throw modelica_runtime_error("wrong number of arguments");
}
}
//return value();
}
protected:
Fn m_fn;
};
template <class Fn>
unary_fcn<Fn>* generate_unary_fcn(Fn fn)
{
return new unary_fcn<Fn>(fn);
}
template <class Fn>
class binary_fcn : public builtin_function
{
public:
binary_fcn(Fn fn) : m_fcn(fn) {}
virtual ~binary_fcn() {}
value do_apply(value args)
{
return value(true);
}
protected:
Fn m_fcn;
};
template <class Fn>
binary_fcn<Fn> generate_binary_fcn(Fn fn)
{
binary_fcn<Fn> tmp(fn);
return fn;
}
#endif