From e4f28de3de7b8bd72c89b87884302bfc7f943b4f Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 3 Jan 2022 12:14:01 +0000 Subject: [PATCH 01/12] Fix #1311 --- vendor/microui/microui.odin | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/vendor/microui/microui.odin b/vendor/microui/microui.odin index 9d3e01fa0..947f59f40 100644 --- a/vendor/microui/microui.odin +++ b/vendor/microui/microui.odin @@ -1030,9 +1030,7 @@ number_textbox :: proc(ctx: ^Context, value: ^Real, r: Rect, id: Id, fmt_string: if ctx.number_edit_id == id { res := textbox_raw(ctx, ctx.number_edit_buf[:], &ctx.number_edit_len, id, r, {}) if .SUBMIT in res || ctx.focus_id != id { - ok: bool - value^, ok = parse_real(string(ctx.number_edit_buf[:ctx.number_edit_len])) - assert(ok == true) + value^, _ = parse_real(string(ctx.number_edit_buf[:ctx.number_edit_len])) ctx.number_edit_id = 0 } else { return true From 236b08cb4921d5c6000d5029f2936271acb45f29 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 3 Jan 2022 12:51:32 +0000 Subject: [PATCH 02/12] Fix #1356 --- src/check_type.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/check_type.cpp b/src/check_type.cpp index b4f30d2f0..282da4d0a 100644 --- a/src/check_type.cpp +++ b/src/check_type.cpp @@ -922,20 +922,19 @@ void check_bit_set_type(CheckerContext *c, Type *type, Type *named_type, Ast *no i64 lower = big_int_to_i64(&i); i64 upper = big_int_to_i64(&j); - bool lower_changed = false; + i64 actual_lower = lower; i64 bits = MAX_BITS; if (type->BitSet.underlying != nullptr) { bits = 8*type_size_of(type->BitSet.underlying); if (lower > 0) { - lower = 0; - lower_changed = true; + actual_lower = 0; } else if (lower < 0) { error(bs->elem, "bit_set does not allow a negative lower bound (%lld) when an underlying type is set", lower); } } - i64 bits_required = upper-lower; + i64 bits_required = upper-actual_lower; switch (be->op.kind) { case Token_Ellipsis: case Token_RangeFull: @@ -959,7 +958,7 @@ void check_bit_set_type(CheckerContext *c, Type *type, Type *named_type, Ast *no break; } if (!is_valid) { - if (lower_changed) { + if (actual_lower != lower) { error(bs->elem, "bit_set range is greater than %lld bits, %lld bits are required (internal the lower changed was changed 0 as an underlying type was set)", bits, bits_required); } else { error(bs->elem, "bit_set range is greater than %lld bits, %lld bits are required", bits, bits_required); From e6b8f7e77a419c8ff9e5f7de23fe15bef63264b1 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 3 Jan 2022 12:54:31 +0000 Subject: [PATCH 03/12] Fix #1398 --- src/check_expr.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/check_expr.cpp b/src/check_expr.cpp index 67e2f3bd7..cfffffd9f 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -7688,6 +7688,14 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast *node, Type } } + if (t->kind == Type_Matrix) { + if (cl->elems.count > 0 && cl->elems[0]->kind != Ast_FieldValue) { + if (0 < max && max < max_type_count) { + error(node, "Expected %lld values for this matrix literal, got %lld", cast(long long)max_type_count, cast(long long)max); + } + } + } + break; } From 12f459b5fb7904bfa926b5ad3fc5f80c6b5b4193 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 3 Jan 2022 13:12:39 +0000 Subject: [PATCH 04/12] Fix #1344 --- src/check_stmt.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp index 396388629..c3b8c46ca 100644 --- a/src/check_stmt.cpp +++ b/src/check_stmt.cpp @@ -58,6 +58,30 @@ bool contains_deferred_call(Ast *node) { return false; } +Ast *last_stmt_blocking_in_list(Slice const &stmts) { + for_array(i, stmts) { + Ast *n = stmts[i]; + switch (n->kind) { + case Ast_ReturnStmt: + return n; + case Ast_BranchStmt: + return n; + case Ast_ExprStmt: + if (is_diverging_stmt(n)) { + return n; + } + break; + case Ast_BlockStmt: + n = last_stmt_blocking_in_list(n->BlockStmt.stmts); + if (n != nullptr) { + return n; + } + break; + } + } + return nullptr; +} + void check_stmt_list(CheckerContext *ctx, Slice const &stmts, u32 flags) { if (stmts.count == 0) { return; @@ -102,6 +126,7 @@ void check_stmt_list(CheckerContext *ctx, Slice const &stmts, u32 flags) check_stmt(ctx, n, new_flags); if (i+1 < max_non_constant_declaration) { + never_executed_error:; switch (n->kind) { case Ast_ReturnStmt: error(n, "Statements after this 'return' are never executed"); @@ -116,6 +141,13 @@ void check_stmt_list(CheckerContext *ctx, Slice const &stmts, u32 flags) error(n, "Statements after a diverging procedure call are never executed"); } break; + + case Ast_BlockStmt: + n = last_stmt_blocking_in_list(n->BlockStmt.stmts); + if (n != nullptr) { + goto never_executed_error; + } + break; } } else if (i+1 == max_non_constant_declaration) { if (is_diverging_stmt(n)) { From defc1672c3d1b27c4720f53e95a0e1be0775e5e9 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 3 Jan 2022 13:48:12 +0000 Subject: [PATCH 05/12] Revert fix #1344 --- src/check_stmt.cpp | 32 -------------------------------- 1 file changed, 32 deletions(-) diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp index c3b8c46ca..396388629 100644 --- a/src/check_stmt.cpp +++ b/src/check_stmt.cpp @@ -58,30 +58,6 @@ bool contains_deferred_call(Ast *node) { return false; } -Ast *last_stmt_blocking_in_list(Slice const &stmts) { - for_array(i, stmts) { - Ast *n = stmts[i]; - switch (n->kind) { - case Ast_ReturnStmt: - return n; - case Ast_BranchStmt: - return n; - case Ast_ExprStmt: - if (is_diverging_stmt(n)) { - return n; - } - break; - case Ast_BlockStmt: - n = last_stmt_blocking_in_list(n->BlockStmt.stmts); - if (n != nullptr) { - return n; - } - break; - } - } - return nullptr; -} - void check_stmt_list(CheckerContext *ctx, Slice const &stmts, u32 flags) { if (stmts.count == 0) { return; @@ -126,7 +102,6 @@ void check_stmt_list(CheckerContext *ctx, Slice const &stmts, u32 flags) check_stmt(ctx, n, new_flags); if (i+1 < max_non_constant_declaration) { - never_executed_error:; switch (n->kind) { case Ast_ReturnStmt: error(n, "Statements after this 'return' are never executed"); @@ -141,13 +116,6 @@ void check_stmt_list(CheckerContext *ctx, Slice const &stmts, u32 flags) error(n, "Statements after a diverging procedure call are never executed"); } break; - - case Ast_BlockStmt: - n = last_stmt_blocking_in_list(n->BlockStmt.stmts); - if (n != nullptr) { - goto never_executed_error; - } - break; } } else if (i+1 == max_non_constant_declaration) { if (is_diverging_stmt(n)) { From 68e5f57e278ea7a3404508783daf2cc299a202e2 Mon Sep 17 00:00:00 2001 From: Platin21 Date: Mon, 3 Jan 2022 20:34:57 +0100 Subject: [PATCH 06/12] Fixes open system call (Thanks TIM!) --- core/os/os_darwin.odin | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/core/os/os_darwin.odin b/core/os/os_darwin.odin index d40c80aeb..d882dcbbd 100644 --- a/core/os/os_darwin.odin +++ b/core/os/os_darwin.odin @@ -296,6 +296,8 @@ foreign libc { @(link_name="readdir_r$INODE64") _unix_readdir_r :: proc(dirp: Dir, entry: ^Dirent, result: ^^Dirent) -> c.int --- @(link_name="fcntl") _unix_fcntl :: proc(fd: Handle, cmd: c.int, buf: ^byte) -> c.int --- + @(link_name="fchmod") _unix_fchmod :: proc(fildes: Handle, mode: u16) -> c.int ---; + @(link_name="malloc") _unix_malloc :: proc(size: int) -> rawptr --- @(link_name="calloc") _unix_calloc :: proc(num, size: int) -> rawptr --- @(link_name="free") _unix_free :: proc(ptr: rawptr) --- @@ -305,6 +307,8 @@ foreign libc { @(link_name="chdir") _unix_chdir :: proc(buf: cstring) -> c.int --- @(link_name="realpath") _unix_realpath :: proc(path: cstring, resolved_path: rawptr) -> rawptr --- + @(link_name="strerror") _darwin_string_error :: proc(num : c.int) -> cstring ---; + @(link_name="exit") _unix_exit :: proc(status: c.int) -> ! --- } @@ -319,16 +323,35 @@ get_last_error :: proc() -> int { return __error()^ } -open :: proc(path: string, flags: int = O_RDONLY, mode: int = 0) -> (Handle, Errno) { +get_last_error_string :: proc() -> string { + return cast(string)_darwin_string_error(cast(c.int)get_last_error()); +} + +open :: proc(path: string, flags: int = O_RDWR|O_CREATE, mode: int = 0) -> (Handle, Errno) { cstr := strings.clone_to_cstring(path) handle := _unix_open(cstr, i32(flags), u16(mode)) delete(cstr) if handle == -1 { return INVALID_HANDLE, 1 } + +when ODIN_OS == "darwin" && ODIN_ARCH == "arm64" { + if mode != 0 { + err := fchmod(handle, cast(u16)mode) + if err != 0 { + _unix_close(handle) + return INVALID_HANDLE, 1 + } + } +} + return handle, 0 } +fchmod :: proc(fildes: Handle, mode: u16) -> Errno { + return cast(Errno)_unix_fchmod(fildes, mode) +} + close :: proc(fd: Handle) { _unix_close(fd) } From 8ff6f955715f70f4d369f8c52c8fc5e5c1658cc0 Mon Sep 17 00:00:00 2001 From: Platin21 Date: Mon, 3 Jan 2022 20:40:56 +0100 Subject: [PATCH 07/12] Removes the default create flag --- core/os/os_darwin.odin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/os/os_darwin.odin b/core/os/os_darwin.odin index d882dcbbd..b32453a5d 100644 --- a/core/os/os_darwin.odin +++ b/core/os/os_darwin.odin @@ -327,7 +327,7 @@ get_last_error_string :: proc() -> string { return cast(string)_darwin_string_error(cast(c.int)get_last_error()); } -open :: proc(path: string, flags: int = O_RDWR|O_CREATE, mode: int = 0) -> (Handle, Errno) { +open :: proc(path: string, flags: int = O_RDWR, mode: int = 0) -> (Handle, Errno) { cstr := strings.clone_to_cstring(path) handle := _unix_open(cstr, i32(flags), u16(mode)) delete(cstr) From f818d0feb1fe0bb421ba27060ea6ff812bf67117 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 3 Jan 2022 19:43:22 +0000 Subject: [PATCH 08/12] Fix #1344 --- src/llvm_backend_stmt.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/llvm_backend_stmt.cpp b/src/llvm_backend_stmt.cpp index 016e464b8..20b444058 100644 --- a/src/llvm_backend_stmt.cpp +++ b/src/llvm_backend_stmt.cpp @@ -2188,6 +2188,7 @@ void lb_build_stmt(lbProcedure *p, Ast *node) { lb_emit_defer_stmts(p, lbDeferExit_Branch, block); } lb_emit_jump(p, block); + lb_start_block(p, lb_create_block(p, "unreachable")); case_end; } } From f15bb0b424d854e4ba84c14046b56d7b8357eb94 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 3 Jan 2022 19:45:27 +0000 Subject: [PATCH 09/12] Fix quaternion casting --- core/math/linalg/glsl/linalg_glsl.odin | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/math/linalg/glsl/linalg_glsl.odin b/core/math/linalg/glsl/linalg_glsl.odin index 3b4976452..053182794 100644 --- a/core/math/linalg/glsl/linalg_glsl.odin +++ b/core/math/linalg/glsl/linalg_glsl.odin @@ -1597,7 +1597,7 @@ quatNlerp :: proc "c" (a, b: quat, t: f32) -> (c: quat) { c.y = a.y + (b.y-a.y)*t c.z = a.z + (b.z-a.z)*t c.w = a.w + (b.w-a.w)*t - return c/builtin.abs(c) + return c/quat(builtin.abs(c)) } quatSlerp :: proc "c" (x, y: quat, t: f32) -> (q: quat) { @@ -1699,7 +1699,7 @@ dquatNlerp :: proc "c" (a, b: dquat, t: f64) -> (c: dquat) { c.y = a.y + (b.y-a.y)*t c.z = a.z + (b.z-a.z)*t c.w = a.w + (b.w-a.w)*t - return c/builtin.abs(c) + return c/dquat(builtin.abs(c)) } dquatSlerp :: proc "c" (x, y: dquat, t: f64) -> (q: dquat) { From 17613185e79b324948c14257f64c388c8e2a52fb Mon Sep 17 00:00:00 2001 From: gingerBill Date: Tue, 4 Jan 2022 11:44:34 +0000 Subject: [PATCH 10/12] Support struct field tags in odin doc format --- core/odin/doc-format/doc_format.odin | 4 +++- src/docs_format.cpp | 3 ++- src/docs_writer.cpp | 9 +++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/core/odin/doc-format/doc_format.odin b/core/odin/doc-format/doc_format.odin index c80be2489..83cd89ca2 100644 --- a/core/odin/doc-format/doc_format.odin +++ b/core/odin/doc-format/doc_format.odin @@ -11,7 +11,7 @@ String :: distinct Array(byte) Version_Type_Major :: 0 Version_Type_Minor :: 2 -Version_Type_Patch :: 1 +Version_Type_Patch :: 2 Version_Type :: struct { major, minor, patch: u8, @@ -242,6 +242,8 @@ Type :: struct { polymorphic_params: Type_Index, // Used By: .Struct, .Union where_clauses: Array(String), + // Used By: .Struct + tags: Array(String), } Type_Flags_Basic :: distinct bit_set[Type_Flag_Basic; u32le] diff --git a/src/docs_format.cpp b/src/docs_format.cpp index 1c3af6257..5cfac4817 100644 --- a/src/docs_format.cpp +++ b/src/docs_format.cpp @@ -15,7 +15,7 @@ struct OdinDocVersionType { #define OdinDocVersionType_Major 0 #define OdinDocVersionType_Minor 2 -#define OdinDocVersionType_Patch 1 +#define OdinDocVersionType_Patch 2 struct OdinDocHeaderBase { u8 magic[8]; @@ -137,6 +137,7 @@ struct OdinDocType { OdinDocArray entities; OdinDocTypeIndex polmorphic_params; OdinDocArray where_clauses; + OdinDocArray tags; // struct field tags }; struct OdinDocAttribute { diff --git a/src/docs_writer.cpp b/src/docs_writer.cpp index e8e8892ec..56ad0561e 100644 --- a/src/docs_writer.cpp +++ b/src/docs_writer.cpp @@ -598,6 +598,15 @@ OdinDocTypeIndex odin_doc_type(OdinDocWriter *w, Type *type) { } doc_type.where_clauses = odin_doc_where_clauses(w, st->where_clauses); } + + auto tags = array_make(heap_allocator(), type->Struct.fields.count); + defer (array_free(&tags)); + + for_array(i, type->Struct.fields) { + tags[i] = odin_doc_write_string(w, type->Struct.tags[i]); + } + + doc_type.tags = odin_write_slice(w, tags.data, tags.count); } break; case Type_Union: From 72862ce30d55891f1b04d3aadd085d7822f1b960 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Tue, 4 Jan 2022 11:48:18 +0000 Subject: [PATCH 11/12] Fix minor typo in c/frontend/preprocess --- core/c/frontend/preprocessor/preprocess.odin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/c/frontend/preprocessor/preprocess.odin b/core/c/frontend/preprocessor/preprocess.odin index 62b4183bc..9651cc81c 100644 --- a/core/c/frontend/preprocessor/preprocess.odin +++ b/core/c/frontend/preprocessor/preprocess.odin @@ -956,7 +956,7 @@ substitute_token :: proc(cpp: ^Preprocessor, tok: ^Token, args: ^Macro_Arg) -> ^ continue } - if tok.lit == "__VA__OPT__" && tok.next.lit == "(" { + if tok.lit == "__VA_OPT__" && tok.next.lit == "(" { opt_arg := read_macro_arg_one(cpp, &tok, tok.next.next, true) if has_varargs(args) { for t := opt_arg.tok; t.kind != .EOF; t = t.next { From 8c9597b24bc7397143b1a9039362be1c7ae53aeb Mon Sep 17 00:00:00 2001 From: Tyler Erickson Date: Tue, 4 Jan 2022 16:45:16 -0800 Subject: [PATCH 12/12] add schar to core:c and core:c/libc --- core/c/c.odin | 2 ++ core/c/libc/types.odin | 2 ++ 2 files changed, 4 insertions(+) diff --git a/core/c/c.odin b/core/c/c.odin index d135fa93c..139d9920a 100644 --- a/core/c/c.odin +++ b/core/c/c.odin @@ -3,6 +3,8 @@ package c import builtin "core:builtin" char :: builtin.u8 // assuming -funsigned-char + +schar :: builtin.i8 short :: builtin.i16 int :: builtin.i32 long :: builtin.i32 when (ODIN_OS == "windows" || size_of(builtin.rawptr) == 4) else builtin.i64 diff --git a/core/c/libc/types.odin b/core/c/libc/types.odin index 7199cf57b..a49e52fb6 100644 --- a/core/c/libc/types.odin +++ b/core/c/libc/types.odin @@ -3,6 +3,8 @@ package libc import "core:c" char :: c.char // assuming -funsigned-char + +schar :: c.schar short :: c.short int :: c.int long :: c.long