mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-02 04:38:16 +00:00
while; range is now for; remove ++ and --
This commit is contained in:
+5
-5
@@ -313,19 +313,19 @@ __bounds_check_error :: proc(file: string, line, column: int, index, count: int)
|
||||
__debug_trap();
|
||||
}
|
||||
|
||||
__slice_expr_error :: proc(file: string, line, column: int, low, high, max: int) {
|
||||
if 0 <= low && low <= high && high <= max {
|
||||
__slice_expr_error :: proc(file: string, line, column: int, low, high: int) {
|
||||
if 0 <= low && low <= high {
|
||||
return;
|
||||
}
|
||||
fmt.fprintf(os.stderr, "%(%:%) Invalid slice indices: [%:%:%]\n",
|
||||
file, line, column, low, high, max);
|
||||
fmt.fprintf(os.stderr, "%(%:%) Invalid slice indices: [%:%]\n",
|
||||
file, line, column, low, high);
|
||||
__debug_trap();
|
||||
}
|
||||
__substring_expr_error :: proc(file: string, line, column: int, low, high: int) {
|
||||
if 0 <= low && low <= high {
|
||||
return;
|
||||
}
|
||||
fmt.fprintf(os.stderr, "%(%:%) Invalid substring indices: [%:%:%]\n",
|
||||
fmt.fprintf(os.stderr, "%(%:%) Invalid substring indices: [%:%]\n",
|
||||
file, line, column, low, high);
|
||||
__debug_trap();
|
||||
}
|
||||
|
||||
+4
-4
@@ -37,8 +37,8 @@ fetch_or32 :: proc(a: ^i32, operand: i32) -> i32 {
|
||||
spin_lock32 :: proc(a: ^i32, time_out: int) -> bool { // NOTE(bill) time_out = -1 as default
|
||||
old_value := compare_exchange32(a, 1, 0);
|
||||
counter := 0;
|
||||
for old_value != 0 && (time_out < 0 || counter < time_out) {
|
||||
counter++;
|
||||
while old_value != 0 && (time_out < 0 || counter < time_out) {
|
||||
counter += 1;
|
||||
yield_thread();
|
||||
old_value = compare_exchange32(a, 1, 0);
|
||||
mfence();
|
||||
@@ -81,8 +81,8 @@ fetch_or64 :: proc(a: ^i64, operand: i64) -> i64 {
|
||||
spin_lock64 :: proc(a: ^i64, time_out: int) -> bool { // NOTE(bill) time_out = -1 as default
|
||||
old_value := compare_exchange64(a, 1, 0);
|
||||
counter := 0;
|
||||
for old_value != 0 && (time_out < 0 || counter < time_out) {
|
||||
counter++;
|
||||
while old_value != 0 && (time_out < 0 || counter < time_out) {
|
||||
counter += 1;
|
||||
yield_thread();
|
||||
old_value = compare_exchange64(a, 1, 0);
|
||||
mfence();
|
||||
|
||||
+95
-90
@@ -4,84 +4,90 @@
|
||||
|
||||
PRINT_BUF_SIZE :: 1<<12;
|
||||
|
||||
fprint :: proc(fd: os.Handle, args: ..any) -> int {
|
||||
data: [PRINT_BUF_SIZE]byte;
|
||||
buf := data[:0];
|
||||
bprint(^buf, ..args);
|
||||
os.write(fd, buf);
|
||||
return buf.count;
|
||||
}
|
||||
|
||||
fprintln :: proc(fd: os.Handle, args: ..any) -> int {
|
||||
data: [PRINT_BUF_SIZE]byte;
|
||||
buf := data[:0];
|
||||
bprintln(^buf, ..args);
|
||||
os.write(fd, buf);
|
||||
return buf.count;
|
||||
}
|
||||
fprintf :: proc(fd: os.Handle, fmt: string, args: ..any) -> int {
|
||||
data: [PRINT_BUF_SIZE]byte;
|
||||
buf := data[:0];
|
||||
bprintf(^buf, fmt, ..args);
|
||||
os.write(fd, buf);
|
||||
return buf.count;
|
||||
Buffer :: struct {
|
||||
data: []byte;
|
||||
length: int;
|
||||
}
|
||||
|
||||
|
||||
print :: proc(args: ..any) -> int {
|
||||
return fprint(os.stdout, ..args);
|
||||
fprint :: proc(fd: os.Handle, args: ...any) -> int {
|
||||
data: [PRINT_BUF_SIZE]byte;
|
||||
buf := Buffer{data[:], 0};
|
||||
bprint(^buf, ...args);
|
||||
os.write(fd, buf.data[:buf.length]);
|
||||
return buf.length;
|
||||
}
|
||||
println :: proc(args: ..any) -> int {
|
||||
return fprintln(os.stdout, ..args);
|
||||
|
||||
fprintln :: proc(fd: os.Handle, args: ...any) -> int {
|
||||
data: [PRINT_BUF_SIZE]byte;
|
||||
buf := Buffer{data[:], 0};
|
||||
bprintln(^buf, ...args);
|
||||
os.write(fd, buf.data[:buf.length]);
|
||||
return buf.length;
|
||||
}
|
||||
printf :: proc(fmt: string, args: ..any) -> int {
|
||||
return fprintf(os.stdout, fmt, ..args);
|
||||
fprintf :: proc(fd: os.Handle, fmt: string, args: ...any) -> int {
|
||||
data: [PRINT_BUF_SIZE]byte;
|
||||
buf := Buffer{data[:], 0};
|
||||
bprintf(^buf, fmt, ...args);
|
||||
os.write(fd, buf.data[:buf.length]);
|
||||
return buf.length;
|
||||
}
|
||||
|
||||
|
||||
print :: proc(args: ...any) -> int {
|
||||
return fprint(os.stdout, ...args);
|
||||
}
|
||||
println :: proc(args: ...any) -> int {
|
||||
return fprintln(os.stdout, ...args);
|
||||
}
|
||||
printf :: proc(fmt: string, args: ...any) -> int {
|
||||
return fprintf(os.stdout, fmt, ...args);
|
||||
}
|
||||
|
||||
|
||||
|
||||
fprint_type :: proc(fd: os.Handle, info: ^Type_Info) {
|
||||
data: [PRINT_BUF_SIZE]byte;
|
||||
buf := data[:0];
|
||||
buf := Buffer{data[:], 0};
|
||||
bprint_type(^buf, info);
|
||||
os.write(fd, buf);
|
||||
os.write(fd, buf.data[:buf.length]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
print_byte_buffer :: proc(buf: ^[]byte, b: []byte) {
|
||||
if buf.count < buf.capacity {
|
||||
n := min(buf.capacity-buf.count, b.count);
|
||||
print_byte_buffer :: proc(buf: ^Buffer, b: []byte) {
|
||||
if buf.length < buf.data.count {
|
||||
n := min(buf.data.count-buf.length, b.count);
|
||||
if n > 0 {
|
||||
mem.copy(buf.data + buf.count, b.data, n);
|
||||
buf.count += n;
|
||||
copy(buf.data[buf.length:], b[:n]);
|
||||
buf.length += n;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bprint_string :: proc(buf: ^[]byte, s: string) {
|
||||
bprint_string :: proc(buf: ^Buffer, s: string) {
|
||||
print_byte_buffer(buf, s as []byte);
|
||||
}
|
||||
|
||||
|
||||
byte_reverse :: proc(b: []byte) {
|
||||
n := b.count;
|
||||
for i := 0; i < n/2; i++ {
|
||||
for i : 0..<n/2 {
|
||||
b[i], b[n-1-i] = b[n-1-i], b[i];
|
||||
}
|
||||
}
|
||||
|
||||
bprint_rune :: proc(buf: ^[]byte, r: rune) {
|
||||
bprint_rune :: proc(buf: ^Buffer, r: rune) {
|
||||
b, n := utf8.encode_rune(r);
|
||||
bprint_string(buf, b[:n] as string);
|
||||
}
|
||||
|
||||
bprint_space :: proc(buf: ^[]byte) { bprint_rune(buf, ' '); }
|
||||
bprint_nl :: proc (buf: ^[]byte) { bprint_rune(buf, '\n'); }
|
||||
bprint_space :: proc(buf: ^Buffer) { bprint_rune(buf, ' '); }
|
||||
bprint_nl :: proc (buf: ^Buffer) { bprint_rune(buf, '\n'); }
|
||||
|
||||
__NUM_TO_CHAR_TABLE := "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz@$";
|
||||
|
||||
bprint_bool :: proc(buffer: ^[]byte, b: bool) {
|
||||
bprint_bool :: proc(buffer: ^Buffer, b: bool) {
|
||||
if b {
|
||||
bprint_string(buffer, "true");
|
||||
} else {
|
||||
@@ -89,31 +95,31 @@ bprint_bool :: proc(buffer: ^[]byte, b: bool) {
|
||||
}
|
||||
}
|
||||
|
||||
bprint_pointer :: proc(buffer: ^[]byte, p: rawptr) #inline {
|
||||
bprint_pointer :: proc(buffer: ^Buffer, p: rawptr) #inline {
|
||||
bprint_string(buffer, "0x");
|
||||
bprint_u64(buffer, p as uint as u64);
|
||||
}
|
||||
|
||||
// bprint_f16 :: proc (buffer: ^[]byte, f: f32) #inline { print__f64(buffer, f as f64, 4); }
|
||||
bprint_f32 :: proc (buffer: ^[]byte, f: f32) #inline { print__f64(buffer, f as f64, 7); }
|
||||
bprint_f64 :: proc (buffer: ^[]byte, f: f64) #inline { print__f64(buffer, f as f64, 16); }
|
||||
bprint_u64 :: proc(buffer: ^[]byte, value: u64) {
|
||||
// bprint_f16 :: proc (buffer: ^Buffer, f: f32) #inline { print__f64(buffer, f as f64, 4); }
|
||||
bprint_f32 :: proc (buffer: ^Buffer, f: f32) #inline { print__f64(buffer, f as f64, 7); }
|
||||
bprint_f64 :: proc (buffer: ^Buffer, f: f64) #inline { print__f64(buffer, f as f64, 16); }
|
||||
bprint_u64 :: proc(buffer: ^Buffer, value: u64) {
|
||||
i := value;
|
||||
buf :[20]byte;
|
||||
len := 0;
|
||||
if i == 0 {
|
||||
buf[len] = '0';
|
||||
len++;
|
||||
len += 1;
|
||||
}
|
||||
for i > 0 {
|
||||
while i > 0 {
|
||||
buf[len] = __NUM_TO_CHAR_TABLE[i % 10];
|
||||
len++;
|
||||
len += 1;
|
||||
i /= 10;
|
||||
}
|
||||
byte_reverse(buf[:len]);
|
||||
bprint_string(buffer, buf[:len] as string);
|
||||
}
|
||||
bprint_i64 :: proc(buffer: ^[]byte, value: i64) {
|
||||
bprint_i64 :: proc(buffer: ^Buffer, value: i64) {
|
||||
// TODO(bill): Cleanup printing
|
||||
i := value;
|
||||
if i < 0 {
|
||||
@@ -124,14 +130,14 @@ bprint_i64 :: proc(buffer: ^[]byte, value: i64) {
|
||||
}
|
||||
|
||||
/*
|
||||
bprint_u128 :: proc(buffer: ^[]byte, value u128) {
|
||||
bprint_u128 :: proc(buffer: ^Buffer, value u128) {
|
||||
a := value transmute [2]u64;
|
||||
if a[1] != 0 {
|
||||
bprint_u64(buffer, a[1]);
|
||||
}
|
||||
bprint_u64(buffer, a[0]);
|
||||
}
|
||||
bprint_i128 :: proc(buffer: ^[]byte, value i128) {
|
||||
bprint_i128 :: proc(buffer: ^Buffer, value i128) {
|
||||
i := value;
|
||||
if i < 0 {
|
||||
i = -i;
|
||||
@@ -142,7 +148,7 @@ bprint_i128 :: proc(buffer: ^[]byte, value i128) {
|
||||
*/
|
||||
|
||||
|
||||
print__f64 :: proc(buffer: ^[]byte, value: f64, decimal_places: int) {
|
||||
print__f64 :: proc(buffer: ^Buffer, value: f64, decimal_places: int) {
|
||||
f := value;
|
||||
if f == 0 {
|
||||
bprint_rune(buffer, '0');
|
||||
@@ -159,16 +165,17 @@ print__f64 :: proc(buffer: ^[]byte, value: f64, decimal_places: int) {
|
||||
|
||||
bprint_rune(buffer, '.');
|
||||
|
||||
mult :f64 = 10.0;
|
||||
for ; decimal_places >= 0; decimal_places-- {
|
||||
mult: f64 = 10.0;
|
||||
while decimal_places >= 0 {
|
||||
i = (f * mult) as u64;
|
||||
bprint_u64(buffer, i as u64);
|
||||
f -= i as f64 / mult;
|
||||
mult *= 10;
|
||||
decimal_places -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
bprint_type :: proc(buf: ^[]byte, ti: ^Type_Info) {
|
||||
bprint_type :: proc(buf: ^Buffer, ti: ^Type_Info) {
|
||||
if ti == nil {
|
||||
return;
|
||||
}
|
||||
@@ -224,7 +231,7 @@ bprint_type :: proc(buf: ^[]byte, ti: ^Type_Info) {
|
||||
case Tuple:
|
||||
count := info.fields.count;
|
||||
if count != 1 { bprint_string(buf, "("); }
|
||||
for i := 0; i < count; i++ {
|
||||
for i : 0..<count {
|
||||
if i > 0 { bprint_string(buf, ", "); }
|
||||
|
||||
f := info.fields[i];
|
||||
@@ -257,37 +264,37 @@ bprint_type :: proc(buf: ^[]byte, ti: ^Type_Info) {
|
||||
if info.packed { bprint_string(buf, "#packed "); }
|
||||
if info.ordered { bprint_string(buf, "#ordered "); }
|
||||
bprint_string(buf, "{");
|
||||
for i := 0; i < info.fields.count; i++ {
|
||||
for field, i : info.fields {
|
||||
if i > 0 {
|
||||
bprint_string(buf, ", ");
|
||||
}
|
||||
bprint_any(buf, info.fields[i].name);
|
||||
bprint_any(buf, field.name);
|
||||
bprint_string(buf, ": ");
|
||||
bprint_type(buf, info.fields[i].type_info);
|
||||
bprint_type(buf, field.type_info);
|
||||
}
|
||||
bprint_string(buf, "}");
|
||||
|
||||
case Union:
|
||||
bprint_string(buf, "union {");
|
||||
for i := 0; i < info.fields.count; i++ {
|
||||
for field, i : info.fields {
|
||||
if i > 0 {
|
||||
bprint_string(buf, ", ");
|
||||
}
|
||||
bprint_any(buf, info.fields[i].name);
|
||||
bprint_any(buf, field.name);
|
||||
bprint_string(buf, ": ");
|
||||
bprint_type(buf, info.fields[i].type_info);
|
||||
bprint_type(buf, field.type_info);
|
||||
}
|
||||
bprint_string(buf, "}");
|
||||
|
||||
case Raw_Union:
|
||||
bprint_string(buf, "raw_union {");
|
||||
for i := 0; i < info.fields.count; i++ {
|
||||
for field, i : info.fields {
|
||||
if i > 0 {
|
||||
bprint_string(buf, ", ");
|
||||
}
|
||||
bprint_any(buf, info.fields[i].name);
|
||||
bprint_any(buf, field.name);
|
||||
bprint_string(buf, ": ");
|
||||
bprint_type(buf, info.fields[i].type_info);
|
||||
bprint_type(buf, field.type_info);
|
||||
}
|
||||
bprint_string(buf, "}");
|
||||
|
||||
@@ -307,7 +314,7 @@ make_any :: proc(type_info: ^Type_Info, data: rawptr) -> any {
|
||||
return a;
|
||||
}
|
||||
|
||||
bprint_any :: proc(buf: ^[]byte, arg: any) {
|
||||
bprint_any :: proc(buf: ^Buffer, arg: any) {
|
||||
if arg.type_info == nil {
|
||||
bprint_string(buf, "<nil>");
|
||||
return;
|
||||
@@ -326,8 +333,7 @@ bprint_any :: proc(buf: ^[]byte, arg: any) {
|
||||
case Struct:
|
||||
bprint_string(buf, info.name);
|
||||
bprint_string(buf, "{");
|
||||
for i := 0; i < b.fields.count; i++ {
|
||||
f := b.fields[i];
|
||||
for f, i : b.fields {
|
||||
if i > 0 {
|
||||
bprint_string(buf, ", ");
|
||||
}
|
||||
@@ -397,7 +403,7 @@ bprint_any :: proc(buf: ^[]byte, arg: any) {
|
||||
bprintf(buf, "[%]%{", info.count, info.elem);
|
||||
defer bprint_string(buf, "}");
|
||||
|
||||
for i := 0; i < info.count; i++ {
|
||||
for i : 0..<info.count {
|
||||
if i > 0 {
|
||||
bprint_string(buf, ", ");
|
||||
}
|
||||
@@ -411,7 +417,7 @@ bprint_any :: proc(buf: ^[]byte, arg: any) {
|
||||
bprintf(buf, "[]%{", info.elem);
|
||||
defer bprint_string(buf, "}");
|
||||
|
||||
for i := 0; i < slice.count; i++ {
|
||||
for i : 0..<slice.count {
|
||||
if i > 0 {
|
||||
bprint_string(buf, ", ");
|
||||
}
|
||||
@@ -438,7 +444,7 @@ bprint_any :: proc(buf: ^[]byte, arg: any) {
|
||||
return;
|
||||
}
|
||||
|
||||
for i := 0; i < info.count; i++ {
|
||||
for i : 0..<info.count {
|
||||
if i > 0 {
|
||||
bprint_string(buf, ", ");
|
||||
}
|
||||
@@ -452,14 +458,14 @@ bprint_any :: proc(buf: ^[]byte, arg: any) {
|
||||
bprintf(buf, "%{", arg.type_info);
|
||||
defer bprint_string(buf, "}");
|
||||
|
||||
for i := 0; i < info.fields.count; i++ {
|
||||
for f, i : info.fields {
|
||||
if i > 0 {
|
||||
bprint_string(buf, ", ");
|
||||
}
|
||||
bprint_string(buf, info.fields[i].name);
|
||||
bprint_string(buf, f.name);
|
||||
bprint_string(buf, " = ");
|
||||
data := arg.data as ^byte + info.fields[i].offset;
|
||||
ti := info.fields[i].type_info;
|
||||
data := arg.data as ^byte + f.offset;
|
||||
ti := f.type_info;
|
||||
bprint_any(buf, make_any(ti, data));
|
||||
}
|
||||
|
||||
@@ -479,7 +485,7 @@ bprint_any :: proc(buf: ^[]byte, arg: any) {
|
||||
}
|
||||
|
||||
|
||||
bprintf :: proc(buf: ^[]byte, fmt: string, args: ..any) -> int {
|
||||
bprintf :: proc(buf: ^Buffer, fmt: string, args: ...any) -> int {
|
||||
is_digit :: proc(r: rune) -> bool #inline {
|
||||
return '0' <= r && r <= '9';
|
||||
}
|
||||
@@ -487,7 +493,7 @@ bprintf :: proc(buf: ^[]byte, fmt: string, args: ..any) -> int {
|
||||
parse_int :: proc(s: string, offset: int) -> (int, int) {
|
||||
result := 0;
|
||||
|
||||
for ; offset < s.count; offset++ {
|
||||
for _ : offset..<s.count {
|
||||
c := s[offset] as rune;
|
||||
if !is_digit(c) {
|
||||
break;
|
||||
@@ -503,7 +509,7 @@ bprintf :: proc(buf: ^[]byte, fmt: string, args: ..any) -> int {
|
||||
prev := 0;
|
||||
implicit_index := 0;
|
||||
|
||||
for i := 0; i < fmt.count; i++ {
|
||||
while i := 0; i < fmt.count { defer i += 1;
|
||||
r := fmt[i] as rune;
|
||||
index := implicit_index;
|
||||
|
||||
@@ -512,13 +518,13 @@ bprintf :: proc(buf: ^[]byte, fmt: string, args: ..any) -> int {
|
||||
}
|
||||
|
||||
bprint_string(buf, fmt[prev:i]);
|
||||
i++; // Skip %
|
||||
i += 1; // Skip %
|
||||
if i < fmt.count {
|
||||
next := fmt[i] as rune;
|
||||
|
||||
if next == '%' {
|
||||
bprint_string(buf, "%");
|
||||
i++;
|
||||
i += 1;
|
||||
prev = i;
|
||||
continue;
|
||||
}
|
||||
@@ -540,11 +546,11 @@ bprintf :: proc(buf: ^[]byte, fmt: string, args: ..any) -> int {
|
||||
}
|
||||
|
||||
bprint_string(buf, fmt[prev:]);
|
||||
return buf.count;
|
||||
return buf.length;
|
||||
}
|
||||
|
||||
|
||||
bprint :: proc(buf: ^[]byte, args: ..any) -> int {
|
||||
bprint :: proc(buf: ^Buffer, args: ...any) -> int {
|
||||
is_type_string :: proc(info: ^Type_Info) -> bool {
|
||||
using Type_Info;
|
||||
if info == nil {
|
||||
@@ -560,8 +566,7 @@ bprint :: proc(buf: ^[]byte, args: ..any) -> int {
|
||||
|
||||
|
||||
prev_string := false;
|
||||
for i := 0; i < args.count; i++ {
|
||||
arg := args[i];
|
||||
for arg, i : args {
|
||||
is_string := arg.data != nil && is_type_string(arg.type_info);
|
||||
if i > 0 && !is_string && !prev_string {
|
||||
bprint_space(buf);
|
||||
@@ -569,16 +574,16 @@ bprint :: proc(buf: ^[]byte, args: ..any) -> int {
|
||||
bprint_any(buf, arg);
|
||||
prev_string = is_string;
|
||||
}
|
||||
return buf.count;
|
||||
return buf.length;
|
||||
}
|
||||
|
||||
bprintln :: proc(buf: ^[]byte, args: ..any) -> int {
|
||||
for i := 0; i < args.count; i++ {
|
||||
bprintln :: proc(buf: ^Buffer, args: ...any) -> int {
|
||||
for arg, i : args {
|
||||
if i > 0 {
|
||||
append(buf, ' ');
|
||||
bprint_space(buf);
|
||||
}
|
||||
bprint_any(buf, args[i]);
|
||||
bprint_any(buf, arg);
|
||||
}
|
||||
bprint_nl(buf);
|
||||
return buf.count;
|
||||
return buf.length;
|
||||
}
|
||||
|
||||
+15
-15
@@ -1,7 +1,7 @@
|
||||
crc32 :: proc(data: rawptr, len: int) -> u32 {
|
||||
result := ~(0 as u32);
|
||||
s := slice_ptr(data as ^u8, len);
|
||||
for i := 0; i < len; i++ {
|
||||
for i : 0..<len {
|
||||
b := s[i] as u32;
|
||||
result = result>>8 ~ __CRC32_TABLE[(result ~ b) & 0xff];
|
||||
}
|
||||
@@ -10,7 +10,7 @@ crc32 :: proc(data: rawptr, len: int) -> u32 {
|
||||
crc64 :: proc(data: rawptr, len: int) -> u64 {
|
||||
result := ~(0 as u64);
|
||||
s := slice_ptr(data as ^u8, len);
|
||||
for i := 0; i < len; i++ {
|
||||
for i : 0..<len {
|
||||
b := s[i] as u64;
|
||||
result = result>>8 ~ __CRC64_TABLE[(result ~ b) & 0xff];
|
||||
}
|
||||
@@ -20,8 +20,8 @@ crc64 :: proc(data: rawptr, len: int) -> u64 {
|
||||
fnv32 :: proc(data: rawptr, len: int) -> u32 {
|
||||
s := slice_ptr(data as ^u8, len);
|
||||
|
||||
h :u32 = 0x811c9dc5;
|
||||
for i := 0; i < len; i++ {
|
||||
h: u32 = 0x811c9dc5;
|
||||
for i : 0..<len {
|
||||
h = (h * 0x01000193) ~ s[i] as u32;
|
||||
}
|
||||
return h;
|
||||
@@ -30,8 +30,8 @@ fnv32 :: proc(data: rawptr, len: int) -> u32 {
|
||||
fnv64 :: proc(data: rawptr, len: int) -> u64 {
|
||||
s := slice_ptr(data as ^u8, len);
|
||||
|
||||
h :u64 = 0xcbf29ce484222325;
|
||||
for i := 0; i < len; i++ {
|
||||
h: u64 = 0xcbf29ce484222325;
|
||||
for i : 0..<len {
|
||||
h = (h * 0x100000001b3) ~ s[i] as u64;
|
||||
}
|
||||
return h;
|
||||
@@ -40,8 +40,8 @@ fnv64 :: proc(data: rawptr, len: int) -> u64 {
|
||||
fnv32a :: proc(data: rawptr, len: int) -> u32 {
|
||||
s := slice_ptr(data as ^u8, len);
|
||||
|
||||
h :u32 = 0x811c9dc5;
|
||||
for i := 0; i < len; i++ {
|
||||
h: u32 = 0x811c9dc5;
|
||||
for i : 0..<len {
|
||||
h = (h ~ s[i] as u32) * 0x01000193;
|
||||
}
|
||||
return h;
|
||||
@@ -51,7 +51,7 @@ fnv64a :: proc(data: rawptr, len: int) -> u64 {
|
||||
s := slice_ptr(data as ^u8, len);
|
||||
|
||||
h :u64 = 0xcbf29ce484222325;
|
||||
for i := 0; i < len; i++ {
|
||||
for i : 0..<len {
|
||||
h = (h ~ s[i] as u64) * 0x100000001b3;
|
||||
}
|
||||
return h;
|
||||
@@ -70,7 +70,7 @@ murmur64 :: proc(data_: rawptr, len: int) -> u64 {
|
||||
data := slice_ptr(data_ as ^u64, len/size_of(u64));
|
||||
data2 := slice_ptr(data_ as ^u8, len);
|
||||
|
||||
for i := 0; i < data.count; i++ {
|
||||
for i : 0 ..< data.count {
|
||||
k := data[i];
|
||||
|
||||
k *= m;
|
||||
@@ -108,9 +108,9 @@ murmur64 :: proc(data_: rawptr, len: int) -> u64 {
|
||||
data := slice_ptr(data_ as ^u32, len/size_of(u32));
|
||||
|
||||
i := 0;
|
||||
for len >= 8 {
|
||||
while len >= 8 {
|
||||
k1, k2: u32;
|
||||
k1 = data[i]; i++;
|
||||
k1 = data[i]; i += 1;
|
||||
k1 *= m;
|
||||
k1 ~= k1>>r;
|
||||
k1 *= m;
|
||||
@@ -118,7 +118,7 @@ murmur64 :: proc(data_: rawptr, len: int) -> u64 {
|
||||
h1 ~= k1;
|
||||
len -= 4;
|
||||
|
||||
k2 = data[i]; i++;
|
||||
k2 = data[i]; i += 1;
|
||||
k2 *= m;
|
||||
k2 ~= k2>>r;
|
||||
k2 *= m;
|
||||
@@ -127,9 +127,9 @@ murmur64 :: proc(data_: rawptr, len: int) -> u64 {
|
||||
len -= 4;
|
||||
}
|
||||
|
||||
if (len >= 4) {
|
||||
if len >= 4 {
|
||||
k1: u32;
|
||||
k1 = data[i]; i++;
|
||||
k1 = data[i]; i += 1;
|
||||
k1 *= m;
|
||||
k1 ~= k1>>r;
|
||||
k1 *= m;
|
||||
|
||||
+4
-4
@@ -145,8 +145,8 @@ mat4_identity :: proc() -> Mat4 {
|
||||
}
|
||||
|
||||
mat4_transpose :: proc(m: Mat4) -> Mat4 {
|
||||
for j := 0; j < 4; j++ {
|
||||
for i := 0; i < 4; i++ {
|
||||
for j : 0..<4 {
|
||||
for i : 0..<4 {
|
||||
m[i][j], m[j][i] = m[j][i], m[i][j];
|
||||
}
|
||||
}
|
||||
@@ -155,8 +155,8 @@ mat4_transpose :: proc(m: Mat4) -> Mat4 {
|
||||
|
||||
mat4_mul :: proc(a, b: Mat4) -> Mat4 {
|
||||
c: Mat4;
|
||||
for j := 0; j < 4; j++ {
|
||||
for i := 0; i < 4; i++ {
|
||||
for j : 0..<4 {
|
||||
for i : 0..<4 {
|
||||
c[j][i] = a[0][i]*b[j][0] +
|
||||
a[1][i]*b[j][1] +
|
||||
a[2][i]*b[j][2] +
|
||||
|
||||
+15
-12
@@ -40,9 +40,9 @@ compare :: proc(dst, src: rawptr, n: int) -> int #link_name "__mem_compare" {
|
||||
la := slice_ptr(^a[0] as ^int, fast);
|
||||
lb := slice_ptr(^b[0] as ^int, fast);
|
||||
|
||||
for ; curr_block < fast; curr_block++ {
|
||||
for _ : curr_block ..< fast {
|
||||
if (la[curr_block] ~ lb[curr_block]) != 0 {
|
||||
for pos := curr_block*size_of(int); pos < n; pos++ {
|
||||
for pos : curr_block*size_of(int) ..< n {
|
||||
if (a[pos] ~ b[pos]) != 0 {
|
||||
return a[pos] as int - b[pos] as int;
|
||||
}
|
||||
@@ -51,7 +51,7 @@ compare :: proc(dst, src: rawptr, n: int) -> int #link_name "__mem_compare" {
|
||||
|
||||
}
|
||||
|
||||
for ; offset < n; offset++ {
|
||||
for _ : offset ..< n {
|
||||
if (a[offset] ~ b[offset]) != 0 {
|
||||
return a[offset] as int - b[offset] as int;
|
||||
}
|
||||
@@ -96,13 +96,14 @@ allocation_header_fill :: proc(header: ^Allocation_Header, data: rawptr, size: i
|
||||
header.size = size;
|
||||
ptr := (header+1) as ^int;
|
||||
|
||||
for i := 0; ptr as rawptr < data; i++ {
|
||||
while i := 0; ptr as rawptr < data {
|
||||
(ptr+i)^ = -1;
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
allocation_header :: proc(data: rawptr) -> ^Allocation_Header {
|
||||
p := data as ^int;
|
||||
for (p-1)^ == -1 {
|
||||
while (p-1)^ == -1 {
|
||||
p = (p-1);
|
||||
}
|
||||
return (p as ^Allocation_Header)-1;
|
||||
@@ -115,6 +116,7 @@ allocation_header :: proc(data: rawptr) -> ^Allocation_Header {
|
||||
// Custom allocators
|
||||
Arena :: struct {
|
||||
backing: Allocator;
|
||||
offset: int;
|
||||
memory: []byte;
|
||||
temp_count: int;
|
||||
}
|
||||
@@ -144,7 +146,8 @@ free_arena :: proc(using a: ^Arena) {
|
||||
if backing.procedure != nil {
|
||||
push_allocator backing {
|
||||
free(memory.data);
|
||||
memory = memory[0:0:0];
|
||||
memory = memory[0:0];
|
||||
offset = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -166,15 +169,15 @@ arena_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
|
||||
case ALLOC:
|
||||
total_size := size + alignment;
|
||||
|
||||
if arena.memory.count + total_size > arena.memory.capacity {
|
||||
if arena.offset + total_size > arena.memory.count {
|
||||
fmt.fprintln(os.stderr, "Arena out of memory");
|
||||
return nil;
|
||||
}
|
||||
|
||||
#no_bounds_check end := ^arena.memory[arena.memory.count];
|
||||
#no_bounds_check end := ^arena.memory[arena.offset];
|
||||
|
||||
ptr := align_forward(end, alignment);
|
||||
arena.memory.count += total_size;
|
||||
arena.offset += total_size;
|
||||
return zero(ptr, size);
|
||||
|
||||
case FREE:
|
||||
@@ -182,7 +185,7 @@ arena_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
|
||||
// Use Arena_Temp_Memory if you want to free a block
|
||||
|
||||
case FREE_ALL:
|
||||
arena.memory.count = 0;
|
||||
arena.offset = 0;
|
||||
|
||||
case RESIZE:
|
||||
return default_resize_align(old_memory, old_size, size, alignment);
|
||||
@@ -195,7 +198,7 @@ begin_arena_temp_memory :: proc(a: ^Arena) -> Arena_Temp_Memory {
|
||||
tmp: Arena_Temp_Memory;
|
||||
tmp.arena = a;
|
||||
tmp.original_count = a.memory.count;
|
||||
a.temp_count++;
|
||||
a.temp_count += 1;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
@@ -203,7 +206,7 @@ end_arena_temp_memory :: proc(using tmp: Arena_Temp_Memory) {
|
||||
assert(arena.memory.count >= original_count);
|
||||
assert(arena.temp_count > 0);
|
||||
arena.memory.count = original_count;
|
||||
arena.temp_count--;
|
||||
arena.temp_count -= 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -222,7 +222,7 @@ read_entire_file :: proc(name: string) -> ([]byte, bool) {
|
||||
single_read_length: i32;
|
||||
total_read: i64;
|
||||
|
||||
for total_read < length {
|
||||
while total_read < length {
|
||||
remaining := length - total_read;
|
||||
to_read: u32;
|
||||
MAX :: 1<<32-1;
|
||||
|
||||
+3
-3
@@ -52,7 +52,7 @@ mutex_lock :: proc(m: ^Mutex) {
|
||||
}
|
||||
}
|
||||
atomic.store32(^m.owner, thread_id);
|
||||
m.recursion++;
|
||||
m.recursion += 1;
|
||||
}
|
||||
mutex_try_lock :: proc(m: ^Mutex) -> bool {
|
||||
thread_id := current_thread_id();
|
||||
@@ -68,7 +68,7 @@ mutex_try_lock :: proc(m: ^Mutex) -> bool {
|
||||
}
|
||||
atomic.store32(^m.owner, thread_id);
|
||||
}
|
||||
m.recursion++;
|
||||
m.recursion += 1;
|
||||
return true;
|
||||
}
|
||||
mutex_unlock :: proc(m: ^Mutex) {
|
||||
@@ -76,7 +76,7 @@ mutex_unlock :: proc(m: ^Mutex) {
|
||||
thread_id := current_thread_id();
|
||||
assert(thread_id == atomic.load32(^m.owner));
|
||||
|
||||
m.recursion--;
|
||||
m.recursion -= 1;
|
||||
recursion = m.recursion;
|
||||
if recursion == 0 {
|
||||
atomic.store32(^m.owner, thread_id);
|
||||
|
||||
+9
-6
@@ -132,10 +132,11 @@ valid_rune :: proc(r: rune) -> bool {
|
||||
|
||||
valid_string :: proc(s: string) -> bool {
|
||||
n := s.count;
|
||||
for i := 0; i < n; {
|
||||
i := 0;
|
||||
while i < n {
|
||||
si := s[i];
|
||||
if si < RUNE_SELF { // ascii
|
||||
i++;
|
||||
i += 1;
|
||||
continue;
|
||||
}
|
||||
x := accept_sizes[si];
|
||||
@@ -166,20 +167,22 @@ valid_string :: proc(s: string) -> bool {
|
||||
rune_count :: proc(s: string) -> int {
|
||||
count := 0;
|
||||
n := s.count;
|
||||
for i := 0; i < n; count++ {
|
||||
i := 0;
|
||||
while i < n {
|
||||
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 := (x & 7) as int;
|
||||
if i+size > n {
|
||||
i++;
|
||||
i += 1;
|
||||
continue;
|
||||
}
|
||||
ar := accept_ranges[x>>4];
|
||||
|
||||
Reference in New Issue
Block a user