aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorftphikari <ftphikari@gmail.com>2022-06-08 19:55:42 +0300
committerGitHub <noreply@github.com>2022-06-08 19:55:42 +0300
commit5d4291d9fa5921ebfcaf7be6bc1dbb18197c02ec (patch)
tree6d6d6668795b59b0ddbdd947359d2900b4fda6c8
parentb70cd03e9ef2445d35dc5da9d58f2c79c3f4f7f5 (diff)
parentbfcb527b42832868ce0edf9817b3a00a933dcde8 (diff)
Merge branch 'odin-lang:master' into master
-rw-r--r--core/intrinsics/intrinsics.odin3
-rw-r--r--core/mem/allocators.odin9
-rw-r--r--core/mem/mem.odin2
-rw-r--r--core/simd/simd.odin3
-rw-r--r--core/slice/map.odin4
-rw-r--r--core/slice/sort.odin2
-rw-r--r--core/strings/builder.odin12
-rw-r--r--core/strings/intern.odin7
-rw-r--r--core/sys/windows/comdlg32.odin5
-rw-r--r--core/sys/windows/util.odin17
-rw-r--r--core/time/perf.odin8
-rw-r--r--src/check_builtin.cpp9
-rw-r--r--src/check_expr.cpp6
13 files changed, 56 insertions, 31 deletions
diff --git a/core/intrinsics/intrinsics.odin b/core/intrinsics/intrinsics.odin
index 9994a1914..22b5d953d 100644
--- a/core/intrinsics/intrinsics.odin
+++ b/core/intrinsics/intrinsics.odin
@@ -194,8 +194,7 @@ constant_utf16_cstring :: proc($literal: string) -> [^]u16 ---
simd_add :: proc(a, b: #simd[N]T) -> #simd[N]T ---
simd_sub :: proc(a, b: #simd[N]T) -> #simd[N]T ---
simd_mul :: proc(a, b: #simd[N]T) -> #simd[N]T ---
-simd_div :: proc(a, b: #simd[N]T) -> #simd[N]T ---
-simd_rem :: proc(a, b: #simd[N]T) -> #simd[N]T ---
+simd_div :: proc(a, b: #simd[N]T) -> #simd[N]T where type_is_float(T) ---
// Keeps Odin's Behaviour
// (x << y) if y <= mask else 0
diff --git a/core/mem/allocators.odin b/core/mem/allocators.odin
index d006e4574..6bedbf691 100644
--- a/core/mem/allocators.odin
+++ b/core/mem/allocators.odin
@@ -52,15 +52,16 @@ arena_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
switch mode {
case .Alloc:
- total_size := size + alignment
+ #no_bounds_check end := &arena.data[arena.offset]
+
+ ptr := align_forward(end, uintptr(alignment))
+
+ total_size := size + ptr_sub((^byte)(ptr), (^byte)(end))
if arena.offset + total_size > len(arena.data) {
return nil, .Out_Of_Memory
}
- #no_bounds_check end := &arena.data[arena.offset]
-
- ptr := align_forward(end, uintptr(alignment))
arena.offset += total_size
arena.peak_used = max(arena.peak_used, arena.offset)
zero(ptr, size)
diff --git a/core/mem/mem.odin b/core/mem/mem.odin
index 46fed4289..fd91a6c97 100644
--- a/core/mem/mem.odin
+++ b/core/mem/mem.odin
@@ -152,7 +152,7 @@ slice_ptr :: proc "contextless" (ptr: ^$T, len: int) -> []T {
return ([^]T)(ptr)[:len]
}
-byte_slice :: #force_inline proc "contextless" (data: rawptr, len: int) -> []byte {
+byte_slice :: #force_inline proc "contextless" (data: rawptr, #any_int len: int) -> []byte {
return ([^]u8)(data)[:max(len, 0)]
}
diff --git a/core/simd/simd.odin b/core/simd/simd.odin
index 390ff377a..a0a4df28d 100644
--- a/core/simd/simd.odin
+++ b/core/simd/simd.odin
@@ -61,8 +61,7 @@ b64x8 :: #simd[8]b64
add :: intrinsics.simd_add
sub :: intrinsics.simd_sub
mul :: intrinsics.simd_mul
-div :: intrinsics.simd_div
-rem :: intrinsics.simd_rem // integers only
+div :: intrinsics.simd_div // floats only
// Keeps Odin's Behaviour
// (x << y) if y <= mask else 0
diff --git a/core/slice/map.odin b/core/slice/map.odin
index 1c5512ceb..9de00b174 100644
--- a/core/slice/map.odin
+++ b/core/slice/map.odin
@@ -2,11 +2,9 @@ package slice
import "core:intrinsics"
import "core:runtime"
-import "core:mem"
_ :: intrinsics
_ :: runtime
-_ :: mem
map_keys :: proc(m: $M/map[$K]$V, allocator := context.allocator) -> (keys: []K) {
keys = make(type_of(keys), len(m), allocator)
@@ -52,7 +50,7 @@ map_entries :: proc(m: $M/map[$K]$V, allocator := context.allocator) -> (entries
map_entry_infos :: proc(m: $M/map[$K]$V, allocator := context.allocator) -> (entries: []Map_Entry_Info(K, V)) #no_bounds_check {
m := m
- rm := (^mem.Raw_Map)(&m)
+ rm := (^runtime.Raw_Map)(&m)
info := runtime.type_info_base(type_info_of(M)).variant.(runtime.Type_Info_Map)
gs := runtime.type_info_base(info.generated_struct).variant.(runtime.Type_Info_Struct)
diff --git a/core/slice/sort.odin b/core/slice/sort.odin
index 8a2dec039..b6e455056 100644
--- a/core/slice/sort.odin
+++ b/core/slice/sort.odin
@@ -103,7 +103,7 @@ is_sorted_by :: proc(array: $T/[]$E, less: proc(i, j: E) -> bool) -> bool {
is_sorted_by_cmp :: is_sorted_cmp
is_sorted_cmp :: proc(array: $T/[]$E, cmp: proc(i, j: E) -> Ordering) -> bool {
for i := len(array)-1; i > 0; i -= 1 {
- if cmp(array[i], array[i-1]) == .Equal {
+ if cmp(array[i], array[i-1]) == .Less {
return false
}
}
diff --git a/core/strings/builder.odin b/core/strings/builder.odin
index d51e21827..a910b0988 100644
--- a/core/strings/builder.odin
+++ b/core/strings/builder.odin
@@ -1,6 +1,6 @@
package strings
-import "core:mem"
+import "core:runtime"
import "core:unicode/utf8"
import "core:strconv"
import "core:io"
@@ -129,12 +129,12 @@ reset_builder :: proc(b: ^Builder) {
strings.write_byte(&builder, 'b') -> "ab"
*/
builder_from_bytes :: proc(backing: []byte) -> Builder {
- s := transmute(mem.Raw_Slice)backing
- d := mem.Raw_Dynamic_Array{
+ s := transmute(runtime.Raw_Slice)backing
+ d := runtime.Raw_Dynamic_Array{
data = s.data,
len = 0,
cap = s.len,
- allocator = mem.nil_allocator(),
+ allocator = runtime.nil_allocator(),
}
return Builder{
buf = transmute([dynamic]byte)d,
@@ -276,7 +276,7 @@ pop_byte :: proc(b: ^Builder) -> (r: byte) {
}
r = b.buf[len(b.buf)-1]
- d := cast(^mem.Raw_Dynamic_Array)&b.buf
+ d := cast(^runtime.Raw_Dynamic_Array)&b.buf
d.len = max(d.len-1, 0)
return
}
@@ -289,7 +289,7 @@ pop_rune :: proc(b: ^Builder) -> (r: rune, width: int) {
}
r, width = utf8.decode_last_rune(b.buf[:])
- d := cast(^mem.Raw_Dynamic_Array)&b.buf
+ d := cast(^runtime.Raw_Dynamic_Array)&b.buf
d.len = max(d.len-width, 0)
return
}
diff --git a/core/strings/intern.odin b/core/strings/intern.odin
index 27c3db084..1e9577e61 100644
--- a/core/strings/intern.odin
+++ b/core/strings/intern.odin
@@ -1,6 +1,6 @@
package strings
-import "core:mem"
+import "core:runtime"
// custom string entry struct
Intern_Entry :: struct {
@@ -11,7 +11,7 @@ Intern_Entry :: struct {
// "intern" is a more memory efficient string map
// `allocator` is used to allocate the actual `Intern_Entry` strings
Intern :: struct {
- allocator: mem.Allocator,
+ allocator: runtime.Allocator,
entries: map[string]^Intern_Entry,
}
@@ -54,7 +54,8 @@ _intern_get_entry :: proc(m: ^Intern, text: string) -> ^Intern_Entry #no_bounds_
}
entry_size := int(offset_of(Intern_Entry, str)) + len(text) + 1
- new_entry := (^Intern_Entry)(mem.alloc(entry_size, align_of(Intern_Entry), m.allocator))
+ ptr, _ := runtime.mem_alloc(entry_size, align_of(Intern_Entry), m.allocator)
+ new_entry := (^Intern_Entry)(ptr)
new_entry.len = len(text)
copy(new_entry.str[:new_entry.len], text)
diff --git a/core/sys/windows/comdlg32.odin b/core/sys/windows/comdlg32.odin
index 0f5b29789..8284050f1 100644
--- a/core/sys/windows/comdlg32.odin
+++ b/core/sys/windows/comdlg32.odin
@@ -2,7 +2,6 @@
package sys_windows
foreign import "system:Comdlg32.lib"
-import "core:strings"
LPOFNHOOKPROC :: #type proc "stdcall" (hdlg: HWND, msg: u32, wparam: WPARAM, lparam: LPARAM) -> UINT_PTR
@@ -47,6 +46,9 @@ SAVE_TITLE :: "Select file to save"
SAVE_FLAGS :: u32(OFN_OVERWRITEPROMPT | OFN_EXPLORER)
SAVE_EXT :: "txt"
+/*
+import "core:strings"
+
Open_Save_Mode :: enum {
Open = 0,
Save = 1,
@@ -119,6 +121,7 @@ select_file_to_save :: proc(title := SAVE_TITLE, dir := ".",
path, ok = _open_file_dialog(title, dir, filters, default_filter, flags, default_ext, Open_Save_Mode.Save, allocator)
return
}
+*/
// TODO: Implement convenience function for select_file_to_open with ALLOW_MULTI_SELECT that takes
// it output of the form "path\u0000\file1u\0000file2" and turns it into []string with the path + file pre-concatenated for you.
diff --git a/core/sys/windows/util.odin b/core/sys/windows/util.odin
index 1c8b9175b..c350032f0 100644
--- a/core/sys/windows/util.odin
+++ b/core/sys/windows/util.odin
@@ -1,7 +1,6 @@
// +build windows
package sys_windows
-import "core:strings"
import "core:runtime"
import "core:intrinsics"
@@ -100,6 +99,20 @@ utf16_to_utf8 :: proc(s: []u16, allocator := context.temp_allocator) -> (res: st
// AdvAPI32, NetAPI32 and UserENV helpers.
allowed_username :: proc(username: string) -> bool {
+ contains_any :: proc(s, chars: string) -> bool {
+ if chars == "" {
+ return false
+ }
+ for c in transmute([]byte)s {
+ for b in transmute([]byte)chars {
+ if c == b {
+ return true
+ }
+ }
+ }
+ return false
+ }
+
/*
User account names are limited to 20 characters and group names are limited to 256 characters.
In addition, account names cannot be terminated by a period and they cannot include commas or any of the following printable characters:
@@ -120,7 +133,7 @@ allowed_username :: proc(username: string) -> bool {
return false
}
}
- if strings.contains_any(username, _DISALLOWED) {
+ if contains_any(username, _DISALLOWED) {
return false
}
diff --git a/core/time/perf.odin b/core/time/perf.odin
index f49b57f5b..53406646f 100644
--- a/core/time/perf.odin
+++ b/core/time/perf.odin
@@ -1,6 +1,6 @@
package time
-import "core:mem"
+import "core:runtime"
Tick :: struct {
_nsec: i64, // relative amount
@@ -50,9 +50,9 @@ Benchmark_Error :: enum {
}
Benchmark_Options :: struct {
- setup: #type proc(options: ^Benchmark_Options, allocator: mem.Allocator) -> (err: Benchmark_Error),
- bench: #type proc(options: ^Benchmark_Options, allocator: mem.Allocator) -> (err: Benchmark_Error),
- teardown: #type proc(options: ^Benchmark_Options, allocator: mem.Allocator) -> (err: Benchmark_Error),
+ setup: #type proc(options: ^Benchmark_Options, allocator: runtime.Allocator) -> (err: Benchmark_Error),
+ bench: #type proc(options: ^Benchmark_Options, allocator: runtime.Allocator) -> (err: Benchmark_Error),
+ teardown: #type proc(options: ^Benchmark_Options, allocator: runtime.Allocator) -> (err: Benchmark_Error),
rounds: int,
bytes: int,
diff --git a/src/check_builtin.cpp b/src/check_builtin.cpp
index 92e3987a0..8108604ba 100644
--- a/src/check_builtin.cpp
+++ b/src/check_builtin.cpp
@@ -452,6 +452,13 @@ bool check_builtin_simd_operation(CheckerContext *c, Operand *operand, Ast *call
return false;
}
+ if (id == BuiltinProc_simd_div && is_type_integer(elem)) {
+ gbString xs = type_to_string(x.type);
+ error(x.expr, "'%.*s' is not supported for integer elements, got '%s'", LIT(builtin_name), xs);
+ gb_string_free(xs);
+ // don't return
+ }
+
operand->mode = Addressing_Value;
operand->type = x.type;
return true;
@@ -460,7 +467,6 @@ bool check_builtin_simd_operation(CheckerContext *c, Operand *operand, Ast *call
// Integer only
case BuiltinProc_simd_add_sat:
case BuiltinProc_simd_sub_sat:
- case BuiltinProc_simd_rem:
case BuiltinProc_simd_and:
case BuiltinProc_simd_or:
case BuiltinProc_simd_xor:
@@ -492,7 +498,6 @@ bool check_builtin_simd_operation(CheckerContext *c, Operand *operand, Ast *call
switch (id) {
case BuiltinProc_simd_add_sat:
case BuiltinProc_simd_sub_sat:
- case BuiltinProc_simd_rem:
if (!is_type_integer(elem)) {
gbString xs = type_to_string(x.type);
error(x.expr, "'%.*s' expected a #simd type with an integer element, got '%s'", LIT(builtin_name), xs);
diff --git a/src/check_expr.cpp b/src/check_expr.cpp
index f954f1583..58972d2cf 100644
--- a/src/check_expr.cpp
+++ b/src/check_expr.cpp
@@ -1618,6 +1618,9 @@ bool check_binary_op(CheckerContext *c, Operand *o, Token op) {
if (is_type_matrix(main_type)) {
error(op, "Operator '%.*s' is only allowed with matrix types", LIT(op.string));
return false;
+ } else if (is_type_simd_vector(main_type) && is_type_integer(type)) {
+ error(op, "Operator '%.*s' is only allowed with #simd types with integer elements", LIT(op.string));
+ return false;
}
/*fallthrough*/
case Token_Mul:
@@ -1669,6 +1672,9 @@ bool check_binary_op(CheckerContext *c, Operand *o, Token op) {
if (!is_type_integer(type)) {
error(op, "Operator '%.*s' is only allowed with integers", LIT(op.string));
return false;
+ } else if (is_type_simd_vector(main_type)) {
+ error(op, "Operator '%.*s' is only allowed with #simd types with integer elements", LIT(op.string));
+ return false;
}
break;