80 lines
1.4 KiB
C
80 lines
1.4 KiB
C
#ifndef BASE_H
|
|
#define BASE_H
|
|
|
|
#include <stdio.h>
|
|
#include <stdint.h>
|
|
|
|
//= rhjr: types
|
|
|
|
typedef uint8_t u8;
|
|
typedef uint16_t u16;
|
|
typedef uint32_t u32;
|
|
typedef uint64_t u64;
|
|
|
|
typedef int8_t i8;
|
|
typedef int16_t i16;
|
|
typedef int32_t i32;
|
|
typedef int64_t i64;
|
|
|
|
typedef uint8_t b8;
|
|
typedef uint16_t b16;
|
|
typedef uint32_t b32;
|
|
typedef uint64_t b64;
|
|
|
|
#define internal static
|
|
#define global static
|
|
|
|
//= rhjr: allocator
|
|
|
|
#define ARENA_DEFAULT_SIZE 2048
|
|
|
|
typedef struct Arena
|
|
{
|
|
u8 *backing_buffer;
|
|
i64 offset;
|
|
i64 size;
|
|
}
|
|
Arena;
|
|
|
|
internal void arena_init(Arena *arena, u8 *backing_buffer, i64 size);
|
|
internal void * arena_alloc(Arena *arena, i64 size);
|
|
internal void arena_release(Arena *arena);
|
|
|
|
//= rhjr: strings
|
|
|
|
typedef struct String8 String8;
|
|
struct String8
|
|
{
|
|
u8* str;
|
|
i64 length;
|
|
};
|
|
|
|
typedef struct String8Node String8Node;
|
|
struct String8Node
|
|
{
|
|
String8Node *next;
|
|
String8 string;
|
|
};
|
|
|
|
typedef struct String8List String8List;
|
|
struct String8List
|
|
{
|
|
String8Node *first;
|
|
String8Node *last;
|
|
i64 num_of_nodes;
|
|
i64 total_length;
|
|
};
|
|
|
|
String8 str8(u8 *cstr, i64 length);
|
|
String8 str8_from_cstr(u8* cstr);
|
|
|
|
#define str8_lit(string) str8((u8*)(string), sizeof(string) - 1)
|
|
#define str8_lit_comp(string) (u8*)(string), length)
|
|
|
|
String8 str8_range (u8 *first_char, u8 *last_char);
|
|
|
|
void str8_list_push (Arena *arena, String8List *list, String8 string);
|
|
String8 str8_list_join (Arena *arena, String8List *list);
|
|
|
|
#endif // BASE_H
|