Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class lisp::RefType
- {
- public:
- RefType(TypeClass* type) :typeClass(type), refCount(1), weakRefCount(1) {}
- //type info pointer stored directly.
- TypeClass* typeClass; //if it's cloneable etc. It'll actually be part of the typeclass, not the vtable. typeClass pretty much replaces vtables here.
- //other refcounting functions here....
- int refCount, weakRefCount;
- protected:
- ~RefType(){} //deleted only by refcounting - heap object. note it's non-virtual
- //unassignable, unmoveable.
- };
- class Array : public lisp::RefType
- {
- public:
- Array() : RefType(reflect()) {}
- static TypeClass* reflect();
- //functions....
- private:
- Vector<lisp::Expr> data;
- };
- //inside s-expr
- class Expr
- {
- ...
- void setRefType(RefType* refType){...}
- RefType* refType(){} //getter
- template <typename T>
- T* refClass()
- {
- if (auto out = refType())
- {
- if (T::reflect() == out->typeClass) return static_cast<T*>(out);
- }
- return nullptr;
- }
- {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement