Remove atomic, ++, and --

This commit is contained in:
Ginger Bill
2017-07-18 18:58:41 +01:00
parent d16aa79492
commit 65f079ebc4
23 changed files with 179 additions and 239 deletions
+33 -11
View File
@@ -1,4 +1,22 @@
import "fmt.odin"; import (
"fmt.odin";
"atomics.odin";
"bits.odin";
"hash.odin";
"math.odin";
"mem.odin";
"opengl.odin";
"os.odin";
"pool.odin";
"raw.odin";
"sort.odin";
"strconv.odin";
"strings.odin";
"sync.odin";
"types.odin";
"utf8.odin";
"utf16.odin";
)
Table :: struct(Key, Value: type) { Table :: struct(Key, Value: type) {
Slot :: struct { Slot :: struct {
@@ -61,7 +79,7 @@ put :: proc(table: ^Table($Key, $Value), key: Key, value: Value) {
} }
} }
table.count++; table.count += 1;
} }
slot := &table.slots[index]; slot := &table.slots[index];
@@ -95,8 +113,9 @@ find_index :: proc(table: ^Table($Key, $Value), key: Key, hash: u32) -> int {
} }
} }
index++; if index += 1; index >= cap(table.slots) {
if index >= cap(table.slots) do index = 0; index = 0;
}
} }
return -1; return -1;
@@ -121,8 +140,8 @@ Vector :: struct(N: int, T: type) {
when N >= 3 do z: T; when N >= 3 do z: T;
when N >= 4 do w: T; when N >= 4 do w: T;
}; };
}
}; } };
} }
Vector3 :: Vector(3, f32); Vector3 :: Vector(3, f32);
@@ -137,15 +156,18 @@ add :: proc(a, b: $T/Vector) -> T {
foo1 :: proc(a: type/Vector) { fmt.println("foo1", a{}); } foo1 :: proc(a: type/Vector) { fmt.println("foo1", a{}); }
// foo2 :: proc(a: type/Vector(3, f32)) {} // foo2 :: proc(a: type/Vector(3, f32)) {}
foo3 :: proc(a: type/Vector(3, $T)) {fmt.println("foo3", a{}); } foo3 :: proc(a: type/Vector(3, $T)) { fmt.println("foo3", a{}); }
// foo4 :: proc(a: type/Vector3) {} // foo4 :: proc(a: type/Vector3) {}
main :: proc() { main :: proc() {
Foo :: struct {
a := 123;
b := true;
}
v1 := Foo{};
fmt.println(v1);
foo1(Vector(3, f32)); foo1(Vector(3, f32));
foo1(Vector3); foo1(Vector3);
foo3(Vector(3, f32)); foo3(Vector(3, f32));
+2 -4
View File
@@ -64,7 +64,6 @@ TypeInfo :: struct #ordered {
Pointer :: struct #ordered { Pointer :: struct #ordered {
elem: ^TypeInfo; // nil -> rawptr elem: ^TypeInfo; // nil -> rawptr
}; };
Atomic :: struct #ordered {elem: ^TypeInfo};
Procedure :: struct #ordered { Procedure :: struct #ordered {
params: ^TypeInfo; // TypeInfo.Tuple params: ^TypeInfo; // TypeInfo.Tuple
results: ^TypeInfo; // TypeInfo.Tuple results: ^TypeInfo; // TypeInfo.Tuple
@@ -117,7 +116,6 @@ TypeInfo :: struct #ordered {
Boolean, Boolean,
Any, Any,
Pointer, Pointer,
Atomic,
Procedure, Procedure,
Array, Array,
DynamicArray, DynamicArray,
@@ -821,7 +819,7 @@ __dynamic_array_append_nothing :: proc(array_: rawptr, elem_size, elem_align: in
data := cast(^u8)array.data; data := cast(^u8)array.data;
assert(data != nil); assert(data != nil);
__mem_zero(data + (elem_size*array.len), elem_size); __mem_zero(data + (elem_size*array.len), elem_size);
array.len++; array.len += 1;
return array.len; return array.len;
} }
@@ -1007,7 +1005,7 @@ __dynamic_map_erase :: proc(using h: __MapHeader, fr: __MapFindResult) {
} }
if fr.entry_index == m.entries.len-1 { 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); __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); last := __dynamic_map_find(h, __dynamic_map_get_entry(h, fr.entry_index).key);
+2 -2
View File
@@ -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); old_value := compare_exchange(a, 1, 0);
counter := 0; counter := 0;
for old_value != 0 && (time_out < 0 || counter < time_out) { for old_value != 0 && (time_out < 0 || counter < time_out) {
counter++; counter += 1;
yield_thread(); yield_thread();
old_value = compare_exchange(a, 1, 0); old_value = compare_exchange(a, 1, 0);
mfence(); 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); old_value := compare_exchange(a, 1, 0);
counter := 0; counter := 0;
for old_value != 0 && (time_out < 0 || counter < time_out) { for old_value != 0 && (time_out < 0 || counter < time_out) {
counter++; counter += 1;
yield_thread(); yield_thread();
old_value = compare_exchange(a, 1, 0); old_value = compare_exchange(a, 1, 0);
mfence(); mfence();
+22 -22
View File
@@ -29,13 +29,13 @@ decimal_to_string :: proc(buf: []u8, a: ^Decimal) -> string {
w := 0; w := 0;
if a.decimal_point <= 0 { if a.decimal_point <= 0 {
buf[w] = '0'; w++; buf[w] = '0'; w+=1;
buf[w] = '.'; w++; buf[w] = '.'; w+=1;
w += digit_zero(buf[w .. w-a.decimal_point]); w += digit_zero(buf[w .. w-a.decimal_point]);
w += copy(buf[w..], a.digits[0..a.count]); w += copy(buf[w..], a.digits[0..a.count]);
} else if a.decimal_point < a.count { } else if a.decimal_point < a.count {
w += copy(buf[w..], a.digits[0..a.decimal_point]); 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]); w += copy(buf[w..], a.digits[a.decimal_point .. a.count]);
} else { } else {
w += copy(buf[w..], a.digits[0..a.count]); 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 trailing zeros
trim :: proc(a: ^Decimal) { trim :: proc(a: ^Decimal) {
for a.count > 0 && a.digits[a.count-1] == '0' { for a.count > 0 && a.digits[a.count-1] == '0' {
a.count--; a.count -= 1;
} }
if a.count == 0 { if a.count == 0 {
a.decimal_point = 0; a.decimal_point = 0;
@@ -63,14 +63,14 @@ assign :: proc(a: ^Decimal, i: u64) {
j := i/10; j := i/10;
i -= 10*j; i -= 10*j;
buf[n] = u8('0'+i); buf[n] = u8('0'+i);
n++; n+=1;
i = j; i = j;
} }
a.count = 0; a.count = 0;
for n--; n >= 0; n-- { for n -= 1; n >= 0; n -= 1 {
a.digits[a.count] = buf[n]; a.digits[a.count] = buf[n];
a.count++; a.count+=1;
} }
a.decimal_point = a.count; a.decimal_point = a.count;
trim(a); trim(a);
@@ -83,7 +83,7 @@ shift_right :: proc(a: ^Decimal, k: uint) {
w := 0; // write index w := 0; // write index
n: uint; n: uint;
for ; n>>k == 0; r++ { for ; n>>k == 0; r+=1 {
if r >= a.count { if r >= a.count {
if n == 0 { if n == 0 {
// Just in case // Just in case
@@ -92,7 +92,7 @@ shift_right :: proc(a: ^Decimal, k: uint) {
} }
for n>>k == 0 { for n>>k == 0 {
n = n * 10; n = n * 10;
r++; r+=1;
} }
break; break;
} }
@@ -103,12 +103,12 @@ shift_right :: proc(a: ^Decimal, k: uint) {
mask: uint = (1<<k) - 1; mask: uint = (1<<k) - 1;
for ; r < a.count; r++ { for ; r < a.count; r+=1 {
c := uint(a.digits[r]); c := uint(a.digits[r]);
dig := n>>k; dig := n>>k;
n &= mask; n &= mask;
a.digits[w] = u8('0' + dig); a.digits[w] = u8('0' + dig);
w++; w+=1;
n = n*10 + c - '0'; n = n*10 + c - '0';
} }
@@ -117,7 +117,7 @@ shift_right :: proc(a: ^Decimal, k: uint) {
n &= mask; n &= mask;
if w < len(a.digits) { if w < len(a.digits) {
a.digits[w] = u8('0' + dig); a.digits[w] = u8('0' + dig);
w++; w+=1;
} else if dig > 0 { } else if dig > 0 {
a.trunc = true; a.trunc = true;
} }
@@ -136,11 +136,11 @@ shift_left :: proc(a: ^Decimal, k: uint) {
w := a.count+delta; // write index w := a.count+delta; // write index
n: uint; n: uint;
for r--; r >= 0; r-- { for r -= 1; r >= 0; r -= 1 {
n += (uint(a.digits[r]) - '0') << k; n += (uint(a.digits[r]) - '0') << k;
quo := n/10; quo := n/10;
rem := n - 10*quo; rem := n - 10*quo;
w--; w -= 1;
if w < len(a.digits) { if w < len(a.digits) {
a.digits[w] = u8('0' + rem); a.digits[w] = u8('0' + rem);
} else if rem != 0 { } else if rem != 0 {
@@ -152,7 +152,7 @@ shift_left :: proc(a: ^Decimal, k: uint) {
for n > 0 { for n > 0 {
quo := n/10; quo := n/10;
rem := n - 10*quo; rem := n - 10*quo;
w--; w -= 1;
if 0 <= w && w < len(a.digits) { if 0 <= w && w < len(a.digits) {
a.digits[w] = u8('0' + rem); a.digits[w] = u8('0' + rem);
} else if rem != 0 { } else if rem != 0 {
@@ -213,9 +213,9 @@ round :: proc(a: ^Decimal, nd: int) {
round_up :: proc(a: ^Decimal, nd: int) { round_up :: proc(a: ^Decimal, nd: int) {
if nd < 0 || nd >= a.count { return; } 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' { if c := a.digits[i]; c < '9' {
a.digits[i]++; a.digits[i]+=1;
a.count = i+1; a.count = i+1;
return; return;
} }
@@ -224,7 +224,7 @@ round_up :: proc(a: ^Decimal, nd: int) {
// Number is just 9s // Number is just 9s
a.digits[0] = '1'; a.digits[0] = '1';
a.count = 1; a.count = 1;
a.decimal_point++; a.decimal_point+=1;
} }
round_down :: proc(a: ^Decimal, nd: int) { round_down :: proc(a: ^Decimal, nd: int) {
@@ -239,17 +239,17 @@ rounded_integer :: proc(a: ^Decimal) -> u64 {
if a.decimal_point > 20 { if a.decimal_point > 20 {
return 0xffff_ffff_ffff_ffff; return 0xffff_ffff_ffff_ffff;
} }
i: int; i: int = 0;
n: u64 = 0; n: u64 = 0;
m := min(a.decimal_point, a.count); 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'); n = n*10 + u64(a.digits[i]-'0');
} }
for ; i < a.decimal_point; i++ { for ; i < a.decimal_point; i += 1 {
n *= 10; n *= 10;
} }
if can_round_up(a, a.decimal_point) { if can_round_up(a, a.decimal_point) {
n++; n+=1;
} }
return n; return n;
} }
+9 -15
View File
@@ -207,9 +207,6 @@ write_type :: proc(buf: ^StringBuffer, ti: ^TypeInfo) {
case Boolean: write_string(buf, "bool"); case Boolean: write_string(buf, "bool");
case Any: case Any:
write_string(buf, "any"); write_string(buf, "any");
case Atomic:
write_string(buf, "atomic ");
write_type(buf, info.elem);
case Pointer: case Pointer:
if info.elem == nil { 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..]) { for i < len(s[offset..]) {
c := rune(s[offset+i]); c := rune(s[offset+i]);
if !is_digit(c) do break; if !is_digit(c) do break;
i++; i += 1;
result *= 10; result *= 10;
result += int(c)-'0'; 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; prec = fi.width;
if neg || fi.plus || fi.space { if neg || fi.plus || fi.space {
// There needs to be space for the "sign" // 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); fmt_pointer(fi, (cast(^rawptr)v.data)^, verb);
} }
case Atomic:
fmt_arg(fi, any{v.data, info.elem}, verb);
case Array: case Array:
write_byte(fi.buf, '['); write_byte(fi.buf, '[');
defer 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; prev_i := i;
for i < end && fmt[i] != '%' { for i < end && fmt[i] != '%' {
i++; i += 1;
} }
if i > prev_i { if i > prev_i {
write_string(b, fmt[prev_i..i]); write_string(b, fmt[prev_i..i]);
@@ -1019,9 +1013,9 @@ sbprintf :: proc(b: ^StringBuffer, fmt: string, args: ...any) -> string {
} }
// Process a "verb" // Process a "verb"
i++; i += 1;
prefix_loop: for ; i < end; i++ { prefix_loop: for ; i < end; i += 1 {
match fmt[i] { match fmt[i] {
case '+': case '+':
fi.plus = true; fi.plus = true;
@@ -1043,7 +1037,7 @@ sbprintf :: proc(b: ^StringBuffer, fmt: string, args: ...any) -> string {
// Width // Width
if i < end && fmt[i] == '*' { if i < end && fmt[i] == '*' {
i++; i += 1;
fi.width, arg_index, fi.width_set = int_from_arg(args, arg_index); fi.width, arg_index, fi.width_set = int_from_arg(args, arg_index);
if !fi.width_set { if !fi.width_set {
write_string(b, "%!(BAD WIDTH)"); write_string(b, "%!(BAD WIDTH)");
@@ -1064,13 +1058,13 @@ sbprintf :: proc(b: ^StringBuffer, fmt: string, args: ...any) -> string {
// Precision // Precision
if i < end && fmt[i] == '.' { if i < end && fmt[i] == '.' {
i++; i += 1;
if was_prev_index { // %[6].2d if was_prev_index { // %[6].2d
fi.good_arg_index = false; fi.good_arg_index = false;
} }
if i < end && fmt[i] == '*' { if i < end && fmt[i] == '*' {
arg_index, i, was_prev_index = _arg_number(&fi, arg_index, fmt, i, len(args)); 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); fi.prec, arg_index, fi.prec_set = int_from_arg(args, arg_index);
if fi.prec < 0 { if fi.prec < 0 {
fi.prec = 0; fi.prec = 0;
@@ -1109,7 +1103,7 @@ sbprintf :: proc(b: ^StringBuffer, fmt: string, args: ...any) -> string {
write_string(b, "%!(MISSING ARGUMENT)"); write_string(b, "%!(MISSING ARGUMENT)");
} else { } else {
fmt_arg(&fi, args[arg_index], verb); fmt_arg(&fi, args[arg_index], verb);
arg_index++; arg_index += 1;
} }
} }
+3 -3
View File
@@ -146,7 +146,7 @@ murmur64 :: proc(data: []u8) -> u64 {
for len >= 8 { for len >= 8 {
k1, k2: u32; k1, k2: u32;
k1 = data32[i]; i++; k1 = data32[i]; i += 1;
k1 *= m; k1 *= m;
k1 ~= k1>>r; k1 ~= k1>>r;
k1 *= m; k1 *= m;
@@ -154,7 +154,7 @@ murmur64 :: proc(data: []u8) -> u64 {
h1 ~= k1; h1 ~= k1;
len -= 4; len -= 4;
k2 = data32[i]; i++; k2 = data32[i]; i += 1;
k2 *= m; k2 *= m;
k2 ~= k2>>r; k2 ~= k2>>r;
k2 *= m; k2 *= m;
@@ -165,7 +165,7 @@ murmur64 :: proc(data: []u8) -> u64 {
if len >= 4 { if len >= 4 {
k1: u32; k1: u32;
k1 = data32[i]; i++; k1 = data32[i]; i += 1;
k1 *= m; k1 *= m;
k1 ~= k1>>r; k1 ~= k1>>r;
k1 *= m; k1 *= m;
+4 -3
View File
@@ -74,8 +74,9 @@ AllocationHeader :: struct {
allocation_header_fill :: proc(header: ^AllocationHeader, data: rawptr, size: int) { allocation_header_fill :: proc(header: ^AllocationHeader, data: rawptr, size: int) {
header.size = size; header.size = size;
ptr := cast(^int)(header+1); 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; (ptr+i)^ = -1;
} }
} }
@@ -176,7 +177,7 @@ begin_arena_temp_memory :: proc(a: ^Arena) -> ArenaTempMemory {
tmp: ArenaTempMemory; tmp: ArenaTempMemory;
tmp.arena = a; tmp.arena = a;
tmp.original_count = len(a.memory); tmp.original_count = len(a.memory);
a.temp_count++; a.temp_count += 1;
return tmp; return tmp;
} }
@@ -184,7 +185,7 @@ end_arena_temp_memory :: proc(using tmp: ArenaTempMemory) {
assert(len(arena.memory) >= original_count); assert(len(arena.memory) >= original_count);
assert(arena.temp_count > 0); assert(arena.temp_count > 0);
arena.memory = arena.memory[..original_count]; arena.memory = arena.memory[..original_count];
arena.temp_count--; arena.temp_count -= 1;
} }
+14 -14
View File
@@ -264,7 +264,7 @@ current_thread_id :: proc() -> int {
_alloc_command_line_arguments :: proc() -> []string { _alloc_command_line_arguments :: proc() -> []string {
alloc_ucs2_to_utf8 :: proc(wstr: ^u16) -> string { alloc_ucs2_to_utf8 :: proc(wstr: ^u16) -> string {
wstr_len := 0; 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; len := 2*wstr_len-1;
buf := make([]u8, len+1); buf := make([]u8, len+1);
@@ -275,29 +275,29 @@ _alloc_command_line_arguments :: proc() -> []string {
match { match {
case str[j] < 0x80: case str[j] < 0x80:
if i+1 > len do return ""; if i+1 > len do return "";
buf[i] = u8(str[j]); i++; buf[i] = u8(str[j]); i += 1;
j++; j += 1;
case str[j] < 0x800: case str[j] < 0x800:
if i+2 > len do return ""; if i+2 > len do return "";
buf[i] = u8(0xc0 + (str[j]>>6)); i++; buf[i] = u8(0xc0 + (str[j]>>6)); i += 1;
buf[i] = u8(0x80 + (str[j]&0x3f)); i++; buf[i] = u8(0x80 + (str[j]&0x3f)); i += 1;
j++; j += 1;
case 0xd800 <= str[j] && str[j] < 0xdc00: case 0xd800 <= str[j] && str[j] < 0xdc00:
if i+4 > len do return ""; if i+4 > len do return "";
c := rune((str[j] - 0xd800) << 10) + rune((str[j+1]) - 0xdc00) + 0x10000; c := rune((str[j] - 0xd800) << 10) + rune((str[j+1]) - 0xdc00) + 0x10000;
buf[i] = u8(0xf0 + (c >> 18)); i++; buf[i] = u8(0xf0 + (c >> 18)); i += 1;
buf[i] = u8(0x80 + ((c >> 12) & 0x3f)); i++; buf[i] = u8(0x80 + ((c >> 12) & 0x3f)); i += 1;
buf[i] = u8(0x80 + ((c >> 6) & 0x3f)); i++; buf[i] = u8(0x80 + ((c >> 6) & 0x3f)); i += 1;
buf[i] = u8(0x80 + ((c ) & 0x3f)); i++; buf[i] = u8(0x80 + ((c ) & 0x3f)); i += 1;
j += 2; j += 2;
case 0xdc00 <= str[j] && str[j] < 0xe000: case 0xdc00 <= str[j] && str[j] < 0xe000:
return ""; return "";
case: case:
if i+3 > len do return ""; if i+3 > len do return "";
buf[i] = 0xe0 + u8 (str[j] >> 12); i++; buf[i] = 0xe0 + u8 (str[j] >> 12); i += 1;
buf[i] = 0x80 + u8((str[j] >> 6) & 0x3f); i++; buf[i] = 0x80 + u8((str[j] >> 6) & 0x3f); i += 1;
buf[i] = 0x80 + u8((str[j] ) & 0x3f); i++; buf[i] = 0x80 + u8((str[j] ) & 0x3f); i += 1;
j++; j += 1;
} }
} }
+17 -13
View File
@@ -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); assert(f != nil);
count := len(array); 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); count := len(array);
init_j, last_j := 0, count-1; 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); assert(f != nil);
a := array; a := array;
n := len(a); 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(a[i..n], f);
} }
quick_sort :: proc(array: []$T) { quick_sort :: proc(array: $A/[]$T) {
a := array; a := array;
n := len(a); n := len(a);
if n < 2 do return; if n < 2 do return;
@@ -94,19 +94,21 @@ quick_sort :: proc(array: []$T) {
_log2 :: proc(n: int) -> int { _log2 :: proc(n: int) -> int {
res := 0; res := 0;
for ; n != 0; n >>= 1 do res++; for ; n != 0; n >>= 1 do res += 1;
return res; return res;
} }
merge_sort :: proc(array: []$T, f: proc(T, T) -> int) { merge_sort :: proc(array: $A/[]$T, f: proc(T, T) -> int) {
merge_slices :: proc(arr1, arr2, out: []$T, f: proc(T, T) -> int) { merge_slices :: proc(arr1, arr2, out: A, f: proc(T, T) -> int) {
N1, N2 := len(arr1), len(arr2); N1, N2 := len(arr1), len(arr2);
i, j := 0, 0; i, j := 0, 0;
for k in 0..N1+N2 { for k in 0..N1+N2 {
if j == N2 || i < N1 && j < N2 && f(arr1[i], arr2[j]) < 0 { 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 { } 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); if M & 1 == 0 do copy(arr2, arr1);
} }
merge_sort :: proc(array: []$T) { merge_sort :: proc(array: $A/[]$T) {
merge_slices :: proc(arr1, arr2, out: []$T) { merge_slices :: proc(arr1, arr2, out: A) {
N1, N2 := len(arr1), len(arr2); N1, N2 := len(arr1), len(arr2);
i, j := 0, 0; i, j := 0, 0;
for k in 0..N1+N2 { for k in 0..N1+N2 {
if j == N2 || i < N1 && j < N2 && arr1[i] < arr2[j] { if j == N2 || i < N1 && j < N2 && arr1[i] < arr2[j] {
out[k] = arr1[i]; i++; out[k] = arr1[i];
i += 1;
} else { } else {
out[k] = arr2[j]; j++; out[k] = arr2[j];
j += 1;
} }
} }
} }
+24 -28
View File
@@ -119,29 +119,25 @@ parse_f64 :: proc(s: string) -> f64 {
sign: f64 = 1; sign: f64 = 1;
match s[i] { match s[i] {
case '-': i++; sign = -1; case '-': i += 1; sign = -1;
case '+': i++; case '+': i += 1;
} }
value: f64 = 0; value: f64 = 0;
for ; i < len(s); i++ { for ; i < len(s); i += 1 {
r := rune(s[i]); r := rune(s[i]);
if r == '_' { if r == '_' do continue;
continue;
}
v := _digit_value(r); v := _digit_value(r);
if v >= 10 { if v >= 10 do break;
break;
}
value *= 10; value *= 10;
value += f64(v); value += f64(v);
} }
if s[i] == '.' { if s[i] == '.' {
pow10: f64 = 10; pow10: f64 = 10;
i++; i += 1;
for ; i < len(s); i++ { for ; i < len(s); i += 1 {
r := rune(s[i]); r := rune(s[i]);
if r == '_' { if r == '_' {
continue; continue;
@@ -159,15 +155,15 @@ parse_f64 :: proc(s: string) -> f64 {
scale: f64 = 1; scale: f64 = 1;
if s[i] == 'e' || s[i] == 'E' { if s[i] == 'e' || s[i] == 'E' {
i++; i += 1;
match s[i] { match s[i] {
case '-': i++; frac = true; case '-': i += 1; frac = true;
case '+': i++; case '+': i += 1;
} }
exp: u32 = 0; exp: u32 = 0;
for ; i < len(s); i++ { for ; i < len(s); i += 1 {
r := rune(s[i]); r := rune(s[i]);
if r == '_' { if r == '_' {
continue; continue;
@@ -261,7 +257,7 @@ generic_ftoa :: proc(buf: []u8, val: f64, fmt: u8, prec, bit_size: int) -> []u8
return buf; return buf;
case 0: // denormalized case 0: // denormalized
exp++; exp += 1;
case: case:
mant |= u64(1) << flt.mantbits; 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 { if digs.decimal_point > 0 {
m := min(digs.count, digs.decimal_point); m := min(digs.count, digs.decimal_point);
append(&buf, ...digs.digits[..m]); append(&buf, ...digs.digits[..m]);
for ; m < digs.decimal_point; m++ { for ; m < digs.decimal_point; m += 1 {
append(&buf, '0'); append(&buf, '0');
} }
} else { } 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); u, neg = is_integer_negative(u, is_signed, bit_size);
b := u128(base); b := u128(base);
for u >= b { for u >= b {
i--; a[i] = digits[uint(u % b)]; i-=1; a[i] = digits[uint(u % b)];
u /= b; u /= b;
} }
i--; a[i] = digits[uint(u % b)]; i-=1; a[i] = digits[uint(u % b)];
if flags&IntFlag.Prefix != 0 { if flags&IntFlag.Prefix != 0 {
ok := true; ok := true;
match base { match base {
case 2: i--; a[i] = 'b'; case 2: i-=1; a[i] = 'b';
case 8: i--; a[i] = 'o'; case 8: i-=1; a[i] = 'o';
case 10: i--; a[i] = 'd'; case 10: i-=1; a[i] = 'd';
case 12: i--; a[i] = 'z'; case 12: i-=1; a[i] = 'z';
case 16: i--; a[i] = 'x'; case 16: i-=1; a[i] = 'x';
case: ok = false; case: ok = false;
} }
if ok { if ok {
i--; a[i] = '0'; i-=1; a[i] = '0';
} }
} }
if neg { if neg {
i--; a[i] = '-'; i-=1; a[i] = '-';
} else if flags&IntFlag.Plus != 0 { } else if flags&IntFlag.Plus != 0 {
i--; a[i] = '+'; i-=1; a[i] = '+';
} else if flags&IntFlag.Space != 0 { } else if flags&IntFlag.Space != 0 {
i--; a[i] = ' '; i-=1; a[i] = ' ';
} }
append(&buf, ...a[i..]); append(&buf, ...a[i..]);
+1 -1
View File
@@ -16,6 +16,6 @@ new_c_string :: proc(s: string) -> ^u8 {
to_odin_string :: proc(c: ^u8) -> string { to_odin_string :: proc(c: ^u8) -> string {
len := 0; len := 0;
for (c+len)^ != 0 do len++; for (c+len)^ != 0 do len+=1;
return string(mem.slice_ptr(c, len)); return string(mem.slice_ptr(c, len));
} }
+3 -3
View File
@@ -56,7 +56,7 @@ mutex_lock :: proc(m: ^Mutex) {
} }
} }
atomics.store(&m._owner, thread_id); atomics.store(&m._owner, thread_id);
m._recursion++; m._recursion += 1;
} }
mutex_try_lock :: proc(m: ^Mutex) -> bool { mutex_try_lock :: proc(m: ^Mutex) -> bool {
thread_id := current_thread_id(); thread_id := current_thread_id();
@@ -72,7 +72,7 @@ mutex_try_lock :: proc(m: ^Mutex) -> bool {
} }
atomics.store(&m._owner, thread_id); atomics.store(&m._owner, thread_id);
} }
m._recursion++; m._recursion += 1;
return true; return true;
} }
mutex_unlock :: proc(m: ^Mutex) { mutex_unlock :: proc(m: ^Mutex) {
@@ -80,7 +80,7 @@ mutex_unlock :: proc(m: ^Mutex) {
thread_id := current_thread_id(); thread_id := current_thread_id();
assert(thread_id == atomics.load(&m._owner)); assert(thread_id == atomics.load(&m._owner));
m._recursion--; m._recursion -= 1;
recursion = m._recursion; recursion = m._recursion;
if recursion == 0 { if recursion == 0 {
atomics.store(&m._owner, thread_id); atomics.store(&m._owner, thread_id);
+3 -3
View File
@@ -29,7 +29,7 @@ encode_surrogate_pair :: proc(r: rune) -> (r1, r2: rune) {
encode :: proc(d: []u16, s: []rune) { encode :: proc(d: []u16, s: []rune) {
n := len(s); 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); max_n := min(len(d), n);
n = 0; n = 0;
@@ -38,7 +38,7 @@ encode :: proc(d: []u16, s: []rune) {
match r { match r {
case 0.._surr1, _surr3.._surr_self: case 0.._surr1, _surr3.._surr_self:
d[n] = u16(r); d[n] = u16(r);
n++; n += 1;
case _surr_self..MAX_RUNE: case _surr_self..MAX_RUNE:
r1, r2 := encode_surrogate_pair(r); r1, r2 := encode_surrogate_pair(r);
@@ -48,7 +48,7 @@ encode :: proc(d: []u16, s: []rune) {
case: case:
d[n] = u16(REPLACEMENT_CHAR); d[n] = u16(REPLACEMENT_CHAR);
n++; n += 1;
} }
} }
} }
+7 -11
View File
@@ -151,12 +151,8 @@ decode_last_rune :: proc(s: []u8) -> (rune, int) {
limit = max(end - UTF_MAX, 0); limit = max(end - UTF_MAX, 0);
start--; for start-=1; start >= limit; start-=1 {
for start >= limit { if rune_start(s[start]) do break;
if rune_start(s[start]) {
break;
}
start--;
} }
start = max(start, 0); start = max(start, 0);
@@ -187,7 +183,7 @@ valid_string :: proc(s: string) -> bool {
for i := 0; i < n; { for i := 0; i < n; {
si := s[i]; si := s[i];
if si < RUNE_SELF { // ascii if si < RUNE_SELF { // ascii
i++; i += 1;
continue; continue;
} }
x := accept_sizes[si]; x := accept_sizes[si];
@@ -223,20 +219,20 @@ rune_count :: proc(s: []u8) -> int {
n := len(s); n := len(s);
for i := 0; i < n; { for i := 0; i < n; {
defer count++; defer count += 1;
si := s[i]; si := s[i];
if si < RUNE_SELF { // ascii if si < RUNE_SELF { // ascii
i++; i += 1;
continue; continue;
} }
x := accept_sizes[si]; x := accept_sizes[si];
if x == 0xf1 { if x == 0xf1 {
i++; i += 1;
continue; continue;
} }
size := int(x & 7); size := int(x & 7);
if i+size > n { if i+size > n {
i++; i += 1;
continue; continue;
} }
ar := accept_ranges[x>>4]; ar := accept_ranges[x>>4];
-17
View File
@@ -1711,11 +1711,6 @@ bool is_polymorphic_type_assignable(Checker *c, Type *poly, Type *source, bool c
return is_polymorphic_type_assignable(c, poly->Pointer.elem, source->Pointer.elem, true, modify_type); return is_polymorphic_type_assignable(c, poly->Pointer.elem, source->Pointer.elem, true, modify_type);
} }
return false; return false;
case Type_Atomic:
if (source->kind == Type_Atomic) {
return is_polymorphic_type_assignable(c, poly->Atomic.elem, source->Atomic.elem, true, modify_type);
}
return false;
case Type_Array: case Type_Array:
if (source->kind == Type_Array && if (source->kind == Type_Array &&
poly->Array.count == source->Array.count) { poly->Array.count == source->Array.count) {
@@ -2942,13 +2937,6 @@ bool check_type_internal(Checker *c, AstNode *e, Type **type, Type *named_type)
return true; return true;
case_end; case_end;
case_ast_node(at, AtomicType, e);
Type *elem = check_type(c, at->type);
i64 esz = type_size_of(c->allocator, elem);
*type = make_type_atomic(c->allocator, elem);
return true;
case_end;
case_ast_node(at, ArrayType, e); case_ast_node(at, ArrayType, e);
if (at->count != nullptr) { if (at->count != nullptr) {
Type *elem = check_type(c, at->elem, nullptr); Type *elem = check_type(c, at->elem, nullptr);
@@ -8399,11 +8387,6 @@ gbString write_expr_to_string(gbString str, AstNode *node) {
} }
str = gb_string_appendc(str, "}"); str = gb_string_appendc(str, "}");
case_end; case_end;
case_ast_node(at, AtomicType, node);
str = gb_string_appendc(str, "atomic ");
str = write_expr_to_string(str, at->type);
case_end;
} }
return str; return str;
+2
View File
@@ -629,6 +629,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
check_stmt(c, ts->stmt, flags); check_stmt(c, ts->stmt, flags);
case_end; case_end;
#if 0
case_ast_node(s, IncDecStmt, node); case_ast_node(s, IncDecStmt, node);
TokenKind op = s->op.kind; TokenKind op = s->op.kind;
switch (op) { switch (op) {
@@ -671,6 +672,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
} }
check_assignment_variable(c, &x, left); check_assignment_variable(c, &x, left);
case_end; case_end;
#endif
case_ast_node(as, AssignStmt, node); case_ast_node(as, AssignStmt, node);
switch (as->op.kind) { switch (as->op.kind) {
+13 -19
View File
@@ -1142,10 +1142,6 @@ void add_type_info_type(Checker *c, Type *t) {
add_type_info_type(c, bt->Pointer.elem); add_type_info_type(c, bt->Pointer.elem);
break; break;
case Type_Atomic:
add_type_info_type(c, bt->Atomic.elem);
break;
case Type_Array: case Type_Array:
add_type_info_type(c, bt->Array.elem); add_type_info_type(c, bt->Array.elem);
add_type_info_type(c, make_type_pointer(c->allocator, bt->Array.elem)); add_type_info_type(c, make_type_pointer(c->allocator, bt->Array.elem));
@@ -1361,7 +1357,7 @@ void init_preload(Checker *c) {
GB_ASSERT(is_type_union(tiv_type)); GB_ASSERT(is_type_union(tiv_type));
TypeUnion *tiv = &tiv_type->Union; TypeUnion *tiv = &tiv_type->Union;
if (tiv->variant_count != 23) { if (tiv->variant_count != 22) {
compiler_error("Invalid `TypeInfo` layout"); compiler_error("Invalid `TypeInfo` layout");
} }
t_type_info_named = tiv->variants[ 1]; t_type_info_named = tiv->variants[ 1];
@@ -1373,19 +1369,18 @@ void init_preload(Checker *c) {
t_type_info_boolean = tiv->variants[ 7]; t_type_info_boolean = tiv->variants[ 7];
t_type_info_any = tiv->variants[ 8]; t_type_info_any = tiv->variants[ 8];
t_type_info_pointer = tiv->variants[ 9]; t_type_info_pointer = tiv->variants[ 9];
t_type_info_atomic = tiv->variants[10]; t_type_info_procedure = tiv->variants[10];
t_type_info_procedure = tiv->variants[11]; t_type_info_array = tiv->variants[11];
t_type_info_array = tiv->variants[12]; t_type_info_dynamic_array = tiv->variants[12];
t_type_info_dynamic_array = tiv->variants[13]; t_type_info_slice = tiv->variants[13];
t_type_info_slice = tiv->variants[14]; t_type_info_vector = tiv->variants[14];
t_type_info_vector = tiv->variants[15]; t_type_info_tuple = tiv->variants[15];
t_type_info_tuple = tiv->variants[16]; t_type_info_struct = tiv->variants[16];
t_type_info_struct = tiv->variants[17]; t_type_info_raw_union = tiv->variants[17];
t_type_info_raw_union = tiv->variants[18]; t_type_info_union = tiv->variants[18];
t_type_info_union = tiv->variants[19]; t_type_info_enum = tiv->variants[19];
t_type_info_enum = tiv->variants[20]; t_type_info_map = tiv->variants[20];
t_type_info_map = tiv->variants[21]; t_type_info_bit_field = tiv->variants[21];
t_type_info_bit_field = tiv->variants[22];
t_type_info_named_ptr = make_type_pointer(c->allocator, t_type_info_named); t_type_info_named_ptr = make_type_pointer(c->allocator, t_type_info_named);
t_type_info_integer_ptr = make_type_pointer(c->allocator, t_type_info_integer); t_type_info_integer_ptr = make_type_pointer(c->allocator, t_type_info_integer);
@@ -1396,7 +1391,6 @@ void init_preload(Checker *c) {
t_type_info_boolean_ptr = make_type_pointer(c->allocator, t_type_info_boolean); t_type_info_boolean_ptr = make_type_pointer(c->allocator, t_type_info_boolean);
t_type_info_any_ptr = make_type_pointer(c->allocator, t_type_info_any); t_type_info_any_ptr = make_type_pointer(c->allocator, t_type_info_any);
t_type_info_pointer_ptr = make_type_pointer(c->allocator, t_type_info_pointer); t_type_info_pointer_ptr = make_type_pointer(c->allocator, t_type_info_pointer);
t_type_info_atomic_ptr = make_type_pointer(c->allocator, t_type_info_atomic);
t_type_info_procedure_ptr = make_type_pointer(c->allocator, t_type_info_procedure); t_type_info_procedure_ptr = make_type_pointer(c->allocator, t_type_info_procedure);
t_type_info_array_ptr = make_type_pointer(c->allocator, t_type_info_array); t_type_info_array_ptr = make_type_pointer(c->allocator, t_type_info_array);
t_type_info_dynamic_array_ptr = make_type_pointer(c->allocator, t_type_info_dynamic_array); t_type_info_dynamic_array_ptr = make_type_pointer(c->allocator, t_type_info_dynamic_array);
+4 -8
View File
@@ -151,7 +151,7 @@ struct irProcedure {
Entity * entity; \ Entity * entity; \
Type * type; \ Type * type; \
bool zero_initialized; \ bool zero_initialized; \
Array<irValue *> referrers; \ Array<irValue *> referrers; \
i64 alignment; \ i64 alignment; \
}) \ }) \
IR_INSTR_KIND(ZeroInit, struct { irValue *address; }) \ IR_INSTR_KIND(ZeroInit, struct { irValue *address; }) \
@@ -1481,7 +1481,7 @@ irValue *ir_emit_store(irProcedure *p, irValue *address, irValue *value) {
GB_ASSERT_MSG(are_types_identical(core_type(a), core_type(b)), "%s %s", type_to_string(a), type_to_string(b)); GB_ASSERT_MSG(are_types_identical(core_type(a), core_type(b)), "%s %s", type_to_string(a), type_to_string(b));
} }
#endif #endif
return ir_emit(p, ir_instr_store(p, address, value, is_type_atomic(a))); return ir_emit(p, ir_instr_store(p, address, value, false));
} }
irValue *ir_emit_load(irProcedure *p, irValue *address) { irValue *ir_emit_load(irProcedure *p, irValue *address) {
GB_ASSERT(address != nullptr); GB_ASSERT(address != nullptr);
@@ -6233,6 +6233,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) {
ir_build_when_stmt(proc, ws); ir_build_when_stmt(proc, ws);
case_end; case_end;
#if 0
case_ast_node(s, IncDecStmt, node); case_ast_node(s, IncDecStmt, node);
TokenKind op = Token_Add; TokenKind op = Token_Add;
if (s->op.kind == Token_Dec) { if (s->op.kind == Token_Dec) {
@@ -6241,6 +6242,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) {
irAddr addr = ir_build_addr(proc, s->expr); irAddr addr = ir_build_addr(proc, s->expr);
ir_build_assign_op(proc, addr, v_one, op); ir_build_assign_op(proc, addr, v_one, op);
case_end; case_end;
#endif
case_ast_node(vd, ValueDecl, node); case_ast_node(vd, ValueDecl, node);
if (vd->is_mutable) { if (vd->is_mutable) {
@@ -8024,12 +8026,6 @@ void ir_gen_tree(irGen *s) {
irValue *gep = ir_get_type_info_ptr(proc, t->Pointer.elem); irValue *gep = ir_get_type_info_ptr(proc, t->Pointer.elem);
ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 0), gep); ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 0), gep);
} break; } break;
case Type_Atomic: {
ir_emit_comment(proc, str_lit("TypeInfoAtomic"));
tag = ir_emit_conv(proc, variant_ptr, t_type_info_atomic_ptr);
irValue *gep = ir_get_type_info_ptr(proc, t->Atomic.elem);
ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 0), gep);
} break;
case Type_Array: { case Type_Array: {
ir_emit_comment(proc, str_lit("TypeInfoArray")); ir_emit_comment(proc, str_lit("TypeInfoArray"));
tag = ir_emit_conv(proc, variant_ptr, t_type_info_array_ptr); tag = ir_emit_conv(proc, variant_ptr, t_type_info_array_ptr);
+7 -10
View File
@@ -252,9 +252,6 @@ void ir_print_type(irFileBuffer *f, irModule *m, Type *t) {
ir_print_type(f, m, t->Pointer.elem); ir_print_type(f, m, t->Pointer.elem);
ir_fprintf(f, "*"); ir_fprintf(f, "*");
return; return;
case Type_Atomic:
ir_print_type(f, m, t->Atomic.elem);
return;
case Type_Array: case Type_Array:
ir_fprintf(f, "[%lld x ", t->Array.count); ir_fprintf(f, "[%lld x ", t->Array.count);
ir_print_type(f, m, t->Array.elem); ir_print_type(f, m, t->Array.elem);
@@ -890,7 +887,7 @@ void ir_print_instr(irFileBuffer *f, irModule *m, irValue *value) {
ir_print_type(f, m, type); ir_print_type(f, m, type);
ir_fprintf(f, "* "); ir_fprintf(f, "* ");
ir_print_value(f, m, instr->Store.address, type); ir_print_value(f, m, instr->Store.address, type);
if (is_type_atomic(type)) { if (instr->Store.atomic) {
// TODO(bill): Do ordering // TODO(bill): Do ordering
ir_fprintf(f, " unordered"); ir_fprintf(f, " unordered");
ir_fprintf(f, ", align %lld\n", type_align_of(m->allocator, type)); ir_fprintf(f, ", align %lld\n", type_align_of(m->allocator, type));
@@ -901,18 +898,18 @@ void ir_print_instr(irFileBuffer *f, irModule *m, irValue *value) {
case irInstr_Load: { case irInstr_Load: {
Type *type = instr->Load.type; Type *type = instr->Load.type;
ir_fprintf(f, "%%%d = load ", value->index); ir_fprintf(f, "%%%d = load ", value->index);
if (is_type_atomic(type)) { // if (is_type_atomic(type)) {
ir_fprintf(f, "atomic "); // ir_fprintf(f, "atomic ");
} // }
ir_print_type(f, m, type); ir_print_type(f, m, type);
ir_fprintf(f, ", "); ir_fprintf(f, ", ");
ir_print_type(f, m, type); ir_print_type(f, m, type);
ir_fprintf(f, "* "); ir_fprintf(f, "* ");
ir_print_value(f, m, instr->Load.address, type); ir_print_value(f, m, instr->Load.address, type);
if (is_type_atomic(type)) { // if (is_type_atomic(type)) {
// TODO(bill): Do ordering // TODO(bill): Do ordering
ir_fprintf(f, " unordered"); // ir_fprintf(f, " unordered");
} // }
ir_fprintf(f, ", align %lld\n", type_align_of(m->allocator, type)); ir_fprintf(f, ", align %lld\n", type_align_of(m->allocator, type));
} break; } break;
+2 -24
View File
@@ -402,10 +402,6 @@ AST_NODE_KIND(_TypeBegin, "", i32) \
Token token; \ Token token; \
AstNode *type; \ AstNode *type; \
}) \ }) \
AST_NODE_KIND(AtomicType, "atomic type", struct { \
Token token; \
AstNode *type; \
}) \
AST_NODE_KIND(ArrayType, "array type", struct { \ AST_NODE_KIND(ArrayType, "array type", struct { \
Token token; \ Token token; \
AstNode *count; \ AstNode *count; \
@@ -598,7 +594,6 @@ Token ast_node_token(AstNode *node) {
case AstNode_PolyType: return node->PolyType.token; case AstNode_PolyType: return node->PolyType.token;
case AstNode_ProcType: return node->ProcType.token; case AstNode_ProcType: return node->ProcType.token;
case AstNode_PointerType: return node->PointerType.token; case AstNode_PointerType: return node->PointerType.token;
case AstNode_AtomicType: return node->AtomicType.token;
case AstNode_ArrayType: return node->ArrayType.token; case AstNode_ArrayType: return node->ArrayType.token;
case AstNode_DynamicArrayType: return node->DynamicArrayType.token; case AstNode_DynamicArrayType: return node->DynamicArrayType.token;
case AstNode_VectorType: return node->VectorType.token; case AstNode_VectorType: return node->VectorType.token;
@@ -854,9 +849,6 @@ AstNode *clone_ast_node(gbAllocator a, AstNode *node) {
case AstNode_PointerType: case AstNode_PointerType:
n->PointerType.type = clone_ast_node(a, n->PointerType.type); n->PointerType.type = clone_ast_node(a, n->PointerType.type);
break; break;
case AstNode_AtomicType:
n->AtomicType.type = clone_ast_node(a, n->AtomicType.type);
break;
case AstNode_ArrayType: case AstNode_ArrayType:
n->ArrayType.count = clone_ast_node(a, n->ArrayType.count); n->ArrayType.count = clone_ast_node(a, n->ArrayType.count);
n->ArrayType.elem = clone_ast_node(a, n->ArrayType.elem); n->ArrayType.elem = clone_ast_node(a, n->ArrayType.elem);
@@ -1435,13 +1427,6 @@ AstNode *ast_pointer_type(AstFile *f, Token token, AstNode *type) {
return result; return result;
} }
AstNode *ast_atomic_type(AstFile *f, Token token, AstNode *type) {
AstNode *result = make_ast_node(f, AstNode_AtomicType);
result->AtomicType.token = token;
result->AtomicType.type = type;
return result;
}
AstNode *ast_array_type(AstFile *f, Token token, AstNode *count, AstNode *elem) { AstNode *ast_array_type(AstFile *f, Token token, AstNode *count, AstNode *elem) {
AstNode *result = make_ast_node(f, AstNode_ArrayType); AstNode *result = make_ast_node(f, AstNode_ArrayType);
result->ArrayType.token = token; result->ArrayType.token = token;
@@ -1850,9 +1835,6 @@ bool is_semicolon_optional_for_node(AstFile *f, AstNode *s) {
case AstNode_PointerType: case AstNode_PointerType:
return is_semicolon_optional_for_node(f, s->PointerType.type); return is_semicolon_optional_for_node(f, s->PointerType.type);
case AstNode_AtomicType:
return is_semicolon_optional_for_node(f, s->AtomicType.type);
case AstNode_StructType: case AstNode_StructType:
case AstNode_UnionType: case AstNode_UnionType:
case AstNode_RawUnionType: case AstNode_RawUnionType:
@@ -2390,12 +2372,6 @@ AstNode *parse_operand(AstFile *f, bool lhs) {
return ast_pointer_type(f, token, elem); return ast_pointer_type(f, token, elem);
} break; } break;
case Token_atomic: {
Token token = expect_token(f, Token_atomic);
AstNode *elem = parse_type(f);
return ast_atomic_type(f, token, elem);
} break;
case Token_OpenBracket: { case Token_OpenBracket: {
Token token = expect_token(f, Token_OpenBracket); Token token = expect_token(f, Token_OpenBracket);
AstNode *count_expr = nullptr; AstNode *count_expr = nullptr;
@@ -3402,12 +3378,14 @@ AstNode *parse_simple_stmt(AstFile *f, StmtAllowFlag flags) {
#if 0
switch (token.kind) { switch (token.kind) {
case Token_Inc: case Token_Inc:
case Token_Dec: case Token_Dec:
advance_token(f); advance_token(f);
return ast_inc_dec_stmt(f, token, lhs[0]); return ast_inc_dec_stmt(f, token, lhs[0]);
} }
#endif
return ast_expr_stmt(f, lhs[0]); return ast_expr_stmt(f, lhs[0]);
} }
+2
View File
@@ -1956,6 +1956,7 @@ void ssa_build_stmt_internal(ssaProc *p, AstNode *node) {
ssa_build_when_stmt(p, ws); ssa_build_when_stmt(p, ws);
case_end; case_end;
#if 0
case_ast_node(s, IncDecStmt, node); case_ast_node(s, IncDecStmt, node);
TokenKind op = Token_Add; TokenKind op = Token_Add;
if (s->op.kind == Token_Dec) { if (s->op.kind == Token_Dec) {
@@ -1965,6 +1966,7 @@ void ssa_build_stmt_internal(ssaProc *p, AstNode *node) {
Type *t = ssa_addr_type(addr); Type *t = ssa_addr_type(addr);
ssa_build_assign_op(p, addr, ssa_const_int(p, t, 1), op); ssa_build_assign_op(p, addr, ssa_const_int(p, t, 1), op);
case_end; case_end;
#endif
case_ast_node(as, AssignStmt, node); case_ast_node(as, AssignStmt, node);
ssa_emit_comment(p, str_lit("AssignStmt")); ssa_emit_comment(p, str_lit("AssignStmt"));
+5 -5
View File
@@ -55,8 +55,8 @@ TOKEN_KIND(Token__AssignOpEnd, "_AssignOpEnd"), \
TOKEN_KIND(Token_ArrowRight, "->"), \ TOKEN_KIND(Token_ArrowRight, "->"), \
TOKEN_KIND(Token_ArrowLeft, "<-"), \ TOKEN_KIND(Token_ArrowLeft, "<-"), \
TOKEN_KIND(Token_DoubleArrowRight, "=>"), \ TOKEN_KIND(Token_DoubleArrowRight, "=>"), \
TOKEN_KIND(Token_Inc, "++"), \ /* TOKEN_KIND(Token_Inc, "++"), */ \
TOKEN_KIND(Token_Dec, "--"), \ /* TOKEN_KIND(Token_Dec, "--"), */ \
TOKEN_KIND(Token_Undef, "---"), \ TOKEN_KIND(Token_Undef, "---"), \
\ \
TOKEN_KIND(Token__ComparisonBegin, "_ComparisonBegin"), \ TOKEN_KIND(Token__ComparisonBegin, "_ComparisonBegin"), \
@@ -126,7 +126,6 @@ TOKEN_KIND(Token__KeywordBegin, "_KeywordBegin"), \
TOKEN_KIND(Token_asm, "asm"), \ TOKEN_KIND(Token_asm, "asm"), \
TOKEN_KIND(Token_yield, "yield"), \ TOKEN_KIND(Token_yield, "yield"), \
TOKEN_KIND(Token_await, "await"), \ TOKEN_KIND(Token_await, "await"), \
TOKEN_KIND(Token_atomic, "atomic"), \
TOKEN_KIND(Token__KeywordEnd, "_KeywordEnd"), \ TOKEN_KIND(Token__KeywordEnd, "_KeywordEnd"), \
TOKEN_KIND(Token_Count, "") TOKEN_KIND(Token_Count, "")
@@ -929,7 +928,8 @@ Token tokenizer_get_token(Tokenizer *t) {
break; break;
case '~': token.kind = token_kind_variant2(t, Token_Xor, Token_XorEq); break; case '~': token.kind = token_kind_variant2(t, Token_Xor, Token_XorEq); break;
case '!': token.kind = token_kind_variant2(t, Token_Not, Token_NotEq); break; case '!': token.kind = token_kind_variant2(t, Token_Not, Token_NotEq); break;
case '+': token.kind = token_kind_variant3(t, Token_Add, Token_AddEq, '+', Token_Inc); break; // case '+': token.kind = token_kind_variant3(t, Token_Add, Token_AddEq, '+', Token_Inc); break;
case '+': token.kind = token_kind_variant2(t, Token_Add, Token_AddEq); break;
case '-': case '-':
token.kind = Token_Sub; token.kind = Token_Sub;
if (t->curr_rune == '=') { if (t->curr_rune == '=') {
@@ -937,7 +937,7 @@ Token tokenizer_get_token(Tokenizer *t) {
token.kind = Token_SubEq; token.kind = Token_SubEq;
} else if (t->curr_rune == '-') { } else if (t->curr_rune == '-') {
advance_to_next_rune(t); advance_to_next_rune(t);
token.kind = Token_Dec; token.kind = Token_Invalid;
if (t->curr_rune == '-') { if (t->curr_rune == '-') {
advance_to_next_rune(t); advance_to_next_rune(t);
token.kind = Token_Undef; token.kind = Token_Undef;
-23
View File
@@ -111,7 +111,6 @@ struct TypeRecord {
Type * specialized; \ Type * specialized; \
}) \ }) \
TYPE_KIND(Pointer, struct { Type *elem; }) \ TYPE_KIND(Pointer, struct { Type *elem; }) \
TYPE_KIND(Atomic, struct { Type *elem; }) \
TYPE_KIND(Array, struct { Type *elem; i64 count; }) \ TYPE_KIND(Array, struct { Type *elem; i64 count; }) \
TYPE_KIND(DynamicArray, struct { Type *elem; }) \ TYPE_KIND(DynamicArray, struct { Type *elem; }) \
TYPE_KIND(Vector, struct { Type *elem; i64 count; }) \ TYPE_KIND(Vector, struct { Type *elem; i64 count; }) \
@@ -355,7 +354,6 @@ gb_global Type *t_type_info_any = nullptr;
gb_global Type *t_type_info_string = nullptr; gb_global Type *t_type_info_string = nullptr;
gb_global Type *t_type_info_boolean = nullptr; gb_global Type *t_type_info_boolean = nullptr;
gb_global Type *t_type_info_pointer = nullptr; gb_global Type *t_type_info_pointer = nullptr;
gb_global Type *t_type_info_atomic = nullptr;
gb_global Type *t_type_info_procedure = nullptr; gb_global Type *t_type_info_procedure = nullptr;
gb_global Type *t_type_info_array = nullptr; gb_global Type *t_type_info_array = nullptr;
gb_global Type *t_type_info_dynamic_array = nullptr; gb_global Type *t_type_info_dynamic_array = nullptr;
@@ -379,7 +377,6 @@ gb_global Type *t_type_info_any_ptr = nullptr;
gb_global Type *t_type_info_string_ptr = nullptr; gb_global Type *t_type_info_string_ptr = nullptr;
gb_global Type *t_type_info_boolean_ptr = nullptr; gb_global Type *t_type_info_boolean_ptr = nullptr;
gb_global Type *t_type_info_pointer_ptr = nullptr; gb_global Type *t_type_info_pointer_ptr = nullptr;
gb_global Type *t_type_info_atomic_ptr = nullptr;
gb_global Type *t_type_info_procedure_ptr = nullptr; gb_global Type *t_type_info_procedure_ptr = nullptr;
gb_global Type *t_type_info_array_ptr = nullptr; gb_global Type *t_type_info_array_ptr = nullptr;
gb_global Type *t_type_info_dynamic_array_ptr = nullptr; gb_global Type *t_type_info_dynamic_array_ptr = nullptr;
@@ -456,9 +453,6 @@ Type *core_type(Type *t) {
case Type_Enum: case Type_Enum:
t = t->Enum.base_type; t = t->Enum.base_type;
continue; continue;
case Type_Atomic:
t = t->Atomic.elem;
continue;
} }
break; break;
} }
@@ -500,12 +494,6 @@ Type *make_type_pointer(gbAllocator a, Type *elem) {
return t; return t;
} }
Type *make_type_atomic(gbAllocator a, Type *elem) {
Type *t = alloc_type(a, Type_Atomic);
t->Atomic.elem = elem;
return t;
}
Type *make_type_array(gbAllocator a, Type *elem, i64 count) { Type *make_type_array(gbAllocator a, Type *elem, i64 count) {
Type *t = alloc_type(a, Type_Array); Type *t = alloc_type(a, Type_Array);
t->Array.elem = elem; t->Array.elem = elem;
@@ -774,10 +762,6 @@ bool is_type_pointer(Type *t) {
} }
return t->kind == Type_Pointer; return t->kind == Type_Pointer;
} }
bool is_type_atomic(Type *t) {
t = base_type(t);
return t->kind == Type_Atomic;
}
bool is_type_tuple(Type *t) { bool is_type_tuple(Type *t) {
t = base_type(t); t = base_type(t);
return t->kind == Type_Tuple; return t->kind == Type_Tuple;
@@ -975,8 +959,6 @@ bool is_type_polymorphic(Type *t) {
case Type_Pointer: case Type_Pointer:
return is_type_polymorphic(t->Pointer.elem); return is_type_polymorphic(t->Pointer.elem);
case Type_Atomic:
return is_type_polymorphic(t->Atomic.elem);
case Type_Array: case Type_Array:
return is_type_polymorphic(t->Array.elem); return is_type_polymorphic(t->Array.elem);
case Type_DynamicArray: case Type_DynamicArray:
@@ -2307,11 +2289,6 @@ gbString write_type_to_string(gbString str, Type *type) {
str = write_type_to_string(str, type->Pointer.elem); str = write_type_to_string(str, type->Pointer.elem);
break; break;
case Type_Atomic:
str = gb_string_appendc(str, "atomic ");
str = write_type_to_string(str, type->Atomic.elem);
break;
case Type_Array: case Type_Array:
str = gb_string_appendc(str, gb_bprintf("[%d]", cast(int)type->Array.count)); str = gb_string_appendc(str, gb_bprintf("[%d]", cast(int)type->Array.count));
str = write_type_to_string(str, type->Array.elem); str = write_type_to_string(str, type->Array.elem);