mirror of
				https://github.com/Ed94/gencpp.git
				synced 2025-10-31 06:50:53 -07:00 
			
		
		
		
	Finished first pass reviewing memory.hpp for C lib generation
This commit is contained in:
		| @@ -165,6 +165,46 @@ struct CodeSpecifiers | ||||
|  | ||||
| 		return -1; | ||||
| 	} | ||||
| 	s32 remove( SpecifierT to_remove ) | ||||
| 	{ | ||||
| 		if ( ast == nullptr ) | ||||
| 		{ | ||||
| 			log_failure("CodeSpecifiers: Attempted to append to a null specifiers AST!"); | ||||
| 			return -1; | ||||
| 		} | ||||
|  | ||||
| 		if ( raw()->NumEntries == AST::ArrSpecs_Cap ) | ||||
| 		{ | ||||
| 			log_failure("CodeSpecifiers: Attempted to append over %d specifiers to a specifiers AST!", AST::ArrSpecs_Cap ); | ||||
| 			return -1; | ||||
| 		} | ||||
|  | ||||
| 		s32 result = -1; | ||||
|  | ||||
| 		s32 curr = 0; | ||||
| 		s32 next = 0; | ||||
| 		for(; next < raw()->NumEntries; ++ curr, ++ next) | ||||
| 		{ | ||||
| 			SpecifierT spec = raw()->ArrSpecs[next]; | ||||
| 			if (spec == to_remove) | ||||
| 			{ | ||||
| 				result = next; | ||||
|  | ||||
| 				next ++; | ||||
| 				if (next >= raw()->NumEntries) | ||||
| 					break; | ||||
|  | ||||
| 				spec = raw()->ArrSpecs[next]; | ||||
| 			} | ||||
|  | ||||
| 			raw()->ArrSpecs[ curr ] = spec; | ||||
| 		} | ||||
|  | ||||
| 		if (result > -1) { | ||||
| 			raw()->NumEntries --; | ||||
| 		} | ||||
| 		return result; | ||||
| 	} | ||||
| 	void to_string( String& result ); | ||||
| 	AST* raw() | ||||
| 	{ | ||||
|   | ||||
| @@ -133,6 +133,7 @@ extern CodeType t_typename; | ||||
|  | ||||
| #pragma region Macros | ||||
|  | ||||
| #ifndef token_fmt | ||||
| #	define gen_main main | ||||
|  | ||||
| #	define __ NoCode | ||||
| @@ -151,6 +152,7 @@ extern CodeType t_typename; | ||||
|  | ||||
| 	// Takes a format string (char const*) and a list of tokens (StrC) and returns a StrC of the formatted string. | ||||
| #	define token_fmt( ... ) GEN_NS token_fmt_impl( (num_args( __VA_ARGS__ ) + 1) / 2, __VA_ARGS__ ) | ||||
| #endif | ||||
|  | ||||
| #pragma endregion Macros | ||||
|  | ||||
|   | ||||
| @@ -714,8 +714,8 @@ Code parse_class_struct( TokType which, bool inplace_def = false ) | ||||
| 	char interface_arr_mem[ kilobytes(4) ] {0}; | ||||
| 	Array<CodeType> interfaces; { | ||||
| 		Arena arena = arena_init_from_memory( interface_arr_mem, kilobytes(4) ); | ||||
| 		array_init_reserve<CodeType>( allocator_info(arena), 4 ); | ||||
| 	}  | ||||
| 		interfaces  = array_init_reserve<CodeType>( allocator_info(arena), 4 ); | ||||
| 	} | ||||
|  | ||||
| 	// TODO(Ed) : Make an AST_DerivedType, we'll store any arbitary derived type into there as a linear linked list of them. | ||||
| 	if ( check( TokType::Assign_Classifer ) ) | ||||
|   | ||||
| @@ -123,8 +123,8 @@ typedef s8  b8; | ||||
| typedef s16 b16; | ||||
| typedef s32 b32; | ||||
|  | ||||
| using mem_ptr       = void*; | ||||
| using mem_ptr_const = void const*; | ||||
| typedef void*       mem_ptr; | ||||
| typedef void const* mem_ptr_const ; | ||||
|  | ||||
| #if ! GEN_COMPILER_C | ||||
| template<typename Type> uptr to_uptr( Type* ptr ) { return (uptr)ptr; } | ||||
|   | ||||
| @@ -52,9 +52,9 @@ template<class Type> bool         resize(Array<Type>& array, usize num); | ||||
| template<class Type> bool         set_capacity(Array<Type>& array, usize new_capacity); | ||||
| template<class Type> ArrayHeader* get_header(Array<Type>& array); | ||||
|  | ||||
| template<class Type> forceinline Type* begin(Array<Type>& array) { return array;      } | ||||
| template<class Type> forceinline Type* end(Array<Type>& array)   { return array + get_header(array)->Num; } | ||||
| template<class Type> forceinline Type* next(Type* entry)         { return entry + 1; } | ||||
| template<class Type> forceinline Type* begin(Array<Type>& array)             { return array;      } | ||||
| template<class Type> forceinline Type* end(Array<Type>& array)               { return array + get_header(array)->Num; } | ||||
| template<class Type> forceinline Type* next(Array<Type>& array, Type* entry) { return entry + 1; } | ||||
|  | ||||
| struct ArrayHeader { | ||||
| 	AllocatorInfo Allocator; | ||||
| @@ -250,7 +250,7 @@ bool fill(Array<Type>& array, usize begin, usize end, Type value) | ||||
| template<class Type> inline | ||||
| void free(Array<Type>& array) { | ||||
| 	ArrayHeader* header = get_header(array); | ||||
| 	gen::free(header->Allocator, header); | ||||
| 	GEN_NS free(header->Allocator, header); | ||||
| 	Type*& Data = rcast(Type*&, array); | ||||
| 	Data = nullptr; | ||||
| } | ||||
|   | ||||
| @@ -200,7 +200,7 @@ | ||||
| // This is intended to only really be used internally or with the C-library variant | ||||
| // C++ users can just use the for-range directly. | ||||
| #if GEN_COMPILER_C | ||||
| #	define foreach(Type, entry_id, iterable) for ( Type entry_id = begin(iterable); entry_id != end(iterable); entry_id = next(entry_id) ) | ||||
| #	define foreach(Type, entry_id, iterable) for ( Type entry_id = begin(iterable); entry_id != end(iterable); entry_id = next(iterable, entry_id) ) | ||||
| #else | ||||
| #	define foreach(Type, entry_id, iterable) for ( Type entry_id : iterable ) | ||||
| #endif | ||||
|   | ||||
| @@ -80,10 +80,7 @@ enum AllocType : u8 | ||||
| 	EAllocation_RESIZE, | ||||
| }; | ||||
|  | ||||
| using AllocatorProc = void* ( void* allocator_data, AllocType type | ||||
| 	, ssize size, ssize alignment | ||||
| 	, void* old_memory, ssize old_size | ||||
| 	, u64 flags ); | ||||
| typedef void*(AllocatorProc)( void* allocator_data, AllocType type, ssize size, ssize alignment, void* old_memory, ssize old_size, u64 flags ); | ||||
|  | ||||
| struct AllocatorInfo | ||||
| { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user