mirror of
https://github.com/odin-lang/Odin.git
synced 2026-06-05 02:04:06 +00:00
Remove atomic, ++, and --
This commit is contained in:
@@ -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) {
|
||||
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];
|
||||
@@ -95,8 +113,9 @@ find_index :: proc(table: ^Table($Key, $Value), key: Key, hash: u32) -> int {
|
||||
}
|
||||
}
|
||||
|
||||
index++;
|
||||
if index >= cap(table.slots) do index = 0;
|
||||
if index += 1; index >= cap(table.slots) {
|
||||
index = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
@@ -121,8 +140,8 @@ Vector :: struct(N: int, T: type) {
|
||||
when N >= 3 do z: T;
|
||||
when N >= 4 do w: T;
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
} };
|
||||
}
|
||||
|
||||
Vector3 :: Vector(3, f32);
|
||||
@@ -137,15 +156,18 @@ add :: proc(a, b: $T/Vector) -> T {
|
||||
|
||||
foo1 :: proc(a: type/Vector) { fmt.println("foo1", a{}); }
|
||||
// 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) {}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
main :: proc() {
|
||||
Foo :: struct {
|
||||
a := 123;
|
||||
b := true;
|
||||
}
|
||||
v1 := Foo{};
|
||||
fmt.println(v1);
|
||||
|
||||
foo1(Vector(3, f32));
|
||||
foo1(Vector3);
|
||||
foo3(Vector(3, f32));
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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..]);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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 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:
|
||||
if (source->kind == Type_Array &&
|
||||
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;
|
||||
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);
|
||||
if (at->count != 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, "}");
|
||||
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;
|
||||
|
||||
@@ -629,6 +629,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
|
||||
check_stmt(c, ts->stmt, flags);
|
||||
case_end;
|
||||
|
||||
#if 0
|
||||
case_ast_node(s, IncDecStmt, node);
|
||||
TokenKind op = s->op.kind;
|
||||
switch (op) {
|
||||
@@ -671,6 +672,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
|
||||
}
|
||||
check_assignment_variable(c, &x, left);
|
||||
case_end;
|
||||
#endif
|
||||
|
||||
case_ast_node(as, AssignStmt, node);
|
||||
switch (as->op.kind) {
|
||||
|
||||
@@ -1142,10 +1142,6 @@ void add_type_info_type(Checker *c, Type *t) {
|
||||
add_type_info_type(c, bt->Pointer.elem);
|
||||
break;
|
||||
|
||||
case Type_Atomic:
|
||||
add_type_info_type(c, bt->Atomic.elem);
|
||||
break;
|
||||
|
||||
case Type_Array:
|
||||
add_type_info_type(c, 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));
|
||||
TypeUnion *tiv = &tiv_type->Union;
|
||||
|
||||
if (tiv->variant_count != 23) {
|
||||
if (tiv->variant_count != 22) {
|
||||
compiler_error("Invalid `TypeInfo` layout");
|
||||
}
|
||||
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_any = tiv->variants[ 8];
|
||||
t_type_info_pointer = tiv->variants[ 9];
|
||||
t_type_info_atomic = tiv->variants[10];
|
||||
t_type_info_procedure = tiv->variants[11];
|
||||
t_type_info_array = tiv->variants[12];
|
||||
t_type_info_dynamic_array = tiv->variants[13];
|
||||
t_type_info_slice = tiv->variants[14];
|
||||
t_type_info_vector = tiv->variants[15];
|
||||
t_type_info_tuple = tiv->variants[16];
|
||||
t_type_info_struct = tiv->variants[17];
|
||||
t_type_info_raw_union = tiv->variants[18];
|
||||
t_type_info_union = tiv->variants[19];
|
||||
t_type_info_enum = tiv->variants[20];
|
||||
t_type_info_map = tiv->variants[21];
|
||||
t_type_info_bit_field = tiv->variants[22];
|
||||
t_type_info_procedure = tiv->variants[10];
|
||||
t_type_info_array = tiv->variants[11];
|
||||
t_type_info_dynamic_array = tiv->variants[12];
|
||||
t_type_info_slice = tiv->variants[13];
|
||||
t_type_info_vector = tiv->variants[14];
|
||||
t_type_info_tuple = tiv->variants[15];
|
||||
t_type_info_struct = tiv->variants[16];
|
||||
t_type_info_raw_union = tiv->variants[17];
|
||||
t_type_info_union = tiv->variants[18];
|
||||
t_type_info_enum = tiv->variants[19];
|
||||
t_type_info_map = tiv->variants[20];
|
||||
t_type_info_bit_field = tiv->variants[21];
|
||||
|
||||
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);
|
||||
@@ -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_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_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_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);
|
||||
|
||||
12
src/ir.cpp
12
src/ir.cpp
@@ -151,7 +151,7 @@ struct irProcedure {
|
||||
Entity * entity; \
|
||||
Type * type; \
|
||||
bool zero_initialized; \
|
||||
Array<irValue *> referrers; \
|
||||
Array<irValue *> referrers; \
|
||||
i64 alignment; \
|
||||
}) \
|
||||
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));
|
||||
}
|
||||
#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) {
|
||||
GB_ASSERT(address != nullptr);
|
||||
@@ -6233,6 +6233,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) {
|
||||
ir_build_when_stmt(proc, ws);
|
||||
case_end;
|
||||
|
||||
#if 0
|
||||
case_ast_node(s, IncDecStmt, node);
|
||||
TokenKind op = Token_Add;
|
||||
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);
|
||||
ir_build_assign_op(proc, addr, v_one, op);
|
||||
case_end;
|
||||
#endif
|
||||
|
||||
case_ast_node(vd, ValueDecl, node);
|
||||
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);
|
||||
ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 0), gep);
|
||||
} 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: {
|
||||
ir_emit_comment(proc, str_lit("TypeInfoArray"));
|
||||
tag = ir_emit_conv(proc, variant_ptr, t_type_info_array_ptr);
|
||||
|
||||
@@ -252,9 +252,6 @@ void ir_print_type(irFileBuffer *f, irModule *m, Type *t) {
|
||||
ir_print_type(f, m, t->Pointer.elem);
|
||||
ir_fprintf(f, "*");
|
||||
return;
|
||||
case Type_Atomic:
|
||||
ir_print_type(f, m, t->Atomic.elem);
|
||||
return;
|
||||
case Type_Array:
|
||||
ir_fprintf(f, "[%lld x ", t->Array.count);
|
||||
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_fprintf(f, "* ");
|
||||
ir_print_value(f, m, instr->Store.address, type);
|
||||
if (is_type_atomic(type)) {
|
||||
if (instr->Store.atomic) {
|
||||
// TODO(bill): Do ordering
|
||||
ir_fprintf(f, " unordered");
|
||||
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: {
|
||||
Type *type = instr->Load.type;
|
||||
ir_fprintf(f, "%%%d = load ", value->index);
|
||||
if (is_type_atomic(type)) {
|
||||
ir_fprintf(f, "atomic ");
|
||||
}
|
||||
// if (is_type_atomic(type)) {
|
||||
// ir_fprintf(f, "atomic ");
|
||||
// }
|
||||
ir_print_type(f, m, type);
|
||||
ir_fprintf(f, ", ");
|
||||
ir_print_type(f, m, type);
|
||||
ir_fprintf(f, "* ");
|
||||
ir_print_value(f, m, instr->Load.address, type);
|
||||
if (is_type_atomic(type)) {
|
||||
// if (is_type_atomic(type)) {
|
||||
// TODO(bill): Do ordering
|
||||
ir_fprintf(f, " unordered");
|
||||
}
|
||||
// ir_fprintf(f, " unordered");
|
||||
// }
|
||||
ir_fprintf(f, ", align %lld\n", type_align_of(m->allocator, type));
|
||||
} break;
|
||||
|
||||
|
||||
@@ -402,10 +402,6 @@ AST_NODE_KIND(_TypeBegin, "", i32) \
|
||||
Token token; \
|
||||
AstNode *type; \
|
||||
}) \
|
||||
AST_NODE_KIND(AtomicType, "atomic type", struct { \
|
||||
Token token; \
|
||||
AstNode *type; \
|
||||
}) \
|
||||
AST_NODE_KIND(ArrayType, "array type", struct { \
|
||||
Token token; \
|
||||
AstNode *count; \
|
||||
@@ -598,7 +594,6 @@ Token ast_node_token(AstNode *node) {
|
||||
case AstNode_PolyType: return node->PolyType.token;
|
||||
case AstNode_ProcType: return node->ProcType.token;
|
||||
case AstNode_PointerType: return node->PointerType.token;
|
||||
case AstNode_AtomicType: return node->AtomicType.token;
|
||||
case AstNode_ArrayType: return node->ArrayType.token;
|
||||
case AstNode_DynamicArrayType: return node->DynamicArrayType.token;
|
||||
case AstNode_VectorType: return node->VectorType.token;
|
||||
@@ -854,9 +849,6 @@ AstNode *clone_ast_node(gbAllocator a, AstNode *node) {
|
||||
case AstNode_PointerType:
|
||||
n->PointerType.type = clone_ast_node(a, n->PointerType.type);
|
||||
break;
|
||||
case AstNode_AtomicType:
|
||||
n->AtomicType.type = clone_ast_node(a, n->AtomicType.type);
|
||||
break;
|
||||
case AstNode_ArrayType:
|
||||
n->ArrayType.count = clone_ast_node(a, n->ArrayType.count);
|
||||
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;
|
||||
}
|
||||
|
||||
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 *result = make_ast_node(f, AstNode_ArrayType);
|
||||
result->ArrayType.token = token;
|
||||
@@ -1850,9 +1835,6 @@ bool is_semicolon_optional_for_node(AstFile *f, AstNode *s) {
|
||||
case AstNode_PointerType:
|
||||
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_UnionType:
|
||||
case AstNode_RawUnionType:
|
||||
@@ -2390,12 +2372,6 @@ AstNode *parse_operand(AstFile *f, bool lhs) {
|
||||
return ast_pointer_type(f, token, elem);
|
||||
} 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: {
|
||||
Token token = expect_token(f, Token_OpenBracket);
|
||||
AstNode *count_expr = nullptr;
|
||||
@@ -3402,12 +3378,14 @@ AstNode *parse_simple_stmt(AstFile *f, StmtAllowFlag flags) {
|
||||
|
||||
|
||||
|
||||
#if 0
|
||||
switch (token.kind) {
|
||||
case Token_Inc:
|
||||
case Token_Dec:
|
||||
advance_token(f);
|
||||
return ast_inc_dec_stmt(f, token, lhs[0]);
|
||||
}
|
||||
#endif
|
||||
|
||||
return ast_expr_stmt(f, lhs[0]);
|
||||
}
|
||||
|
||||
@@ -1956,6 +1956,7 @@ void ssa_build_stmt_internal(ssaProc *p, AstNode *node) {
|
||||
ssa_build_when_stmt(p, ws);
|
||||
case_end;
|
||||
|
||||
#if 0
|
||||
case_ast_node(s, IncDecStmt, node);
|
||||
TokenKind op = Token_Add;
|
||||
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);
|
||||
ssa_build_assign_op(p, addr, ssa_const_int(p, t, 1), op);
|
||||
case_end;
|
||||
#endif
|
||||
|
||||
case_ast_node(as, AssignStmt, node);
|
||||
ssa_emit_comment(p, str_lit("AssignStmt"));
|
||||
|
||||
@@ -55,8 +55,8 @@ TOKEN_KIND(Token__AssignOpEnd, "_AssignOpEnd"), \
|
||||
TOKEN_KIND(Token_ArrowRight, "->"), \
|
||||
TOKEN_KIND(Token_ArrowLeft, "<-"), \
|
||||
TOKEN_KIND(Token_DoubleArrowRight, "=>"), \
|
||||
TOKEN_KIND(Token_Inc, "++"), \
|
||||
TOKEN_KIND(Token_Dec, "--"), \
|
||||
/* TOKEN_KIND(Token_Inc, "++"), */ \
|
||||
/* TOKEN_KIND(Token_Dec, "--"), */ \
|
||||
TOKEN_KIND(Token_Undef, "---"), \
|
||||
\
|
||||
TOKEN_KIND(Token__ComparisonBegin, "_ComparisonBegin"), \
|
||||
@@ -126,7 +126,6 @@ TOKEN_KIND(Token__KeywordBegin, "_KeywordBegin"), \
|
||||
TOKEN_KIND(Token_asm, "asm"), \
|
||||
TOKEN_KIND(Token_yield, "yield"), \
|
||||
TOKEN_KIND(Token_await, "await"), \
|
||||
TOKEN_KIND(Token_atomic, "atomic"), \
|
||||
TOKEN_KIND(Token__KeywordEnd, "_KeywordEnd"), \
|
||||
TOKEN_KIND(Token_Count, "")
|
||||
|
||||
@@ -929,7 +928,8 @@ Token tokenizer_get_token(Tokenizer *t) {
|
||||
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_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 '-':
|
||||
token.kind = Token_Sub;
|
||||
if (t->curr_rune == '=') {
|
||||
@@ -937,7 +937,7 @@ Token tokenizer_get_token(Tokenizer *t) {
|
||||
token.kind = Token_SubEq;
|
||||
} else if (t->curr_rune == '-') {
|
||||
advance_to_next_rune(t);
|
||||
token.kind = Token_Dec;
|
||||
token.kind = Token_Invalid;
|
||||
if (t->curr_rune == '-') {
|
||||
advance_to_next_rune(t);
|
||||
token.kind = Token_Undef;
|
||||
|
||||
@@ -111,7 +111,6 @@ struct TypeRecord {
|
||||
Type * specialized; \
|
||||
}) \
|
||||
TYPE_KIND(Pointer, struct { Type *elem; }) \
|
||||
TYPE_KIND(Atomic, struct { Type *elem; }) \
|
||||
TYPE_KIND(Array, struct { Type *elem; i64 count; }) \
|
||||
TYPE_KIND(DynamicArray, struct { Type *elem; }) \
|
||||
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_boolean = 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_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_boolean_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_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:
|
||||
t = t->Enum.base_type;
|
||||
continue;
|
||||
case Type_Atomic:
|
||||
t = t->Atomic.elem;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -500,12 +494,6 @@ Type *make_type_pointer(gbAllocator a, Type *elem) {
|
||||
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 *t = alloc_type(a, Type_Array);
|
||||
t->Array.elem = elem;
|
||||
@@ -774,10 +762,6 @@ bool is_type_pointer(Type *t) {
|
||||
}
|
||||
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) {
|
||||
t = base_type(t);
|
||||
return t->kind == Type_Tuple;
|
||||
@@ -975,8 +959,6 @@ bool is_type_polymorphic(Type *t) {
|
||||
|
||||
case Type_Pointer:
|
||||
return is_type_polymorphic(t->Pointer.elem);
|
||||
case Type_Atomic:
|
||||
return is_type_polymorphic(t->Atomic.elem);
|
||||
case Type_Array:
|
||||
return is_type_polymorphic(t->Array.elem);
|
||||
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);
|
||||
break;
|
||||
|
||||
case Type_Atomic:
|
||||
str = gb_string_appendc(str, "atomic ");
|
||||
str = write_type_to_string(str, type->Atomic.elem);
|
||||
break;
|
||||
|
||||
case Type_Array:
|
||||
str = gb_string_appendc(str, gb_bprintf("[%d]", cast(int)type->Array.count));
|
||||
str = write_type_to_string(str, type->Array.elem);
|
||||
|
||||
Reference in New Issue
Block a user