mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 07:38:48 +00:00
Minor changes in runtime
This commit is contained in:
+11
-10
@@ -184,32 +184,33 @@ mem_free_all :: #force_inline proc(allocator := context.allocator, loc := #calle
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
mem_resize :: proc(ptr: rawptr, old_size, new_size: int, alignment: int = DEFAULT_ALIGNMENT, allocator := context.allocator, loc := #caller_location) -> ([]byte, Allocator_Error) {
|
mem_resize :: proc(ptr: rawptr, old_size, new_size: int, alignment: int = DEFAULT_ALIGNMENT, allocator := context.allocator, loc := #caller_location) -> (data: []byte, err: Allocator_Error) {
|
||||||
if allocator.procedure == nil {
|
if allocator.procedure == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
if new_size == 0 {
|
if new_size == 0 {
|
||||||
if ptr != nil {
|
if ptr != nil {
|
||||||
_, err := allocator.procedure(allocator.data, .Free, 0, 0, ptr, old_size, loc)
|
_, err = allocator.procedure(allocator.data, .Free, 0, 0, ptr, old_size, loc)
|
||||||
return nil, err
|
return
|
||||||
}
|
}
|
||||||
return nil, nil
|
return
|
||||||
} else if ptr == nil {
|
} else if ptr == nil {
|
||||||
return allocator.procedure(allocator.data, .Alloc, new_size, alignment, nil, 0, loc)
|
return allocator.procedure(allocator.data, .Alloc, new_size, alignment, nil, 0, loc)
|
||||||
} else if old_size == new_size && uintptr(ptr) % uintptr(alignment) == 0 {
|
} else if old_size == new_size && uintptr(ptr) % uintptr(alignment) == 0 {
|
||||||
return ([^]byte)(ptr)[:old_size], nil
|
data = ([^]byte)(ptr)[:old_size]
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := allocator.procedure(allocator.data, .Resize, new_size, alignment, ptr, old_size, loc)
|
data, err = allocator.procedure(allocator.data, .Resize, new_size, alignment, ptr, old_size, loc)
|
||||||
if err == .Mode_Not_Implemented {
|
if err == .Mode_Not_Implemented {
|
||||||
data, err = allocator.procedure(allocator.data, .Alloc, new_size, alignment, nil, 0, loc)
|
data, err = allocator.procedure(allocator.data, .Alloc, new_size, alignment, nil, 0, loc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return data, err
|
return
|
||||||
}
|
}
|
||||||
copy(data, ([^]byte)(ptr)[:old_size])
|
copy(data, ([^]byte)(ptr)[:old_size])
|
||||||
_, err = allocator.procedure(allocator.data, .Free, 0, 0, ptr, old_size, loc)
|
_, err = allocator.procedure(allocator.data, .Free, 0, 0, ptr, old_size, loc)
|
||||||
}
|
}
|
||||||
return data, err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
memory_equal :: proc "contextless" (x, y: rawptr, n: int) -> bool {
|
memory_equal :: proc "contextless" (x, y: rawptr, n: int) -> bool {
|
||||||
@@ -223,7 +224,7 @@ memory_equal :: proc "contextless" (x, y: rawptr, n: int) -> bool {
|
|||||||
|
|
||||||
when size_of(uint) == 8 {
|
when size_of(uint) == 8 {
|
||||||
if word_length := length >> 3; word_length != 0 {
|
if word_length := length >> 3; word_length != 0 {
|
||||||
for i in 0..<word_length {
|
for _ in 0..<word_length {
|
||||||
if intrinsics.unaligned_load((^u64)(a)) != intrinsics.unaligned_load((^u64)(b)) {
|
if intrinsics.unaligned_load((^u64)(a)) != intrinsics.unaligned_load((^u64)(b)) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -254,7 +255,7 @@ memory_equal :: proc "contextless" (x, y: rawptr, n: int) -> bool {
|
|||||||
return true
|
return true
|
||||||
} else {
|
} else {
|
||||||
if word_length := length >> 2; word_length != 0 {
|
if word_length := length >> 2; word_length != 0 {
|
||||||
for i in 0..<word_length {
|
for _ in 0..<word_length {
|
||||||
if intrinsics.unaligned_load((^u32)(a)) != intrinsics.unaligned_load((^u32)(b)) {
|
if intrinsics.unaligned_load((^u32)(a)) != intrinsics.unaligned_load((^u32)(b)) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
+20
-19
@@ -2,6 +2,9 @@ package runtime
|
|||||||
|
|
||||||
_INTEGER_DIGITS :: "0123456789abcdefghijklmnopqrstuvwxyz"
|
_INTEGER_DIGITS :: "0123456789abcdefghijklmnopqrstuvwxyz"
|
||||||
|
|
||||||
|
@(private="file")
|
||||||
|
_INTEGER_DIGITS_VAR := _INTEGER_DIGITS
|
||||||
|
|
||||||
when !ODIN_DISALLOW_RTTI {
|
when !ODIN_DISALLOW_RTTI {
|
||||||
print_any_single :: proc(arg: any) {
|
print_any_single :: proc(arg: any) {
|
||||||
x := arg
|
x := arg
|
||||||
@@ -105,14 +108,14 @@ encode_rune :: proc "contextless" (c: rune) -> ([4]u8, int) {
|
|||||||
return buf, 4
|
return buf, 4
|
||||||
}
|
}
|
||||||
|
|
||||||
print_string :: proc "contextless" (str: string) -> (int, _OS_Errno) {
|
print_string :: proc "contextless" (str: string) -> (n: int) {
|
||||||
return os_write(transmute([]byte)str)
|
n, _ = os_write(transmute([]byte)str)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
print_strings :: proc "contextless" (args: ..string) -> (n: int, err: _OS_Errno) {
|
print_strings :: proc "contextless" (args: ..string) -> (n: int) {
|
||||||
for str in args {
|
for str in args {
|
||||||
m: int
|
m, err := os_write(transmute([]byte)str)
|
||||||
m, err = os_write(transmute([]byte)str)
|
|
||||||
n += m
|
n += m
|
||||||
if err != 0 {
|
if err != 0 {
|
||||||
break
|
break
|
||||||
@@ -121,8 +124,9 @@ print_strings :: proc "contextless" (args: ..string) -> (n: int, err: _OS_Errno)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
print_byte :: proc "contextless" (b: byte) -> (int, _OS_Errno) {
|
print_byte :: proc "contextless" (b: byte) -> (n: int) {
|
||||||
return os_write([]byte{b})
|
n, _ = os_write([]byte{b})
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
print_encoded_rune :: proc "contextless" (r: rune) {
|
print_encoded_rune :: proc "contextless" (r: rune) {
|
||||||
@@ -141,11 +145,10 @@ print_encoded_rune :: proc "contextless" (r: rune) {
|
|||||||
if r <= 0 {
|
if r <= 0 {
|
||||||
print_string("\\x00")
|
print_string("\\x00")
|
||||||
} else if r < 32 {
|
} else if r < 32 {
|
||||||
digits := _INTEGER_DIGITS
|
|
||||||
n0, n1 := u8(r) >> 4, u8(r) & 0xf
|
n0, n1 := u8(r) >> 4, u8(r) & 0xf
|
||||||
print_string("\\x")
|
print_string("\\x")
|
||||||
print_byte(digits[n0])
|
print_byte(_INTEGER_DIGITS_VAR[n0])
|
||||||
print_byte(digits[n1])
|
print_byte(_INTEGER_DIGITS_VAR[n1])
|
||||||
} else {
|
} else {
|
||||||
print_rune(r)
|
print_rune(r)
|
||||||
}
|
}
|
||||||
@@ -153,7 +156,7 @@ print_encoded_rune :: proc "contextless" (r: rune) {
|
|||||||
print_byte('\'')
|
print_byte('\'')
|
||||||
}
|
}
|
||||||
|
|
||||||
print_rune :: proc "contextless" (r: rune) -> (int, _OS_Errno) #no_bounds_check {
|
print_rune :: proc "contextless" (r: rune) -> int #no_bounds_check {
|
||||||
RUNE_SELF :: 0x80
|
RUNE_SELF :: 0x80
|
||||||
|
|
||||||
if r < RUNE_SELF {
|
if r < RUNE_SELF {
|
||||||
@@ -161,29 +164,27 @@ print_rune :: proc "contextless" (r: rune) -> (int, _OS_Errno) #no_bounds_check
|
|||||||
}
|
}
|
||||||
|
|
||||||
b, n := encode_rune(r)
|
b, n := encode_rune(r)
|
||||||
return os_write(b[:n])
|
m, _ := os_write(b[:n])
|
||||||
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
print_u64 :: proc "contextless" (x: u64) #no_bounds_check {
|
print_u64 :: proc "contextless" (x: u64) #no_bounds_check {
|
||||||
digits := _INTEGER_DIGITS
|
|
||||||
|
|
||||||
a: [129]byte
|
a: [129]byte
|
||||||
i := len(a)
|
i := len(a)
|
||||||
b := u64(10)
|
b := u64(10)
|
||||||
u := x
|
u := x
|
||||||
for u >= b {
|
for u >= b {
|
||||||
i -= 1; a[i] = digits[u % b]
|
i -= 1; a[i] = _INTEGER_DIGITS_VAR[u % b]
|
||||||
u /= b
|
u /= b
|
||||||
}
|
}
|
||||||
i -= 1; a[i] = digits[u % b]
|
i -= 1; a[i] = _INTEGER_DIGITS_VAR[u % b]
|
||||||
|
|
||||||
os_write(a[i:])
|
os_write(a[i:])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
print_i64 :: proc "contextless" (x: i64) #no_bounds_check {
|
print_i64 :: proc "contextless" (x: i64) #no_bounds_check {
|
||||||
digits := _INTEGER_DIGITS
|
|
||||||
b :: i64(10)
|
b :: i64(10)
|
||||||
|
|
||||||
u := x
|
u := x
|
||||||
@@ -193,10 +194,10 @@ print_i64 :: proc "contextless" (x: i64) #no_bounds_check {
|
|||||||
a: [129]byte
|
a: [129]byte
|
||||||
i := len(a)
|
i := len(a)
|
||||||
for u >= b {
|
for u >= b {
|
||||||
i -= 1; a[i] = digits[u % b]
|
i -= 1; a[i] = _INTEGER_DIGITS_VAR[u % b]
|
||||||
u /= b
|
u /= b
|
||||||
}
|
}
|
||||||
i -= 1; a[i] = digits[u % b]
|
i -= 1; a[i] = _INTEGER_DIGITS_VAR[u % b]
|
||||||
if neg {
|
if neg {
|
||||||
i -= 1; a[i] = '-'
|
i -= 1; a[i] = '-'
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user