mirror of
https://github.com/odin-lang/Odin.git
synced 2026-04-19 13:00:28 +00:00
Merge branch 'master' of github.com:odin-lang/Odin
This commit is contained in:
@@ -244,6 +244,11 @@ constant_utf16_cstring :: proc($literal: string) -> [^]u16 ---
|
||||
|
||||
constant_log2 :: proc($v: $T) -> T where type_is_integer(T) ---
|
||||
|
||||
constant_floor :: proc($v: $T) -> T where type_is_integer(T) || type_is_float(T) ---
|
||||
constant_trunc :: proc($v: $T) -> T where type_is_integer(T) || type_is_float(T) ---
|
||||
constant_ceil :: proc($v: $T) -> T where type_is_integer(T) || type_is_float(T) ---
|
||||
constant_round :: proc($v: $T) -> T where type_is_integer(T) || type_is_float(T) ---
|
||||
|
||||
// SIMD related
|
||||
simd_add :: proc(a, b: #simd[N]T) -> #simd[N]T ---
|
||||
simd_sub :: proc(a, b: #simd[N]T) -> #simd[N]T ---
|
||||
|
||||
@@ -13,6 +13,7 @@ gb_global BuiltinTypeIsProc *builtin_type_is_procs[BuiltinProc__type_simple_bool
|
||||
nullptr, // BuiltinProc__type_simple_boolean_begin
|
||||
|
||||
is_type_boolean,
|
||||
is_type_bit_field,
|
||||
is_type_integer,
|
||||
is_type_rune,
|
||||
is_type_float,
|
||||
@@ -24,6 +25,7 @@ gb_global BuiltinTypeIsProc *builtin_type_is_procs[BuiltinProc__type_simple_bool
|
||||
is_type_cstring16,
|
||||
is_type_typeid,
|
||||
is_type_any,
|
||||
|
||||
is_type_endian_platform,
|
||||
is_type_endian_little,
|
||||
is_type_endian_big,
|
||||
@@ -34,8 +36,8 @@ gb_global BuiltinTypeIsProc *builtin_type_is_procs[BuiltinProc__type_simple_bool
|
||||
is_type_indexable,
|
||||
is_type_sliceable,
|
||||
is_type_comparable,
|
||||
is_type_simple_compare,
|
||||
is_type_nearly_simple_compare,
|
||||
is_type_simple_compare, // easily compared using memcmp
|
||||
is_type_nearly_simple_compare, // easily compared using memcmp (including floats)
|
||||
is_type_dereferenceable,
|
||||
is_type_valid_for_keys,
|
||||
is_type_valid_for_matrix_elems,
|
||||
@@ -47,14 +49,12 @@ gb_global BuiltinTypeIsProc *builtin_type_is_procs[BuiltinProc__type_simple_bool
|
||||
is_type_enumerated_array,
|
||||
is_type_slice,
|
||||
is_type_dynamic_array,
|
||||
|
||||
is_type_map,
|
||||
is_type_struct,
|
||||
is_type_union,
|
||||
is_type_enum,
|
||||
is_type_proc,
|
||||
is_type_bit_set,
|
||||
is_type_bit_field,
|
||||
is_type_simd_vector,
|
||||
is_type_matrix,
|
||||
is_type_raw_union,
|
||||
@@ -4768,6 +4768,42 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As
|
||||
break;
|
||||
}
|
||||
|
||||
case BuiltinProc_constant_floor:
|
||||
case BuiltinProc_constant_trunc:
|
||||
case BuiltinProc_constant_ceil:
|
||||
case BuiltinProc_constant_round:
|
||||
{
|
||||
Operand o = {};
|
||||
check_expr(c, &o, ce->args[0]);
|
||||
|
||||
if (!is_type_integer_or_float(o.type) && (o.mode != Addressing_Constant)) {
|
||||
error(ce->args[0], "Expected a constant number for '%.*s'", LIT(builtin_name));
|
||||
return false;
|
||||
}
|
||||
operand->mode = Addressing_Constant;
|
||||
operand->type = o.type;
|
||||
|
||||
ExactValue value = o.value;
|
||||
if (value.kind == ExactValue_Integer) {
|
||||
// do nothing
|
||||
} else if (value.kind == ExactValue_Float) {
|
||||
f64 f = value.value_float;
|
||||
switch (id) {
|
||||
case BuiltinProc_constant_floor: f = floor(f); break;
|
||||
case BuiltinProc_constant_trunc: f = trunc(f); break;
|
||||
case BuiltinProc_constant_ceil: f = ceil(f); break;
|
||||
case BuiltinProc_constant_round: f = round(f); break;
|
||||
default:
|
||||
GB_PANIC("Unhandled built-in: %.*s", LIT(builtin_name));
|
||||
break;
|
||||
}
|
||||
value = exact_value_float(f);
|
||||
}
|
||||
|
||||
operand->value = value;
|
||||
break;
|
||||
}
|
||||
|
||||
case BuiltinProc_soa_struct: {
|
||||
Operand x = {};
|
||||
Operand y = {};
|
||||
@@ -6552,17 +6588,18 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As
|
||||
|
||||
|
||||
case BuiltinProc_type_is_boolean:
|
||||
case BuiltinProc_type_is_bit_field:
|
||||
case BuiltinProc_type_is_integer:
|
||||
case BuiltinProc_type_is_rune:
|
||||
case BuiltinProc_type_is_float:
|
||||
case BuiltinProc_type_is_complex:
|
||||
case BuiltinProc_type_is_quaternion:
|
||||
case BuiltinProc_type_is_typeid:
|
||||
case BuiltinProc_type_is_any:
|
||||
case BuiltinProc_type_is_string:
|
||||
case BuiltinProc_type_is_string16:
|
||||
case BuiltinProc_type_is_cstring:
|
||||
case BuiltinProc_type_is_cstring16:
|
||||
case BuiltinProc_type_is_typeid:
|
||||
case BuiltinProc_type_is_any:
|
||||
case BuiltinProc_type_is_endian_platform:
|
||||
case BuiltinProc_type_is_endian_little:
|
||||
case BuiltinProc_type_is_endian_big:
|
||||
@@ -6573,8 +6610,8 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As
|
||||
case BuiltinProc_type_is_indexable:
|
||||
case BuiltinProc_type_is_sliceable:
|
||||
case BuiltinProc_type_is_comparable:
|
||||
case BuiltinProc_type_is_simple_compare:
|
||||
case BuiltinProc_type_is_nearly_simple_compare:
|
||||
case BuiltinProc_type_is_simple_compare: // easily compared using memcmp
|
||||
case BuiltinProc_type_is_nearly_simple_compare: // easily compared using memcmp (including floats)
|
||||
case BuiltinProc_type_is_dereferenceable:
|
||||
case BuiltinProc_type_is_valid_map_key:
|
||||
case BuiltinProc_type_is_valid_matrix_elements:
|
||||
@@ -6591,7 +6628,6 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As
|
||||
case BuiltinProc_type_is_enum:
|
||||
case BuiltinProc_type_is_proc:
|
||||
case BuiltinProc_type_is_bit_set:
|
||||
case BuiltinProc_type_is_bit_field:
|
||||
case BuiltinProc_type_is_simd_vector:
|
||||
case BuiltinProc_type_is_matrix:
|
||||
case BuiltinProc_type_is_raw_union:
|
||||
|
||||
@@ -49,6 +49,11 @@ enum BuiltinProcId {
|
||||
|
||||
BuiltinProc_constant_log2,
|
||||
|
||||
BuiltinProc_constant_floor,
|
||||
BuiltinProc_constant_trunc,
|
||||
BuiltinProc_constant_ceil,
|
||||
BuiltinProc_constant_round,
|
||||
|
||||
BuiltinProc_transpose,
|
||||
BuiltinProc_outer_product,
|
||||
BuiltinProc_hadamard_product,
|
||||
@@ -420,7 +425,11 @@ gb_global BuiltinProc builtin_procs[BuiltinProc_COUNT] = {
|
||||
|
||||
{STR_LIT("has_target_feature"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
|
||||
{STR_LIT("constant_log2"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
{STR_LIT("constant_log2"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
{STR_LIT("constant_floor"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
{STR_LIT("constant_trunc"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
{STR_LIT("constant_ceil"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
{STR_LIT("constant_round"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
|
||||
{STR_LIT("transpose"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
{STR_LIT("outer_product"), 2, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
@@ -615,17 +624,18 @@ gb_global BuiltinProc builtin_procs[BuiltinProc_COUNT] = {
|
||||
|
||||
{STR_LIT(""), 0, false, Expr_Stmt, BuiltinProcPkg_intrinsics},
|
||||
{STR_LIT("type_is_boolean"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
{STR_LIT("type_is_bit_field"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
{STR_LIT("type_is_integer"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
{STR_LIT("type_is_rune"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
{STR_LIT("type_is_float"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
{STR_LIT("type_is_complex"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
{STR_LIT("type_is_quaternion"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
{STR_LIT("type_is_typeid"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
{STR_LIT("type_is_any"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
{STR_LIT("type_is_string"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
{STR_LIT("type_is_string16"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
{STR_LIT("type_is_cstring"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
{STR_LIT("type_is_cstring16"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
{STR_LIT("type_is_cstring"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
{STR_LIT("type_is_cstring16"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
{STR_LIT("type_is_typeid"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
{STR_LIT("type_is_any"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
|
||||
{STR_LIT("type_is_endian_platform"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
{STR_LIT("type_is_endian_little"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
@@ -656,7 +666,6 @@ gb_global BuiltinProc builtin_procs[BuiltinProc_COUNT] = {
|
||||
{STR_LIT("type_is_enum"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
{STR_LIT("type_is_proc"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
{STR_LIT("type_is_bit_set"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
{STR_LIT("type_is_bit_field"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
{STR_LIT("type_is_simd_vector"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
{STR_LIT("type_is_matrix"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
{STR_LIT("type_is_raw_union"), 1, false, Expr_Expr, BuiltinProcPkg_intrinsics},
|
||||
|
||||
@@ -2739,7 +2739,7 @@ gb_internal Ast *parse_operand(AstFile *f, bool lhs) {
|
||||
while (allow_token(f, Token_Comma)) {
|
||||
Ast *dummy_name = parse_ident(f);
|
||||
if (!err_once) {
|
||||
error(dummy_name, "'bit_field' fields do not support multiple names per field");
|
||||
syntax_error(dummy_name, "'bit_field' fields do not support multiple names per field");
|
||||
err_once = true;
|
||||
}
|
||||
}
|
||||
@@ -3299,8 +3299,16 @@ gb_internal Ast *parse_atom_expr(AstFile *f, Ast *operand, bool lhs) {
|
||||
open = expect_token(f, Token_OpenBracket);
|
||||
|
||||
if (f->curr_token.kind == Token_CloseBracket) {
|
||||
error(f->curr_token, "Expected an operand, got ]");
|
||||
ERROR_BLOCK();
|
||||
syntax_error(f->curr_token, "Expected an operand, got ]");
|
||||
close = expect_token(f, Token_CloseBracket);
|
||||
|
||||
if (f->allow_type) {
|
||||
gbString s = expr_to_string(operand);
|
||||
error_line("\tSuggestion: If a type was wanted, did you mean '[]%s'?", s);
|
||||
gb_string_free(s);
|
||||
}
|
||||
|
||||
operand = ast_index_expr(f, operand, nullptr, open, close);
|
||||
break;
|
||||
}
|
||||
@@ -6594,7 +6602,7 @@ gb_internal bool parse_file_tag(const String &lc, const Token &tok, AstFile *f)
|
||||
} else if (lc == "no-instrumentation") {
|
||||
f->flags |= AstFile_NoInstrumentation;
|
||||
} else {
|
||||
error(tok, "Unknown tag '%.*s'", LIT(lc));
|
||||
syntax_error(tok, "Unknown tag '%.*s'", LIT(lc));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -1296,6 +1296,15 @@ gb_internal bool is_type_rune(Type *t) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
gb_internal bool is_type_integer_or_float(Type *t) {
|
||||
t = base_type(t);
|
||||
if (t == nullptr) { return false; }
|
||||
if (t->kind == Type_Basic) {
|
||||
return (t->Basic.flags & (BasicFlag_Integer|BasicFlag_Float)) != 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
gb_internal bool is_type_numeric(Type *t) {
|
||||
t = base_type(t);
|
||||
if (t == nullptr) { return false; }
|
||||
|
||||
Reference in New Issue
Block a user