This repository has been archived on 2025-02-04. You can view files and clone it, but cannot push or open issues or pull requests.
helpless/main.c
Charlie db73d0bd2e - Basic fixed-length string with replacement for C standard printing & fmt stuff
- Jai-like print procedures
	- %s formats 'string' and to format a char* you do %cs
	- It detects if %cs pointer is outside of program memory or stack and asserts
	- AND same for if a char* is passed to %s
	- Print directly writes to stdout without any allocations
	- Basic utlity procedures
	- Buncha string tests
- Beef up assert to display file & line as well
- Don't define memcpy procedures if compiler has intrinsics for them
- Init memory arena for allocations in initialization time before heap is ready (stack memory)
- os_compare_and_swap
- Spinlock "primitive" (wrapper around a bool using compare_and_swap)
- Switched to using spinlock instead of os mutex in heap for synchronization.
- is_pointer_valid() which checks if address is in program_memory or thread stack
2024-06-28 18:50:30 +02:00

55 lines
1.4 KiB
C

int oogabooga_main(int argc, char **argv) {
print(cstr("This is our print! %i\n"), 5);
// alloc calls to context.allocator.proc which by default is set to the
// heap allocator in memory.c
int *a = (int*)alloc(sizeof(int));
dealloc(a);
// We can do an old school memory dump to save our game with the global variables
// (void*) program_memory and (u64) program_memory_size
// program_memory will ALWAYS have the same virtual memory base address, so all
// pointers will remain valid when read back from disk.
// We can push allocator like jai
push_allocator(temp);
// all calls to alloc() here will be with the temporary allocator
pop_allocator(); // But this is C so we have to pop it manually!
// or we can just do this for temporary allocation
int *b = talloc(sizeof(int));
// Call each frame
reset_temporary_storage();
Context c = context;
// ... modify c
push_context(c);
// ... do stuff in modified context
pop_context();
// For now, context only has the allocator and CONTEXT_EXTRA which can be defined
// to add some custom stuff to context
// But it needs to be in build.c before including oogabooga.c.
// #define CONTEXT_EXTRA struct { int monkee; }
context.extra.monkee = 69;
int hello;
hello = 5;
#ifdef DEBUG
printf("Hello, balls! (debug)\n");
#endif
#ifdef RELEASE
printf("Hello, balls! (release)\n");
#endif
printf("Program exit as expected\n");
return 0;
}