Browse Source

Merge remote-tracking branch 'origin/master'

hikari 2 years ago
parent
commit
42144d957b

+ 2 - 2
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)

+ 2 - 2
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)

+ 2 - 2
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)

+ 2 - 2
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))

+ 2 - 2
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)

+ 6 - 1
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,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(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
+			}
 
 			id := info.types[i].id
 			data := rawptr(uintptr(v.data) + info.offsets[i])

+ 8 - 1
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:

+ 3 - 3
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)),
 	},
 }

+ 2 - 2
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

+ 2 - 2
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

+ 2 - 2
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

+ 2 - 2
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)

+ 21 - 12
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
 }

+ 4 - 1
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);
 	}
@@ -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;
 	}