mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 07:38:48 +00:00
Merge branch 'odin-lang:master' into master
This commit is contained in:
+15
-9
@@ -253,18 +253,24 @@ bprintf :: proc(buf: []byte, fmt: string, args: ..any) -> string {
|
|||||||
// - args: A variadic list of arguments to be formatted
|
// - args: A variadic list of arguments to be formatted
|
||||||
// - loc: The location of the caller
|
// - loc: The location of the caller
|
||||||
//
|
//
|
||||||
// Returns: True if the condition is met, otherwise triggers a runtime assertion with a formatted message
|
@(disabled=ODIN_DISABLE_ASSERT)
|
||||||
//
|
assertf :: proc(condition: bool, fmt: string, args: ..any, loc := #caller_location) {
|
||||||
assertf :: proc(condition: bool, fmt: string, args: ..any, loc := #caller_location) -> bool {
|
|
||||||
if !condition {
|
if !condition {
|
||||||
p := context.assertion_failure_proc
|
// NOTE(dragos): We are using the same trick as in builtin.assert
|
||||||
if p == nil {
|
// to improve performance to make the CPU not
|
||||||
p = runtime.default_assertion_failure_proc
|
// execute speculatively, making it about an order of
|
||||||
|
// magnitude faster
|
||||||
|
@(cold)
|
||||||
|
internal :: proc(loc: runtime.Source_Code_Location, fmt: string, args: ..any) {
|
||||||
|
p := context.assertion_failure_proc
|
||||||
|
if p == nil {
|
||||||
|
p = runtime.default_assertion_failure_proc
|
||||||
|
}
|
||||||
|
message := tprintf(fmt, ..args)
|
||||||
|
p("Runtime assertion", message, loc)
|
||||||
}
|
}
|
||||||
message := tprintf(fmt, ..args)
|
internal(loc, fmt, ..args)
|
||||||
p("Runtime assertion", message, loc)
|
|
||||||
}
|
}
|
||||||
return condition
|
|
||||||
}
|
}
|
||||||
// Runtime panic with a formatted message
|
// Runtime panic with a formatted message
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -116,6 +116,42 @@ panicf :: proc(fmt_str: string, args: ..any, location := #caller_location) -> !
|
|||||||
runtime.panic("log.panicf", location)
|
runtime.panic("log.panicf", location)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@(disabled=ODIN_DISABLE_ASSERT)
|
||||||
|
assert :: proc(condition: bool, message := "", loc := #caller_location) {
|
||||||
|
if !condition {
|
||||||
|
@(cold)
|
||||||
|
internal :: proc(message: string, loc: runtime.Source_Code_Location) {
|
||||||
|
p := context.assertion_failure_proc
|
||||||
|
if p == nil {
|
||||||
|
p = runtime.default_assertion_failure_proc
|
||||||
|
}
|
||||||
|
log(.Fatal, message, location=loc)
|
||||||
|
p("runtime assertion", message, loc)
|
||||||
|
}
|
||||||
|
internal(message, loc)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@(disabled=ODIN_DISABLE_ASSERT)
|
||||||
|
assertf :: proc(condition: bool, fmt_str: string, args: ..any, loc := #caller_location) {
|
||||||
|
if !condition {
|
||||||
|
// NOTE(dragos): We are using the same trick as in builtin.assert
|
||||||
|
// to improve performance to make the CPU not
|
||||||
|
// execute speculatively, making it about an order of
|
||||||
|
// magnitude faster
|
||||||
|
@(cold)
|
||||||
|
internal :: proc(loc: runtime.Source_Code_Location, fmt_str: string, args: ..any) {
|
||||||
|
p := context.assertion_failure_proc
|
||||||
|
if p == nil {
|
||||||
|
p = runtime.default_assertion_failure_proc
|
||||||
|
}
|
||||||
|
message := fmt.tprintf(fmt_str, ..args)
|
||||||
|
log(.Fatal, message, location=loc)
|
||||||
|
p("Runtime assertion", message, loc)
|
||||||
|
}
|
||||||
|
internal(loc, fmt_str, ..args)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -436,6 +436,24 @@ expect_closing_brace_of_field_list :: proc(p: ^Parser) -> tokenizer.Token {
|
|||||||
return expect_brace
|
return expect_brace
|
||||||
}
|
}
|
||||||
|
|
||||||
|
expect_closing_parentheses_of_field_list :: proc(p: ^Parser) -> tokenizer.Token {
|
||||||
|
token := p.curr_tok
|
||||||
|
if allow_token(p, .Close_Paren) {
|
||||||
|
return token
|
||||||
|
}
|
||||||
|
|
||||||
|
if allow_token(p, .Semicolon) && !tokenizer.is_newline(token) {
|
||||||
|
str := tokenizer.token_to_string(token)
|
||||||
|
error(p, end_of_line_pos(p, p.prev_tok), "expected a comma, got %s", str)
|
||||||
|
}
|
||||||
|
|
||||||
|
for p.curr_tok.kind != .Close_Paren && p.curr_tok.kind != .EOF && !is_non_inserted_semicolon(p.curr_tok) {
|
||||||
|
advance_token(p)
|
||||||
|
}
|
||||||
|
|
||||||
|
return expect_token(p, .Close_Paren)
|
||||||
|
}
|
||||||
|
|
||||||
is_non_inserted_semicolon :: proc(tok: tokenizer.Token) -> bool {
|
is_non_inserted_semicolon :: proc(tok: tokenizer.Token) -> bool {
|
||||||
return tok.kind == .Semicolon && tok.text != "\n"
|
return tok.kind == .Semicolon && tok.text != "\n"
|
||||||
}
|
}
|
||||||
@@ -2095,7 +2113,7 @@ parse_proc_type :: proc(p: ^Parser, tok: tokenizer.Token) -> ^ast.Proc_Type {
|
|||||||
|
|
||||||
expect_token(p, .Open_Paren)
|
expect_token(p, .Open_Paren)
|
||||||
params, _ := parse_field_list(p, .Close_Paren, ast.Field_Flags_Signature_Params)
|
params, _ := parse_field_list(p, .Close_Paren, ast.Field_Flags_Signature_Params)
|
||||||
expect_token(p, .Close_Paren)
|
expect_closing_parentheses_of_field_list(p)
|
||||||
results, diverging := parse_results(p)
|
results, diverging := parse_results(p)
|
||||||
|
|
||||||
is_generic := false
|
is_generic := false
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ _heap_allocator_proc :: proc(allocator_data: rawptr, mode: mem.Allocator_Mode,
|
|||||||
case .Free_All:
|
case .Free_All:
|
||||||
return nil, .Mode_Not_Implemented
|
return nil, .Mode_Not_Implemented
|
||||||
|
|
||||||
case .Resize:
|
case .Resize, .Resize_Non_Zeroed:
|
||||||
if old_memory == nil {
|
if old_memory == nil {
|
||||||
return aligned_alloc(size, alignment, true)
|
return aligned_alloc(size, alignment, true)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ reserve :: proc{reserve_dynamic_array, reserve_map}
|
|||||||
@builtin
|
@builtin
|
||||||
non_zero_reserve :: proc{non_zero_reserve_dynamic_array}
|
non_zero_reserve :: proc{non_zero_reserve_dynamic_array}
|
||||||
|
|
||||||
// `resize` will try to resize memory of a passed dynamic array or map to the requested element count (setting the `len`, and possibly `cap`).
|
// `resize` will try to resize memory of a passed dynamic array to the requested element count (setting the `len`, and possibly `cap`).
|
||||||
@builtin
|
@builtin
|
||||||
resize :: proc{resize_dynamic_array}
|
resize :: proc{resize_dynamic_array}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1085,7 +1085,7 @@ gb_internal void init_universal(void) {
|
|||||||
|
|
||||||
add_global_constant("ODIN_COMPILE_TIMESTAMP", t_untyped_integer, exact_value_i64(odin_compile_timestamp()));
|
add_global_constant("ODIN_COMPILE_TIMESTAMP", t_untyped_integer, exact_value_i64(odin_compile_timestamp()));
|
||||||
|
|
||||||
add_global_bool_constant("__ODIN_LLVM_F16_SUPPORTED", lb_use_new_pass_system());
|
add_global_bool_constant("__ODIN_LLVM_F16_SUPPORTED", lb_use_new_pass_system() && !is_arch_wasm());
|
||||||
|
|
||||||
{
|
{
|
||||||
GlobalEnumValue values[3] = {
|
GlobalEnumValue values[3] = {
|
||||||
|
|||||||
Reference in New Issue
Block a user