Functional-lang  0.0
An example functional programming language
gc.hpp
Go to the documentation of this file.
1 #ifndef FUNC_GC_HPP
2 #define FUNC_GC_HPP
3 
8 #include "func/global.hpp"
9 
10 class GCObj;
11 class GCMain;
12 
15 class GCObj {
16  bool marked = false;
17 protected:
19  virtual void markSelf(GCMain &main);
20 public:
22  GCObj(GCMain &main) noexcept;
23 
24  virtual ~GCObj() {}
25 
27  virtual bool isMarked(GCMain &main) const noexcept;
28 
30  virtual void mark(GCMain &main) noexcept;
31 };
32 
35 class GCMain {
36  bool markBit;
37  std::size_t countNewObjs;
38 
40  std::vector<GCObj*> marks;
41 public:
42  GCMain() : markBit(true), marks() {}
43  virtual ~GCMain();
44 
51  bool getMarkBit() const noexcept;
52 
56  std::size_t getCountNewObjects() const noexcept;
57 
61  void add(GCObj *obj);
62 
68  void collect();
69 };
70 
71 #endif /* FUNC_GC_HPP */
virtual void mark(GCMain &main) noexcept
If not marked mark itself and children.
GCObj(GCMain &main) noexcept
Initialize as not marked.
void add(GCObj *obj)
Adds obj to all objects available.
Implements a tracing garbage collector.
Definition: gc.hpp:35
std::size_t getCountNewObjects() const noexcept
void collect()
Collects garbage.
virtual void markSelf(GCMain &main)
Marks itself.
Garbage collection object (objects to collect).
Definition: gc.hpp:15
virtual bool isMarked(GCMain &main) const noexcept
File for managing external headers.
bool getMarkBit() const noexcept