ztsdb
valuevar_ic.hpp
1 // (C) 2015-2017 Leonardo Silvestri
2 //
3 // This file is part of ztsdb.
4 //
5 // ztsdb is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // ztsdb is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with ztsdb. If not, see <http://www.gnu.org/licenses/>.
17 
22 
23  struct VBuiltinG {
24 
25  typedef std::tuple<std::string, Value, yy::location> arg_t;
26 
27  struct ArgInfo {
28  const set<val::ValType> typeset;
29  const bool doEval;
30  };
31 
32  static const unsigned MAXNAME = 128;
33  // get R out of here if possible LLL
35  string name,
36  string signature_s,
37  function<Value(vector<arg_t>&, zcore::InterpCtx&)> f_p,
38  bool evalEllipsis_p=true,
39  map<string, ArgInfo> argInfo_p = {});
40 
41  function<Value(vector<arg_t>&, zcore::InterpCtx& ic)> f;
42  shared_ptr<Invoke> invoke;
43  shared_ptr<Function> signature;
44  bool evalEllipsis;
45  map<string, int> argMap; // maps each argument name to a position
46  map<string, ArgInfo> argInfo;
47  int ellipsisPos;
48 
49  Value operator()(interp::BuiltinFrame& a, zcore::InterpCtx& ic) const;
50  void checkArgs(const interp::BuiltinFrame& r) const;
51  };
52 
53  inline Value& gval(Value& val) {
54  if (val.which()!=vt_ptr) {
55  return val;
56  }
57  else {
58  auto& ptr = get<VPtr>(val);
59  if (ptr.p == nullptr)
60  throw std::out_of_range("gval: null ptr!");
61  return *ptr.p;
62  }
63  }
64 
65  inline const Value& gval(const Value& val) {
66  if (val.which()!=vt_ptr)
67  return val;
68  else {
69  const auto& ptr = get<VPtr>(val);
70  if (ptr.p == nullptr)
71  throw std::out_of_range("gval: null ptr!");
72  return *ptr.p;
73  }
74  }
75 
76  // access the tuples of 'val::VBuiltinG::arg_t' clearer.
77  inline const std::string& getName(const VBuiltinG::arg_t& x) { return get<0>(x); }
78  inline Value& getVal(VBuiltinG::arg_t& x) { return gval(get<1>(x)); }
79  inline const Value& getVal(const VBuiltinG::arg_t& x) { return gval(get<1>(x)); }
80  inline const yy::location& getLoc(const VBuiltinG::arg_t& x) { return get<2>(x); }
81 
82 
interp::BuiltinFrame
Type of frame used when invoking builtin functions (see 'val::BuiltinG').
Definition: env.hpp:305
val
Contains the types that constitute the output of an evaluation by the interpreter.
Definition: display.hpp:31
VBuiltinG::ArgInfo
Definition: valuevar_ic.hpp:27
yy::location
Abstract a location.
Definition: location.hpp:54
VBuiltinG::checkArgs
void checkArgs(const interp::BuiltinFrame &r) const
Check that the arguments are of the correct type.
Definition: valuevar_ic.cpp:62
zcore::InterpCtx
Definition: interp_ctx.hpp:129
VBuiltinG::VBuiltinG
VBuiltinG(interp::BaseFrame *r, string name, string signature_s, function< Value(vector< arg_t > &, zcore::InterpCtx &)> f_p, bool evalEllipsis_p=true, map< string, ArgInfo > argInfo_p={})
Definition: valuevar_ic.cpp:26
interp::BaseFrame
Definition: env.hpp:42
VBuiltinG
Definition: valuevar_ic.hpp:23