BUUUUUNCH of shit, but added logger, more stl nonsense, improved code quaklity, squashed bugs.

This commit is contained in:
2025-05-31 16:12:31 +03:00
parent 3b1b2bfb06
commit 2a31d770ed
31 changed files with 1543 additions and 21 deletions

View File

@@ -1,4 +1,4 @@
CC = clang
all: ../build/libc+ test compile_commands.json
@@ -6,10 +6,10 @@ clean:
rm -rf test *.o compile_commands.json
test: test.o
cc -o $@ $^ -L../build -l:libc+.a -ggdb # -nostdlib++ -lsupc++
$(CC) -o $@ $^ -L../build -l:libc+.a -ggdb # -nostdlib++ -lsupc++
%.o: %.cpp
cc -c -o $@ $< -std=c++23 -I../src/include -ggdb # -nostdinc++
$(CC) -c -o $@ $< -std=c++23 -I../src/include -ggdb # -nostdinc++
../build/libc+:
$(MAKE) -C ../

BIN
test/test

Binary file not shown.

View File

@@ -1,11 +1,95 @@
#include "io/print.hpp"
#include <std.hpp>
#include <format/obj_fmt_helper.hpp>
#include <sync/mutex.hpp>
#include <sync/spinlock.hpp>
#include <stddef.h>
#include <pthread.h>
#include <unistd.h>
int main(int argc, char* argv[]) {
#include <logger.hpp>
struct Foo {
int bar = 1;
float baz = 2.0;
// IMPL: Format
String fmt_to_str() {
auto h = ObjFmtHelper("Foo");
h.add_field("bar", this->bar);
h.add_field("baz", this->baz);
return h.finish();
}
};
Vec<int> test_vec() {
Vec<int> v = Vec<int>();
v.push(1);
v.push(2);
v.push(3);
v.push(4);
return v;
}
void test_fmt(Vec<int> v) {
Foo f = Foo();
println("Hello!!!! {}, {}, {}, {}", "meow", 420.0, 49, v);
println("> {}", f);
}
extern "C" void* test_mutex_thread(void* arg) {
Mutex<int>* m = (Mutex<int>*)arg;
auto val = m->lock();
println("mutex: changing {} to 69", *val);
*val = 69;
println("mutex: 5 second eep!! (eepy boyo)");
sleep(5);
return NULL;
}
void test_mutex() {
Mutex<int>* m = new Mutex<int>(0);
pthread_t thread;
println("mutex: Creating thread for mutex");
if (pthread_create(&thread, NULL, test_mutex_thread, (void*)m) != 0) {
println("Uh oh (mutex)");
}
pthread_join(thread, NULL);
auto val = m->lock();
println("mutex: Value was {}", *val);
}
extern "C" void* test_spinlock_thread(void* arg) {
SpinLock<int>* sl = (SpinLock<int>*)arg;
println("spinlock: changing {} to 5", *sl->lock());
*sl->lock() = 5;
println("spinlock: 5 second eep!! (eepy girlie)");
sleep(5);
return NULL;
}
void test_spinlock() {
SpinLock<int>* sl = new SpinLock<int>(0);
pthread_t thread;
println("spinlock: Creating thread for spinlock");
if (pthread_create(&thread, NULL, test_spinlock_thread, (void*)sl) != 0) {
println("Uh oh (spinlock)");
}
pthread_join(thread, NULL);
println("spinlock: Value was {}", *sl->lock());
}
/// https://github.com/yosh-matsuda/field-reflection
int main(int argc, char* argv[]) {
// Vec<int> v = test_vec();
// test_fmt(v);
// test_spinlock();
// test_mutex();
log::debug("hemlo!!");
log::info("hemlo!!");
log::warn("hemlo!!");
log::error("hemlo!!");
return 0;
}