This commit is contained in:
Krzosa Karol
2023-03-29 08:14:36 +02:00
parent 1c5f6731a4
commit 7da3e27c05
4 changed files with 23 additions and 40 deletions

View File

@@ -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 set clang-flags=-O0 -Wall -Wno-unused-function -fno-exceptions -fdiagnostics-absolute-paths -g -o main.exe -Wl,user32.lib
pushd %~dp0 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 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 rem ubuntu run clang core_main.cpp -O0 -Wall -Wno-unused-function -fno-exceptions -fdiagnostics-absolute-paths -g -o core.out

View File

@@ -22,10 +22,9 @@
}, 4); }, 4);
Fix backlog 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 - [ ] 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 - [ ] 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 - [ ] 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 - [ ] 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} result := String{data, filesize}

View File

@@ -114,10 +114,9 @@ CORE_Static void
check_value_bounds(Token *pos, Value *a) { check_value_bounds(Token *pos, Value *a) {
if (!is_int(a->type)) return; if (!is_int(a->type)) return;
Arena *scratch = pctx->scratch; Scratch_Scope scratch(pctx->scratch);
Scratch_Scope __scope(scratch);
if (!bigint_fits_in_bits(&a->big_int_val, a->type->size * 8, is_signed_int(a->type))) { 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)); 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 * CORE_Static Ast_Decl *
search_for_single_decl(Ast_Scope *scope, Intern_String name, bool error_if_no_matches = true) { search_for_single_decl(Ast_Scope *scope, Intern_String name, bool error_if_no_matches = true) {
Arena *scratch = pctx->scratch; Scratch_Scope scratch(pctx->scratch);
Scratch_Scope _scope(scratch);
Scope_Search search = make_scope_search(scratch, scope, name); Scope_Search search = make_scope_search(scratch.arena, scope, name);
scope_search(&search); scope_search(&search);
if (search.results.len == 0) { 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 * CORE_Static Ast_Decl *
resolve_name(Ast_Scope *scope, Token *pos, Intern_String name, Search_Flag search_flags) { resolve_name(Ast_Scope *scope, Token *pos, Intern_String name, Search_Flag search_flags) {
Arena *scratch = pctx->scratch; Scratch_Scope scratch(pctx->scratch);
Scratch_Scope _scope(scratch); Scope_Search search = make_scope_search(scratch.arena, scope, name);
Scope_Search search = make_scope_search(scratch, scope, name);
search.search_only_current_scope = search_flags & SEARCH_ONLY_CURRENT_SCOPE; search.search_only_current_scope = search_flags & SEARCH_ONLY_CURRENT_SCOPE;
scope_search(&search); 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 // Search for all possible candidates in three scopes
// The current module, left type definition module, right type definition module // The current module, left type definition module, right type definition module
Arena *scratch = pctx->scratch; Scratch_Scope scratch(pctx->scratch);
Scratch_Scope _scope(scratch); Scope_Search search = make_scope_search(scratch.arena, scope, op_info->op);
Scope_Search search = make_scope_search(scratch, scope, op_info->op);
if (left->ast && left->ast->parent_scope) search.scopes.add(left->ast->parent_scope); 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); if (right && right->ast && right->ast->parent_scope) search.scopes.add(right->ast->parent_scope);
search.exit_on_find = false; search.exit_on_find = false;
scope_search(&search); scope_search(&search);
// Resolve them until we hit a match // Resolve them until we hit a match
Array<Ast_Decl *> matching_ops = {scratch}; Array<Ast_Decl *> matching_ops = {scratch.arena};
For(search.results) { For(search.results) {
resolve_decl(it); resolve_decl(it);
if (it->type->func.hash_without_ret == argument_hash) { 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 // 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 // as such we probably don't want to call any resolve stuff here
Arena *scratch = pctx->scratch; Scratch_Scope scratch(pctx->scratch);
Scratch_Scope _scope(scratch); Scope_Search search = make_scope_search(scratch.arena, scope, decl->name);
Scope_Search search = make_scope_search(scratch, scope, decl->name);
search.search_only_current_scope = true; search.search_only_current_scope = true;
scope_search(&search); scope_search(&search);
if (search.results.len != 0) { 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)) if (!ast && is_flag_set(flags, AST_CAN_BE_NULL))
return 0; return 0;
Arena *scratch = pctx->scratch;
Scratch_Scope _scope(scratch);
Operand resolved = resolve_expr(ast, flags | RESOLVE_TYPESPEC, 0, 0); Operand resolved = resolve_expr(ast, flags | RESOLVE_TYPESPEC, 0, 0);
if (is_flag_set(flags, RESOLVE_TYPESPEC_COMPLETE)) if (is_flag_set(flags, RESOLVE_TYPESPEC_COMPLETE))
type_complete(resolved.type_val); 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"); else compiler_error(0, "Compiler error: Null expression");
} }
Arena *scratch = pctx->scratch;
Scratch_Scope _scope(scratch);
Operand op = resolve_expr(expr, flags, 0, 0); Operand op = resolve_expr(expr, flags, 0, 0);
if (!is_bool(op.type)) { if (!is_bool(op.type)) {
compiler_error(expr->pos, "Expected type [Bool] got instead type %Q :: %s", typestring(op.type), error); 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) { switch (ast->kind) {
CASE(RETURN, Return) { // @todo: need to check if all paths return a value CASE(RETURN, Return) { // @todo: need to check if all paths return a value
Arena *scratch = pctx->scratch; Scratch_Scope scratch(pctx->scratch);
Scratch_Scope _scope(scratch); Array<Ast_Type *> types = {scratch.arena};
Array<Ast_Type *> types = {scratch};
int i = 0; int i = 0;
For(node->expr) { For(node->expr) {
@@ -915,10 +905,9 @@ resolve_stmt(Ast *ast, Ast_Type *ret) {
CORE_Static Ast_Type * CORE_Static Ast_Type *
resolve_lambda_type(Ast_Lambda *lambda) { resolve_lambda_type(Ast_Lambda *lambda) {
Arena *scratch = pctx->scratch; Scratch_Scope scratch(pctx->scratch);
Scratch_Scope _scope(scratch); Array<Ast_Type *> args = {scratch.arena};
Array<Ast_Type *> args = {scratch}; Array<Ast_Type *> ret = {scratch.arena};
Array<Ast_Type *> ret = {scratch};
For(lambda->ret) { For(lambda->ret) {
Ast_Type *type = resolve_typespec(it, AST_CANT_BE_NULL); Ast_Type *type = resolve_typespec(it, AST_CANT_BE_NULL);
ret.add(type); 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; node->resolved_decl = name.resolved_decl;
Arena *scratch = pctx->scratch; Scratch_Scope scratch(pctx->scratch);
Scratch_Scope _scope(scratch); Array<Ast_Call_Item *> items = {scratch.arena};
Array<Ast_Call_Item *> items = {scratch};
S64 default_iter = 0; S64 default_iter = 0;
/* /*
@@ -1689,16 +1677,15 @@ resolve_decl(Ast_Decl *ast) {
try_resolving_lambda_scope(&result, lambda, node->type); try_resolving_lambda_scope(&result, lambda, node->type);
node->value = result.value; node->value = result.value;
Arena *scratch = pctx->scratch; Scratch_Scope scratch(pctx->scratch);
Scratch_Scope _scope(scratch);
node->unique_name = node->name; node->unique_name = node->name;
if (!is_flag_set(node->expr->flags, AST_FOREIGN)) { 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)) { 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(); BREAK();

View File

@@ -7,9 +7,6 @@ PushStruct :: (a: *MA.Arena, $Type): *Type
return result 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 PushStruct :: (a: *MA.Arena, type: Type): *void
ti := GetTypeInfo(type) ti := GetTypeInfo(type)
result := MA.PushSize(a, ti.size->U64) result := MA.PushSize(a, ti.size->U64)