mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Minor code clean up
This commit is contained in:
@@ -1077,9 +1077,9 @@ parse_stmt :: proc(p: ^Parser) -> ^ast.Stmt {
|
|||||||
stmt := parse_stmt(p);
|
stmt := parse_stmt(p);
|
||||||
switch name {
|
switch name {
|
||||||
case "bounds_check":
|
case "bounds_check":
|
||||||
stmt.state_flags |= {ast.Node_State_Flag.Bounds_Check};
|
stmt.state_flags |= {.Bounds_Check};
|
||||||
case "no_bounds_check":
|
case "no_bounds_check":
|
||||||
stmt.state_flags |= {ast.Node_State_Flag.No_Bounds_Check};
|
stmt.state_flags |= {.No_Bounds_Check};
|
||||||
}
|
}
|
||||||
return stmt;
|
return stmt;
|
||||||
case "complete":
|
case "complete":
|
||||||
@@ -1723,6 +1723,29 @@ string_to_calling_convention :: proc(s: string) -> ast.Proc_Calling_Convention {
|
|||||||
return Invalid;
|
return Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
parse_proc_tags :: proc(p: ^Parser) -> (tags: Proc_Tags) {
|
||||||
|
for p.curr_tok.kind == token.Hash {
|
||||||
|
tok := expect_token(p, token.Hash);
|
||||||
|
ident := expect_token(p, token.Ident);
|
||||||
|
|
||||||
|
switch ident.text {
|
||||||
|
case "require_results":
|
||||||
|
tags |= {.Require_Results};
|
||||||
|
case "bounds_check":
|
||||||
|
tags |= {.Bounds_Check};
|
||||||
|
case "no_bounds_check":
|
||||||
|
tags |= {.No_Bounds_Check};
|
||||||
|
case:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if .Bounds_Check in tags && .No_Bounds_Check in tags {
|
||||||
|
p.err(p.curr_tok.pos, "#bounds_check and #no_bounds_check applied to the same procedure type");
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
parse_proc_type :: proc(p: ^Parser, tok: token.Token) -> ^ast.Proc_Type {
|
parse_proc_type :: proc(p: ^Parser, tok: token.Token) -> ^ast.Proc_Type {
|
||||||
cc := ast.Proc_Calling_Convention.Invalid;
|
cc := ast.Proc_Calling_Convention.Invalid;
|
||||||
if p.curr_tok.kind == token.String {
|
if p.curr_tok.kind == token.String {
|
||||||
|
|||||||
+12
-18
@@ -251,8 +251,10 @@ Map_Entry_Header :: struct {
|
|||||||
Map_Header :: struct {
|
Map_Header :: struct {
|
||||||
m: ^mem.Raw_Map,
|
m: ^mem.Raw_Map,
|
||||||
is_key_string: bool,
|
is_key_string: bool,
|
||||||
|
|
||||||
entry_size: int,
|
entry_size: int,
|
||||||
entry_align: int,
|
entry_align: int,
|
||||||
|
|
||||||
value_offset: uintptr,
|
value_offset: uintptr,
|
||||||
value_size: int,
|
value_size: int,
|
||||||
}
|
}
|
||||||
@@ -833,29 +835,23 @@ __get_map_key :: proc "contextless" (key: $K) -> Map_Key {
|
|||||||
return map_key;
|
return map_key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_fnv64a :: proc(data: []byte, seed: u64 = 0xcbf29ce484222325) -> u64 {
|
||||||
|
h: u64 = seed;
|
||||||
|
for b in data {
|
||||||
|
h = (h ~ u64(b)) * 0x100000001b3;
|
||||||
|
}
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
default_hash :: proc(data: []byte) -> u64 {
|
default_hash :: proc(data: []byte) -> u64 {
|
||||||
fnv64a :: proc(data: []byte) -> u64 {
|
return _fnv64a(data);
|
||||||
h: u64 = 0xcbf29ce484222325;
|
|
||||||
for b in data {
|
|
||||||
h = (h ~ u64(b)) * 0x100000001b3;
|
|
||||||
}
|
|
||||||
return h;
|
|
||||||
}
|
|
||||||
return fnv64a(data);
|
|
||||||
}
|
}
|
||||||
default_hash_string :: proc(s: string) -> u64 do return default_hash(([]byte)(s));
|
default_hash_string :: proc(s: string) -> u64 do return default_hash(([]byte)(s));
|
||||||
|
|
||||||
|
|
||||||
source_code_location_hash :: proc(s: Source_Code_Location) -> u64 {
|
source_code_location_hash :: proc(s: Source_Code_Location) -> u64 {
|
||||||
fnv64a :: proc(data: []byte, seed: u64 = 0xcbf29ce484222325) -> u64 {
|
hash := _fnv64a(cast([]byte)s.file_path);
|
||||||
h: u64 = seed;
|
|
||||||
for b in data {
|
|
||||||
h = (h ~ u64(b)) * 0x100000001b3;
|
|
||||||
}
|
|
||||||
return h;
|
|
||||||
}
|
|
||||||
hash := fnv64a(cast([]byte)s.file_path);
|
|
||||||
hash = hash ~ (u64(s.line) * 0x100000001b3);
|
hash = hash ~ (u64(s.line) * 0x100000001b3);
|
||||||
hash = hash ~ (u64(s.column) * 0x100000001b3);
|
hash = hash ~ (u64(s.column) * 0x100000001b3);
|
||||||
return hash;
|
return hash;
|
||||||
@@ -863,7 +859,6 @@ source_code_location_hash :: proc(s: Source_Code_Location) -> u64 {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
__slice_resize :: proc(array_: ^$T/[]$E, new_count: int, allocator: mem.Allocator, loc := #caller_location) -> bool {
|
__slice_resize :: proc(array_: ^$T/[]$E, new_count: int, allocator: mem.Allocator, loc := #caller_location) -> bool {
|
||||||
array := (^mem.Raw_Slice)(array_);
|
array := (^mem.Raw_Slice)(array_);
|
||||||
|
|
||||||
@@ -942,7 +937,6 @@ __dynamic_map_get :: proc(h: Map_Header, key: Map_Key) -> rawptr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
__dynamic_map_set :: proc(h: Map_Header, key: Map_Key, value: rawptr, loc := #caller_location) #no_bounds_check {
|
__dynamic_map_set :: proc(h: Map_Header, key: Map_Key, value: rawptr, loc := #caller_location) #no_bounds_check {
|
||||||
|
|
||||||
index: int;
|
index: int;
|
||||||
assert(value != nil);
|
assert(value != nil);
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -5439,7 +5439,8 @@ ExprKind check_call_expr(CheckerContext *c, Operand *operand, Ast *call) {
|
|||||||
operand->mode = Addressing_NoValue;
|
operand->mode = Addressing_NoValue;
|
||||||
} else {
|
} else {
|
||||||
GB_ASSERT(is_type_tuple(result_type));
|
GB_ASSERT(is_type_tuple(result_type));
|
||||||
switch (result_type->Tuple.variables.count) {
|
isize count = result_type->Tuple.variables.count;
|
||||||
|
switch (count) {
|
||||||
case 0:
|
case 0:
|
||||||
operand->mode = Addressing_NoValue;
|
operand->mode = Addressing_NoValue;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -2049,6 +2049,7 @@ bool check_procedure_type(CheckerContext *ctx, Type *type, Ast *proc_type_node,
|
|||||||
type->Proc.is_polymorphic = pt->generic;
|
type->Proc.is_polymorphic = pt->generic;
|
||||||
type->Proc.specialization_count = specialization_count;
|
type->Proc.specialization_count = specialization_count;
|
||||||
type->Proc.diverging = pt->diverging;
|
type->Proc.diverging = pt->diverging;
|
||||||
|
type->Proc.tags = pt->tags;
|
||||||
|
|
||||||
if (param_count > 0) {
|
if (param_count > 0) {
|
||||||
Entity *end = params->Tuple.variables[param_count-1];
|
Entity *end = params->Tuple.variables[param_count-1];
|
||||||
|
|||||||
@@ -151,7 +151,6 @@ enum ProcTag {
|
|||||||
ProcTag_bounds_check = 1<<0,
|
ProcTag_bounds_check = 1<<0,
|
||||||
ProcTag_no_bounds_check = 1<<1,
|
ProcTag_no_bounds_check = 1<<1,
|
||||||
ProcTag_require_results = 1<<4,
|
ProcTag_require_results = 1<<4,
|
||||||
ProcTag_no_context = 1<<6,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum ProcCallingConvention {
|
enum ProcCallingConvention {
|
||||||
|
|||||||
@@ -198,6 +198,7 @@ struct TypeUnion {
|
|||||||
bool has_proc_default_values; \
|
bool has_proc_default_values; \
|
||||||
bool has_named_results; \
|
bool has_named_results; \
|
||||||
bool diverging; /* no return */ \
|
bool diverging; /* no return */ \
|
||||||
|
u64 tags; \
|
||||||
isize specialization_count; \
|
isize specialization_count; \
|
||||||
ProcCallingConvention calling_convention; \
|
ProcCallingConvention calling_convention; \
|
||||||
}) \
|
}) \
|
||||||
|
|||||||
Reference in New Issue
Block a user