Errors work better with sublime
This commit is contained in:
@@ -5,6 +5,6 @@ rem cl main.cpp -I.. user32.lib
|
||||
rem clang core_main.cpp -O0 -Wall -Wno-unused-function -fno-exceptions -fdiagnostics-absolute-paths -g -o main.exe -Wl,user32.lib
|
||||
rem ubuntu run clang core_main.cpp -O0 -Wall -Wno-unused-function -fno-exceptions -fdiagnostics-absolute-paths -g -o core.out
|
||||
|
||||
main examples/language_basics.core
|
||||
main examples/arms_race/arms_race.core
|
||||
|
||||
popd
|
||||
|
||||
@@ -6,6 +6,8 @@ global String single_header_library_name = ""_s;
|
||||
|
||||
thread_local Parse_Ctx *pctx;
|
||||
|
||||
global bool color_codes_enabled;
|
||||
|
||||
Arena *bigint_allocator;
|
||||
global S64 bigint_allocation_count;
|
||||
|
||||
|
||||
@@ -266,6 +266,9 @@ int main(int argument_count, char **arguments){
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if OS_UNIX
|
||||
color_codes_enabled = true;
|
||||
#endif
|
||||
#if OS_WINDOWS
|
||||
// Set output mode to handle virtual terminal sequences
|
||||
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
@@ -273,7 +276,10 @@ int main(int argument_count, char **arguments){
|
||||
DWORD dwMode = 0;
|
||||
if (GetConsoleMode(hOut, &dwMode)) {
|
||||
dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
|
||||
if (!SetConsoleMode(hOut, dwMode)) {
|
||||
if (SetConsoleMode(hOut, dwMode)) {
|
||||
color_codes_enabled = true;
|
||||
}
|
||||
else{
|
||||
log_info("Failed to enable colored terminal output C");
|
||||
}
|
||||
}
|
||||
@@ -295,7 +301,6 @@ int main(int argument_count, char **arguments){
|
||||
test_string_builder();
|
||||
test_intern_table();
|
||||
|
||||
log_info("Test");
|
||||
// emit_line_directives = false;
|
||||
// emit_type_info = false;
|
||||
For(args){
|
||||
|
||||
@@ -10,23 +10,28 @@ print_token_line(Token *token){
|
||||
|
||||
// Print from line begin to token
|
||||
int i1 = token->str - token->line_begin;
|
||||
printf("%.*s", i1, token->line_begin);
|
||||
log_info_no_nl("%.*s", i1, token->line_begin);
|
||||
|
||||
// Print token part
|
||||
printf( PRINTF_RED "%.*s" PRINTF_RESET, (int)token->len, token->str);
|
||||
if(color_codes_enabled){
|
||||
log_info_no_nl( PRINTF_RED "%.*s" PRINTF_RESET, (int)token->len, token->str);
|
||||
} else {
|
||||
log_info_no_nl("%.*s", (int)token->len, token->str);
|
||||
}
|
||||
|
||||
|
||||
// Print to end of line from token
|
||||
int iend = 0;
|
||||
U8 *pointer = token->str + token->len;
|
||||
while(pointer[iend]!='\n' && pointer[iend]!=0) iend++;
|
||||
printf("%.*s", iend, pointer);
|
||||
printf("\n");
|
||||
log_info_no_nl("%.*s", iend, pointer);
|
||||
log_info_no_nl("\n");
|
||||
}
|
||||
|
||||
CORE_Static void
|
||||
print_token_context(Token *token){
|
||||
if(!token) return;
|
||||
printf("\n");
|
||||
log_info_no_nl("\n");
|
||||
print_token_line(token);
|
||||
}
|
||||
|
||||
@@ -35,24 +40,25 @@ compiler_error(Token *token1, Token *token2, const char *str, ...){
|
||||
Scratch scratch;
|
||||
STRING_FMT(scratch, str, string);
|
||||
|
||||
printf("\n%s", string.str);
|
||||
log_info_no_nl("\n%s", string.str);
|
||||
if(token1){
|
||||
if(token1->kind == TK_Error){
|
||||
printf("\nToken Error: %.*s", (int)token1->error_val.len, token1->error_val.str);
|
||||
log_info_no_nl("\nToken Error: %.*s", (int)token1->error_val.len, token1->error_val.str);
|
||||
}
|
||||
print_token_context(token1);
|
||||
}
|
||||
|
||||
if(token2){
|
||||
if(token2->kind == TK_Error){
|
||||
printf("\nToken Error: %.*s", (int)token2->error_val.len, token2->error_val.str);
|
||||
log_info_no_nl("\nToken Error: %.*s", (int)token2->error_val.len, token2->error_val.str);
|
||||
}
|
||||
print_token_context(token2);
|
||||
}
|
||||
|
||||
if(token1) printf("\n%s:%d token_di:%u", token1->file.str, (S32)token1->line + 1, token1->di);
|
||||
if(token2) printf("\n%s:%d token_di:%u", token2->file.str, (S32)token2->line + 1, token2->di);
|
||||
if(token1) log_info_no_nl("\n%s:%d", token1->file.str, (S32)token1->line + 1);
|
||||
if(token2) log_info_no_nl("\n%s:%d", token2->file.str, (S32)token2->line + 1);
|
||||
|
||||
fflush(stdout);
|
||||
Breakpoint;
|
||||
}
|
||||
|
||||
@@ -61,17 +67,19 @@ compiler_error(Token *token, const char *str, ...){
|
||||
Scratch scratch;
|
||||
STRING_FMT(scratch, str, string);
|
||||
|
||||
printf("\n%s", string.str);
|
||||
if(token) log_info_no_nl("\n%s:%d %Q", token->file.str, (S32)token->line + 1, string);
|
||||
else log_info_no_nl("\n%s", string.str);
|
||||
if(token){
|
||||
if(token->kind == TK_Error){
|
||||
printf("\nToken Error: %.*s", (int)token->error_val.len, token->error_val.str);
|
||||
log_info_no_nl("\nToken Error: %.*s", (int)token->error_val.len, token->error_val.str);
|
||||
}
|
||||
|
||||
print_token_context(token);
|
||||
}
|
||||
|
||||
if(token) printf("\n%s:%d token_di:%u", token->file.str, (S32)token->line + 1, token->di);
|
||||
|
||||
|
||||
fflush(stdout);
|
||||
Breakpoint;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user