diff --git a/src/compiler/compiler.c b/src/compiler/compiler.c index 91c8b1cd8..0b710dcd6 100644 --- a/src/compiler/compiler.c +++ b/src/compiler/compiler.c @@ -223,19 +223,8 @@ static const char *dynamic_lib_name(void) { return str_cat(name, compiler.build.extension); } - - switch (compiler.build.arch_os_target) - { - case WINDOWS_AARCH64: - case WINDOWS_X64: - case MINGW_X64: - return str_cat(name, ".dll"); - case MACOS_X64: - case MACOS_AARCH64: - return str_cat(name, ".dylib"); - default: - return str_cat(name, ".so"); - } + + return str_cat(name, compiler.platform.dylib_suffix); } const char *static_lib_name(void) diff --git a/src/compiler/compiler.h b/src/compiler/compiler.h index 89386ee34..cbb04d318 100644 --- a/src/compiler/compiler.h +++ b/src/compiler/compiler.h @@ -13,7 +13,7 @@ void compile_clean(BuildOptions *options); void execute_scripts(void); void init_build_target(BuildTarget *build_target, BuildOptions *build_options); void init_default_build_target(BuildTarget *target, BuildOptions *options); -void symtab_init(uint32_t max_size); +void symtab_init(uint32_t capacity); void symtab_destroy(); void print_syntax(BuildOptions *options); void vendor_fetch(BuildOptions *options); diff --git a/src/compiler/compiler_internal.h b/src/compiler/compiler_internal.h index 0c7a6cef1..9c6064869 100644 --- a/src/compiler/compiler_internal.h +++ b/src/compiler/compiler_internal.h @@ -2367,7 +2367,7 @@ void unit_register_global_decl(CompilationUnit *unit, Decl *decl); void unit_register_external_symbol(SemaContext *context, Decl *decl); bool unit_add_import(CompilationUnit *unit, Path *path, bool private_import, bool is_non_recursive); -bool unit_add_alias(CompilationUnit *unit, Decl *decl); +bool unit_add_alias(CompilationUnit *unit, Decl *alias); bool context_set_module_from_filename(ParseContext *context); bool context_set_module(ParseContext *context, Path *path); bool context_is_macro(SemaContext *context); @@ -2559,7 +2559,7 @@ Decl *sema_resolve_method(Decl *type, const char *method_name); Decl *sema_resolve_method_only(Decl *type, const char *method_name); Decl *sema_find_extension_method_in_list(Decl **extensions, Type *type, const char *method_name); bool sema_resolve_type_decl(SemaContext *context, Type *type); -bool sema_check_type_variable_array(SemaContext *context, TypeInfo *type); +bool sema_check_type_variable_array(SemaContext *context, TypeInfo *type_info); Decl *sema_find_symbol(SemaContext *context, const char *symbol); Decl *sema_find_template_symbol(SemaContext *context, const char *symbol, Path *path); Decl *sema_find_path_symbol(SemaContext *context, const char *symbol, Path *path); diff --git a/src/compiler/llvm_codegen.c b/src/compiler/llvm_codegen.c index e4b8d4297..90f4d4909 100644 --- a/src/compiler/llvm_codegen.c +++ b/src/compiler/llvm_codegen.c @@ -1775,9 +1775,9 @@ static GenContext *llvm_gen_module(Module *module, LLVMContextRef shared_context return gen_context; } -void llvm_attribute_add_int(GenContext *context, LLVMValueRef value_to_add_attribute_to, unsigned attribute, uint64_t val, int index) +void llvm_attribute_add_int(GenContext *c, LLVMValueRef value_to_add_attribute_to, unsigned attribute, uint64_t val, int index) { - LLVMAttributeRef llvm_attr = LLVMCreateEnumAttribute(context->context, attribute, val); + LLVMAttributeRef llvm_attr = LLVMCreateEnumAttribute(c->context, attribute, val); LLVMAddAttributeAtIndex(value_to_add_attribute_to, (LLVMAttributeIndex)index, llvm_attr); } diff --git a/src/compiler/llvm_codegen_expr.c b/src/compiler/llvm_codegen_expr.c index d108bde70..7df5136ad 100644 --- a/src/compiler/llvm_codegen_expr.c +++ b/src/compiler/llvm_codegen_expr.c @@ -6341,12 +6341,12 @@ EARLY_EXIT: } -LLVMValueRef llvm_emit_call_intrinsic(GenContext *context, unsigned intrinsic, LLVMTypeRef *types, unsigned type_count, +LLVMValueRef llvm_emit_call_intrinsic(GenContext *c, unsigned intrinsic, LLVMTypeRef *types, unsigned type_count, LLVMValueRef *values, unsigned arg_count) { - LLVMValueRef decl = LLVMGetIntrinsicDeclaration(context->module, intrinsic, types, type_count); - LLVMTypeRef type = LLVMIntrinsicGetType(context->context, intrinsic, types, type_count); - return LLVMBuildCall2(context->builder, type, decl, values, arg_count, ""); + LLVMValueRef decl = LLVMGetIntrinsicDeclaration(c->module, intrinsic, types, type_count); + LLVMTypeRef type = LLVMIntrinsicGetType(c->context, intrinsic, types, type_count); + return LLVMBuildCall2(c->builder, type, decl, values, arg_count, ""); } static inline void llvm_emit_optional(GenContext *c, BEValue *be_value, Expr *expr) diff --git a/src/compiler/llvm_codegen_internal.h b/src/compiler/llvm_codegen_internal.h index 6f973323d..d4ac5e32e 100644 --- a/src/compiler/llvm_codegen_internal.h +++ b/src/compiler/llvm_codegen_internal.h @@ -365,7 +365,7 @@ bool llvm_types_are_similar(LLVMTypeRef original, LLVMTypeRef coerce); // -- Attributes --- void llvm_attribute_add_range(GenContext *c, LLVMValueRef value_to_add_attribute_to, unsigned attribute, int index_start, int index_end); void llvm_attribute_add(GenContext *c, LLVMValueRef value_to_add_attribute_to, unsigned attribute, int index); -void llvm_attribute_add_call(GenContext *context, LLVMValueRef call, unsigned attribute, int index, int64_t value); +void llvm_attribute_add_call(GenContext *c, LLVMValueRef call, unsigned attribute, int index, int64_t value); void llvm_attribute_add_call_type(GenContext *c, LLVMValueRef call, unsigned attribute, int index, LLVMTypeRef type); void llvm_attribute_add_string(GenContext *c, LLVMValueRef value_to_add_attribute_to, const char *attribute, const char *value, int index); void llvm_attribute_add_type(GenContext *c, LLVMValueRef value_to_add_attribute_to, unsigned attribute, LLVMTypeRef type, int index); diff --git a/src/compiler/sema_internal.h b/src/compiler/sema_internal.h index 22b1214eb..07fcae40e 100644 --- a/src/compiler/sema_internal.h +++ b/src/compiler/sema_internal.h @@ -66,7 +66,7 @@ unsigned sema_context_push_ct_stack(SemaContext *context); void sema_context_pop_ct_stack(SemaContext *context, unsigned old_state); bool sema_analyse_function_body(SemaContext *context, Decl *func); -bool sema_analyse_contracts(SemaContext *context, AstId doc, AstId **asserts, SourceSpan span, bool *has_ensures); +bool sema_analyse_contracts(SemaContext *context, AstId doc, AstId **asserts, SourceSpan call_span, bool *has_ensures); void sema_append_contract_asserts(AstId assert_first, Ast* compound_stmt); Decl *sema_create_runner_main(SemaContext *context, Decl *decl); diff --git a/src/compiler/sema_passes.c b/src/compiler/sema_passes.c index d481b450f..38f148cfb 100644 --- a/src/compiler/sema_passes.c +++ b/src/compiler/sema_passes.c @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Christoffer Lerno. All rights reserved. +// Copyright (c) 2020-2026 Christoffer Lerno. All rights reserved. // Use of this source code is governed by a LGPLv3.0 // a copy of which can be found in the LICENSE file. diff --git a/src/compiler/sema_stmts.c b/src/compiler/sema_stmts.c index b47e8a843..2369911ef 100644 --- a/src/compiler/sema_stmts.c +++ b/src/compiler/sema_stmts.c @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Christoffer Lerno. All rights reserved. +// Copyright (c) 2020-2026 Christoffer Lerno. All rights reserved. // Use of this source code is governed by a LGPLv3.0 // a copy of which can be found in the LICENSE file. @@ -104,6 +104,7 @@ static inline bool sema_analyse_asm_stmt(SemaContext *context, Ast *stmt) static inline bool sema_analyse_assert_stmt(SemaContext *context, Ast *statement) { Expr *expr = exprptr(statement->assert_stmt.expr); + assert(expr != NULL); // Verify that the message is a string if it exists. Expr *message_expr = exprptrzero(statement->assert_stmt.message); diff --git a/src/compiler/sema_types.c b/src/compiler/sema_types.c index 908df2113..36fe6987d 100644 --- a/src/compiler/sema_types.c +++ b/src/compiler/sema_types.c @@ -464,7 +464,6 @@ INLINE bool sema_resolve_generic_type(SemaContext *context, TypeInfo *type_info) default: break; } - bool was_recursive = false; if (compiler.generic_depth >= MAX_GENERIC_DEPTH) { RETURN_SEMA_ERROR(type_info, "Generic resolution of this type has become deeply nested, it was aborted after reaching %d recursions.", compiler.generic_depth); @@ -474,10 +473,10 @@ INLINE bool sema_resolve_generic_type(SemaContext *context, TypeInfo *type_info) inner->span, type_info->generic.params, type_info->span); compiler.generic_depth--; if (!decl_ok(type)) return false; - if (!sema_analyse_decl(context, type)) return false; ASSERT_SPAN(type_info, type != NULL); + if (!sema_analyse_decl(context, type)) return false; type_info->type = type->type; - if (!was_recursive) return true; + if (compiler.generic_depth == 0) return true; if (!context->current_macro && (context->call_env.kind == CALL_ENV_FUNCTION || context->call_env.kind == CALL_ENV_FUNCTION_STATIC) && !context->call_env.current_function->func_decl.in_macro) { diff --git a/src/compiler/target.c b/src/compiler/target.c index 62d0c7e9a..fa799bbaf 100644 --- a/src/compiler/target.c +++ b/src/compiler/target.c @@ -14,8 +14,8 @@ static bool cpu_features_contains(CpuFeatures *cpu_features, int feature); static ObjectFormatType object_format_from_os(OsType os, ArchType arch_type); static unsigned arch_pointer_bit_width(OsType os, ArchType arch); static unsigned arch_int_register_bit_width(OsType os, ArchType arch); -static ArchType arch_from_llvm_string(StringSlice string); -static EnvironmentType environment_type_from_llvm_string(StringSlice string); +static ArchType arch_from_llvm_string(StringSlice slice); +static EnvironmentType environment_type_from_llvm_string(StringSlice env); static bool arch_is_supported(ArchType arch); static unsigned os_target_c_type_bits(OsType os, ArchType arch, CType type); static AlignData os_target_alignment_of_int(OsType os, ArchType arch, uint32_t bits); @@ -2140,21 +2140,21 @@ FOUND:; } -void target_setup(BuildTarget *target) +void target_setup(BuildTarget *build_target) { - if (target->win.def && !file_exists(target->win.def)) + if (build_target->win.def && !file_exists(build_target->win.def)) { - error_exit("Failed to find Windows def file: '%s' in path.", target->win.def); + error_exit("Failed to find Windows def file: '%s' in path.", build_target->win.def); } #ifndef XTENSA_ENABLE - if (target->arch_os_target == ELF_XTENSA) + if (build_target->arch_os_target == ELF_XTENSA) { error_exit("Xtensa support is not available with this LLVM version."); } #endif - compiler.platform.target_triple = arch_to_target_triple(target->arch_os_target, target->linuxpaths.libc); + compiler.platform.target_triple = arch_to_target_triple(build_target->arch_os_target, build_target->linuxpaths.libc); ASSERT(compiler.platform.target_triple); compiler.platform.alloca_address_space = 0; @@ -2163,7 +2163,7 @@ void target_setup(BuildTarget *target) // Create a specific target machine LLVMCodeGenOptLevel level; - switch (target->optlevel) + switch (build_target->optlevel) { case OPTIMIZATION_NOT_SET: UNREACHABLE_VOID; @@ -2205,9 +2205,9 @@ void target_setup(BuildTarget *target) compiler.platform.environment_type = environment_type_from_llvm_string(target_triple_string); if (compiler.platform.environment_type == ENV_TYPE_ANDROID) compiler.platform.os = OS_TYPE_ANDROID; - if (target->debug_info == DEBUG_INFO_NOT_SET) + if (build_target->debug_info == DEBUG_INFO_NOT_SET) { - target->debug_info = DEBUG_INFO_FULL; + build_target->debug_info = DEBUG_INFO_FULL; } compiler.platform.float_abi = false; @@ -2267,7 +2267,7 @@ void target_setup(BuildTarget *target) break; case ARCH_TYPE_WASM32: case ARCH_TYPE_WASM64: - target_setup_wasm_abi(target); + target_setup_wasm_abi(build_target); break; case ARCH_TYPE_ARMB: case ARCH_TYPE_ARM: @@ -2297,13 +2297,13 @@ void target_setup(BuildTarget *target) break; case ARCH_TYPE_RISCV64: case ARCH_TYPE_RISCV32: - target_setup_riscv_abi(target); + target_setup_riscv_abi(build_target); break; case ARCH_TYPE_X86: - target_setup_x86_abi(target); + target_setup_x86_abi(build_target); break; case ARCH_TYPE_X86_64: - target_setup_x64_abi(target); + target_setup_x64_abi(build_target); if (compiler.platform.os == OS_TYPE_WIN32) { compiler.platform.abi = ABI_WIN64; @@ -2328,11 +2328,12 @@ void target_setup(BuildTarget *target) compiler.platform.environment_type, compiler.build.type != TARGET_TYPE_EXECUTABLE); compiler.platform.pic_required = arch_os_pic_default_forced(compiler.platform.arch, compiler.platform.os); + compiler.platform.dylib_suffix = os_dynamic_library_suffix(compiler.platform.os); // Override PIC, but only if the platform does not require PIC - if (target->reloc_model != RELOC_DEFAULT - && (target->reloc_model != RELOC_NONE || !compiler.platform.pic_required)) + if (build_target->reloc_model != RELOC_DEFAULT + && (build_target->reloc_model != RELOC_NONE || !compiler.platform.pic_required)) { - compiler.platform.reloc_model = target->reloc_model; + compiler.platform.reloc_model = build_target->reloc_model; } if (compiler.platform.os == OS_TYPE_IOS) diff --git a/src/compiler/target.h b/src/compiler/target.h index 1716135c0..9721246d4 100644 --- a/src/compiler/target.h +++ b/src/compiler/target.h @@ -69,6 +69,7 @@ typedef struct #endif const char *cpu; const char *features; + const char *dylib_suffix; Warnings warning; ArchType arch; OsType os;