Core: Small cleanup

This commit is contained in:
Krzosa Karol
2023-04-21 15:19:38 +02:00
parent 19fa0509c6
commit 07dcb418dd
5 changed files with 13 additions and 26 deletions

View File

@@ -344,5 +344,5 @@ operator!=(Intern_String a, Intern_String b) {
return !result; return !result;
} }
#define For_Linked_List_Named(a, it) for (auto *it = (a); it; it = it->next) // @todo: reference? #define For_Linked_List_Named(a, it) for (auto *it = (a); it; it = it->next)
#define For_Linked_List(a) For_Linked_List_Named(a, it) #define For_Linked_List(a) For_Linked_List_Named(a, it)

View File

@@ -22,10 +22,10 @@ LPDWORD :: *DWORD
LRESULT :: S64 LRESULT :: S64
WPARAM :: U64 WPARAM :: U64
LPARAM :: S64 LPARAM :: S64
BYTE :: U8 // @todo? unsigned char BYTE :: uchar
WORD :: S16 // short WORD :: short
LONG :: S32 // @todo long LONG :: long
UINT :: U32 // @todo uint UINT :: uint
ATOM :: WORD ATOM :: WORD
LARGE_INTEGER :: S64 LARGE_INTEGER :: S64
PLARGE_INTEGER :: *LARGE_INTEGER PLARGE_INTEGER :: *LARGE_INTEGER

View File

@@ -311,7 +311,6 @@ lex__stream(Core_Ctx *lexer) {
else goto indent_loop_break; else goto indent_loop_break;
} break; } break;
// @todo: add [;;] operator which adds new scope
// @todo: also need some way to detect indentation so that // @todo: also need some way to detect indentation so that
// first of all we can check for consistency and second of // first of all we can check for consistency and second of
// all because we would know by how much to indent // all because we would know by how much to indent

View File

@@ -28,18 +28,11 @@ Fix backlog
- [ ] 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}
- [ ] Fix tuple being able to colapse into a single variable
- [ ] Fix Found multiple definitions of not showing multiple definitions in the error message
- [ ] How to cast from U64 to pointer? - [ ] How to cast from U64 to pointer?
``` ```
Future features Future features
- [ ] Add some directive that passes metadata arguments to compiler, stores them
in array and then those can be searched etc. Then we could add the link thing there
- [ ] The ability for a type to also be a namespace seems like a good idea, a common pattern
emerges. Not sure how to execute it though without complications. Data for sure needs
to be nicely visible in a struct and those functions should be separate
- [ ] Other kinds of casts, a cast from structs of same layout, a cast without conversion - [ ] Other kinds of casts, a cast from structs of same layout, a cast without conversion
- [ ] Inject symbols into a declaration / namespace ?? - [ ] Inject symbols into a declaration / namespace ??
- [ ] Using directive to bring symbols into local scope - [ ] Using directive to bring symbols into local scope
@@ -102,17 +95,16 @@ static void compile_file(Allocator *allocator, String filename, U32 compile_flag
F64 total_compiler_time = os_time() - pctx->time.start; F64 total_compiler_time = os_time() - pctx->time.start;
printf("%f - ", total_compiler_time); printf("%f - ", total_compiler_time);
Arena *scratch = pctx->scratch; Scoped_Arena scratch(pctx->scratch);
Scoped_Arena _scope(scratch);
F64 begin = os_time(); F64 begin = os_time();
if (!is_flag_set(compile_flags, DONT_USE_C_COMPILER)) { if (!is_flag_set(compile_flags, DONT_USE_C_COMPILER)) {
String_Builder builder = {scratch}; String_Builder builder = {scratch.arena};
builder.addf("clang generated_main.c -Wall -Wno-unused-function -Wno-parentheses-equality -g -o a" OS_EXE " "); builder.addf("clang generated_main.c -Wall -Wno-unused-function -Wno-parentheses-equality -g -o a" OS_EXE " ");
For(pctx->files_to_link) { For(pctx->files_to_link) {
builder.addf("-l%Q ", it->intern_val); builder.addf("-l%Q ", it->intern_val);
} }
String compiler_call = string_flatten(scratch, &builder); String compiler_call = string_flatten(scratch.arena, &builder);
system((const char *)compiler_call.str); system((const char *)compiler_call.str);
printf("%s\n", compiler_call.str); printf("%s\n", compiler_call.str);
} }
@@ -135,9 +127,9 @@ static void compile_file(Allocator *allocator, String filename, U32 compile_flag
if (is_flag_set(compile_flags, COMPILE_AND_RUN)) { if (is_flag_set(compile_flags, COMPILE_AND_RUN)) {
String testing = compile_flags & COMPILE_TESTING ? "testing"_s : ""_s; String testing = compile_flags & COMPILE_TESTING ? "testing"_s : ""_s;
#if OS_WINDOWS #if OS_WINDOWS
String sys = string_fmt(scratch, "a.exe %Q", testing); String sys = string_fmt(scratch.arena, "a.exe %Q", testing);
#else #else
String sys = string_fmt(scratch, "./a.out %Q", testing); String sys = string_fmt(scratch.arena, "./a.out %Q", testing);
#endif #endif
int result = system((char *)sys.str); int result = system((char *)sys.str);
assert(result != -1); assert(result != -1);

View File

@@ -1276,9 +1276,6 @@ resolve_expr(Ast_Expr *ast, Resolve_Flag flags, Ast_Type *compound_and_const_str
node->resolved_type = pctx->type_u8; node->resolved_type = pctx->type_u8;
} }
// @todo: type_architecture?
// we only try to convert the index cause array can't be const
// right now
try_propagating_resolved_type_to_untyped_literals(node->index, pctx->type_int); try_propagating_resolved_type_to_untyped_literals(node->index, pctx->type_int);
try_propagating_resolved_type_to_untyped_literals(node->expr, left.type); try_propagating_resolved_type_to_untyped_literals(node->expr, left.type);
@@ -1607,7 +1604,7 @@ resolve_expr(Ast_Expr *ast, Resolve_Flag flags, Ast_Type *compound_and_const_str
} }
} }
/* @todo: /*
We need an algorithm and other concretes for correct matching of arrays, var args and others. We need an algorithm and other concretes for correct matching of arrays, var args and others.
(a: int = 5, b: int) Disallowed, this is not lua where table has indexed and keyed values at the same time (a: int = 5, b: int) Disallowed, this is not lua where table has indexed and keyed values at the same time
@@ -1685,9 +1682,8 @@ resolve_expr(Ast_Expr *ast, Resolve_Flag flags, Ast_Type *compound_and_const_str
// Might be wise to revise it later but the approach of starting with // Might be wise to revise it later but the approach of starting with
// lambda_args seems correct. // lambda_args seems correct.
For2(lambda->args, lambda_arg) { For2(lambda->args, lambda_arg) {
// assert(lambda_arg->type); // @todo: maybe add this check at the end // Variadic functions cannot have default arguments
// we make sure of that when resolving the lambda
// @todo: Change inside resolve lambda, no default arguments allowed!!!!!!
if (lambda_arg->kind == AST_VARGS_LAMBDA_PARAM) { if (lambda_arg->kind == AST_VARGS_LAMBDA_PARAM) {
For(node->exprs) { For(node->exprs) {
if (is_flag_set(it->call_flags, CALL_NAME)) { if (is_flag_set(it->call_flags, CALL_NAME)) {