Bugfixes during hiatus

Found while doing some metaprogramming for day 42 of handmade hero.
This commit is contained in:
2023-10-22 21:41:36 -04:00
parent 3dd5482a46
commit 912cc6b538
6 changed files with 82 additions and 52 deletions

View File

@ -1125,7 +1125,10 @@ String AST::to_string()
if ( bitfield_is_equal( u32, ModuleFlags, ModuleFlag::Export ))
result.append( "export " );
result.append_fmt( "template< %S >\n%S", Params->to_string(), Declaration->to_string() );
if ( Params )
result.append_fmt( "template< %S >\n%S", Params->to_string(), Declaration->to_string() );
else
result.append_fmt( "template<>\n%S", Declaration->to_string() );
}
break;

View File

@ -175,21 +175,21 @@ void define_constants()
#endif
# undef def_constant_code_type
# pragma push_macro( "forceinline" )
# pragma push_macro( "global" )
# pragma push_macro( "internal" )
# pragma push_macro( "local_persist" )
# pragma push_macro( "neverinline" )
# undef forceinline
# undef global
# undef internal
# undef local_persist
# undef neverinline
# define def_constant_spec( Type_, ... ) \
spec_##Type_ = def_specifiers( num_args(__VA_ARGS__), __VA_ARGS__); \
spec_##Type_.set_global();
# pragma push_macro("forceinline")
# pragma push_macro("global")
# pragma push_macro("internal")
# pragma push_macro("local_persist")
# pragma push_macro("neverinline")
# undef forceinline
# undef global
# undef internal
# undef local_persist
# undef neverinline
def_constant_spec( const, ESpecifier::Const );
def_constant_spec( consteval, ESpecifier::Consteval );
def_constant_spec( constexpr, ESpecifier::Constexpr );
@ -218,11 +218,11 @@ void define_constants()
spec_local_persist = def_specifiers( 1, ESpecifier::Local_Persist );
spec_local_persist.set_global();
# pragma pop_macro( "forceinline" )
# pragma pop_macro( "global" )
# pragma pop_macro( "internal" )
# pragma pop_macro( "local_persist" )
# pragma pop_macro( "neverinline" )
# pragma pop_macro("forceinline")
# pragma pop_macro("global")
# pragma pop_macro("internal")
# pragma pop_macro("local_persist")
# pragma pop_macro("neverinline")
# undef def_constant_spec
}

View File

@ -775,6 +775,18 @@ namespace Parser
if (left)
move_forward();
if ( current == '=' )
{
token.Length++;
token.IsAssign = true;
// token.Flags |= TokFlags::Assignment;
// token.Type = TokType::Assign_Multiply;
if ( left )
move_forward();
}
goto FoundToken;
}
case ';':
@ -973,7 +985,14 @@ namespace Parser
if ( left )
{
if ( current == '/' )
if ( current == '=' )
{
// token.Type = TokeType::Assign_Divide;
move_forward();
token.Length++;
token.IsAssign = true;
}
else if ( current == '/' )
{
token.Type = TokType::Comment;
token.Length = 2;
@ -2820,7 +2839,7 @@ CodeOperator parse_operator_after_ret_type(
if ( currtok.Text[1] == '=' )
op = Assign_Add;
if ( currtok.Text[1] == '+' )
else if ( currtok.Text[1] == '+' )
op = Increment;
else
@ -2840,7 +2859,7 @@ CodeOperator parse_operator_after_ret_type(
break;
}
if ( currtok.Text[1] == '=' )
else if ( currtok.Text[1] == '=' )
op = Assign_Subtract;
else
@ -3196,6 +3215,12 @@ CodeParam parse_params( bool use_template_capture )
Context.pop();
return { nullptr };
}
else if ( check ( TokType::Operator ) && currtok.Text[0] == '>' )
{
eat( TokType::Operator );
Context.pop();
return { nullptr };
}
CodeType type = { nullptr };
Code value = { nullptr };

View File

@ -35,17 +35,17 @@ OpValidateResult operator__validate( OperatorT op, CodeParam params_code, CodeTy
return OpValidateResult::Fail; \
}
# define check_param_eq_ret() \
if ( ! is_member_symbol && params_code->ValueType != ret_type ) \
{ \
log_failure("gen_def_operator: operator%s requires first parameter to equal return type\n" \
"param types: %s\n" \
"return type: %s", \
to_str(op), \
params_code.debug_str(), \
ret_type.debug_str() \
); \
return OpValidateResult::Fail; \
# define check_param_eq_ret() \
if ( ! is_member_symbol && ! params_code->ValueType.is_equal( ret_type) ) \
{ \
log_failure("gen::def_operator: operator%s requires first parameter to equal return type\n" \
"param types: %s\n" \
"return type: %s", \
to_str(op).Ptr, \
params_code.debug_str(), \
ret_type.debug_str() \
); \
return OpValidateResult::Fail; \
}
#pragma endregion Helper Macros
@ -947,6 +947,7 @@ CodeOperator def_operator( OperatorT op, StrC nspace
result = (CodeOperator) make_code();
result->Name = get_cached_string( { str_len(name), name } );
result->ModuleFlags = mflags;
result->Op = op;
if ( body )
{