mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-04 22:58:46 +00:00
Add implicit selector expressions for in/notin
This commit is contained in:
+12
-16
@@ -47,12 +47,10 @@ arena_allocator :: proc(arena: ^Arena) -> Allocator {
|
|||||||
arena_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
|
arena_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
|
||||||
size, alignment: int,
|
size, alignment: int,
|
||||||
old_memory: rawptr, old_size: int, flags: u64, location := #caller_location) -> rawptr {
|
old_memory: rawptr, old_size: int, flags: u64, location := #caller_location) -> rawptr {
|
||||||
using Allocator_Mode;
|
|
||||||
arena := cast(^Arena)allocator_data;
|
arena := cast(^Arena)allocator_data;
|
||||||
|
|
||||||
|
|
||||||
switch mode {
|
switch mode {
|
||||||
case Alloc:
|
case .Alloc:
|
||||||
total_size := size + alignment;
|
total_size := size + alignment;
|
||||||
|
|
||||||
if arena.offset + total_size > len(arena.data) {
|
if arena.offset + total_size > len(arena.data) {
|
||||||
@@ -66,14 +64,14 @@ arena_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
|
|||||||
arena.peak_used = max(arena.peak_used, arena.offset);
|
arena.peak_used = max(arena.peak_used, arena.offset);
|
||||||
return zero(ptr, size);
|
return zero(ptr, size);
|
||||||
|
|
||||||
case Free:
|
case .Free:
|
||||||
// NOTE(bill): Free all at once
|
// NOTE(bill): Free all at once
|
||||||
// Use Arena_Temp_Memory if you want to free a block
|
// Use Arena_Temp_Memory if you want to free a block
|
||||||
|
|
||||||
case Free_All:
|
case .Free_All:
|
||||||
arena.offset = 0;
|
arena.offset = 0;
|
||||||
|
|
||||||
case Resize:
|
case .Resize:
|
||||||
return default_resize_align(old_memory, old_size, size, alignment, arena_allocator(arena));
|
return default_resize_align(old_memory, old_size, size, alignment, arena_allocator(arena));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,7 +225,6 @@ stack_allocator :: proc(stack: ^Stack) -> Allocator {
|
|||||||
stack_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
|
stack_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
|
||||||
size, alignment: int,
|
size, alignment: int,
|
||||||
old_memory: rawptr, old_size: int, flags: u64, location := #caller_location) -> rawptr {
|
old_memory: rawptr, old_size: int, flags: u64, location := #caller_location) -> rawptr {
|
||||||
using Allocator_Mode;
|
|
||||||
s := cast(^Stack)allocator_data;
|
s := cast(^Stack)allocator_data;
|
||||||
|
|
||||||
if s.data == nil {
|
if s.data == nil {
|
||||||
@@ -256,9 +253,9 @@ stack_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch mode {
|
switch mode {
|
||||||
case Alloc:
|
case .Alloc:
|
||||||
return raw_alloc(s, size, alignment);
|
return raw_alloc(s, size, alignment);
|
||||||
case Free:
|
case .Free:
|
||||||
if old_memory == nil {
|
if old_memory == nil {
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
@@ -288,11 +285,11 @@ stack_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
|
|||||||
s.prev_offset = int(header.prev_offset);
|
s.prev_offset = int(header.prev_offset);
|
||||||
|
|
||||||
|
|
||||||
case Free_All:
|
case .Free_All:
|
||||||
s.prev_offset = 0;
|
s.prev_offset = 0;
|
||||||
s.curr_offset = 0;
|
s.curr_offset = 0;
|
||||||
|
|
||||||
case Resize:
|
case .Resize:
|
||||||
if old_memory == nil {
|
if old_memory == nil {
|
||||||
return raw_alloc(s, size, alignment);
|
return raw_alloc(s, size, alignment);
|
||||||
}
|
}
|
||||||
@@ -374,7 +371,6 @@ small_stack_allocator :: proc(stack: ^Small_Stack) -> Allocator {
|
|||||||
small_stack_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
|
small_stack_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
|
||||||
size, alignment: int,
|
size, alignment: int,
|
||||||
old_memory: rawptr, old_size: int, flags: u64, location := #caller_location) -> rawptr {
|
old_memory: rawptr, old_size: int, flags: u64, location := #caller_location) -> rawptr {
|
||||||
using Allocator_Mode;
|
|
||||||
s := cast(^Small_Stack)allocator_data;
|
s := cast(^Small_Stack)allocator_data;
|
||||||
|
|
||||||
if s.data == nil {
|
if s.data == nil {
|
||||||
@@ -403,9 +399,9 @@ small_stack_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch mode {
|
switch mode {
|
||||||
case Alloc:
|
case .Alloc:
|
||||||
return raw_alloc(s, size, alignment);
|
return raw_alloc(s, size, alignment);
|
||||||
case Free:
|
case .Free:
|
||||||
if old_memory == nil {
|
if old_memory == nil {
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
@@ -428,10 +424,10 @@ small_stack_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
|
|||||||
|
|
||||||
s.offset = int(old_offset);
|
s.offset = int(old_offset);
|
||||||
|
|
||||||
case Free_All:
|
case .Free_All:
|
||||||
s.offset = 0;
|
s.offset = 0;
|
||||||
|
|
||||||
case Resize:
|
case .Resize:
|
||||||
if old_memory == nil {
|
if old_memory == nil {
|
||||||
return raw_alloc(s, size, alignment);
|
return raw_alloc(s, size, alignment);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -475,7 +475,7 @@ append_bits :: proc(buf: []byte, u: u64, base: int, is_signed: bool, bit_size: i
|
|||||||
}
|
}
|
||||||
i-=1; a[i] = digits[u % b];
|
i-=1; a[i] = digits[u % b];
|
||||||
|
|
||||||
if Int_Flag.Prefix in flags {
|
if .Prefix in flags {
|
||||||
ok := true;
|
ok := true;
|
||||||
switch base {
|
switch base {
|
||||||
case 2: i-=1; a[i] = 'b';
|
case 2: i-=1; a[i] = 'b';
|
||||||
@@ -493,9 +493,9 @@ append_bits :: proc(buf: []byte, u: u64, base: int, is_signed: bool, bit_size: i
|
|||||||
switch {
|
switch {
|
||||||
case neg:
|
case neg:
|
||||||
i-=1; a[i] = '-';
|
i-=1; a[i] = '-';
|
||||||
case Int_Flag.Plus in flags:
|
case .Plus in flags:
|
||||||
i-=1; a[i] = '+';
|
i-=1; a[i] = '+';
|
||||||
case Int_Flag.Space in flags:
|
case .Space in flags:
|
||||||
i-=1; a[i] = ' ';
|
i-=1; a[i] = ' ';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+13
-1
@@ -2144,8 +2144,20 @@ void check_binary_expr(CheckerContext *c, Operand *x, Ast *node, bool use_lhs_as
|
|||||||
|
|
||||||
case Token_in:
|
case Token_in:
|
||||||
case Token_notin:
|
case Token_notin:
|
||||||
check_expr(c, x, be->left);
|
// IMPORTANT NOTE(bill): This uses right-left evaluation in type checking only no in
|
||||||
|
|
||||||
check_expr(c, y, be->right);
|
check_expr(c, y, be->right);
|
||||||
|
|
||||||
|
if (is_type_bit_set(y->type)) {
|
||||||
|
Type *elem = base_type(y->type)->BitSet.elem;
|
||||||
|
check_expr_with_type_hint(c, x, be->left, elem);
|
||||||
|
} else if (is_type_map(y->type)) {
|
||||||
|
Type *key = base_type(y->type)->Map.key;
|
||||||
|
check_expr_with_type_hint(c, x, be->left, key);
|
||||||
|
} else {
|
||||||
|
check_expr(c, x, be->left);
|
||||||
|
}
|
||||||
|
|
||||||
if (x->mode == Addressing_Invalid) {
|
if (x->mode == Addressing_Invalid) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user