diff --git a/core/mem/alloc.odin b/core/mem/alloc.odin index f2ffeb323..dcb7db229 100644 --- a/core/mem/alloc.odin +++ b/core/mem/alloc.odin @@ -294,6 +294,12 @@ pool_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode, pool_free_all(pool); case Allocator_Mode.Resize: panic("Allocator_Mode.Resize is not supported for a pool"); + if old_size >= size { + return old_memory; + } + ptr := pool_alloc(pool, size); + copy(ptr, old_memory, old_size); + return ptr; } return nil; } diff --git a/core/os/os.odin b/core/os/os.odin index 1ff97d094..eda3b66cf 100644 --- a/core/os/os.odin +++ b/core/os/os.odin @@ -1,6 +1,8 @@ package os import "core:mem" +import "core:strconv" +import "core:unicode/utf8" write_string :: proc(fd: Handle, str: string) -> (int, Errno) { return write(fd, cast([]byte)str); @@ -10,6 +12,44 @@ write_byte :: proc(fd: Handle, b: byte) -> (int, Errno) { return write(fd, []byte{b}); } +write_rune :: proc(fd: Handle, r: rune) -> (int, Errno) { + if r < utf8.RUNE_SELF { + return write_byte(fd, byte(r)); + } + + b, n := utf8.encode_rune(r); + return write(fd, b[:n]); +} + +write_encoded_rune :: proc(fd: Handle, r: rune) { + write_byte(fd, '\''); + + switch r { + case '\a': write_string(fd, "\\a"); + case '\b': write_string(fd, "\\b"); + case '\e': write_string(fd, "\\e"); + case '\f': write_string(fd, "\\f"); + case '\n': write_string(fd, "\\n"); + case '\r': write_string(fd, "\\r"); + case '\t': write_string(fd, "\\t"); + case '\v': write_string(fd, "\\v"); + case: + if r < 32 { + write_string(fd, "\\x"); + b: [2]byte; + s := strconv.append_bits(b[:], u64(r), 16, true, 64, strconv.digits, nil); + switch len(s) { + case 0: write_string(fd, "00"); + case 1: write_rune(fd, '0'); + case 2: write_string(fd, s); + } + } else { + write_rune(fd, r); + } + } + write_byte(fd, '\''); +} + read_entire_file :: proc(name: string) -> (data: []byte, success: bool) { fd, err := open(name, O_RDONLY, 0); diff --git a/core/runtime/internal.odin b/core/runtime/internal.odin index 4f308eb3a..80ade1272 100644 --- a/core/runtime/internal.odin +++ b/core/runtime/internal.odin @@ -204,6 +204,27 @@ print_type :: proc(fd: os.Handle, ti: ^Type_Info) { print_u64(fd, u64(info.bits[i])); } os.write_string(fd, "}"); + + case Type_Info_Bit_Set: + os.write_string(fd, "bit_set["); + + switch elem in type_info_base(info.elem).variant { + case Type_Info_Enum: + print_type(fd, info.elem); + case Type_Info_Rune: + os.write_encoded_rune(fd, rune(info.lower)); + os.write_string(fd, ".."); + os.write_encoded_rune(fd, rune(info.upper)); + case: + print_i64(fd, info.lower); + os.write_string(fd, ".."); + print_i64(fd, info.upper); + } + if info.underlying != nil { + os.write_string(fd, "; "); + print_type(fd, info.underlying); + } + os.write_byte(fd, ']'); } } @@ -265,7 +286,6 @@ bounds_check_error :: proc "contextless" (file: string, line, column: int, index slice_expr_error :: proc "contextless" (file: string, line, column: int, lo, hi: int, len: int) { if 0 <= lo && lo <= hi && hi <= len do return; - fd := os.stderr; print_caller_location(fd, Source_Code_Location{file, line, column, ""}); os.write_string(fd, " Invalid slice indices: "); @@ -366,18 +386,6 @@ make_map_expr_error_loc :: inline proc "contextless" (using loc := #caller_locat foreign { @(link_name="llvm.sqrt.f32") _sqrt_f32 :: proc(x: f32) -> f32 --- @(link_name="llvm.sqrt.f64") _sqrt_f64 :: proc(x: f64) -> f64 --- - - @(link_name="llvm.sin.f32") _sin_f32 :: proc(θ: f32) -> f32 --- - @(link_name="llvm.sin.f64") _sin_f64 :: proc(θ: f64) -> f64 --- - - @(link_name="llvm.cos.f32") _cos_f32 :: proc(θ: f32) -> f32 --- - @(link_name="llvm.cos.f64") _cos_f64 :: proc(θ: f64) -> f64 --- - - @(link_name="llvm.pow.f32") _pow_f32 :: proc(x, power: f32) -> f32 --- - @(link_name="llvm.pow.f64") _pow_f64 :: proc(x, power: f64) -> f64 --- - - @(link_name="llvm.fmuladd.f32") _fmuladd32 :: proc(a, b, c: f32) -> f32 --- - @(link_name="llvm.fmuladd.f64") _fmuladd64 :: proc(a, b, c: f64) -> f64 --- } abs_f32 :: inline proc "contextless" (x: f32) -> f32 { foreign { diff --git a/src/ir.cpp b/src/ir.cpp index 4cf885994..ffd9f4f67 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -4582,7 +4582,6 @@ irValue *ir_build_builtin_proc(irProcedure *proc, Ast *expr, TypeAndValue tv, Bu ir_emit_store(proc, ir_emit_struct_ep(proc, dst, 1), imag); return ir_emit_load(proc, dst); - break; } case BuiltinProc_real: { @@ -4590,14 +4589,12 @@ irValue *ir_build_builtin_proc(irProcedure *proc, Ast *expr, TypeAndValue tv, Bu irValue *val = ir_build_expr(proc, ce->args[0]); irValue *real = ir_emit_struct_ev(proc, val, 0); return ir_emit_conv(proc, real, tv.type); - break; } case BuiltinProc_imag: { ir_emit_comment(proc, str_lit("imag")); irValue *val = ir_build_expr(proc, ce->args[0]); irValue *imag = ir_emit_struct_ev(proc, val, 1); return ir_emit_conv(proc, imag, tv.type); - break; } case BuiltinProc_conj: { @@ -4614,7 +4611,6 @@ irValue *ir_build_builtin_proc(irProcedure *proc, Ast *expr, TypeAndValue tv, Bu ir_emit_store(proc, ir_emit_struct_ep(proc, res, 1), imag); } return ir_emit_load(proc, res); - break; } case BuiltinProc_expand_to_tuple: { @@ -4675,10 +4671,13 @@ irValue *ir_build_builtin_proc(irProcedure *proc, Ast *expr, TypeAndValue tv, Bu } case BuiltinProc_abs: { - ir_emit_comment(proc, str_lit("abs")); gbAllocator a = ir_allocator(); irValue *x = ir_build_expr(proc, ce->args[0]); Type *t = ir_type(x); + if (is_type_unsigned(t)) { + return x; + } + ir_emit_comment(proc, str_lit("abs")); if (is_type_complex(t)) { i64 sz = 8*type_size_of(t); auto args = array_make(ir_allocator(), 1); @@ -4704,15 +4703,13 @@ irValue *ir_build_builtin_proc(irProcedure *proc, Ast *expr, TypeAndValue tv, Bu return ir_emit_select(proc, cond, neg, x); } - case BuiltinProc_clamp: { + case BuiltinProc_clamp: ir_emit_comment(proc, str_lit("clamp")); - Type *t = type_of_expr(expr); - return ir_emit_clamp(proc, t, + return ir_emit_clamp(proc, type_of_expr(expr), ir_build_expr(proc, ce->args[0]), ir_build_expr(proc, ce->args[1]), ir_build_expr(proc, ce->args[2])); } - } GB_PANIC("Unhandled built-in procedure"); return nullptr;