From: Brendan Hansen Date: Thu, 23 Mar 2023 23:58:20 +0000 (-0500) Subject: changed: pointer promotes to multi-pointer X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=de57f38ce2787cc021bd1416e50c206606cc0c22;p=onyx.git changed: pointer promotes to multi-pointer --- diff --git a/compiler/src/types.c b/compiler/src/types.c index ba0c25ef..4611cbed 100644 --- a/compiler/src/types.c +++ b/compiler/src/types.c @@ -135,6 +135,15 @@ b32 types_are_compatible_(Type* t1, Type* t2, b32 recurse_pointers) { } } + // Pointers promote to multi-pointers + // &u8 -> [&] u8 + if (t2->kind == Type_Kind_MultiPointer) { + if (!recurse_pointers) return 1; + + if (types_are_compatible(t1->Pointer.elem, t2->Pointer.elem)) return 1; + } + + // Pointer decays to rawptr if (t2->kind == Type_Kind_Basic && t2->Basic.kind == Basic_Kind_Rawptr) return 1; break; diff --git a/core/alloc/alloc.onyx b/core/alloc/alloc.onyx index b9733c0f..0577b32b 100644 --- a/core/alloc/alloc.onyx +++ b/core/alloc/alloc.onyx @@ -16,12 +16,12 @@ as_allocator :: #match { from_stack :: macro (size: u32) -> rawptr { // This should do something about the alignment... // Everything so far has assume that the stack is aligned to 16 bytes. - defer __stack_top = ~~(cast([&]u8) __stack_top + size); + defer __stack_top = cast([&]u8, __stack_top) + size; return __stack_top; } array_from_stack :: macro ($T: type_expr, size: u32) -> [] T { - defer __stack_top = ~~(cast([&]u8) __stack_top + size * sizeof T); + defer __stack_top = cast([&]u8, __stack_top) + size * sizeof T; return (cast([&]T) __stack_top)[0 .. size]; } diff --git a/core/conv/conv.onyx b/core/conv/conv.onyx index e3dbdb69..e3975f64 100644 --- a/core/conv/conv.onyx +++ b/core/conv/conv.onyx @@ -155,7 +155,7 @@ i64_to_str :: (n: i64, base: u64, buf: [] u8, min_length := 0, prefix := false) n = -n; } - c: [&] u8 = ~~&buf[buf.count - 1]; + c: [&] u8 = &buf[buf.count - 1]; len := 0; BASE64_MAP := "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/"; @@ -217,7 +217,7 @@ i64_to_str :: (n: i64, base: u64, buf: [] u8, min_length := 0, prefix := false) // Converts an unsigned number into a string using the buffer provided. // Behaves like i64_to_str. u64_to_str :: (n: u64, base: u64, buf: [] u8, min_length := 0, prefix := false) -> str { - c: [&] u8 = ~~&buf[buf.count - 1]; + c: [&] u8 = &buf[buf.count - 1]; len := 0; BASE64_MAP := "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/"; diff --git a/core/conv/format.onyx b/core/conv/format.onyx index 2744345c..59a4c196 100644 --- a/core/conv/format.onyx +++ b/core/conv/format.onyx @@ -252,7 +252,7 @@ format_va :: (buffer: &dyn_str, format: str, va: [] any) -> str { flush=.{ buffer, flush_to_dyn_str } }; - final := format_va(&output, format, ~~va); + final := format_va(&output, format, va); string.concat(buffer, final); return *buffer; } @@ -339,7 +339,7 @@ format_va :: (output: &Format_Output, format: str, va: [] any) -> str { i += 1; } - formatting.minimum_width = ~~digits; + formatting.minimum_width = digits; } case #char "!" { @@ -551,7 +551,7 @@ format_any :: (output: &Format_Output, formatting: &Format, v: any) { format.quote_strings = true; output->write("Some("); - format_any(output, &format, .{ ~~(cast([&] u8) v.data + s.members[1].offset), s.members[1].type }); + format_any(output, &format, .{ cast([&] u8) v.data + s.members[1].offset, s.members[1].type }); output->write(")"); } else { @@ -586,7 +586,7 @@ format_any :: (output: &Format_Output, formatting: &Format, v: any) { output->write(member.name); output->write(" = "); - format_any(output, &format, .{ ~~(cast([&] u8) v.data + member.offset), member.type }); + format_any(output, &format, .{ cast([&] u8) v.data + member.offset, member.type }); } } @@ -645,7 +645,7 @@ format_any :: (output: &Format_Output, formatting: &Format, v: any) { for _: format.indentation do output->write(#char " "); } - format_any(output, &format, .{ ~~(cast([&] u8) data + get_type_info(a.of).size * i), a.of }); + format_any(output, &format, .{ cast([&] u8) data + get_type_info(a.of).size * i, a.of }); } @@ -669,7 +669,7 @@ format_any :: (output: &Format_Output, formatting: &Format, v: any) { for i: a.count { if i != 0 do output->write(", "); - format_any(output, formatting, .{ ~~(cast([&] u8) data + get_type_info(a.of).size * i), a.of }); + format_any(output, formatting, .{ cast([&] u8) data + get_type_info(a.of).size * i, a.of }); } output->write(" ]"); diff --git a/core/conv/parse.onyx b/core/conv/parse.onyx index 1e708be3..d0f7fe1e 100644 --- a/core/conv/parse.onyx +++ b/core/conv/parse.onyx @@ -56,7 +56,7 @@ parse_any :: (target: rawptr, data_type: type_expr, to_parse: str, string_alloca case f64 { dest := cast(&f64) target; - *dest = ~~ str_to_f64(to_parse); + *dest = str_to_f64(to_parse); return true; } diff --git a/core/runtime/platform/onyx/fs.onyx b/core/runtime/platform/onyx/fs.onyx index 8ef4f1b9..3b49f1bf 100644 --- a/core/runtime/platform/onyx/fs.onyx +++ b/core/runtime/platform/onyx/fs.onyx @@ -97,7 +97,7 @@ __file_stream_vtable := io.Stream_Vtable.{ write_byte = (use fs: &os.File, byte: u8) -> io.Error { b := byte; bytes_wrote: u64; - error := __file_write(data, .{ ~~&b, 1 }, &bytes_wrote); + error := __file_write(data, .{ &b, 1 }, &bytes_wrote); return error; }, diff --git a/core/string/string.onyx b/core/string/string.onyx index e0309725..ab4dc6f8 100644 --- a/core/string/string.onyx +++ b/core/string/string.onyx @@ -48,7 +48,7 @@ copy :: (orig: str, dest: str) { #match as_str from_cstr from_cstr :: (s: cstr) -> str { - return .{ data = ~~s, count = length(s) }; + return .{ data = s, count = length(s) }; }