41 #ifndef RENVIRONMENT_H
42 #define RENVIRONMENT_H
48 #include <boost/serialization/access.hpp>
49 #include <boost/serialization/base_object.hpp>
50 #include <boost/serialization/nvp.hpp>
71 #define DETACH_LOCAL_FRAMES
114 : m_environment(env), m_prev_state(env->m_in_loop)
116 env->m_in_loop =
true;
121 m_environment->m_in_loop = m_prev_state;
148 : m_environment(env), m_prev_state(env->m_can_return)
150 env->m_can_return =
true;
155 m_environment->m_can_return = m_prev_state;
171 m_single_stepping(false), m_locked(false), m_cached(false),
172 m_leaked(false), m_in_loop(false), m_can_return(false)
190 return s_base_namespace;
255 __attribute__((hot,fastcall))
257 std::pair<Environment*, Frame::Binding*>
275 std::pair<const Environment*, const Frame::Binding*>
366 #ifdef DETACH_LOCAL_FRAMES
391 #ifdef DETACH_LOCAL_FRAMES
436 m_single_stepping = on;
446 return m_single_stepping;
482 return "environment";
496 friend class boost::serialization::access;
502 enum S11nType {EMPTY = 0, BASE, BASENAMESPACE,
503 GLOBAL, PACKAGE_ENV, NAMESPACE, OTHER};
505 struct LeakMonitor :
public GCNode::const_visitor {
510 void operator()(
const GCNode* node);
516 typedef std::pair<Environment*, Frame::Binding*> EBPair;
518 std::tr1::unordered_map<
const Symbol*, EBPair,
519 std::tr1::hash<const Symbol*>,
520 std::equal_to<const Symbol*>,
525 static Cache* s_cache;
533 GCEdge<Environment> m_enclosing;
534 GCEdge<Frame> m_frame;
535 bool m_single_stepping;
542 mutable bool m_leaked;
555 if (m_cached && m_frame)
556 m_frame->decCacheCount();
559 static void cleanup();
565 static void flushFromCache(
const Symbol* sym);
567 static void initialize();
569 bool isCachePortal()
const
571 return (
this == s_global);
574 template<
class Archive>
575 void load(Archive& ar,
const unsigned int version);
583 static const char* package_s11n_aux(
const StringVector* pkg_name);
585 template<
class Archive>
586 void save(Archive& ar,
const unsigned int version)
const;
588 template<
class Archive>
589 void serialize (Archive & ar,
const unsigned int version) {
590 boost::serialization::split_member(ar, *
this, version);
636 std::pair<Environment*, FunctionBase*>
637 findFunction(
const Symbol* symbol, Environment* env,
bool inherits =
true);
684 template <
typename UnaryPredicate>
685 std::pair<Environment*, RObject*>
687 UnaryPredicate pred,
bool inherits)
690 pair<Environment*, RObject*> ans(0, 0);
698 pair<Environment*, Frame::Binding*> pr
715 ans = make_pair(env, val);
719 }
while (!found && inherits && env);
727 namespace serialization {
745 template<
class Archive>
747 const unsigned int version)
760 template<
class Archive>
761 void CXXR::Environment::load(Archive& ar,
const unsigned int version)
763 ar >> BOOST_SERIALIZATION_BASE_OBJECT_NVP(RObject);
765 ar >> BOOST_SERIALIZATION_NVP(envtype);
766 Environment* reloc = 0;
775 reloc = s_base_namespace;
783 ar >> BOOST_SERIALIZATION_NVP(pkgname);
784 reloc = findPackage(pkgname);
789 GCStackRoot<const StringVector> nsspec;
791 reloc = findNamespace(nsspec);
798 ar >> BOOST_SERIALIZATION_NVP(m_single_stepping);
799 ar >> BOOST_SERIALIZATION_NVP(m_locked);
807 template<
class Archive>
808 void CXXR::Environment::save(Archive& ar,
const unsigned int version)
const
810 ar << BOOST_SERIALIZATION_BASE_OBJECT_NVP(RObject);
812 if (
this == s_empty) {
813 S11nType envtype = EMPTY;
814 ar << BOOST_SERIALIZATION_NVP(envtype);
818 if (
this == s_base) {
819 S11nType envtype = BASE;
820 ar << BOOST_SERIALIZATION_NVP(envtype);
824 if (
this == s_base_namespace) {
825 S11nType envtype = BASENAMESPACE;
826 ar << BOOST_SERIALIZATION_NVP(envtype);
830 if (
this == s_global) {
831 S11nType envtype = GLOBAL;
832 ar << BOOST_SERIALIZATION_NVP(envtype);
838 S11nType envtype = PACKAGE_ENV;
839 ar << BOOST_SERIALIZATION_NVP(envtype);
840 std::string pkgname(package_s11n_aux(pkgsv));
841 ar << BOOST_SERIALIZATION_NVP(pkgname);
847 S11nType envtype = NAMESPACE;
848 ar << BOOST_SERIALIZATION_NVP(envtype);
854 S11nType envtype = OTHER;
855 ar << BOOST_SERIALIZATION_NVP(envtype);
858 ar << BOOST_SERIALIZATION_NVP(m_single_stepping);
859 ar << BOOST_SERIALIZATION_NVP(m_locked);
872 extern SEXP R_EmptyEnv;
873 extern SEXP R_BaseEnv;
874 extern SEXP R_GlobalEnv;
875 extern SEXP R_BaseNamespace;
903 using namespace CXXR;
904 const Environment& env = *SEXP_downcast<Environment*>(x);
905 return env.enclosingEnvironment();
921 using namespace CXXR;
922 const Environment& env = *SEXP_downcast<const Environment*>(x);
923 return Rboolean(env.singleStepping());
945 using namespace CXXR;
946 Environment* env = SEXP_downcast<Environment*>(x);
947 return env->frame()->asPairList();
962 using namespace CXXR;
963 Environment& env = *SEXP_downcast<Environment*>(x);
964 env.setSingleStepping(v);
983 using namespace CXXR;
984 const Symbol* sym = SEXP_downcast<Symbol*>(x);
1002 using namespace CXXR;
1003 const Symbol* sym = SEXP_downcast<Symbol*>(x);