From db1b7b2d2125fc1ac7e3a7363ea37796d5371fc0 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Wed, 14 Sep 2022 16:52:01 +0100 Subject: [PATCH 1/7] Allow for ignored fields in struct for `json.unmarshal` --- core/encoding/json/unmarshal.odin | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/core/encoding/json/unmarshal.odin b/core/encoding/json/unmarshal.odin index 97d2421d4..792b1edc6 100644 --- a/core/encoding/json/unmarshal.odin +++ b/core/encoding/json/unmarshal.odin @@ -386,7 +386,14 @@ unmarshal_object :: proc(p: ^Parser, v: any, end_token: Token_Kind) -> (err: Unm continue struct_loop } - return Unsupported_Type_Error{v.id, p.curr_token} + // NOTE(bill, 2022-09-14): Previously this would not be allowed + // {"foo": 123, "bar": 456} + // T :: struct{foo: int} + // `T` is missing the `bar` field + // The line below is commented out to ignore fields in an object which + // do not have a corresponding target field + // + // return Unsupported_Type_Error{v.id, p.curr_token} } case reflect.Type_Info_Map: From 190c3ab0cdc031e45d450e64715452fb2e576d1e Mon Sep 17 00:00:00 2001 From: gingerBill Date: Wed, 14 Sep 2022 17:50:31 +0100 Subject: [PATCH 2/7] Just get the value directly and store it in another global variable // global x := &Foo{} --- src/llvm_backend.cpp | 25 ++++++++++++++++++++++--- src/llvm_backend.hpp | 1 + src/llvm_backend_general.cpp | 15 ++++++++++----- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp index 4eb343fa7..d7f391690 100644 --- a/src/llvm_backend.cpp +++ b/src/llvm_backend.cpp @@ -758,9 +758,29 @@ lbProcedure *lb_create_startup_runtime(lbModule *main_module, lbProcedure *start GB_ASSERT(e->kind == Entity_Variable); e->code_gen_module = entity_module; - Ast *init_expr = var->decl->init_expr; + Ast *init_expr = unparen_expr(var->decl->init_expr); if (init_expr != nullptr) { - lbValue init = lb_build_expr(p, init_expr); + lbValue init = {}; + + if (!(is_type_any(e->type) || is_type_union(e->type))) { + if (init_expr->kind == Ast_UnaryExpr && init_expr->UnaryExpr.op.kind == Token_And) { + // NOTE(bill): Just get the value directly and store it in another global variable + Ast *expr = unparen_expr(init_expr->UnaryExpr.expr); + if (expr->tav.value.kind != ExactValue_Invalid) { + init = lb_build_expr(p, expr); + GB_ASSERT(init.value != nullptr); + GB_ASSERT(LLVMIsConstant(init.value)); + + lbAddr addr = lb_add_global_generated(p->module, init.type, init, nullptr); + LLVMValueRef global_val = lb_make_global_truly_private(addr); + LLVMSetInitializer(var->var.value, global_val); + var->is_initialized = true; + continue; + } + } + } + + init = lb_build_expr(p, init_expr); if (init.value == nullptr) { LLVMTypeRef global_type = llvm_addr_type(p->module, var->var); if (is_type_untyped_undef(init.type)) { @@ -1588,7 +1608,6 @@ void lb_generate_code(lbGenerator *gen) { bool is_foreign = e->Variable.is_foreign; bool is_export = e->Variable.is_export; - lbModule *m = &gen->default_module; String name = lb_get_entity_name(m, e); diff --git a/src/llvm_backend.hpp b/src/llvm_backend.hpp index 79f0f37e7..70f528251 100644 --- a/src/llvm_backend.hpp +++ b/src/llvm_backend.hpp @@ -395,6 +395,7 @@ lbContextData *lb_push_context_onto_stack_from_implicit_parameter(lbProcedure *p lbAddr lb_add_global_generated(lbModule *m, Type *type, lbValue value={}, Entity **entity_=nullptr); lbAddr lb_add_local(lbProcedure *p, Type *type, Entity *e=nullptr, bool zero_init=true, i32 param_index=0, bool force_no_init=false); +LLVMValueRef lb_make_global_truly_private(lbAddr const &addr); void lb_add_foreign_library_path(lbModule *m, Entity *e); diff --git a/src/llvm_backend_general.cpp b/src/llvm_backend_general.cpp index 1f8fccdcb..94429e410 100644 --- a/src/llvm_backend_general.cpp +++ b/src/llvm_backend_general.cpp @@ -926,11 +926,7 @@ void lb_emit_store(lbProcedure *p, lbValue ptr, lbValue value) { return; } else if (LLVMIsConstant(value.value)) { lbAddr addr = lb_add_global_generated(p->module, value.type, value, nullptr); - LLVMValueRef global_data = addr.addr.value; - // make it truly private data - LLVMSetLinkage(global_data, LLVMPrivateLinkage); - LLVMSetUnnamedAddress(global_data, LLVMGlobalUnnamedAddr); - LLVMSetGlobalConstant(global_data, true); + LLVMValueRef global_data = lb_make_global_truly_private(addr); LLVMValueRef dst_ptr = ptr.value; LLVMValueRef src_ptr = global_data; @@ -2669,6 +2665,15 @@ lbValue lb_find_procedure_value_from_entity(lbModule *m, Entity *e) { return {}; } +LLVMValueRef lb_make_global_truly_private(lbAddr const &addr) { + LLVMValueRef global_data = addr.addr.value; + // make it truly private data + LLVMSetLinkage(global_data, LLVMPrivateLinkage); + LLVMSetUnnamedAddress(global_data, LLVMGlobalUnnamedAddr); + LLVMSetGlobalConstant(global_data, true); + return global_data; +} + lbAddr lb_add_global_generated(lbModule *m, Type *type, lbValue value, Entity **entity_) { GB_ASSERT(type != nullptr); type = default_type(type); From 3ea7af4c9ca716baf48bca029f585d2b9a934ac9 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Wed, 14 Sep 2022 17:51:33 +0100 Subject: [PATCH 3/7] Minor fix to `lb_big_int_to_llvm` --- src/llvm_backend_const.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/llvm_backend_const.cpp b/src/llvm_backend_const.cpp index 6a3b14471..45e597a9e 100644 --- a/src/llvm_backend_const.cpp +++ b/src/llvm_backend_const.cpp @@ -352,7 +352,7 @@ LLVMValueRef lb_big_int_to_llvm(lbModule *m, Type *original_type, BigInt const * } } - LLVMValueRef value = LLVMConstIntOfArbitraryPrecision(lb_type(m, original_type), cast(unsigned)(sz+7/8), cast(u64 *)rop); + LLVMValueRef value = LLVMConstIntOfArbitraryPrecision(lb_type(m, original_type), cast(unsigned)((sz+7)/8), cast(u64 *)rop); if (big_int_is_neg(a)) { value = LLVMConstNeg(value); } From a3c04db82831d8d56e4aa4be7c7de6f53286682c Mon Sep 17 00:00:00 2001 From: gingerBill Date: Wed, 14 Sep 2022 17:57:12 +0100 Subject: [PATCH 4/7] Revert "Just get the value directly and store it in another global variable" This reverts commit 190c3ab0cdc031e45d450e64715452fb2e576d1e. --- src/llvm_backend.cpp | 25 +++---------------------- src/llvm_backend.hpp | 1 - src/llvm_backend_general.cpp | 15 +++++---------- 3 files changed, 8 insertions(+), 33 deletions(-) diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp index d7f391690..4eb343fa7 100644 --- a/src/llvm_backend.cpp +++ b/src/llvm_backend.cpp @@ -758,29 +758,9 @@ lbProcedure *lb_create_startup_runtime(lbModule *main_module, lbProcedure *start GB_ASSERT(e->kind == Entity_Variable); e->code_gen_module = entity_module; - Ast *init_expr = unparen_expr(var->decl->init_expr); + Ast *init_expr = var->decl->init_expr; if (init_expr != nullptr) { - lbValue init = {}; - - if (!(is_type_any(e->type) || is_type_union(e->type))) { - if (init_expr->kind == Ast_UnaryExpr && init_expr->UnaryExpr.op.kind == Token_And) { - // NOTE(bill): Just get the value directly and store it in another global variable - Ast *expr = unparen_expr(init_expr->UnaryExpr.expr); - if (expr->tav.value.kind != ExactValue_Invalid) { - init = lb_build_expr(p, expr); - GB_ASSERT(init.value != nullptr); - GB_ASSERT(LLVMIsConstant(init.value)); - - lbAddr addr = lb_add_global_generated(p->module, init.type, init, nullptr); - LLVMValueRef global_val = lb_make_global_truly_private(addr); - LLVMSetInitializer(var->var.value, global_val); - var->is_initialized = true; - continue; - } - } - } - - init = lb_build_expr(p, init_expr); + lbValue init = lb_build_expr(p, init_expr); if (init.value == nullptr) { LLVMTypeRef global_type = llvm_addr_type(p->module, var->var); if (is_type_untyped_undef(init.type)) { @@ -1608,6 +1588,7 @@ void lb_generate_code(lbGenerator *gen) { bool is_foreign = e->Variable.is_foreign; bool is_export = e->Variable.is_export; + lbModule *m = &gen->default_module; String name = lb_get_entity_name(m, e); diff --git a/src/llvm_backend.hpp b/src/llvm_backend.hpp index 70f528251..79f0f37e7 100644 --- a/src/llvm_backend.hpp +++ b/src/llvm_backend.hpp @@ -395,7 +395,6 @@ lbContextData *lb_push_context_onto_stack_from_implicit_parameter(lbProcedure *p lbAddr lb_add_global_generated(lbModule *m, Type *type, lbValue value={}, Entity **entity_=nullptr); lbAddr lb_add_local(lbProcedure *p, Type *type, Entity *e=nullptr, bool zero_init=true, i32 param_index=0, bool force_no_init=false); -LLVMValueRef lb_make_global_truly_private(lbAddr const &addr); void lb_add_foreign_library_path(lbModule *m, Entity *e); diff --git a/src/llvm_backend_general.cpp b/src/llvm_backend_general.cpp index 94429e410..1f8fccdcb 100644 --- a/src/llvm_backend_general.cpp +++ b/src/llvm_backend_general.cpp @@ -926,7 +926,11 @@ void lb_emit_store(lbProcedure *p, lbValue ptr, lbValue value) { return; } else if (LLVMIsConstant(value.value)) { lbAddr addr = lb_add_global_generated(p->module, value.type, value, nullptr); - LLVMValueRef global_data = lb_make_global_truly_private(addr); + LLVMValueRef global_data = addr.addr.value; + // make it truly private data + LLVMSetLinkage(global_data, LLVMPrivateLinkage); + LLVMSetUnnamedAddress(global_data, LLVMGlobalUnnamedAddr); + LLVMSetGlobalConstant(global_data, true); LLVMValueRef dst_ptr = ptr.value; LLVMValueRef src_ptr = global_data; @@ -2665,15 +2669,6 @@ lbValue lb_find_procedure_value_from_entity(lbModule *m, Entity *e) { return {}; } -LLVMValueRef lb_make_global_truly_private(lbAddr const &addr) { - LLVMValueRef global_data = addr.addr.value; - // make it truly private data - LLVMSetLinkage(global_data, LLVMPrivateLinkage); - LLVMSetUnnamedAddress(global_data, LLVMGlobalUnnamedAddr); - LLVMSetGlobalConstant(global_data, true); - return global_data; -} - lbAddr lb_add_global_generated(lbModule *m, Type *type, lbValue value, Entity **entity_) { GB_ASSERT(type != nullptr); type = default_type(type); From 28ad4f8623b31e21a8a63ef69aa85a7f070bc20b Mon Sep 17 00:00:00 2001 From: gingerBill Date: Wed, 14 Sep 2022 18:21:12 +0100 Subject: [PATCH 5/7] Use `json` field tag for `json.marshal` --- core/encoding/json/marshal.odin | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/encoding/json/marshal.odin b/core/encoding/json/marshal.odin index 8f7749aba..6834acd8a 100644 --- a/core/encoding/json/marshal.odin +++ b/core/encoding/json/marshal.odin @@ -302,7 +302,11 @@ marshal_to_writer :: proc(w: io.Writer, v: any, opt: ^Marshal_Options) -> (err: for name, i in info.names { opt_write_iteration(w, opt, i) or_return - opt_write_key(w, opt, name) or_return + if json_name := string(reflect.struct_tag_get(info.tags[i], "json")); json_name != "" { + opt_write_key(w, opt, json_name) or_return + } else { + opt_write_key(w, opt, name) or_return + } id := info.types[i].id data := rawptr(uintptr(v.data) + info.offsets[i]) From 1e595f2e2697342e82af7cae6682378a64ae5897 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Wed, 14 Sep 2022 18:23:46 +0100 Subject: [PATCH 6/7] Add missing import --- core/encoding/json/marshal.odin | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/encoding/json/marshal.odin b/core/encoding/json/marshal.odin index 6834acd8a..10fb4c348 100644 --- a/core/encoding/json/marshal.odin +++ b/core/encoding/json/marshal.odin @@ -5,6 +5,7 @@ import "core:math/bits" import "core:runtime" import "core:strconv" import "core:strings" +import "core:reflect" import "core:io" Marshal_Data_Error :: enum { @@ -302,7 +303,7 @@ marshal_to_writer :: proc(w: io.Writer, v: any, opt: ^Marshal_Options) -> (err: for name, i in info.names { opt_write_iteration(w, opt, i) or_return - if json_name := string(reflect.struct_tag_get(info.tags[i], "json")); json_name != "" { + if json_name := string(reflect.struct_tag_get(auto_cast info.tags[i], "json")); json_name != "" { opt_write_key(w, opt, json_name) or_return } else { opt_write_key(w, opt, name) or_return From f50fc33749d550187a41b62f203c33549073fbf3 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Thu, 15 Sep 2022 10:00:50 +0100 Subject: [PATCH 7/7] Clean up of the core library to make the stream vtables not be pointers directly. --- core/bufio/read_writer.odin | 4 +-- core/bufio/reader.odin | 4 +-- core/bufio/writer.odin | 4 +-- core/bytes/buffer.odin | 4 +-- core/bytes/reader.odin | 4 +-- core/fmt/fmt_js.odin | 6 ++-- core/os/os2/file_stream.odin | 4 +-- core/os/stream.odin | 4 +-- core/strings/builder.odin | 4 +-- core/strings/reader.odin | 4 +-- core/sys/darwin/xnu_system_call_helpers.odin | 33 +++++++++++++------- src/llvm_backend_const.cpp | 3 ++ 12 files changed, 45 insertions(+), 33 deletions(-) diff --git a/core/bufio/read_writer.odin b/core/bufio/read_writer.odin index ccd59a398..f9ae1ed45 100644 --- a/core/bufio/read_writer.odin +++ b/core/bufio/read_writer.odin @@ -15,12 +15,12 @@ read_writer_init :: proc(rw: ^Read_Writer, r: ^Reader, w: ^Writer) { read_writer_to_stream :: proc(rw: ^Read_Writer) -> (s: io.Stream) { s.stream_data = rw - s.stream_vtable = _read_writer_vtable + s.stream_vtable = &_read_writer_vtable return } @(private) -_read_writer_vtable := &io.Stream_VTable{ +_read_writer_vtable := io.Stream_VTable{ impl_read = proc(s: io.Stream, p: []byte) -> (n: int, err: io.Error) { b := (^Read_Writer)(s.stream_data).r return reader_read(b, p) diff --git a/core/bufio/reader.odin b/core/bufio/reader.odin index f17519656..6bfc4cd9d 100644 --- a/core/bufio/reader.odin +++ b/core/bufio/reader.odin @@ -353,14 +353,14 @@ reader_write_to :: proc(b: ^Reader, w: io.Writer) -> (n: i64, err: io.Error) { // reader_to_stream converts a Reader into an io.Stream reader_to_stream :: proc(b: ^Reader) -> (s: io.Stream) { s.stream_data = b - s.stream_vtable = _reader_vtable + s.stream_vtable = &_reader_vtable return } @(private) -_reader_vtable := &io.Stream_VTable{ +_reader_vtable := io.Stream_VTable{ impl_destroy = proc(s: io.Stream) -> io.Error { b := (^Reader)(s.stream_data) reader_destroy(b) diff --git a/core/bufio/writer.odin b/core/bufio/writer.odin index 861358526..9e38395ee 100644 --- a/core/bufio/writer.odin +++ b/core/bufio/writer.odin @@ -223,14 +223,14 @@ writer_read_from :: proc(b: ^Writer, r: io.Reader) -> (n: i64, err: io.Error) { // writer_to_stream converts a Writer into an io.Stream writer_to_stream :: proc(b: ^Writer) -> (s: io.Stream) { s.stream_data = b - s.stream_vtable = _writer_vtable + s.stream_vtable = &_writer_vtable return } @(private) -_writer_vtable := &io.Stream_VTable{ +_writer_vtable := io.Stream_VTable{ impl_destroy = proc(s: io.Stream) -> io.Error { b := (^Writer)(s.stream_data) writer_destroy(b) diff --git a/core/bytes/buffer.odin b/core/bytes/buffer.odin index 96f057a9b..d9f195871 100644 --- a/core/bytes/buffer.odin +++ b/core/bytes/buffer.odin @@ -374,12 +374,12 @@ buffer_read_from :: proc(b: ^Buffer, r: io.Reader) -> (n: i64, err: io.Error) #n buffer_to_stream :: proc(b: ^Buffer) -> (s: io.Stream) { s.stream_data = b - s.stream_vtable = _buffer_vtable + s.stream_vtable = &_buffer_vtable return } @(private) -_buffer_vtable := &io.Stream_VTable{ +_buffer_vtable := io.Stream_VTable{ impl_size = proc(s: io.Stream) -> i64 { b := (^Buffer)(s.stream_data) return i64(buffer_capacity(b)) diff --git a/core/bytes/reader.odin b/core/bytes/reader.odin index b10fd009c..7c37f3061 100644 --- a/core/bytes/reader.odin +++ b/core/bytes/reader.odin @@ -17,7 +17,7 @@ reader_init :: proc(r: ^Reader, s: []byte) { reader_to_stream :: proc(r: ^Reader) -> (s: io.Stream) { s.stream_data = r - s.stream_vtable = _reader_vtable + s.stream_vtable = &_reader_vtable return } @@ -137,7 +137,7 @@ reader_write_to :: proc(r: ^Reader, w: io.Writer) -> (n: i64, err: io.Error) { @(private) -_reader_vtable := &io.Stream_VTable{ +_reader_vtable := io.Stream_VTable{ impl_size = proc(s: io.Stream) -> i64 { r := (^Reader)(s.stream_data) return reader_size(r) diff --git a/core/fmt/fmt_js.odin b/core/fmt/fmt_js.odin index 7a9876127..7f6008889 100644 --- a/core/fmt/fmt_js.odin +++ b/core/fmt/fmt_js.odin @@ -11,7 +11,7 @@ foreign odin_env { } @(private="file") -write_vtable := &io.Stream_VTable{ +write_vtable := io.Stream_VTable{ impl_write = proc(s: io.Stream, p: []byte) -> (n: int, err: io.Error) { fd := u32(uintptr(s.stream_data)) write(fd, p) @@ -22,14 +22,14 @@ write_vtable := &io.Stream_VTable{ @(private="file") stdout := io.Writer{ stream = { - stream_vtable = write_vtable, + stream_vtable = &write_vtable, stream_data = rawptr(uintptr(1)), }, } @(private="file") stderr := io.Writer{ stream = { - stream_vtable = write_vtable, + stream_vtable = &write_vtable, stream_data = rawptr(uintptr(2)), }, } diff --git a/core/os/os2/file_stream.odin b/core/os/os2/file_stream.odin index 5e3db9370..7edbd68fa 100644 --- a/core/os/os2/file_stream.odin +++ b/core/os/os2/file_stream.odin @@ -4,7 +4,7 @@ import "core:io" to_stream :: proc(f: ^File) -> (s: io.Stream) { s.stream_data = f - s.stream_vtable = _file_stream_vtable + s.stream_vtable = &_file_stream_vtable return } @@ -26,7 +26,7 @@ error_to_io_error :: proc(ferr: Error) -> io.Error { @(private) -_file_stream_vtable := &io.Stream_VTable{ +_file_stream_vtable := io.Stream_VTable{ impl_read = proc(s: io.Stream, p: []byte) -> (n: int, err: io.Error) { f := (^File)(s.stream_data) ferr: Error diff --git a/core/os/stream.odin b/core/os/stream.odin index 2c6e1d47f..9506ed3a3 100644 --- a/core/os/stream.odin +++ b/core/os/stream.odin @@ -5,13 +5,13 @@ import "core:io" stream_from_handle :: proc(fd: Handle) -> io.Stream { s: io.Stream s.stream_data = rawptr(uintptr(fd)) - s.stream_vtable = _file_stream_vtable + s.stream_vtable = &_file_stream_vtable return s } @(private) -_file_stream_vtable := &io.Stream_VTable{ +_file_stream_vtable := io.Stream_VTable{ impl_read = proc(s: io.Stream, p: []byte) -> (n: int, err: io.Error) { fd := Handle(uintptr(s.stream_data)) os_err: Errno diff --git a/core/strings/builder.odin b/core/strings/builder.odin index 6de42804d..0386431f1 100644 --- a/core/strings/builder.odin +++ b/core/strings/builder.odin @@ -67,7 +67,7 @@ builder_init :: proc{ } @(private) -_builder_stream_vtable := &io.Stream_VTable{ +_builder_stream_vtable := io.Stream_VTable{ impl_write = proc(s: io.Stream, p: []byte) -> (n: int, err: io.Error) { b := (^Builder)(s.stream_data) n = write_bytes(b, p) @@ -97,7 +97,7 @@ _builder_stream_vtable := &io.Stream_VTable{ // return an `io.Stream` from a builder to_stream :: proc(b: ^Builder) -> io.Stream { - return io.Stream{stream_vtable=_builder_stream_vtable, stream_data=b} + return io.Stream{stream_vtable=&_builder_stream_vtable, stream_data=b} } // return an `io.Writer` from a builder diff --git a/core/strings/reader.odin b/core/strings/reader.odin index a38f1fbe4..038740526 100644 --- a/core/strings/reader.odin +++ b/core/strings/reader.odin @@ -24,7 +24,7 @@ reader_init :: proc(r: ^Reader, s: string) { // returns a stream from the reader data reader_to_stream :: proc(r: ^Reader) -> (s: io.Stream) { s.stream_data = r - s.stream_vtable = _reader_vtable + s.stream_vtable = &_reader_vtable return } @@ -177,7 +177,7 @@ reader_write_to :: proc(r: ^Reader, w: io.Writer) -> (n: i64, err: io.Error) { } @(private) -_reader_vtable := &io.Stream_VTable{ +_reader_vtable := io.Stream_VTable{ impl_size = proc(s: io.Stream) -> i64 { r := (^Reader)(s.stream_data) return reader_size(r) diff --git a/core/sys/darwin/xnu_system_call_helpers.odin b/core/sys/darwin/xnu_system_call_helpers.odin index 94fe0bf47..9522b9908 100644 --- a/core/sys/darwin/xnu_system_call_helpers.odin +++ b/core/sys/darwin/xnu_system_call_helpers.odin @@ -1,11 +1,11 @@ package darwin -import "core:strings" import "core:c" +import "core:runtime" // this package uses the sys prefix for the proc names to indicate that these aren't native syscalls but directly call such sys_write_string :: proc (fd: c.int, message: string) -> bool { - return syscall_write(fd, strings.ptr_from_string(message), cast(u64)len(message)) + return syscall_write(fd, raw_data(message), cast(u64)len(message)) } Offset_From :: enum c.int { @@ -87,11 +87,20 @@ _sys_permission_mode :: #force_inline proc (mode: Permission) -> u32 { return cflags } +@(private) +clone_to_cstring :: proc(s: string, allocator: runtime.Allocator, loc := #caller_location) -> cstring { + c := make([]byte, len(s)+1, allocator, loc) + copy(c, s) + c[len(s)] = 0 + return cstring(&c[0]) +} + + sys_open :: proc(path: string, oflag: Open_Flags, mode: Permission) -> (c.int, bool) { cmode: u32 = 0 cflags: u32 = 0 - cpath: cstring = strings.clone_to_cstring(path, context.temp_allocator) + cpath: cstring = clone_to_cstring(path, context.temp_allocator) cflags = _sys_permission_mode(mode) @@ -123,32 +132,32 @@ sys_open :: proc(path: string, oflag: Open_Flags, mode: Permission) -> (c.int, b } sys_mkdir :: proc(path: string, mode: Permission) -> bool { - cpath: cstring = strings.clone_to_cstring(path, context.temp_allocator) + cpath: cstring = clone_to_cstring(path, context.temp_allocator) cflags := _sys_permission_mode(mode) return syscall_mkdir(cpath, cflags) != -1 } sys_mkdir_at :: proc(fd: c.int, path: string, mode: Permission) -> bool { - cpath: cstring = strings.clone_to_cstring(path, context.temp_allocator) + cpath: cstring = clone_to_cstring(path, context.temp_allocator) cflags := _sys_permission_mode(mode) return syscall_mkdir_at(fd, cpath, cflags) != -1 } sys_rmdir :: proc(path: string, mode: Permission) -> bool { - cpath: cstring = strings.clone_to_cstring(path, context.temp_allocator) + cpath: cstring = clone_to_cstring(path, context.temp_allocator) cflags := _sys_permission_mode(mode) return syscall_rmdir(cpath, cflags) != -1 } sys_rename :: proc(path: string, new_path: string) -> bool { - cpath: cstring = strings.clone_to_cstring(path, context.temp_allocator) - cnpath: cstring = strings.clone_to_cstring(new_path, context.temp_allocator) + cpath: cstring = clone_to_cstring(path, context.temp_allocator) + cnpath: cstring = clone_to_cstring(new_path, context.temp_allocator) return syscall_rename(cpath, cnpath) != -1 } sys_rename_at :: proc(fd: c.int, path: string, to_fd: c.int, new_path: string) -> bool { - cpath: cstring = strings.clone_to_cstring(path, context.temp_allocator) - cnpath: cstring = strings.clone_to_cstring(new_path, context.temp_allocator) + cpath: cstring = clone_to_cstring(path, context.temp_allocator) + cnpath: cstring = clone_to_cstring(new_path, context.temp_allocator) return syscall_rename_at(fd, cpath, to_fd, cnpath) != -1 } @@ -157,12 +166,12 @@ sys_lseek :: proc(fd: c.int, offset: i64, whence: Offset_From) -> i64 { } sys_chmod :: proc(path: string, mode: Permission) -> bool { - cpath: cstring = strings.clone_to_cstring(path, context.temp_allocator) + cpath: cstring = clone_to_cstring(path, context.temp_allocator) cmode := _sys_permission_mode(mode) return syscall_chmod(cpath, cmode) != -1 } sys_lstat :: proc(path: string, status: ^stat) -> bool { - cpath: cstring = strings.clone_to_cstring(path, context.temp_allocator) + cpath: cstring = clone_to_cstring(path, context.temp_allocator) return syscall_lstat(cpath, status) != -1 } diff --git a/src/llvm_backend_const.cpp b/src/llvm_backend_const.cpp index 45e597a9e..53c7c4dcb 100644 --- a/src/llvm_backend_const.cpp +++ b/src/llvm_backend_const.cpp @@ -390,6 +390,9 @@ lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bool allow_loc Entity *e = entity_from_expr(expr); res = lb_find_procedure_value_from_entity(m, e); } + GB_ASSERT(res.value != nullptr); + GB_ASSERT(LLVMGetValueKind(res.value) == LLVMFunctionValueKind); + res.value = LLVMConstPointerCast(res.value, lb_type(m, res.type)); return res; }