diff options
| author | Fabrice <fabrice@schaub-dev.xyz> | 2026-03-01 19:08:38 +0100 |
|---|---|---|
| committer | Fabrice <fabrice@schaub-dev.xyz> | 2026-03-01 19:08:38 +0100 |
| commit | 62ace5068979d4956abd2897e27eb5e078ac95dc (patch) | |
| tree | 33662761749aefad92d0a5925f2337b3375f4907 | |
| parent | caa484d1cff738aa218fea7e20c257192977e7e6 (diff) | |
string handling
| -rw-r--r-- | makefile | 2 | ||||
| -rw-r--r-- | src/common.cc | 56 | ||||
| -rw-r--r-- | src/token.cc | 22 | ||||
| -rw-r--r-- | src/voidc.cc | 2 |
4 files changed, 81 insertions, 1 deletions
@@ -9,7 +9,7 @@ PRINTF := printf # ====== Flags ====== # CCXX_FLAGS := \ -Wall -Wextra -Werror -pedantic \ - -MMD -MP + -MMD -MP -I$(SRC_DIR) CXX_FLAGS := -std=c++14 -nostdlib++ \ $(CCXX_FLAGS) -fno-rtti -fno-exceptions diff --git a/src/common.cc b/src/common.cc new file mode 100644 index 0000000..2099e24 --- /dev/null +++ b/src/common.cc @@ -0,0 +1,56 @@ +#ifndef COMMON_CC +#define COMMON_CC + +#include <cstdint> + +/* typedefs for common 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 uintptr_t usize; +typedef intptr_t isize; + +/* slice and string handling */ + +template<typename T> +struct Slice { + T* ptr; + usize length; + + slice(T* ptr, usize length) : ptr(ptr), length(length) {} + + T* operator[](usize index) { + return ptr + index; + } +}; + +typedef Slice<u8> String; + +/* allocator handling */ + +typedef u8* (*Allocator_Allocate)(u8* self, usize length, usize align); +typedef void (*Allocator_Deallocate)(u8* self, u8* ptr); + +struct Allocator { + u8* self; + Allocator_Allocate allocate; + Allocator_Deallocate deallocate; +}; + +u8* allocate(Allocator* allocator, usize size, usize align) { + return allocator->allocate(allocator->self, size, align); +} + +void deallocate(Allocator* allocator, u8* ptr) { + allocator->deallocate(allocator->self, ptr); +} + +#endif diff --git a/src/token.cc b/src/token.cc new file mode 100644 index 0000000..8217138 --- /dev/null +++ b/src/token.cc @@ -0,0 +1,22 @@ +#ifndef TOKEN_CC +#define TOKEN_CC + +#include "common.cc" + +#define TOKEN_KINDS_NOLEX \ + X(eof) \ + X(invalid_char) \ + X(invalid_literal) + +enum token_kind { +#define X(name) token_kind_##name, + TOKEN_KINDS_NOLEX +#undef X +}; + +struct token { + token_kind kind; + string text; +}; + +#endif diff --git a/src/voidc.cc b/src/voidc.cc index e9436dd..a957815 100644 --- a/src/voidc.cc +++ b/src/voidc.cc @@ -1,3 +1,5 @@ +#include "token.cc" + int main() { } |
