From 562bb6e4c46eb730c8e75bf5ebe12f7e2ed75702 Mon Sep 17 00:00:00 2001 From: Chris Heyes Date: Mon, 15 Oct 2018 21:24:42 +0100 Subject: [PATCH 1/2] Fix syntax error in core/os/os_linux.odin --- core/os/os_linux.odin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/os/os_linux.odin b/core/os/os_linux.odin index 4f6375701..b0f703c17 100644 --- a/core/os/os_linux.odin +++ b/core/os/os_linux.odin @@ -139,7 +139,7 @@ foreign libc { @(link_name="calloc") _unix_calloc :: proc(num, size: int) -> rawptr ---; @(link_name="free") _unix_free :: proc(ptr: rawptr) ---; @(link_name="realloc") _unix_realloc :: proc(ptr: rawptr, size: int) -> rawptr ---; - @(link_name="getenv") _unix_getenv :: proc(cstring) -> cstring --- -> !; + @(link_name="getenv") _unix_getenv :: proc(cstring) -> cstring ---; @(link_name="exit") _unix_exit :: proc(status: int) ---; } From ae02e9c34aa08b642fd6ca5465f988f8f1d98c60 Mon Sep 17 00:00:00 2001 From: Chris Heyes Date: Tue, 16 Oct 2018 23:56:19 +0100 Subject: [PATCH 2/2] Use name of source file as output_name --- src/ir.cpp | 4 ++-- src/string.cpp | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/ir.cpp b/src/ir.cpp index 7ceda6c10..29cc9247c 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -7788,8 +7788,8 @@ bool ir_gen_init(irGen *s, Checker *c) { String init_fullpath = c->parser->init_fullpath; if (build_context.out_filepath.len == 0) { - // s->output_name = filename_from_path(init_fullpath); - s->output_name = str_lit("main"); + s->output_name = remove_directory_from_path(init_fullpath); + s->output_name = remove_extension_from_path(s->output_name); s->output_base = s->output_name; } else { s->output_name = build_context.out_filepath; diff --git a/src/string.cpp b/src/string.cpp index 80a7180a2..7ceeb78a1 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -276,6 +276,15 @@ String filename_from_path(String s) { return make_string(nullptr, 0); } +String remove_extension_from_path(String const &s) { + for (isize i = s.len-1; i >= 0; i--) { + if (s[i] == '.') { + return substring(s, 0, i); + } + } + return s; +} + String remove_directory_from_path(String const &s) { isize len = 0; for (isize i = s.len-1; i >= 0; i--) { @@ -287,6 +296,7 @@ String remove_directory_from_path(String const &s) { } return substring(s, s.len-len, s.len); } + String directory_from_path(String const &s) { isize i = s.len-1; for (; i >= 0; i--) {