2023-08-28 20:46:50 -07:00
|
|
|
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
2023-08-21 17:30:13 -07:00
|
|
|
#pragma once
|
2023-08-21 20:02:20 -07:00
|
|
|
#include "inlines.hpp"
|
2023-08-21 20:28:39 -07:00
|
|
|
#include "gen/ast_inlines.hpp"
|
2023-08-28 20:46:50 -07:00
|
|
|
#endif
|
2023-08-21 17:30:13 -07:00
|
|
|
|
2023-07-24 14:45:27 -07:00
|
|
|
#pragma region Constants
|
2023-07-28 18:44:31 -07:00
|
|
|
|
2023-07-24 14:45:27 -07:00
|
|
|
#ifndef GEN_GLOBAL_BUCKET_SIZE
|
2023-10-25 00:26:25 -07:00
|
|
|
# define GEN_GLOBAL_BUCKET_SIZE megabytes(8)
|
2023-07-24 14:45:27 -07:00
|
|
|
#endif
|
|
|
|
#ifndef GEN_CODEPOOL_NUM_BLOCKS
|
2023-08-21 20:49:23 -07:00
|
|
|
# define GEN_CODEPOOL_NUM_BLOCKS kilobytes(16)
|
2023-07-24 14:45:27 -07:00
|
|
|
#endif
|
|
|
|
#ifndef GEN_SIZE_PER_STRING_ARENA
|
|
|
|
# define GEN_SIZE_PER_STRING_ARENA megabytes(1)
|
|
|
|
#endif
|
|
|
|
#ifndef GEN_MAX_COMMENT_LINE_LENGTH
|
|
|
|
# define GEN_MAX_COMMENT_LINE_LENGTH 1024
|
|
|
|
#endif
|
|
|
|
#ifndef GEN_MAX_NAME_LENGTH
|
|
|
|
# define GEN_MAX_NAME_LENGTH 128
|
|
|
|
#endif
|
|
|
|
#ifndef GEN_MAX_UNTYPED_STR_LENGTH
|
2023-07-25 12:12:51 -07:00
|
|
|
# define GEN_MAX_UNTYPED_STR_LENGTH megabytes(1)
|
2023-07-24 14:45:27 -07:00
|
|
|
#endif
|
|
|
|
#ifndef GEN_TOKEN_FMT_TOKEN_MAP_MEM_SIZE
|
|
|
|
# define GEN_TOKEN_FMT_TOKEN_MAP_MEM_SIZE kilobytes(4)
|
|
|
|
#endif
|
|
|
|
#ifndef GEN_LEX_ALLOCATOR_SIZE
|
2023-08-21 20:49:23 -07:00
|
|
|
# define GEN_LEX_ALLOCATOR_SIZE megabytes(4)
|
2023-07-24 14:45:27 -07:00
|
|
|
#endif
|
|
|
|
#ifndef GEN_BUILDER_STR_BUFFER_RESERVE
|
2023-10-25 00:26:25 -07:00
|
|
|
# define GEN_BUILDER_STR_BUFFER_RESERVE megabytes(2)
|
2023-07-24 14:45:27 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// These constexprs are used for allocation behavior of data structures
|
|
|
|
// or string handling while constructing or serializing.
|
|
|
|
// Change them to suit your needs.
|
|
|
|
|
|
|
|
constexpr s32 InitSize_DataArrays = 16;
|
|
|
|
|
|
|
|
// NOTE: This limits the maximum size of an allocation
|
|
|
|
// If you are generating a string larger than this, increase the size of the bucket here.
|
2024-10-27 15:58:37 -07:00
|
|
|
constexpr usize Global_BucketSize = GEN_GLOBAL_BUCKET_SIZE;
|
2023-07-24 14:45:27 -07:00
|
|
|
constexpr s32 CodePool_NumBlocks = GEN_CODEPOOL_NUM_BLOCKS;
|
|
|
|
constexpr s32 SizePer_StringArena = GEN_SIZE_PER_STRING_ARENA;
|
|
|
|
|
|
|
|
constexpr s32 MaxCommentLineLength = GEN_MAX_COMMENT_LINE_LENGTH;
|
|
|
|
constexpr s32 MaxNameLength = GEN_MAX_NAME_LENGTH;
|
|
|
|
constexpr s32 MaxUntypedStrLength = GEN_MAX_UNTYPED_STR_LENGTH;
|
|
|
|
constexpr s32 TokenFmt_TokenMap_MemSize = GEN_TOKEN_FMT_TOKEN_MAP_MEM_SIZE;
|
|
|
|
constexpr s32 LexAllocator_Size = GEN_LEX_ALLOCATOR_SIZE;
|
|
|
|
constexpr s32 Builder_StrBufferReserve = GEN_BUILDER_STR_BUFFER_RESERVE;
|
|
|
|
|
|
|
|
extern Code access_public;
|
|
|
|
extern Code access_protected;
|
|
|
|
extern Code access_private;
|
|
|
|
|
2023-07-29 22:21:04 -07:00
|
|
|
extern CodeAttributes attrib_api_export;
|
|
|
|
extern CodeAttributes attrib_api_import;
|
|
|
|
|
2023-07-24 14:45:27 -07:00
|
|
|
extern Code module_global_fragment;
|
|
|
|
extern Code module_private_fragment;
|
|
|
|
|
2023-08-04 13:12:13 -07:00
|
|
|
extern Code fmt_newline;
|
|
|
|
|
2023-07-29 22:21:04 -07:00
|
|
|
extern CodePragma pragma_once;
|
|
|
|
|
|
|
|
extern CodeParam param_varadic;
|
|
|
|
|
|
|
|
extern CodePreprocessCond preprocess_else;
|
|
|
|
extern CodePreprocessCond preprocess_endif;
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
extern CodeSpecifiers spec_const;
|
|
|
|
extern CodeSpecifiers spec_consteval;
|
|
|
|
extern CodeSpecifiers spec_constexpr;
|
|
|
|
extern CodeSpecifiers spec_constinit;
|
|
|
|
extern CodeSpecifiers spec_extern_linkage;
|
|
|
|
extern CodeSpecifiers spec_final;
|
2023-08-21 18:40:23 -07:00
|
|
|
extern CodeSpecifiers spec_forceinline;
|
2023-07-24 14:45:27 -07:00
|
|
|
extern CodeSpecifiers spec_global;
|
|
|
|
extern CodeSpecifiers spec_inline;
|
|
|
|
extern CodeSpecifiers spec_internal_linkage;
|
|
|
|
extern CodeSpecifiers spec_local_persist;
|
|
|
|
extern CodeSpecifiers spec_mutable;
|
2023-08-02 09:39:35 -07:00
|
|
|
extern CodeSpecifiers spec_neverinline;
|
2023-09-11 20:22:53 -07:00
|
|
|
extern CodeSpecifiers spec_noexcept;
|
2023-07-24 14:45:27 -07:00
|
|
|
extern CodeSpecifiers spec_override;
|
|
|
|
extern CodeSpecifiers spec_ptr;
|
2023-08-07 00:10:45 -07:00
|
|
|
extern CodeSpecifiers spec_pure;
|
2023-07-24 14:45:27 -07:00
|
|
|
extern CodeSpecifiers spec_ref;
|
|
|
|
extern CodeSpecifiers spec_register;
|
|
|
|
extern CodeSpecifiers spec_rvalue;
|
|
|
|
extern CodeSpecifiers spec_static_member;
|
|
|
|
extern CodeSpecifiers spec_thread_local;
|
|
|
|
extern CodeSpecifiers spec_virtual;
|
|
|
|
extern CodeSpecifiers spec_volatile;
|
2023-07-28 18:44:31 -07:00
|
|
|
|
2023-07-29 22:21:04 -07:00
|
|
|
extern CodeType t_empty; // Used with varaidc parameters. (Exposing just in case its useful for another circumstance)
|
|
|
|
extern CodeType t_auto;
|
|
|
|
extern CodeType t_void;
|
|
|
|
extern CodeType t_int;
|
|
|
|
extern CodeType t_bool;
|
|
|
|
extern CodeType t_char;
|
|
|
|
extern CodeType t_wchar_t;
|
|
|
|
extern CodeType t_class;
|
|
|
|
extern CodeType t_typename;
|
|
|
|
|
|
|
|
#ifdef GEN_DEFINE_LIBRARY_CODE_CONSTANTS
|
|
|
|
// Predefined typename codes. Are set to readonly and are setup during gen::init()
|
|
|
|
|
|
|
|
extern CodeType t_b32;
|
|
|
|
|
|
|
|
extern CodeType t_s8;
|
|
|
|
extern CodeType t_s16;
|
|
|
|
extern CodeType t_s32;
|
|
|
|
extern CodeType t_s64;
|
|
|
|
|
|
|
|
extern CodeType t_u8;
|
|
|
|
extern CodeType t_u16;
|
|
|
|
extern CodeType t_u32;
|
|
|
|
extern CodeType t_u64;
|
|
|
|
|
2024-10-27 15:58:37 -07:00
|
|
|
extern CodeType t_ssize;
|
|
|
|
extern CodeType t_usize;
|
2023-07-29 22:21:04 -07:00
|
|
|
|
|
|
|
extern CodeType t_f32;
|
|
|
|
extern CodeType t_f64;
|
|
|
|
#endif
|
|
|
|
|
2023-07-24 14:45:27 -07:00
|
|
|
#pragma endregion Constants
|
|
|
|
|
|
|
|
#pragma region Macros
|
2023-07-28 18:44:31 -07:00
|
|
|
|
2024-11-30 20:38:27 -08:00
|
|
|
#ifndef token_fmt
|
2023-07-24 14:45:27 -07:00
|
|
|
# define gen_main main
|
|
|
|
|
|
|
|
# define __ NoCode
|
|
|
|
|
|
|
|
// Convienence for defining any name used with the gen api.
|
|
|
|
// Lets you provide the length and string literal to the functions without the need for the DSL.
|
|
|
|
# define name( Id_ ) { sizeof(stringize( Id_ )) - 1, stringize(Id_) }
|
|
|
|
|
|
|
|
// Same as name just used to indicate intention of literal for code instead of names.
|
|
|
|
# define code( ... ) { sizeof(stringize(__VA_ARGS__)) - 1, stringize( __VA_ARGS__ ) }
|
|
|
|
|
|
|
|
# define args( ... ) num_args( __VA_ARGS__ ), __VA_ARGS__
|
|
|
|
|
2023-08-21 18:40:23 -07:00
|
|
|
# define code_str( ... ) GEN_NS untyped_str( code( __VA_ARGS__ ) )
|
|
|
|
# define code_fmt( ... ) GEN_NS untyped_str( token_fmt( __VA_ARGS__ ) )
|
2023-07-24 14:45:27 -07:00
|
|
|
|
|
|
|
// Takes a format string (char const*) and a list of tokens (StrC) and returns a StrC of the formatted string.
|
2023-08-21 18:40:23 -07:00
|
|
|
# define token_fmt( ... ) GEN_NS token_fmt_impl( (num_args( __VA_ARGS__ ) + 1) / 2, __VA_ARGS__ )
|
2024-11-30 20:38:27 -08:00
|
|
|
#endif
|
2023-07-28 18:44:31 -07:00
|
|
|
|
2023-07-24 14:45:27 -07:00
|
|
|
#pragma endregion Macros
|
|
|
|
|
2023-11-21 17:09:14 -08:00
|
|
|
// Used by the lexer to persistently treat all these identifiers as preprocessor defines.
|
|
|
|
// Populate with strings via gen::get_cached_string.
|
|
|
|
// Functional defines must have format: id( ;at minimum to indicate that the define is only valid with arguments.
|
|
|
|
extern Array< StringCached > PreprocessorDefines;
|
|
|
|
|
2023-07-24 14:45:27 -07:00
|
|
|
#ifdef GEN_EXPOSE_BACKEND
|
2023-07-28 18:44:31 -07:00
|
|
|
|
2023-07-24 14:45:27 -07:00
|
|
|
// Global allocator used for data with process lifetime.
|
|
|
|
extern AllocatorInfo GlobalAllocator;
|
|
|
|
extern Array< Arena > Global_AllocatorBuckets;
|
2023-08-03 08:01:43 -07:00
|
|
|
|
2023-07-24 14:45:27 -07:00
|
|
|
extern Array< Pool > CodePools;
|
|
|
|
extern Array< Arena > StringArenas;
|
|
|
|
|
|
|
|
extern StringTable StringCache;
|
|
|
|
|
|
|
|
extern Arena LexArena;
|
|
|
|
|
|
|
|
extern AllocatorInfo Allocator_DataArrays;
|
|
|
|
extern AllocatorInfo Allocator_CodePool;
|
|
|
|
extern AllocatorInfo Allocator_Lexer;
|
|
|
|
extern AllocatorInfo Allocator_StringArena;
|
|
|
|
extern AllocatorInfo Allocator_StringTable;
|
|
|
|
extern AllocatorInfo Allocator_TypeTable;
|
2023-07-28 18:44:31 -07:00
|
|
|
|
2023-07-24 14:45:27 -07:00
|
|
|
#endif
|