30 #include <netinet/in.h>
31 #include <sys/timerfd.h>
32 #include "juice/variant.hpp"
33 #include "juice/variant_binary.hpp"
38 #include "globals.hpp"
39 #include "cow_ptr.hpp"
40 #include "timezone/interval.hpp"
41 #include "type_utils.hpp"
46 using namespace Juice;
78 typedef std::shared_ptr<VI> SpVI;
96 typedef shared_ptr<VFuture> SpFuture;
97 typedef shared_ptr<VTimer> SpTimer;
98 typedef shared_ptr<VBuiltinG> SpBuiltin;
99 typedef shared_ptr<VConn> SpConn;
102 VConn(
const string& ip_p,
int port_p, Global::conn_id_t id_p);
104 void setId(Global::conn_id_t id_p);
108 Global::conn_id_t id;
114 VTimer(
const uint64_t nanosecs_p,
115 shared_ptr<E> loop_p,
116 shared_ptr<E> once_p,
128 size_t loop_failed_n;
165 const map<int, string> vt_to_string = {
166 {0,
"encode_std_string"},
167 {1,
"encode_std_int"},
204 template<>
struct getelttype<vt_double> {
typedef double TP; };
206 template<>
struct getelttype<vt_time> {
typedef Global::dtime TP; };
207 template<>
struct getelttype<vt_duration> {
typedef Global::duration TP; };
212 template<
typename T>
struct rmptr { };
223 typedef int64_t integer_t;
225 typedef Variant<std::string
237 ,recursive_wrapper<VCode>
238 ,std::shared_ptr<VClos>
243 ,recursive_wrapper<VNamed>
245 ,recursive_wrapper<VPtr>
251 VCode(
const E* e) : expr(e->clone()) { }
252 VCode(shared_ptr<E> e) : expr(e) { }
259 if (
val.which() == vt_ptr) {
260 auto& vp = get<VPtr>(
val);
273 VBuiltinG() : _signature(0), signature(&_signature) { }
278 #include "valuevar_ic.hpp"
291 ellipsisPos = v.ellipsisPos;
304 ellipsisPos = v.ellipsisPos;
317 std::swap(argMap, v.argMap);
318 std::swap(ellipsisPos, v.ellipsisPos);
323 std::shared_ptr<Function> f;
324 map<string, int> argMap;
344 void setvalptr(val::Value& val_p,
const std::shared_ptr<interp::BaseFrame>& frame_p);
348 std::string to_string()
const;
356 std::weak_ptr<interp::BaseFrame> frame;
365 inline void push_back(pair<string, Value> p) { a.concat(p.second, p.first); }
366 inline size_t size()
const {
return a.size(); }
370 return VList(a.subsetRows(from, to, addrownums));
373 inline const idx_type getdim(idx_type d)
const {
return a.getdim(d); }
374 inline Vector<zstring> getNamesVector(idx_type d)
const {
return a.getNamesVector(d); }
376 VList& remove(arr::idx_type i);
378 void at(arr::idx_type i,
const val::Value& v);
379 void at(arr::idx_type i, val::Value&& v);
380 inline Value operator[](arr::idx_type i)
const {
383 Value operator[](
const std::string& s);
397 template<
class UnaryPredicate>
398 bool any_of(
const val::Value& v, UnaryPredicate p) {
399 if (v.which() == vt_list) {
400 const auto& vl = get<val::SpVList>(v);
401 for (
size_t i=0; i<vl->size(); ++i) {
402 auto res = any_of((vl->a)[i], p);
417 typedef string result_type;
418 string operator()(
const SpVList&)
const {
return "list"; }
419 string operator()(
const VNull&)
const {
return "NULL"; }
420 string operator()(
const VCode&)
const {
return "expression"; }
421 string operator()(
const std::shared_ptr<VClos>&)
const {
return "function"; }
422 string operator()(
const VConn&)
const {
return "connection"; }
423 string operator()(
const VTimer&)
const {
return "timer"; }
424 string operator()(
const SpBuiltin&)
const {
return "builtin"; }
425 string operator()(
const SpFuture&)
const {
return "future"; }
426 string operator()(
const SpVAD&)
const {
return "double"; }
427 string operator()(
const SpVAS&)
const {
return "character"; }
428 string operator()(
const SpVAB&)
const {
return "logical"; }
429 string operator()(
const SpVADT&)
const {
return "nanotime"; }
430 string operator()(
const SpVADUR&)
const {
return "nanoduration"; }
431 string operator()(
const SpVAIVL&)
const {
return "nanoival"; }
432 string operator()(
const SpVAPRD&)
const {
return "nanoperiod"; }
433 string operator()(
const SpZts&)
const {
return "zts"; }
435 string operator()(
const VArrayD&)
const {
return "double"; }
436 string operator()(
const VArrayS&)
const {
return "character"; }
437 string operator()(
const VArrayB&)
const {
return "logical"; }
438 string operator()(
const VArrayDT&)
const {
return "nanotime"; }
439 string operator()(
const VArrayDUR&)
const {
return "nanoduration"; }
440 string operator()(
const VArrayIVL&)
const {
return "nanoival"; }
441 string operator()(
const VArrayPRD&)
const {
return "nanoperiod"; }
442 string operator()(
const arr::zts&)
const {
return "zts"; }
443 string operator()(
const VList&)
const {
return "list"; }
444 string operator()(
const VClos&)
const {
return "function"; }
445 string operator()(
const VError&)
const {
return "error"; }
447 template <
typename T>
448 string operator()(
const T& t)
const {
return "unknown"; }
452 typedef size_t result_type;
453 size_t operator()(
const VNull& x)
const {
return 0; }
454 size_t operator()(
const SpVList& x)
const {
return x->size(); }
455 size_t operator()(
const SpVAD& x)
const {
return x->size(); }
456 size_t operator()(
const SpVAS& x)
const {
return x->size(); }
457 size_t operator()(
const SpVAB& x)
const {
return x->size(); }
458 size_t operator()(
const SpVADT& x)
const {
return x->size(); }
459 size_t operator()(
const SpVADUR& x)
const {
return x->size(); }
460 size_t operator()(
const SpVAIVL& x)
const {
return x->size(); }
461 size_t operator()(
const SpVAPRD& x)
const {
return x->size(); }
462 size_t operator()(
const SpZts& x)
const {
return x->size(); }
464 template <
typename T>
465 size_t operator()(
const T&)
const {
return 1; }
468 inline bool operator==(
const VNamed& p1,
const VNamed& p2) {
469 return p1.name == p2.name && p1.val == p2.val;
471 inline bool operator==(
const VNull& p1,
const VNull& p2) {
return true; }
472 inline bool operator==(
const VFuture& p1,
const VFuture& p2) {
return false; }
473 inline bool operator==(
const SpVList& p1,
const SpVList& p2) {
return p1->a == p2->a; }
474 inline bool operator==(
const VError& p1,
const VError& p2) {
return p1.what == p2.what; }
477 inline bool operator==(
const VCode& p1,
const VCode& p2) {
return false; }
478 inline bool operator==(
const VClos& p1,
const VClos& p2) {
return false; }
479 inline bool operator==(
const VConn& p1,
const VConn& p2) {
return false; }
480 inline bool operator==(
const VTimer& p1,
const VTimer& p2) {
return false; }
482 inline bool operator==(
const VPtr& p1,
const VPtr& p2) {
return false; }
484 inline size_t size(
const val::Value& v) {
return apply_visitor(
val::SizeOf(), v); }
489 return arr::make_cow<arr::Array<T>>(
false,
492 vector<arr::Vector<arr::zstring>>());
496 inline T get_scalar(
const Value& v) {
497 const auto& a = get<arr::cow_ptr<arr::Array<T>>>(v);
498 if (a->size() != 1) {
499 throw std::out_of_range(
"expecting scalar value");
504 void setTmp(Value& v);
505 void resetTmp(Value& v);
506 void setConst(Value& v);
507 void setLast(Value& v);
508 void setLock(Value& v);
509 void resetLock(Value& v);
510 void setRef(Value& v);
511 void resetRef(Value& v);
512 bool isLocked(
const Value& v);
513 bool isRef(
const Value& v);
514 bool isTmp(
const Value& v);
515 bool isConst(
const Value& v);
522 inline val::Value getInitValue() {
526 TYPE_NB(val::Value, 7);
527 TYPE_NAME(val::Value,
"Value");
530 inline val::Value
convert(
const val::Value& u) {
541 inline bool operator==(
const val::SpVI& a1,
const val::SpVI& a2) {
return *a1 == *a2; }
543 inline bool operator!=(
const val::Value& v1,
const val::Value& v2) {
return !(v1 == v2); }
551 #include "valuevector.hpp"