diff --git a/build.bat b/build.bat index 57bb95f..a4fb019 100644 --- a/build.bat +++ b/build.bat @@ -4,7 +4,7 @@ if exist "..\misc\compile_setup.bat" call "..\misc\compile_setup.bat" set clang-flags=-O0 -Wall -Wno-unused-function -fno-exceptions -fdiagnostics-absolute-paths -g -o main.exe -Wl,user32.lib pushd %~dp0 -cl core_main.cpp -Zi -nologo -W3 -wd4200 -wd4267 -wd4244 -Fe:main.exe user32.lib +cl core_main.cpp -Zi -nologo -W3 -wd4200 -wd4267 -wd4244 -diagnostics:column -Fe:main.exe user32.lib rem clang core_main.cpp %clang-flags% rem ubuntu run clang core_main.cpp -O0 -Wall -Wno-unused-function -fno-exceptions -fdiagnostics-absolute-paths -g -o core.out diff --git a/core_main.cpp b/core_main.cpp index cb0623c..776c428 100644 --- a/core_main.cpp +++ b/core_main.cpp @@ -22,10 +22,9 @@ }, 4); Fix backlog -- [ ] Fix invalid error message: AlmostLinearToSRGB :: (a: Color);; return {sqrtf(a.r), sqrtf(a.g), sqrtf(a.b), a.a} - [ ] Fix and decide what to do when initializing global variable using not constants C:/AProgramming/cparse/compiler/modules/Language.core:180:28: error: initializer element is not a compile-time constant - [ ] Test and bulletproof any, slices -- [ ] Need tests that make sure stuff errors out +- [ ] Test suite that expects test to error out - [ ] String declaration in Language.core this way we can compound create it and access fields and stuff - [ ] This error is valid error case when someone creates a compound out of basic type C:/AProgramming/cparse/compiler/examples/arms_race/arms_race.core:137 Internal compiler error: Invalid type was passed to the compound expression, should have been an array, struct or slice result := String{data, filesize} diff --git a/core_typechecking.cpp b/core_typechecking.cpp index 79c9bfa..cf913ee 100644 --- a/core_typechecking.cpp +++ b/core_typechecking.cpp @@ -114,10 +114,9 @@ CORE_Static void check_value_bounds(Token *pos, Value *a) { if (!is_int(a->type)) return; - Arena *scratch = pctx->scratch; - Scratch_Scope __scope(scratch); + Scratch_Scope scratch(pctx->scratch); if (!bigint_fits_in_bits(&a->big_int_val, a->type->size * 8, is_signed_int(a->type))) { - const char *string = bigint_to_error_string(scratch, &a->big_int_val, 10); + const char *string = bigint_to_error_string(scratch.arena, &a->big_int_val, 10); compiler_error(pos, "Value %s doesn't fit in type %Q", string, typestring(a->type)); } } @@ -519,10 +518,9 @@ make_scope_search(Allocator *arena, Ast_Scope *scope, Intern_String name) { CORE_Static Ast_Decl * search_for_single_decl(Ast_Scope *scope, Intern_String name, bool error_if_no_matches = true) { - Arena *scratch = pctx->scratch; - Scratch_Scope _scope(scratch); + Scratch_Scope scratch(pctx->scratch); - Scope_Search search = make_scope_search(scratch, scope, name); + Scope_Search search = make_scope_search(scratch.arena, scope, name); scope_search(&search); if (search.results.len == 0) { @@ -538,9 +536,8 @@ search_for_single_decl(Ast_Scope *scope, Intern_String name, bool error_if_no_ma CORE_Static Ast_Decl * resolve_name(Ast_Scope *scope, Token *pos, Intern_String name, Search_Flag search_flags) { - Arena *scratch = pctx->scratch; - Scratch_Scope _scope(scratch); - Scope_Search search = make_scope_search(scratch, scope, name); + Scratch_Scope scratch(pctx->scratch); + Scope_Search search = make_scope_search(scratch.arena, scope, name); search.search_only_current_scope = search_flags & SEARCH_ONLY_CURRENT_SCOPE; scope_search(&search); @@ -572,16 +569,15 @@ resolve_operator_overload(Ast_Scope *scope, Ast_Type *left, Ast_Type *right, Tok // Search for all possible candidates in three scopes // The current module, left type definition module, right type definition module - Arena *scratch = pctx->scratch; - Scratch_Scope _scope(scratch); - Scope_Search search = make_scope_search(scratch, scope, op_info->op); + Scratch_Scope scratch(pctx->scratch); + Scope_Search search = make_scope_search(scratch.arena, scope, op_info->op); if (left->ast && left->ast->parent_scope) search.scopes.add(left->ast->parent_scope); if (right && right->ast && right->ast->parent_scope) search.scopes.add(right->ast->parent_scope); search.exit_on_find = false; scope_search(&search); // Resolve them until we hit a match - Array matching_ops = {scratch}; + Array matching_ops = {scratch.arena}; For(search.results) { resolve_decl(it); if (it->type->func.hash_without_ret == argument_hash) { @@ -607,9 +603,8 @@ insert_into_scope(Ast_Scope *scope, Ast_Decl *decl) { // // It's also called when scanning top level declarations of a module // as such we probably don't want to call any resolve stuff here - Arena *scratch = pctx->scratch; - Scratch_Scope _scope(scratch); - Scope_Search search = make_scope_search(scratch, scope, decl->name); + Scratch_Scope scratch(pctx->scratch); + Scope_Search search = make_scope_search(scratch.arena, scope, decl->name); search.search_only_current_scope = true; scope_search(&search); if (search.results.len != 0) { @@ -694,8 +689,6 @@ resolve_typespec(Ast_Expr *ast, Resolve_Flag flags) { if (!ast && is_flag_set(flags, AST_CAN_BE_NULL)) return 0; - Arena *scratch = pctx->scratch; - Scratch_Scope _scope(scratch); Operand resolved = resolve_expr(ast, flags | RESOLVE_TYPESPEC, 0, 0); if (is_flag_set(flags, RESOLVE_TYPESPEC_COMPLETE)) type_complete(resolved.type_val); @@ -712,8 +705,6 @@ resolve_and_require_bool(const char *error, Ast_Expr *expr, Resolve_Flag flags) else compiler_error(0, "Compiler error: Null expression"); } - Arena *scratch = pctx->scratch; - Scratch_Scope _scope(scratch); Operand op = resolve_expr(expr, flags, 0, 0); if (!is_bool(op.type)) { compiler_error(expr->pos, "Expected type [Bool] got instead type %Q :: %s", typestring(op.type), error); @@ -748,9 +739,8 @@ resolve_stmt(Ast *ast, Ast_Type *ret) { switch (ast->kind) { CASE(RETURN, Return) { // @todo: need to check if all paths return a value - Arena *scratch = pctx->scratch; - Scratch_Scope _scope(scratch); - Array types = {scratch}; + Scratch_Scope scratch(pctx->scratch); + Array types = {scratch.arena}; int i = 0; For(node->expr) { @@ -915,10 +905,9 @@ resolve_stmt(Ast *ast, Ast_Type *ret) { CORE_Static Ast_Type * resolve_lambda_type(Ast_Lambda *lambda) { - Arena *scratch = pctx->scratch; - Scratch_Scope _scope(scratch); - Array args = {scratch}; - Array ret = {scratch}; + Scratch_Scope scratch(pctx->scratch); + Array args = {scratch.arena}; + Array ret = {scratch.arena}; For(lambda->ret) { Ast_Type *type = resolve_typespec(it, AST_CANT_BE_NULL); ret.add(type); @@ -1565,9 +1554,8 @@ resolve_expr(Ast_Expr *ast, Resolve_Flag flags, Ast_Type *compound_and_const_str } node->resolved_decl = name.resolved_decl; - Arena *scratch = pctx->scratch; - Scratch_Scope _scope(scratch); - Array items = {scratch}; + Scratch_Scope scratch(pctx->scratch); + Array items = {scratch.arena}; S64 default_iter = 0; /* @@ -1689,16 +1677,15 @@ resolve_decl(Ast_Decl *ast) { try_resolving_lambda_scope(&result, lambda, node->type); node->value = result.value; - Arena *scratch = pctx->scratch; - Scratch_Scope _scope(scratch); + Scratch_Scope scratch(pctx->scratch); node->unique_name = node->name; if (!is_flag_set(node->expr->flags, AST_FOREIGN)) { - node->unique_name = pctx->intern(string_fmt(scratch, "%Q%Q%d", pctx->symbol_prefix, node->name, pctx->lambda_ids++)); + node->unique_name = pctx->intern(string_fmt(scratch.arena, "%Q%Q%d", pctx->symbol_prefix, node->name, pctx->lambda_ids++)); } if (is_flag_set(node->flags, AST_OPERATOR_OVERLOAD)) { - node->unique_name = pctx->intern(string_fmt(scratch, "%QOPERATOR_%Q%d", pctx->symbol_prefix, node->overload_op_info->name, pctx->lambda_ids++)); + node->unique_name = pctx->intern(string_fmt(scratch.arena, "%QOPERATOR_%Q%d", pctx->symbol_prefix, node->overload_op_info->name, pctx->lambda_ids++)); } BREAK(); diff --git a/examples/push_struct.core b/examples/push_struct.core index 9c1b407..94daf95 100644 --- a/examples/push_struct.core +++ b/examples/push_struct.core @@ -7,9 +7,6 @@ PushStruct :: (a: *MA.Arena, $Type): *Type return result */ -Color :: struct ;; r: F32; g: F32; b: F32; a: F32 -AlmostLinearToSRGB :: (a: Color): Color;; return {asd(a.r), asd(a.g), asd(a.b), a.a} - PushStruct :: (a: *MA.Arena, type: Type): *void ti := GetTypeInfo(type) result := MA.PushSize(a, ti.size->U64)