Skip to content

Commit 868b93c

Browse files
committed
bugfixes while testing with unreal (still more needs fixing
1 parent 0b03b3c commit 868b93c

15 files changed

Lines changed: 102 additions & 48 deletions

File tree

base/auxillary/builder.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ Builder builder_open( char const* path )
1515
return result;
1616
}
1717

18-
result.Buffer = strbuilder_make_reserve( _ctx->Allocator_Temp, _ctx->InitSize_BuilderBuffer );
18+
Context* ctx = get_context();
19+
GEN_ASSERT_NOT_NULL(ctx);
20+
result.Buffer = strbuilder_make_reserve( ctx->Allocator_Temp, ctx->InitSize_BuilderBuffer );
1921

2022
// log_fmt("$Builder - Opened file: %s\n", result.File.filename );
2123
return result;

base/auxillary/builder.hpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@ Builder builder_open ( char const* path );
2525
void builder_pad_lines ( Builder* builder, s32 num );
2626
void builder_print ( Builder* builder, Code code );
2727
void builder_print_fmt_va( Builder* builder, char const* fmt, va_list va );
28-
void builder_print_fmt ( Builder* builder, char const* fmt, ... ) {
28+
void builder_write ( Builder* builder );
29+
30+
forceinline void builder_print_fmt ( Builder* builder, char const* fmt, ... ) {
2931
va_list va;
3032
va_start( va, fmt );
3133
builder_print_fmt_va( builder, fmt, va );
3234
va_end( va );
3335
}
34-
void builder_write( Builder* builder );
3536

3637
struct Builder
3738
{
@@ -56,10 +57,10 @@ struct Builder
5657
};
5758

5859
#if GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP
59-
void builder_pad_lines( Builder& builder, s32 num ) { return builder_pad_lines(& builder, num); }
60-
void builder_print ( Builder& builder, Code code ) { return builder_print(& builder, code); }
61-
void builder_write ( Builder& builder ) { return builder_write(& builder ); }
62-
void builder_print_fmt( Builder& builder, char const* fmt, ...) {
60+
forceinline void builder_pad_lines( Builder& builder, s32 num ) { return builder_pad_lines(& builder, num); }
61+
forceinline void builder_print ( Builder& builder, Code code ) { return builder_print(& builder, code); }
62+
forceinline void builder_write ( Builder& builder ) { return builder_write(& builder ); }
63+
forceinline void builder_print_fmt( Builder& builder, char const* fmt, ...) {
6364
va_list va;
6465
va_start( va, fmt );
6566
builder_print_fmt_va( & builder, fmt, va );

base/auxillary/scanner.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Code scan_file( char const* path )
2020
GEN_FATAL("scan_file: %s is empty", path );
2121
}
2222

23-
StrBuilder str = strbuilder_make_reserve( _ctx->Allocator_Temp, fsize );
23+
StrBuilder str = strbuilder_make_reserve( get_context()->Allocator_Temp, fsize );
2424
file_read( & file, str, fsize );
2525
strbuilder_get_header(str)->Length = fsize;
2626

@@ -117,7 +117,7 @@ Code scan_file( char const* path )
117117
}
118118

119119
CodeBody parse_file( const char* path ) {
120-
FileContents file = file_read_contents( _ctx->Allocator_Temp, true, path );
120+
FileContents file = file_read_contents( get_context()->Allocator_Temp, true, path );
121121
Str content = { (char const*)file.data, file.size };
122122
CodeBody code = parse_global_body( content );
123123
log_fmt("\nParsed: %s\n", path);

base/components/inlines.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,9 @@ forceinline void define_params_append (CodeDefineParams appendee
262262
forceinline CodeDefineParams define_params_get (CodeDefineParams self, s32 idx ) { return (CodeDefineParams) (Code) params_get( cast(CodeParams, self), idx); }
263263
forceinline bool define_params_has_entries(CodeDefineParams self) { return params_has_entries( cast(CodeParams, self)); }
264264

265-
CodeDefineParams begin_CodeDefineParams(CodeDefineParams params) { return (CodeDefineParams) (Code) begin_CodeParams( cast(CodeParams, (Code)params)); }
266-
CodeDefineParams end_CodeDefineParams (CodeDefineParams params) { return (CodeDefineParams) (Code) end_CodeParams ( cast(CodeParams, (Code)params)); }
267-
CodeDefineParams next_CodeDefineParams (CodeDefineParams params, CodeDefineParams entry_iter) { return (CodeDefineParams) (Code) next_CodeParams ( cast(CodeParams, (Code)params), cast(CodeParams, (Code)entry_iter)); }
265+
forceinline CodeDefineParams begin_CodeDefineParams(CodeDefineParams params) { return (CodeDefineParams) (Code) begin_CodeParams( cast(CodeParams, (Code)params)); }
266+
forceinline CodeDefineParams end_CodeDefineParams (CodeDefineParams params) { return (CodeDefineParams) (Code) end_CodeParams ( cast(CodeParams, (Code)params)); }
267+
forceinline CodeDefineParams next_CodeDefineParams (CodeDefineParams params, CodeDefineParams entry_iter) { return (CodeDefineParams) (Code) next_CodeParams ( cast(CodeParams, (Code)params), cast(CodeParams, (Code)entry_iter)); }
268268

269269
#if GEN_COMPILER_CPP
270270
forceinline

base/components/interface.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,10 @@ void deinit(Context* ctx)
378378
-- context_counter;
379379
}
380380

381+
Context* get_context() {
382+
return _ctx;
383+
}
384+
381385
void reset(Context* ctx)
382386
{
383387
s32 index = 0;

base/components/interface.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ GEN_API void init(Context* ctx);
100100
// However on Windows at least, it doesn't need to occur as the OS will clean up after the process.
101101
GEN_API void deinit(Context* ctx);
102102

103+
// Retrieves the active context (not usually needed, but here in case...)
104+
GEN_API Context* get_context();
105+
103106
// Clears the allocations, but doesn't free the memoery, then calls init() again.
104107
// Ease of use.
105108
GEN_API void reset(Context* ctx);

base/components/lexer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ s32 lex_preprocessor_define( LexContext* ctx )
155155
array_append( _ctx->Lexer_Tokens, opening_paren );
156156
move_forward();
157157

158-
Token last_parameter;
158+
Token last_parameter = {};
159159
// We need to tokenize the define's arguments now:
160160
while( ctx->left && * ctx->scanner != ')')
161161
{

base/components/parser.cpp

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2490,7 +2490,40 @@ Code parse_operator_function_or_variable( bool expects_function, CodeAttributes
24902490
// Example : <Capture_Start> <Value> <Comma>
24912491
// idx +1 +2
24922492
bool detected_comma = _ctx->parser.Tokens.Arr[ _ctx->parser.Tokens.Idx + 2 ].Type == Tok_Comma;
2493-
if ( detected_capture && ! detected_comma )
2493+
2494+
b32 detected_non_varadic_unpaired_param = detected_comma && nexttok.Type != Tok_Varadic_Argument;
2495+
if (! detected_non_varadic_unpaired_param && nexttok.Type == Tok_Preprocess_Macro_Expr) for( s32 break_scope = 0; break_scope == 0; ++ break_scope)
2496+
{
2497+
Macro* macro = lookup_macro( nexttok.Text );
2498+
if (macro == nullptr || ! macro_is_functional(* macro))
2499+
break;
2500+
2501+
// ( <Macro_Expr> (
2502+
// Idx +1 +2
2503+
s32 idx = _ctx->parser.Tokens.Idx + 1;
2504+
s32 level = 0;
2505+
2506+
// Find end of the token expression
2507+
for ( ; idx < array_num(_ctx->parser.Tokens.Arr); idx++ )
2508+
{
2509+
Token tok = _ctx->parser.Tokens.Arr[ idx ];
2510+
2511+
if ( tok.Type == Tok_Capture_Start )
2512+
level++;
2513+
else if ( tok.Type == Tok_Capture_End && level > 0 )
2514+
level--;
2515+
if (level == 0 && tok.Type == Tok_Capture_End)
2516+
break;
2517+
}
2518+
++ idx; // Will incremnt to possible comma position
2519+
2520+
if ( _ctx->parser.Tokens.Arr[ idx ].Type != Tok_Comma )
2521+
break;
2522+
2523+
detected_non_varadic_unpaired_param = true;
2524+
}
2525+
2526+
if ( detected_capture && ! detected_non_varadic_unpaired_param )
24942527
{
24952528
// Dealing with a function
24962529
result = cast(Code, parse_function_after_name( ModuleFlag_None, attributes, specifiers, type, name ));
@@ -2509,7 +2542,7 @@ Code parse_operator_function_or_variable( bool expects_function, CodeAttributes
25092542
}
25102543
}
25112544

2512-
parser_pop(& _ctx->parser);
2545+
parser_pop(& _ctx->parser);
25132546
return result;
25142547
}
25152548

@@ -3002,7 +3035,7 @@ Code parse_simple_preprocess( TokType which )
30023035
|| str_contains(calling_proc, txt("parse_class_struct_body"))
30033036
)
30043037
{
3005-
if (peektok.Type == Tok_Statement_End)
3038+
if (left && peektok.Type == Tok_Statement_End)
30063039
{
30073040
Token stmt_end = currtok;
30083041
eat( Tok_Statement_End );
@@ -5015,7 +5048,6 @@ CodeTypedef parser_parse_typedef()
50155048
// valid_macro |= macro && macro_expects_body(* macro));
50165049
// }
50175050

5018-
Code macro;
50195051
if ( valid_macro )
50205052
#endif
50215053
{

base/components/parser_types.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
enum TokFlags : u32
1111
{
12-
TF_Operator = bit(0),
12+
TF_Operator = bit(0),
1313
TF_Assign = bit(1),
1414
TF_Preprocess = bit(2),
1515
TF_Preprocess_Cond = bit(3),
@@ -152,6 +152,7 @@ TokType macrotype_to_toktype( MacroType type ) {
152152
return Tok_Invalid;
153153
}
154154

155+
inline
155156
Str macrotype_to_str( MacroType type )
156157
{
157158
local_persist
@@ -216,4 +217,9 @@ b32 macro_expects_body( Macro macro ) {
216217
return bitfield_is_set( b16, macro.Flags, MF_Expects_Body );
217218
}
218219

220+
#if GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP
221+
forceinline b32 is_functional( Macro macro ) { return bitfield_is_set( b16, macro.Flags, MF_Functional ); }
222+
forceinline b32 expects_body ( Macro macro ) { return bitfield_is_set( b16, macro.Flags, MF_Expects_Body ); }
223+
#endif
224+
219225
typedef HashTable(Macro) MacroTable;

base/dependencies/containers.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ Array<Type> array_init_reserve(AllocatorInfo allocator, ssize capacity)
143143
return {rcast(Type*, header + 1)};
144144
}
145145

146+
forceinline
146147
usize array_grow_formula(ssize value) {
147148
return 2 * value + 8;
148149
}
@@ -202,7 +203,7 @@ bool array_append_at(Array<Type>* array, Type item, usize idx)
202203
ArrayHeader* header = array_get_header(* array);
203204

204205
ssize slot = idx;
205-
if (slot >= header->Num)
206+
if (slot >= (ssize)(header->Num))
206207
slot = header->Num - 1;
207208

208209
if (slot < 0)
@@ -354,7 +355,6 @@ bool array_reserve(Array<Type>* array, usize new_capacity)
354355
{
355356
GEN_ASSERT( array != nullptr);
356357
GEN_ASSERT(* array != nullptr);
357-
GEN_ASSERT(num > 0)
358358
ArrayHeader* header = array_get_header(array);
359359

360360
if (header->Capacity < new_capacity)
@@ -763,7 +763,7 @@ HashTableFindResult hashtable__find(HashTable<Type> table, u64 key)
763763
}
764764

765765
template<typename Type> forceinline
766-
bool hashtable_full(HashTable<Type> table) {
766+
b32 hashtable_full(HashTable<Type> table) {
767767
GEN_ASSERT_NOT_NULL(table.Hashes);
768768
GEN_ASSERT_NOT_NULL(table.Entries);
769769
usize critical_load = usize(HashTable_CriticalLoadScale * f32(array_num(table.Hashes)));

0 commit comments

Comments
 (0)