Fixed broken tests
This commit is contained in:
parent
0b0344be69
commit
5e52de10bd
7 changed files with 29 additions and 98 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -11,4 +11,4 @@ llvm.ll
|
|||
|
||||
src/GC/lib/*.o
|
||||
src/GC/lib/*.so
|
||||
src/GC/tests/*.out
|
||||
src/GC/tests/*.out
|
||||
77
.vscode/settings.json
vendored
77
.vscode/settings.json
vendored
|
|
@ -1,77 +0,0 @@
|
|||
{
|
||||
"files.associations": {
|
||||
"array": "cpp",
|
||||
"bitset": "cpp",
|
||||
"string_view": "cpp",
|
||||
"initializer_list": "cpp",
|
||||
"ranges": "cpp",
|
||||
"span": "cpp",
|
||||
"utility": "cpp",
|
||||
"__hash_table": "cpp",
|
||||
"__split_buffer": "cpp",
|
||||
"deque": "cpp",
|
||||
"queue": "cpp",
|
||||
"string": "cpp",
|
||||
"unordered_map": "cpp",
|
||||
"vector": "cpp",
|
||||
"atomic": "cpp",
|
||||
"bit": "cpp",
|
||||
"*.tcc": "cpp",
|
||||
"cctype": "cpp",
|
||||
"charconv": "cpp",
|
||||
"chrono": "cpp",
|
||||
"clocale": "cpp",
|
||||
"cmath": "cpp",
|
||||
"compare": "cpp",
|
||||
"concepts": "cpp",
|
||||
"condition_variable": "cpp",
|
||||
"cstdarg": "cpp",
|
||||
"cstddef": "cpp",
|
||||
"cstdint": "cpp",
|
||||
"cstdio": "cpp",
|
||||
"cstdlib": "cpp",
|
||||
"cstring": "cpp",
|
||||
"ctime": "cpp",
|
||||
"cwchar": "cpp",
|
||||
"cwctype": "cpp",
|
||||
"exception": "cpp",
|
||||
"algorithm": "cpp",
|
||||
"functional": "cpp",
|
||||
"iterator": "cpp",
|
||||
"memory": "cpp",
|
||||
"memory_resource": "cpp",
|
||||
"numeric": "cpp",
|
||||
"optional": "cpp",
|
||||
"random": "cpp",
|
||||
"ratio": "cpp",
|
||||
"system_error": "cpp",
|
||||
"tuple": "cpp",
|
||||
"type_traits": "cpp",
|
||||
"iosfwd": "cpp",
|
||||
"iostream": "cpp",
|
||||
"istream": "cpp",
|
||||
"limits": "cpp",
|
||||
"mutex": "cpp",
|
||||
"new": "cpp",
|
||||
"ostream": "cpp",
|
||||
"sstream": "cpp",
|
||||
"stdexcept": "cpp",
|
||||
"stop_token": "cpp",
|
||||
"streambuf": "cpp",
|
||||
"thread": "cpp",
|
||||
"typeinfo": "cpp",
|
||||
"variant": "cpp",
|
||||
"__bit_reference": "cpp",
|
||||
"__config": "cpp",
|
||||
"__debug": "cpp",
|
||||
"__errc": "cpp",
|
||||
"__locale": "cpp",
|
||||
"__mutex_base": "cpp",
|
||||
"__node_handle": "cpp",
|
||||
"__threading_support": "cpp",
|
||||
"__verbose_abort": "cpp",
|
||||
"ios": "cpp",
|
||||
"locale": "cpp",
|
||||
"semaphore": "cpp"
|
||||
}
|
||||
}
|
||||
|
|
@ -78,11 +78,17 @@ namespace GC {
|
|||
* that the address of the topmost stack frame is
|
||||
* saved as the limit for scanning the stack in collect.
|
||||
*/
|
||||
static void init(); // TODO: make static
|
||||
static void dispose(); // -||-
|
||||
static void *alloc(size_t size); // -||-
|
||||
static void init();
|
||||
static void dispose();
|
||||
static void *alloc(size_t size);
|
||||
|
||||
// DEBUG ONLY
|
||||
static inline Heap *debug_the() { // TODO: make private
|
||||
if (m_instance) // if m_instance is not a nullptr
|
||||
return m_instance;
|
||||
m_instance = new Heap();
|
||||
return m_instance;
|
||||
}
|
||||
void collect(uint flags); // conditional collection
|
||||
void check_init(); // print dummy things
|
||||
void print_contents(); // print dummy things
|
||||
|
|
|
|||
|
|
@ -9,21 +9,24 @@ struct Obj {
|
|||
};
|
||||
|
||||
int main() {
|
||||
GC::Heap *heap = GC::Heap::the2();
|
||||
GC::Heap::init();
|
||||
Obj *obj;
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
obj = static_cast<Obj *>(heap->alloc(sizeof(Obj)));
|
||||
obj = static_cast<Obj *>(GC::Heap::alloc(sizeof(Obj)));
|
||||
obj->a = i * i + 1;
|
||||
obj->b = i * i + 2;
|
||||
obj->c = i * i + 3;
|
||||
}
|
||||
|
||||
// heap->force_collect();
|
||||
auto heap = GC::Heap::debug_the();
|
||||
heap->collect(COLLECT_ALL);
|
||||
|
||||
std::cout << obj->a << ", " << obj->b << ", " << obj->c << std::endl;
|
||||
|
||||
//delete heap;
|
||||
GC::Heap::dispose();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -29,8 +29,8 @@ int main() {
|
|||
GC::Heap *singleton_test() {
|
||||
std::cout << "TESTING SINGLETON INSTANCES" << std::endl;
|
||||
std::cout << "===========================" << std::endl;
|
||||
std::cout << "Call 1:\t" << GC::Heap::the() << std::endl; // First call which initializes the singleton instance
|
||||
GC::Heap *heap = GC::Heap::the(); // Second call which should return the initialized instance
|
||||
std::cout << "Call 1:\t" << GC::Heap::debug_the() << std::endl; // First call which initializes the singleton instance
|
||||
GC::Heap *heap = GC::Heap::debug_the(); // Second call which should return the initialized instance
|
||||
std::cout << "Call 2:\t" << heap << std::endl;
|
||||
std::cout << "===========================" << std::endl;
|
||||
return heap;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
#include "../include/heap.hpp"
|
||||
|
||||
GC::Heap *gc = GC::Heap::the();
|
||||
#include "heap.hpp"
|
||||
|
||||
struct Node {
|
||||
int id;
|
||||
|
|
@ -10,12 +8,12 @@ struct Node {
|
|||
Node *create_chain(int depth) {
|
||||
std::vector<Node*> nodes;
|
||||
if (depth > 0) {
|
||||
Node *last_node = static_cast<Node *>(gc->alloc(sizeof(Node)));
|
||||
Node *last_node = static_cast<Node *>(GC::Heap::alloc(sizeof(Node)));
|
||||
last_node->id = depth;
|
||||
last_node->child = nullptr;
|
||||
nodes.push_back(last_node);
|
||||
for (int i = 0; i < depth; i++) {
|
||||
Node *node = static_cast<Node *>(gc->alloc(sizeof(Node)));
|
||||
Node *node = static_cast<Node *>(GC::Heap::alloc(sizeof(Node)));
|
||||
node->id = depth-i;
|
||||
node->child = nodes[i-1];
|
||||
nodes.push_back(node);
|
||||
|
|
@ -30,7 +28,7 @@ Node *create_chain(int depth) {
|
|||
}
|
||||
|
||||
void create_array(size_t size) {
|
||||
int *arr = static_cast<int *>(gc->alloc(sizeof(int) * size));
|
||||
int *arr = static_cast<int *>(GC::Heap::alloc(sizeof(int) * size));
|
||||
}
|
||||
|
||||
void detach_pointer(long **ptr) {
|
||||
|
|
@ -54,19 +52,20 @@ void test_some_types() {
|
|||
auto stack_start = reinterpret_cast<uintptr_t *>(__builtin_frame_address(0));
|
||||
std::cout << "Stack start from test_some_types:\t" << stack_start << std::endl;
|
||||
|
||||
long *l = static_cast<long *>(gc->alloc(sizeof(long)));
|
||||
long *l = static_cast<long *>(GC::Heap::alloc(sizeof(long)));
|
||||
std::cout << "l points to:\t\t" << l << std::endl;
|
||||
detach_pointer(&l);
|
||||
std::cout << "l points to:\t\t" << l << std::endl;
|
||||
|
||||
// Some more dummy values of different sizes, to test stack pointer alignment
|
||||
int *i = static_cast<int *>(gc->alloc(sizeof(int)));
|
||||
char *c = static_cast<char *>(gc->alloc(sizeof(int)));
|
||||
short *s = static_cast<short *>(gc->alloc(sizeof(short)));
|
||||
int *i = static_cast<int *>(GC::Heap::alloc(sizeof(int)));
|
||||
char *c = static_cast<char *>(GC::Heap::alloc(sizeof(int)));
|
||||
short *s = static_cast<short *>(GC::Heap::alloc(sizeof(short)));
|
||||
}
|
||||
|
||||
int main() {
|
||||
gc->init();
|
||||
GC::Heap::init();
|
||||
GC::Heap *gc = GC::Heap::debug_the();
|
||||
gc->check_init();
|
||||
auto stack_start = reinterpret_cast<uintptr_t *>(__builtin_frame_address(0));
|
||||
std::cout << "Stack start from main:\t" << stack_start << std::endl;
|
||||
|
|
|
|||
|
|
@ -9,11 +9,11 @@ struct Obj {
|
|||
};
|
||||
|
||||
int main() {
|
||||
auto heap = GC::Heap::the2();
|
||||
auto heap = GC::Heap::debug_the();
|
||||
|
||||
std::cout << "heap:\t" << heap << std::endl;
|
||||
|
||||
auto obj = static_cast<Obj *>(heap->alloc(sizeof(Obj)));
|
||||
auto obj = static_cast<Obj *>(GC::Heap::alloc(sizeof(Obj)));
|
||||
|
||||
std::cout << "obj: \t" << obj << std::endl;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue