mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-29 19:00:06 +00:00
Update Standard Library; Fix Type_Info for integers
This commit is contained in:
@@ -1200,6 +1200,7 @@ b32 check_value_is_expressible(Checker *c, ExactValue in_value, Type *type, Exac
|
||||
return false;
|
||||
if (out_value) *out_value = v;
|
||||
i64 i = v.value_integer;
|
||||
u64 u = *cast(u64 *)&i;
|
||||
i64 s = 8*type_size_of(c->sizes, c->allocator, type);
|
||||
u64 umax = ~0ull;
|
||||
if (s < 64) {
|
||||
@@ -1221,7 +1222,7 @@ b32 check_value_is_expressible(Checker *c, ExactValue in_value, Type *type, Exac
|
||||
case Basic_u32:
|
||||
case Basic_u64:
|
||||
case Basic_uint:
|
||||
return !(i < 0 || cast(u64)i > umax);
|
||||
return !(u < 0 || u > umax);
|
||||
|
||||
case Basic_UntypedInteger:
|
||||
return true;
|
||||
|
||||
@@ -1017,10 +1017,14 @@ void check_stmt(Checker *c, AstNode *node, u32 flags) {
|
||||
auto *tuple = &proc_type->Proc.results->Tuple;
|
||||
variables = tuple->variables;
|
||||
}
|
||||
check_init_variables(c, variables, result_count,
|
||||
rs->results, make_string("return statement"));
|
||||
if (gb_array_count(rs->results) == 0) {
|
||||
error(ast_node_token(node), "Expected %td return values, got 0", result_count);
|
||||
} else {
|
||||
check_init_variables(c, variables, result_count,
|
||||
rs->results, make_string("return statement"));
|
||||
}
|
||||
} else if (gb_array_count(rs->results) > 0) {
|
||||
error(ast_node_token(rs->results[0]), "No result values expected");
|
||||
error(ast_node_token(rs->results[0]), "No return values expected");
|
||||
}
|
||||
case_end;
|
||||
|
||||
|
||||
+25
-6
@@ -352,17 +352,15 @@ void ssa_gen_tree(ssaGen *s) {
|
||||
case Basic_i16:
|
||||
case Basic_i32:
|
||||
case Basic_i64:
|
||||
// case Basic_i128:
|
||||
case Basic_u8:
|
||||
case Basic_u16:
|
||||
case Basic_u32:
|
||||
case Basic_u64:
|
||||
// case Basic_u128:
|
||||
case Basic_int:
|
||||
case Basic_uint: {
|
||||
tag = ssa_add_local_generated(proc, t_type_info_integer);
|
||||
b32 is_unsigned = (basic_types[t->Basic.kind].flags & BasicFlag_Unsigned) != 0;
|
||||
ssaValue *bits = ssa_make_const_int(a, type_size_of(m->sizes, a, t));
|
||||
b32 is_unsigned = (t->Basic.flags & BasicFlag_Unsigned) != 0;
|
||||
ssaValue *bits = ssa_make_const_int(a, type_size_of(m->sizes, a, t));
|
||||
ssaValue *is_signed = ssa_make_const_bool(a, !is_unsigned);
|
||||
ssa_emit_store(proc, ssa_emit_struct_gep(proc, tag, v_zero32, t_int_ptr), bits);
|
||||
ssa_emit_store(proc, ssa_emit_struct_gep(proc, tag, v_one32, t_bool_ptr), is_signed);
|
||||
@@ -434,8 +432,12 @@ void ssa_gen_tree(ssaGen *s) {
|
||||
{
|
||||
ssaValue *packed = ssa_make_const_bool(a, t->Record.struct_is_packed);
|
||||
ssaValue *ordered = ssa_make_const_bool(a, t->Record.struct_is_ordered);
|
||||
ssa_emit_store(proc, ssa_emit_struct_gep(proc, tag, v_one32, t_bool_ptr), packed);
|
||||
ssa_emit_store(proc, ssa_emit_struct_gep(proc, tag, v_two32, t_bool_ptr), ordered);
|
||||
ssaValue *size = ssa_make_const_int(a, type_size_of(m->sizes, a, t));
|
||||
ssaValue *align = ssa_make_const_int(a, type_align_of(m->sizes, a, t));
|
||||
ssa_emit_store(proc, ssa_emit_struct_gep(proc, tag, 1, t_bool_ptr), packed);
|
||||
ssa_emit_store(proc, ssa_emit_struct_gep(proc, tag, 2, t_bool_ptr), ordered);
|
||||
ssa_emit_store(proc, ssa_emit_struct_gep(proc, tag, 3, t_int_ptr), size);
|
||||
ssa_emit_store(proc, ssa_emit_struct_gep(proc, tag, 4, t_int_ptr), align);
|
||||
}
|
||||
|
||||
ssaValue *memory = type_info_member_offset(proc, type_info_member_data, t->Record.field_count, &type_info_member_index);
|
||||
@@ -476,9 +478,21 @@ void ssa_gen_tree(ssaGen *s) {
|
||||
} break;
|
||||
case TypeRecord_Union:
|
||||
tag = ssa_add_local_generated(proc, t_type_info_union);
|
||||
{
|
||||
ssaValue *size = ssa_make_const_int(a, type_size_of(m->sizes, a, t));
|
||||
ssaValue *align = ssa_make_const_int(a, type_align_of(m->sizes, a, t));
|
||||
ssa_emit_store(proc, ssa_emit_struct_gep(proc, tag, 3, t_int_ptr), size);
|
||||
ssa_emit_store(proc, ssa_emit_struct_gep(proc, tag, 4, t_int_ptr), align);
|
||||
}
|
||||
break;
|
||||
case TypeRecord_RawUnion: {
|
||||
tag = ssa_add_local_generated(proc, t_type_info_raw_union);
|
||||
{
|
||||
ssaValue *size = ssa_make_const_int(a, type_size_of(m->sizes, a, t));
|
||||
ssaValue *align = ssa_make_const_int(a, type_align_of(m->sizes, a, t));
|
||||
ssa_emit_store(proc, ssa_emit_struct_gep(proc, tag, 3, t_int_ptr), size);
|
||||
ssa_emit_store(proc, ssa_emit_struct_gep(proc, tag, 4, t_int_ptr), align);
|
||||
}
|
||||
|
||||
ssaValue *memory = type_info_member_offset(proc, type_info_member_data, t->Record.field_count, &type_info_member_index);
|
||||
|
||||
@@ -590,6 +604,11 @@ void ssa_gen_tree(ssaGen *s) {
|
||||
case Type_Tuple: {
|
||||
tag = ssa_add_local_generated(proc, t_type_info_tuple);
|
||||
|
||||
{
|
||||
ssaValue *align = ssa_make_const_int(a, type_align_of(m->sizes, a, t));
|
||||
ssa_emit_store(proc, ssa_emit_struct_gep(proc, tag, 4, t_int_ptr), align);
|
||||
}
|
||||
|
||||
ssaValue *memory = type_info_member_offset(proc, type_info_member_data, t->Tuple.variable_count, &type_info_member_index);
|
||||
|
||||
for (isize i = 0; i < t->Tuple.variable_count; i++) {
|
||||
|
||||
+2
-2
@@ -2369,7 +2369,7 @@ ssaValue *ssa_build_single_expr(ssaProcedure *proc, AstNode *expr, TypeAndValue
|
||||
args[1] = src;
|
||||
args[2] = byte_count;
|
||||
|
||||
ssa_emit_global_call(proc, "memory_copy", args, 3);
|
||||
ssa_emit_global_call(proc, "__mem_copy", args, 3);
|
||||
|
||||
return len;
|
||||
} break;
|
||||
@@ -2418,7 +2418,7 @@ ssaValue *ssa_build_single_expr(ssaProcedure *proc, AstNode *expr, TypeAndValue
|
||||
args[1] = item;
|
||||
args[2] = byte_count;
|
||||
|
||||
ssa_emit_global_call(proc, "memory_copy", args, 3);
|
||||
ssa_emit_global_call(proc, "__mem_copy", args, 3);
|
||||
|
||||
// Increment slice length
|
||||
Token add = {Token_Add};
|
||||
|
||||
@@ -106,7 +106,6 @@ ArchData make_arch_data(ArchKind kind) {
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
if (argc < 2) {
|
||||
gb_printf_err("using: %s [run] <filename> \n", argv[0]);
|
||||
|
||||
+1
-1
@@ -770,7 +770,7 @@ Token tokenizer_get_token(Tokenizer *t) {
|
||||
isize comment_scope = 1;
|
||||
advance_to_next_rune(t);
|
||||
while (comment_scope > 0) {
|
||||
if (curr_rune == '/') {
|
||||
if (t->curr_rune == '/') {
|
||||
advance_to_next_rune(t);
|
||||
if (t->curr_rune == '*') {
|
||||
advance_to_next_rune(t);
|
||||
|
||||
Reference in New Issue
Block a user