mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-29 10:50:05 +00:00
Remove atomic, ++, and --
This commit is contained in:
+2
-4
@@ -64,7 +64,6 @@ TypeInfo :: struct #ordered {
|
||||
Pointer :: struct #ordered {
|
||||
elem: ^TypeInfo; // nil -> rawptr
|
||||
};
|
||||
Atomic :: struct #ordered {elem: ^TypeInfo};
|
||||
Procedure :: struct #ordered {
|
||||
params: ^TypeInfo; // TypeInfo.Tuple
|
||||
results: ^TypeInfo; // TypeInfo.Tuple
|
||||
@@ -117,7 +116,6 @@ TypeInfo :: struct #ordered {
|
||||
Boolean,
|
||||
Any,
|
||||
Pointer,
|
||||
Atomic,
|
||||
Procedure,
|
||||
Array,
|
||||
DynamicArray,
|
||||
@@ -821,7 +819,7 @@ __dynamic_array_append_nothing :: proc(array_: rawptr, elem_size, elem_align: in
|
||||
data := cast(^u8)array.data;
|
||||
assert(data != nil);
|
||||
__mem_zero(data + (elem_size*array.len), elem_size);
|
||||
array.len++;
|
||||
array.len += 1;
|
||||
return array.len;
|
||||
}
|
||||
|
||||
@@ -1007,7 +1005,7 @@ __dynamic_map_erase :: proc(using h: __MapHeader, fr: __MapFindResult) {
|
||||
}
|
||||
|
||||
if fr.entry_index == m.entries.len-1 {
|
||||
m.entries.len--;
|
||||
m.entries.len -= 1;
|
||||
}
|
||||
__mem_copy(__dynamic_map_get_entry(h, fr.entry_index), __dynamic_map_get_entry(h, m.entries.len-1), entry_size);
|
||||
last := __dynamic_map_find(h, __dynamic_map_get_entry(h, fr.entry_index).key);
|
||||
|
||||
+2
-2
@@ -37,7 +37,7 @@ spin_lock :: proc(a: ^i32, time_out: int) -> bool { // NOTE(bill) time_out = -1
|
||||
old_value := compare_exchange(a, 1, 0);
|
||||
counter := 0;
|
||||
for old_value != 0 && (time_out < 0 || counter < time_out) {
|
||||
counter++;
|
||||
counter += 1;
|
||||
yield_thread();
|
||||
old_value = compare_exchange(a, 1, 0);
|
||||
mfence();
|
||||
@@ -81,7 +81,7 @@ spin_lock :: proc(a: ^i64, time_out: int) -> bool { // NOTE(bill) time_out = -1
|
||||
old_value := compare_exchange(a, 1, 0);
|
||||
counter := 0;
|
||||
for old_value != 0 && (time_out < 0 || counter < time_out) {
|
||||
counter++;
|
||||
counter += 1;
|
||||
yield_thread();
|
||||
old_value = compare_exchange(a, 1, 0);
|
||||
mfence();
|
||||
|
||||
+22
-22
@@ -29,13 +29,13 @@ decimal_to_string :: proc(buf: []u8, a: ^Decimal) -> string {
|
||||
|
||||
w := 0;
|
||||
if a.decimal_point <= 0 {
|
||||
buf[w] = '0'; w++;
|
||||
buf[w] = '.'; w++;
|
||||
buf[w] = '0'; w+=1;
|
||||
buf[w] = '.'; w+=1;
|
||||
w += digit_zero(buf[w .. w-a.decimal_point]);
|
||||
w += copy(buf[w..], a.digits[0..a.count]);
|
||||
} else if a.decimal_point < a.count {
|
||||
w += copy(buf[w..], a.digits[0..a.decimal_point]);
|
||||
buf[w] = '.'; w++;
|
||||
buf[w] = '.'; w+=1;
|
||||
w += copy(buf[w..], a.digits[a.decimal_point .. a.count]);
|
||||
} else {
|
||||
w += copy(buf[w..], a.digits[0..a.count]);
|
||||
@@ -48,7 +48,7 @@ decimal_to_string :: proc(buf: []u8, a: ^Decimal) -> string {
|
||||
// trim trailing zeros
|
||||
trim :: proc(a: ^Decimal) {
|
||||
for a.count > 0 && a.digits[a.count-1] == '0' {
|
||||
a.count--;
|
||||
a.count -= 1;
|
||||
}
|
||||
if a.count == 0 {
|
||||
a.decimal_point = 0;
|
||||
@@ -63,14 +63,14 @@ assign :: proc(a: ^Decimal, i: u64) {
|
||||
j := i/10;
|
||||
i -= 10*j;
|
||||
buf[n] = u8('0'+i);
|
||||
n++;
|
||||
n+=1;
|
||||
i = j;
|
||||
}
|
||||
|
||||
a.count = 0;
|
||||
for n--; n >= 0; n-- {
|
||||
for n -= 1; n >= 0; n -= 1 {
|
||||
a.digits[a.count] = buf[n];
|
||||
a.count++;
|
||||
a.count+=1;
|
||||
}
|
||||
a.decimal_point = a.count;
|
||||
trim(a);
|
||||
@@ -83,7 +83,7 @@ shift_right :: proc(a: ^Decimal, k: uint) {
|
||||
w := 0; // write index
|
||||
|
||||
n: uint;
|
||||
for ; n>>k == 0; r++ {
|
||||
for ; n>>k == 0; r+=1 {
|
||||
if r >= a.count {
|
||||
if n == 0 {
|
||||
// Just in case
|
||||
@@ -92,7 +92,7 @@ shift_right :: proc(a: ^Decimal, k: uint) {
|
||||
}
|
||||
for n>>k == 0 {
|
||||
n = n * 10;
|
||||
r++;
|
||||
r+=1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -103,12 +103,12 @@ shift_right :: proc(a: ^Decimal, k: uint) {
|
||||
|
||||
mask: uint = (1<<k) - 1;
|
||||
|
||||
for ; r < a.count; r++ {
|
||||
for ; r < a.count; r+=1 {
|
||||
c := uint(a.digits[r]);
|
||||
dig := n>>k;
|
||||
n &= mask;
|
||||
a.digits[w] = u8('0' + dig);
|
||||
w++;
|
||||
w+=1;
|
||||
n = n*10 + c - '0';
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ shift_right :: proc(a: ^Decimal, k: uint) {
|
||||
n &= mask;
|
||||
if w < len(a.digits) {
|
||||
a.digits[w] = u8('0' + dig);
|
||||
w++;
|
||||
w+=1;
|
||||
} else if dig > 0 {
|
||||
a.trunc = true;
|
||||
}
|
||||
@@ -136,11 +136,11 @@ shift_left :: proc(a: ^Decimal, k: uint) {
|
||||
w := a.count+delta; // write index
|
||||
|
||||
n: uint;
|
||||
for r--; r >= 0; r-- {
|
||||
for r -= 1; r >= 0; r -= 1 {
|
||||
n += (uint(a.digits[r]) - '0') << k;
|
||||
quo := n/10;
|
||||
rem := n - 10*quo;
|
||||
w--;
|
||||
w -= 1;
|
||||
if w < len(a.digits) {
|
||||
a.digits[w] = u8('0' + rem);
|
||||
} else if rem != 0 {
|
||||
@@ -152,7 +152,7 @@ shift_left :: proc(a: ^Decimal, k: uint) {
|
||||
for n > 0 {
|
||||
quo := n/10;
|
||||
rem := n - 10*quo;
|
||||
w--;
|
||||
w -= 1;
|
||||
if 0 <= w && w < len(a.digits) {
|
||||
a.digits[w] = u8('0' + rem);
|
||||
} else if rem != 0 {
|
||||
@@ -213,9 +213,9 @@ round :: proc(a: ^Decimal, nd: int) {
|
||||
round_up :: proc(a: ^Decimal, nd: int) {
|
||||
if nd < 0 || nd >= a.count { return; }
|
||||
|
||||
for i := nd-1; i >= 0; i-- {
|
||||
for i := nd-1; i >= 0; i -= 1 {
|
||||
if c := a.digits[i]; c < '9' {
|
||||
a.digits[i]++;
|
||||
a.digits[i]+=1;
|
||||
a.count = i+1;
|
||||
return;
|
||||
}
|
||||
@@ -224,7 +224,7 @@ round_up :: proc(a: ^Decimal, nd: int) {
|
||||
// Number is just 9s
|
||||
a.digits[0] = '1';
|
||||
a.count = 1;
|
||||
a.decimal_point++;
|
||||
a.decimal_point+=1;
|
||||
}
|
||||
|
||||
round_down :: proc(a: ^Decimal, nd: int) {
|
||||
@@ -239,17 +239,17 @@ rounded_integer :: proc(a: ^Decimal) -> u64 {
|
||||
if a.decimal_point > 20 {
|
||||
return 0xffff_ffff_ffff_ffff;
|
||||
}
|
||||
i: int;
|
||||
i: int = 0;
|
||||
n: u64 = 0;
|
||||
m := min(a.decimal_point, a.count);
|
||||
for i = 0; i < m; i++ {
|
||||
for ; i < m; i += 1 {
|
||||
n = n*10 + u64(a.digits[i]-'0');
|
||||
}
|
||||
for ; i < a.decimal_point; i++ {
|
||||
for ; i < a.decimal_point; i += 1 {
|
||||
n *= 10;
|
||||
}
|
||||
if can_round_up(a, a.decimal_point) {
|
||||
n++;
|
||||
n+=1;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
+9
-15
@@ -207,9 +207,6 @@ write_type :: proc(buf: ^StringBuffer, ti: ^TypeInfo) {
|
||||
case Boolean: write_string(buf, "bool");
|
||||
case Any:
|
||||
write_string(buf, "any");
|
||||
case Atomic:
|
||||
write_string(buf, "atomic ");
|
||||
write_type(buf, info.elem);
|
||||
|
||||
case Pointer:
|
||||
if info.elem == nil {
|
||||
@@ -352,7 +349,7 @@ _parse_int :: proc(s: string, offset: int) -> (result: int, offset: int, ok: boo
|
||||
for i < len(s[offset..]) {
|
||||
c := rune(s[offset+i]);
|
||||
if !is_digit(c) do break;
|
||||
i++;
|
||||
i += 1;
|
||||
|
||||
result *= 10;
|
||||
result += int(c)-'0';
|
||||
@@ -478,7 +475,7 @@ _fmt_int :: proc(fi: ^FmtInfo, u: u128, base: int, is_signed: bool, bit_size: in
|
||||
prec = fi.width;
|
||||
if neg || fi.plus || fi.space {
|
||||
// There needs to be space for the "sign"
|
||||
prec--;
|
||||
prec -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -771,9 +768,6 @@ fmt_value :: proc(fi: ^FmtInfo, v: any, verb: rune) {
|
||||
fmt_pointer(fi, (cast(^rawptr)v.data)^, verb);
|
||||
}
|
||||
|
||||
case Atomic:
|
||||
fmt_arg(fi, any{v.data, info.elem}, verb);
|
||||
|
||||
case Array:
|
||||
write_byte(fi.buf, '[');
|
||||
defer write_byte(fi.buf, ']');
|
||||
@@ -1009,7 +1003,7 @@ sbprintf :: proc(b: ^StringBuffer, fmt: string, args: ...any) -> string {
|
||||
|
||||
prev_i := i;
|
||||
for i < end && fmt[i] != '%' {
|
||||
i++;
|
||||
i += 1;
|
||||
}
|
||||
if i > prev_i {
|
||||
write_string(b, fmt[prev_i..i]);
|
||||
@@ -1019,9 +1013,9 @@ sbprintf :: proc(b: ^StringBuffer, fmt: string, args: ...any) -> string {
|
||||
}
|
||||
|
||||
// Process a "verb"
|
||||
i++;
|
||||
i += 1;
|
||||
|
||||
prefix_loop: for ; i < end; i++ {
|
||||
prefix_loop: for ; i < end; i += 1 {
|
||||
match fmt[i] {
|
||||
case '+':
|
||||
fi.plus = true;
|
||||
@@ -1043,7 +1037,7 @@ sbprintf :: proc(b: ^StringBuffer, fmt: string, args: ...any) -> string {
|
||||
|
||||
// Width
|
||||
if i < end && fmt[i] == '*' {
|
||||
i++;
|
||||
i += 1;
|
||||
fi.width, arg_index, fi.width_set = int_from_arg(args, arg_index);
|
||||
if !fi.width_set {
|
||||
write_string(b, "%!(BAD WIDTH)");
|
||||
@@ -1064,13 +1058,13 @@ sbprintf :: proc(b: ^StringBuffer, fmt: string, args: ...any) -> string {
|
||||
|
||||
// Precision
|
||||
if i < end && fmt[i] == '.' {
|
||||
i++;
|
||||
i += 1;
|
||||
if was_prev_index { // %[6].2d
|
||||
fi.good_arg_index = false;
|
||||
}
|
||||
if i < end && fmt[i] == '*' {
|
||||
arg_index, i, was_prev_index = _arg_number(&fi, arg_index, fmt, i, len(args));
|
||||
i++;
|
||||
i += 1;
|
||||
fi.prec, arg_index, fi.prec_set = int_from_arg(args, arg_index);
|
||||
if fi.prec < 0 {
|
||||
fi.prec = 0;
|
||||
@@ -1109,7 +1103,7 @@ sbprintf :: proc(b: ^StringBuffer, fmt: string, args: ...any) -> string {
|
||||
write_string(b, "%!(MISSING ARGUMENT)");
|
||||
} else {
|
||||
fmt_arg(&fi, args[arg_index], verb);
|
||||
arg_index++;
|
||||
arg_index += 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -146,7 +146,7 @@ murmur64 :: proc(data: []u8) -> u64 {
|
||||
|
||||
for len >= 8 {
|
||||
k1, k2: u32;
|
||||
k1 = data32[i]; i++;
|
||||
k1 = data32[i]; i += 1;
|
||||
k1 *= m;
|
||||
k1 ~= k1>>r;
|
||||
k1 *= m;
|
||||
@@ -154,7 +154,7 @@ murmur64 :: proc(data: []u8) -> u64 {
|
||||
h1 ~= k1;
|
||||
len -= 4;
|
||||
|
||||
k2 = data32[i]; i++;
|
||||
k2 = data32[i]; i += 1;
|
||||
k2 *= m;
|
||||
k2 ~= k2>>r;
|
||||
k2 *= m;
|
||||
@@ -165,7 +165,7 @@ murmur64 :: proc(data: []u8) -> u64 {
|
||||
|
||||
if len >= 4 {
|
||||
k1: u32;
|
||||
k1 = data32[i]; i++;
|
||||
k1 = data32[i]; i += 1;
|
||||
k1 *= m;
|
||||
k1 ~= k1>>r;
|
||||
k1 *= m;
|
||||
|
||||
+4
-3
@@ -74,8 +74,9 @@ AllocationHeader :: struct {
|
||||
allocation_header_fill :: proc(header: ^AllocationHeader, data: rawptr, size: int) {
|
||||
header.size = size;
|
||||
ptr := cast(^int)(header+1);
|
||||
n := cast(^int)data - ptr;
|
||||
|
||||
for i := 0; rawptr(ptr) < data; i++ {
|
||||
for i in 0..n {
|
||||
(ptr+i)^ = -1;
|
||||
}
|
||||
}
|
||||
@@ -176,7 +177,7 @@ begin_arena_temp_memory :: proc(a: ^Arena) -> ArenaTempMemory {
|
||||
tmp: ArenaTempMemory;
|
||||
tmp.arena = a;
|
||||
tmp.original_count = len(a.memory);
|
||||
a.temp_count++;
|
||||
a.temp_count += 1;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
@@ -184,7 +185,7 @@ end_arena_temp_memory :: proc(using tmp: ArenaTempMemory) {
|
||||
assert(len(arena.memory) >= original_count);
|
||||
assert(arena.temp_count > 0);
|
||||
arena.memory = arena.memory[..original_count];
|
||||
arena.temp_count--;
|
||||
arena.temp_count -= 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
+14
-14
@@ -264,7 +264,7 @@ current_thread_id :: proc() -> int {
|
||||
_alloc_command_line_arguments :: proc() -> []string {
|
||||
alloc_ucs2_to_utf8 :: proc(wstr: ^u16) -> string {
|
||||
wstr_len := 0;
|
||||
for (wstr+wstr_len)^ != 0 do wstr_len++;
|
||||
for (wstr+wstr_len)^ != 0 do wstr_len += 1;
|
||||
|
||||
len := 2*wstr_len-1;
|
||||
buf := make([]u8, len+1);
|
||||
@@ -275,29 +275,29 @@ _alloc_command_line_arguments :: proc() -> []string {
|
||||
match {
|
||||
case str[j] < 0x80:
|
||||
if i+1 > len do return "";
|
||||
buf[i] = u8(str[j]); i++;
|
||||
j++;
|
||||
buf[i] = u8(str[j]); i += 1;
|
||||
j += 1;
|
||||
case str[j] < 0x800:
|
||||
if i+2 > len do return "";
|
||||
buf[i] = u8(0xc0 + (str[j]>>6)); i++;
|
||||
buf[i] = u8(0x80 + (str[j]&0x3f)); i++;
|
||||
j++;
|
||||
buf[i] = u8(0xc0 + (str[j]>>6)); i += 1;
|
||||
buf[i] = u8(0x80 + (str[j]&0x3f)); i += 1;
|
||||
j += 1;
|
||||
case 0xd800 <= str[j] && str[j] < 0xdc00:
|
||||
if i+4 > len do return "";
|
||||
c := rune((str[j] - 0xd800) << 10) + rune((str[j+1]) - 0xdc00) + 0x10000;
|
||||
buf[i] = u8(0xf0 + (c >> 18)); i++;
|
||||
buf[i] = u8(0x80 + ((c >> 12) & 0x3f)); i++;
|
||||
buf[i] = u8(0x80 + ((c >> 6) & 0x3f)); i++;
|
||||
buf[i] = u8(0x80 + ((c ) & 0x3f)); i++;
|
||||
buf[i] = u8(0xf0 + (c >> 18)); i += 1;
|
||||
buf[i] = u8(0x80 + ((c >> 12) & 0x3f)); i += 1;
|
||||
buf[i] = u8(0x80 + ((c >> 6) & 0x3f)); i += 1;
|
||||
buf[i] = u8(0x80 + ((c ) & 0x3f)); i += 1;
|
||||
j += 2;
|
||||
case 0xdc00 <= str[j] && str[j] < 0xe000:
|
||||
return "";
|
||||
case:
|
||||
if i+3 > len do return "";
|
||||
buf[i] = 0xe0 + u8 (str[j] >> 12); i++;
|
||||
buf[i] = 0x80 + u8((str[j] >> 6) & 0x3f); i++;
|
||||
buf[i] = 0x80 + u8((str[j] ) & 0x3f); i++;
|
||||
j++;
|
||||
buf[i] = 0xe0 + u8 (str[j] >> 12); i += 1;
|
||||
buf[i] = 0x80 + u8((str[j] >> 6) & 0x3f); i += 1;
|
||||
buf[i] = 0x80 + u8((str[j] ) & 0x3f); i += 1;
|
||||
j += 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+17
-13
@@ -1,4 +1,4 @@
|
||||
bubble_sort :: proc(array: []$T, f: proc(T, T) -> int) {
|
||||
bubble_sort :: proc(array: $A/[]$T, f: proc(T, T) -> int) {
|
||||
assert(f != nil);
|
||||
count := len(array);
|
||||
|
||||
@@ -22,7 +22,7 @@ bubble_sort :: proc(array: []$T, f: proc(T, T) -> int) {
|
||||
}
|
||||
}
|
||||
|
||||
bubble_sort :: proc(array: []$T) {
|
||||
bubble_sort :: proc(array: $A/[]$T) {
|
||||
count := len(array);
|
||||
|
||||
init_j, last_j := 0, count-1;
|
||||
@@ -45,7 +45,7 @@ bubble_sort :: proc(array: []$T) {
|
||||
}
|
||||
}
|
||||
|
||||
quick_sort :: proc(array: []$T, f: proc(T, T) -> int) {
|
||||
quick_sort :: proc(array: $A/[]$T, f: proc(T, T) -> int) {
|
||||
assert(f != nil);
|
||||
a := array;
|
||||
n := len(a);
|
||||
@@ -69,7 +69,7 @@ quick_sort :: proc(array: []$T, f: proc(T, T) -> int) {
|
||||
quick_sort(a[i..n], f);
|
||||
}
|
||||
|
||||
quick_sort :: proc(array: []$T) {
|
||||
quick_sort :: proc(array: $A/[]$T) {
|
||||
a := array;
|
||||
n := len(a);
|
||||
if n < 2 do return;
|
||||
@@ -94,19 +94,21 @@ quick_sort :: proc(array: []$T) {
|
||||
|
||||
_log2 :: proc(n: int) -> int {
|
||||
res := 0;
|
||||
for ; n != 0; n >>= 1 do res++;
|
||||
for ; n != 0; n >>= 1 do res += 1;
|
||||
return res;
|
||||
}
|
||||
|
||||
merge_sort :: proc(array: []$T, f: proc(T, T) -> int) {
|
||||
merge_slices :: proc(arr1, arr2, out: []$T, f: proc(T, T) -> int) {
|
||||
merge_sort :: proc(array: $A/[]$T, f: proc(T, T) -> int) {
|
||||
merge_slices :: proc(arr1, arr2, out: A, f: proc(T, T) -> int) {
|
||||
N1, N2 := len(arr1), len(arr2);
|
||||
i, j := 0, 0;
|
||||
for k in 0..N1+N2 {
|
||||
if j == N2 || i < N1 && j < N2 && f(arr1[i], arr2[j]) < 0 {
|
||||
out[k] = arr1[i]; i++;
|
||||
out[k] = arr1[i];
|
||||
i += 1;
|
||||
} else {
|
||||
out[k] = arr2[j]; j++;
|
||||
out[k] = arr2[j];
|
||||
j += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -140,15 +142,17 @@ merge_sort :: proc(array: []$T, f: proc(T, T) -> int) {
|
||||
if M & 1 == 0 do copy(arr2, arr1);
|
||||
}
|
||||
|
||||
merge_sort :: proc(array: []$T) {
|
||||
merge_slices :: proc(arr1, arr2, out: []$T) {
|
||||
merge_sort :: proc(array: $A/[]$T) {
|
||||
merge_slices :: proc(arr1, arr2, out: A) {
|
||||
N1, N2 := len(arr1), len(arr2);
|
||||
i, j := 0, 0;
|
||||
for k in 0..N1+N2 {
|
||||
if j == N2 || i < N1 && j < N2 && arr1[i] < arr2[j] {
|
||||
out[k] = arr1[i]; i++;
|
||||
out[k] = arr1[i];
|
||||
i += 1;
|
||||
} else {
|
||||
out[k] = arr2[j]; j++;
|
||||
out[k] = arr2[j];
|
||||
j += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+24
-28
@@ -119,29 +119,25 @@ parse_f64 :: proc(s: string) -> f64 {
|
||||
|
||||
sign: f64 = 1;
|
||||
match s[i] {
|
||||
case '-': i++; sign = -1;
|
||||
case '+': i++;
|
||||
case '-': i += 1; sign = -1;
|
||||
case '+': i += 1;
|
||||
}
|
||||
|
||||
value: f64 = 0;
|
||||
for ; i < len(s); i++ {
|
||||
for ; i < len(s); i += 1 {
|
||||
r := rune(s[i]);
|
||||
if r == '_' {
|
||||
continue;
|
||||
}
|
||||
if r == '_' do continue;
|
||||
v := _digit_value(r);
|
||||
if v >= 10 {
|
||||
break;
|
||||
}
|
||||
if v >= 10 do break;
|
||||
value *= 10;
|
||||
value += f64(v);
|
||||
}
|
||||
|
||||
if s[i] == '.' {
|
||||
pow10: f64 = 10;
|
||||
i++;
|
||||
i += 1;
|
||||
|
||||
for ; i < len(s); i++ {
|
||||
for ; i < len(s); i += 1 {
|
||||
r := rune(s[i]);
|
||||
if r == '_' {
|
||||
continue;
|
||||
@@ -159,15 +155,15 @@ parse_f64 :: proc(s: string) -> f64 {
|
||||
scale: f64 = 1;
|
||||
|
||||
if s[i] == 'e' || s[i] == 'E' {
|
||||
i++;
|
||||
i += 1;
|
||||
|
||||
match s[i] {
|
||||
case '-': i++; frac = true;
|
||||
case '+': i++;
|
||||
case '-': i += 1; frac = true;
|
||||
case '+': i += 1;
|
||||
}
|
||||
|
||||
exp: u32 = 0;
|
||||
for ; i < len(s); i++ {
|
||||
for ; i < len(s); i += 1 {
|
||||
r := rune(s[i]);
|
||||
if r == '_' {
|
||||
continue;
|
||||
@@ -261,7 +257,7 @@ generic_ftoa :: proc(buf: []u8, val: f64, fmt: u8, prec, bit_size: int) -> []u8
|
||||
return buf;
|
||||
|
||||
case 0: // denormalized
|
||||
exp++;
|
||||
exp += 1;
|
||||
|
||||
case:
|
||||
mant |= u64(1) << flt.mantbits;
|
||||
@@ -310,7 +306,7 @@ format_digits :: proc(buf: []u8, shortest: bool, neg: bool, digs: DecimalSlice,
|
||||
if digs.decimal_point > 0 {
|
||||
m := min(digs.count, digs.decimal_point);
|
||||
append(&buf, ...digs.digits[..m]);
|
||||
for ; m < digs.decimal_point; m++ {
|
||||
for ; m < digs.decimal_point; m += 1 {
|
||||
append(&buf, '0');
|
||||
}
|
||||
} else {
|
||||
@@ -464,32 +460,32 @@ append_bits :: proc(buf: []u8, u: u128, base: int, is_signed: bool, bit_size: in
|
||||
u, neg = is_integer_negative(u, is_signed, bit_size);
|
||||
b := u128(base);
|
||||
for u >= b {
|
||||
i--; a[i] = digits[uint(u % b)];
|
||||
i-=1; a[i] = digits[uint(u % b)];
|
||||
u /= b;
|
||||
}
|
||||
i--; a[i] = digits[uint(u % b)];
|
||||
i-=1; a[i] = digits[uint(u % b)];
|
||||
|
||||
if flags&IntFlag.Prefix != 0 {
|
||||
ok := true;
|
||||
match base {
|
||||
case 2: i--; a[i] = 'b';
|
||||
case 8: i--; a[i] = 'o';
|
||||
case 10: i--; a[i] = 'd';
|
||||
case 12: i--; a[i] = 'z';
|
||||
case 16: i--; a[i] = 'x';
|
||||
case 2: i-=1; a[i] = 'b';
|
||||
case 8: i-=1; a[i] = 'o';
|
||||
case 10: i-=1; a[i] = 'd';
|
||||
case 12: i-=1; a[i] = 'z';
|
||||
case 16: i-=1; a[i] = 'x';
|
||||
case: ok = false;
|
||||
}
|
||||
if ok {
|
||||
i--; a[i] = '0';
|
||||
i-=1; a[i] = '0';
|
||||
}
|
||||
}
|
||||
|
||||
if neg {
|
||||
i--; a[i] = '-';
|
||||
i-=1; a[i] = '-';
|
||||
} else if flags&IntFlag.Plus != 0 {
|
||||
i--; a[i] = '+';
|
||||
i-=1; a[i] = '+';
|
||||
} else if flags&IntFlag.Space != 0 {
|
||||
i--; a[i] = ' ';
|
||||
i-=1; a[i] = ' ';
|
||||
}
|
||||
|
||||
append(&buf, ...a[i..]);
|
||||
|
||||
+1
-1
@@ -16,6 +16,6 @@ new_c_string :: proc(s: string) -> ^u8 {
|
||||
|
||||
to_odin_string :: proc(c: ^u8) -> string {
|
||||
len := 0;
|
||||
for (c+len)^ != 0 do len++;
|
||||
for (c+len)^ != 0 do len+=1;
|
||||
return string(mem.slice_ptr(c, len));
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ mutex_lock :: proc(m: ^Mutex) {
|
||||
}
|
||||
}
|
||||
atomics.store(&m._owner, thread_id);
|
||||
m._recursion++;
|
||||
m._recursion += 1;
|
||||
}
|
||||
mutex_try_lock :: proc(m: ^Mutex) -> bool {
|
||||
thread_id := current_thread_id();
|
||||
@@ -72,7 +72,7 @@ mutex_try_lock :: proc(m: ^Mutex) -> bool {
|
||||
}
|
||||
atomics.store(&m._owner, thread_id);
|
||||
}
|
||||
m._recursion++;
|
||||
m._recursion += 1;
|
||||
return true;
|
||||
}
|
||||
mutex_unlock :: proc(m: ^Mutex) {
|
||||
@@ -80,7 +80,7 @@ mutex_unlock :: proc(m: ^Mutex) {
|
||||
thread_id := current_thread_id();
|
||||
assert(thread_id == atomics.load(&m._owner));
|
||||
|
||||
m._recursion--;
|
||||
m._recursion -= 1;
|
||||
recursion = m._recursion;
|
||||
if recursion == 0 {
|
||||
atomics.store(&m._owner, thread_id);
|
||||
|
||||
+3
-3
@@ -29,7 +29,7 @@ encode_surrogate_pair :: proc(r: rune) -> (r1, r2: rune) {
|
||||
|
||||
encode :: proc(d: []u16, s: []rune) {
|
||||
n := len(s);
|
||||
for r in s do if r >= _surr_self do n++;
|
||||
for r in s do if r >= _surr_self do n += 1;
|
||||
|
||||
max_n := min(len(d), n);
|
||||
n = 0;
|
||||
@@ -38,7 +38,7 @@ encode :: proc(d: []u16, s: []rune) {
|
||||
match r {
|
||||
case 0.._surr1, _surr3.._surr_self:
|
||||
d[n] = u16(r);
|
||||
n++;
|
||||
n += 1;
|
||||
|
||||
case _surr_self..MAX_RUNE:
|
||||
r1, r2 := encode_surrogate_pair(r);
|
||||
@@ -48,7 +48,7 @@ encode :: proc(d: []u16, s: []rune) {
|
||||
|
||||
case:
|
||||
d[n] = u16(REPLACEMENT_CHAR);
|
||||
n++;
|
||||
n += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+7
-11
@@ -151,12 +151,8 @@ decode_last_rune :: proc(s: []u8) -> (rune, int) {
|
||||
|
||||
limit = max(end - UTF_MAX, 0);
|
||||
|
||||
start--;
|
||||
for start >= limit {
|
||||
if rune_start(s[start]) {
|
||||
break;
|
||||
}
|
||||
start--;
|
||||
for start-=1; start >= limit; start-=1 {
|
||||
if rune_start(s[start]) do break;
|
||||
}
|
||||
|
||||
start = max(start, 0);
|
||||
@@ -187,7 +183,7 @@ valid_string :: proc(s: string) -> bool {
|
||||
for i := 0; i < n; {
|
||||
si := s[i];
|
||||
if si < RUNE_SELF { // ascii
|
||||
i++;
|
||||
i += 1;
|
||||
continue;
|
||||
}
|
||||
x := accept_sizes[si];
|
||||
@@ -223,20 +219,20 @@ rune_count :: proc(s: []u8) -> int {
|
||||
n := len(s);
|
||||
|
||||
for i := 0; i < n; {
|
||||
defer count++;
|
||||
defer count += 1;
|
||||
si := s[i];
|
||||
if si < RUNE_SELF { // ascii
|
||||
i++;
|
||||
i += 1;
|
||||
continue;
|
||||
}
|
||||
x := accept_sizes[si];
|
||||
if x == 0xf1 {
|
||||
i++;
|
||||
i += 1;
|
||||
continue;
|
||||
}
|
||||
size := int(x & 7);
|
||||
if i+size > n {
|
||||
i++;
|
||||
i += 1;
|
||||
continue;
|
||||
}
|
||||
ar := accept_ranges[x>>4];
|
||||
|
||||
Reference in New Issue
Block a user