mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-19 04:12:22 -07:00
Make rune a basic type and not an alias; Remove byte
This commit is contained in:
+16
-15
@@ -52,6 +52,7 @@ TypeInfo :: union {
|
||||
|
||||
Named{name: string, base: ^TypeInfo},
|
||||
Integer{signed: bool},
|
||||
Rune{},
|
||||
Float{},
|
||||
Complex{},
|
||||
String{},
|
||||
@@ -110,7 +111,7 @@ TypeInfo :: union {
|
||||
// This will be set by the compiler
|
||||
__type_table: []TypeInfo;
|
||||
|
||||
__argv__: ^^byte;
|
||||
__argv__: ^^u8;
|
||||
__argc__: i32;
|
||||
|
||||
type_info_base :: proc(info: ^TypeInfo) -> ^TypeInfo {
|
||||
@@ -376,8 +377,8 @@ __string_decode_rune :: proc(s: string) -> (rune, int) #inline {
|
||||
|
||||
|
||||
__mem_set :: proc(data: rawptr, value: i32, len: int) -> rawptr {
|
||||
llvm_memset_64bit :: proc(dst: rawptr, val: byte, len: int, align: i32, is_volatile: bool) #foreign __llvm_core "llvm.memset.p0i8.i64";
|
||||
llvm_memset_64bit(data, byte(value), len, 1, false);
|
||||
llvm_memset_64bit :: proc(dst: rawptr, val: u8, len: int, align: i32, is_volatile: bool) #foreign __llvm_core "llvm.memset.p0i8.i64";
|
||||
llvm_memset_64bit(data, u8(value), len, 1, false);
|
||||
return data;
|
||||
}
|
||||
__mem_zero :: proc(data: rawptr, len: int) -> rawptr {
|
||||
@@ -396,7 +397,7 @@ __mem_copy_non_overlapping :: proc(dst, src: rawptr, len: int) -> rawptr {
|
||||
return dst;
|
||||
}
|
||||
|
||||
__mem_compare :: proc(a, b: ^byte, n: int) -> int {
|
||||
__mem_compare :: proc(a, b: ^u8, n: int) -> int {
|
||||
for i in 0..<n {
|
||||
match {
|
||||
case (a+i)^ < (b+i)^:
|
||||
@@ -490,7 +491,7 @@ __dynamic_array_append :: proc(array_: rawptr, elem_size, elem_align: int,
|
||||
// TODO(bill): Better error handling for failed reservation
|
||||
return array.len;
|
||||
}
|
||||
data := ^byte(array.data);
|
||||
data := ^u8(array.data);
|
||||
assert(data != nil);
|
||||
__mem_copy(data + (elem_size*array.len), items, elem_size * item_count);
|
||||
array.len += item_count;
|
||||
@@ -509,7 +510,7 @@ __dynamic_array_append_nothing :: proc(array_: rawptr, elem_size, elem_align: in
|
||||
// TODO(bill): Better error handling for failed reservation
|
||||
return array.len;
|
||||
}
|
||||
data := ^byte(array.data);
|
||||
data := ^u8(array.data);
|
||||
assert(data != nil);
|
||||
__mem_zero(data + (elem_size*array.len), elem_size);
|
||||
array.len++;
|
||||
@@ -526,7 +527,7 @@ __slice_append :: proc(slice_: rawptr, elem_size, elem_align: int,
|
||||
|
||||
item_count = min(slice.cap-slice.len, item_count);
|
||||
if item_count > 0 {
|
||||
data := ^byte(slice.data);
|
||||
data := ^u8(slice.data);
|
||||
assert(data != nil);
|
||||
__mem_copy(data + (elem_size*slice.len), items, elem_size * item_count);
|
||||
slice.len += item_count;
|
||||
@@ -537,8 +538,8 @@ __slice_append :: proc(slice_: rawptr, elem_size, elem_align: int,
|
||||
|
||||
// Map stuff
|
||||
|
||||
__default_hash :: proc(data: []byte) -> u128 {
|
||||
fnv128a :: proc(data: []byte) -> u128 {
|
||||
__default_hash :: proc(data: []u8) -> u128 {
|
||||
fnv128a :: proc(data: []u8) -> u128 {
|
||||
h: u128 = 0x6c62272e07bb014262b821756295c58d;
|
||||
for b in data {
|
||||
h = (h ~ u128(b)) * 0x1000000000000000000013b;
|
||||
@@ -548,7 +549,7 @@ __default_hash :: proc(data: []byte) -> u128 {
|
||||
return fnv128a(data);
|
||||
}
|
||||
__default_hash_string :: proc(s: string) -> u128 {
|
||||
return __default_hash([]byte(s));
|
||||
return __default_hash([]u8(s));
|
||||
}
|
||||
|
||||
__INITIAL_MAP_CAP :: 16;
|
||||
@@ -606,7 +607,7 @@ __dynamic_map_rehash :: proc(using header: __MapHeader, new_count: int) {
|
||||
}
|
||||
|
||||
entry_header := __dynamic_map_get_entry(header, i);
|
||||
data := ^byte(entry_header);
|
||||
data := ^u8(entry_header);
|
||||
|
||||
fr := __dynamic_map_find(new_header, entry_header.key);
|
||||
j := __dynamic_map_add_entry(new_header, entry_header.key);
|
||||
@@ -619,7 +620,7 @@ __dynamic_map_rehash :: proc(using header: __MapHeader, new_count: int) {
|
||||
|
||||
e := __dynamic_map_get_entry(new_header, j);
|
||||
e.next = fr.entry_index;
|
||||
ndata := ^byte(e);
|
||||
ndata := ^u8(e);
|
||||
__mem_copy(ndata+value_offset, data+value_offset, value_size);
|
||||
|
||||
if __dynamic_map_full(new_header) {
|
||||
@@ -634,7 +635,7 @@ __dynamic_map_rehash :: proc(using header: __MapHeader, new_count: int) {
|
||||
__dynamic_map_get :: proc(h: __MapHeader, key: __MapKey) -> rawptr {
|
||||
index := __dynamic_map_find(h, key).entry_index;
|
||||
if index >= 0 {
|
||||
data := ^byte(__dynamic_map_get_entry(h, index));
|
||||
data := ^u8(__dynamic_map_get_entry(h, index));
|
||||
val := data + h.value_offset;
|
||||
return val;
|
||||
}
|
||||
@@ -666,7 +667,7 @@ __dynamic_map_set :: proc(using h: __MapHeader, key: __MapKey, value: rawptr) {
|
||||
{
|
||||
e := __dynamic_map_get_entry(h, index);
|
||||
e.key = key;
|
||||
val := ^byte(e) + value_offset;
|
||||
val := ^u8(e) + value_offset;
|
||||
__mem_copy(val, value, value_size);
|
||||
}
|
||||
|
||||
@@ -733,7 +734,7 @@ __dynamic_map_delete :: proc(using h: __MapHeader, key: __MapKey) {
|
||||
}
|
||||
|
||||
__dynamic_map_get_entry :: proc(using h: __MapHeader, index: int) -> ^__MapEntryHeader {
|
||||
data := ^byte(m.entries.data) + index*entry_size;
|
||||
data := ^u8(m.entries.data) + index*entry_size;
|
||||
return ^__MapEntryHeader(data);
|
||||
}
|
||||
|
||||
|
||||
+9
-9
@@ -3,14 +3,14 @@
|
||||
// NOTE: This is only for floating point printing and nothing else
|
||||
|
||||
Decimal :: struct {
|
||||
digits: [384]byte, // big-endian digits
|
||||
digits: [384]u8, // big-endian digits
|
||||
count: int,
|
||||
decimal_point: int,
|
||||
neg, trunc: bool,
|
||||
}
|
||||
|
||||
decimal_to_string :: proc(buf: []byte, a: ^Decimal) -> string {
|
||||
digit_zero :: proc(buf: []byte) -> int {
|
||||
decimal_to_string :: proc(buf: []u8, a: ^Decimal) -> string {
|
||||
digit_zero :: proc(buf: []u8) -> int {
|
||||
for _, i in buf {
|
||||
buf[i] = '0';
|
||||
}
|
||||
@@ -59,12 +59,12 @@ trim :: proc(a: ^Decimal) {
|
||||
|
||||
|
||||
assign :: proc(a: ^Decimal, i: u64) {
|
||||
buf: [32]byte;
|
||||
buf: [32]u8;
|
||||
n := 0;
|
||||
for i > 0 {
|
||||
j := i/10;
|
||||
i -= 10*j;
|
||||
buf[n] = byte('0'+i);
|
||||
buf[n] = u8('0'+i);
|
||||
n++;
|
||||
i = j;
|
||||
}
|
||||
@@ -110,7 +110,7 @@ shift_right :: proc(a: ^Decimal, k: uint) {
|
||||
c := uint(a.digits[r]);
|
||||
dig := n>>k;
|
||||
n &= mask;
|
||||
a.digits[w] = byte('0' + dig);
|
||||
a.digits[w] = u8('0' + dig);
|
||||
w++;
|
||||
n = n*10 + c - '0';
|
||||
}
|
||||
@@ -119,7 +119,7 @@ shift_right :: proc(a: ^Decimal, k: uint) {
|
||||
dig := n>>k;
|
||||
n &= mask;
|
||||
if w < len(a.digits) {
|
||||
a.digits[w] = byte('0' + dig);
|
||||
a.digits[w] = u8('0' + dig);
|
||||
w++;
|
||||
} else if dig > 0 {
|
||||
a.trunc = true;
|
||||
@@ -145,7 +145,7 @@ shift_left :: proc(a: ^Decimal, k: uint) {
|
||||
rem := n - 10*quo;
|
||||
w--;
|
||||
if w < len(a.digits) {
|
||||
a.digits[w] = byte('0' + rem);
|
||||
a.digits[w] = u8('0' + rem);
|
||||
} else if rem != 0 {
|
||||
a.trunc = true;
|
||||
}
|
||||
@@ -157,7 +157,7 @@ shift_left :: proc(a: ^Decimal, k: uint) {
|
||||
rem := n - 10*quo;
|
||||
w--;
|
||||
if 0 <= w && w < len(a.digits) {
|
||||
a.digits[w] = byte('0' + rem);
|
||||
a.digits[w] = u8('0' + rem);
|
||||
} else if rem != 0 {
|
||||
a.trunc = true;
|
||||
}
|
||||
|
||||
+45
-35
@@ -9,8 +9,8 @@
|
||||
_BUFFER_SIZE :: 1<<12;
|
||||
|
||||
StringBuffer :: union {
|
||||
Static {buf: []byte},
|
||||
Dynamic{buf: [dynamic]byte},
|
||||
Static {buf: []u8},
|
||||
Dynamic{buf: [dynamic]u8},
|
||||
}
|
||||
|
||||
FmtInfo :: struct {
|
||||
@@ -33,14 +33,14 @@ FmtInfo :: struct {
|
||||
}
|
||||
|
||||
|
||||
make_string_buffer_from_slice :: proc(b: []byte) -> StringBuffer {
|
||||
make_string_buffer_from_slice :: proc(b: []u8) -> StringBuffer {
|
||||
return StringBuffer.Static{b};
|
||||
}
|
||||
|
||||
make_string_dynamic_buffer :: proc() -> StringBuffer {
|
||||
return StringBuffer.Dynamic{make([dynamic]byte)};
|
||||
return StringBuffer.Dynamic{make([dynamic]u8)};
|
||||
}
|
||||
string_buffer_data :: proc(buf: ^StringBuffer) -> []byte {
|
||||
string_buffer_data :: proc(buf: ^StringBuffer) -> []u8 {
|
||||
match b in buf {
|
||||
case StringBuffer.Static:
|
||||
return b.buf[..];
|
||||
@@ -49,7 +49,7 @@ string_buffer_data :: proc(buf: ^StringBuffer) -> []byte {
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
string_buffer_data :: proc(buf: StringBuffer) -> []byte {
|
||||
string_buffer_data :: proc(buf: StringBuffer) -> []u8 {
|
||||
match b in buf {
|
||||
case StringBuffer.Static:
|
||||
return b.buf[..];
|
||||
@@ -64,9 +64,9 @@ to_string :: proc(buf: StringBuffer) -> string {
|
||||
|
||||
|
||||
write_string :: proc(buf: ^StringBuffer, s: string) {
|
||||
write_bytes(buf, []byte(s));
|
||||
write_bytes(buf, []u8(s));
|
||||
}
|
||||
write_bytes :: proc(buf: ^StringBuffer, data: []byte) {
|
||||
write_bytes :: proc(buf: ^StringBuffer, data: []u8) {
|
||||
match b in buf {
|
||||
case StringBuffer.Static:
|
||||
append(b.buf, ..data);
|
||||
@@ -74,7 +74,7 @@ write_bytes :: proc(buf: ^StringBuffer, data: []byte) {
|
||||
append(b.buf, ..data);
|
||||
}
|
||||
}
|
||||
write_byte :: proc(buf: ^StringBuffer, data: byte) {
|
||||
write_byte :: proc(buf: ^StringBuffer, data: u8) {
|
||||
match b in buf {
|
||||
case StringBuffer.Static:
|
||||
append(b.buf, data);
|
||||
@@ -84,7 +84,7 @@ write_byte :: proc(buf: ^StringBuffer, data: byte) {
|
||||
}
|
||||
write_rune :: proc(buf: ^StringBuffer, r: rune) {
|
||||
if r < utf8.RUNE_SELF {
|
||||
write_byte(buf, byte(r));
|
||||
write_byte(buf, u8(r));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -93,12 +93,12 @@ write_rune :: proc(buf: ^StringBuffer, r: rune) {
|
||||
}
|
||||
|
||||
write_int :: proc(buf: ^StringBuffer, i: i128, base: int) {
|
||||
b: [129]byte;
|
||||
b: [129]u8;
|
||||
s := strconv.append_bits(b[0..<0], u128(i), base, true, 128, strconv.digits, 0);
|
||||
write_string(buf, s);
|
||||
}
|
||||
write_int :: proc(buf: ^StringBuffer, i: i64, base: int) {
|
||||
b: [129]byte;
|
||||
b: [129]u8;
|
||||
s := strconv.append_bits(b[0..<0], u128(i), base, true, 64, strconv.digits, 0);
|
||||
write_string(buf, s);
|
||||
}
|
||||
@@ -106,7 +106,7 @@ write_int :: proc(buf: ^StringBuffer, i: i64, base: int) {
|
||||
|
||||
|
||||
fprint :: proc(fd: os.Handle, args: ..any) -> int {
|
||||
data: [_BUFFER_SIZE]byte;
|
||||
data: [_BUFFER_SIZE]u8;
|
||||
buf := make_string_buffer_from_slice(data[0..<0]);
|
||||
sbprint(&buf, ..args);
|
||||
res := string_buffer_data(buf);
|
||||
@@ -115,7 +115,7 @@ fprint :: proc(fd: os.Handle, args: ..any) -> int {
|
||||
}
|
||||
|
||||
fprintln :: proc(fd: os.Handle, args: ..any) -> int {
|
||||
data: [_BUFFER_SIZE]byte;
|
||||
data: [_BUFFER_SIZE]u8;
|
||||
buf := make_string_buffer_from_slice(data[0..<0]);
|
||||
sbprintln(&buf, ..args);
|
||||
res := string_buffer_data(buf);
|
||||
@@ -123,7 +123,7 @@ fprintln :: proc(fd: os.Handle, args: ..any) -> int {
|
||||
return len(res);
|
||||
}
|
||||
fprintf :: proc(fd: os.Handle, fmt: string, args: ..any) -> int {
|
||||
data: [_BUFFER_SIZE]byte;
|
||||
data: [_BUFFER_SIZE]u8;
|
||||
buf := make_string_buffer_from_slice(data[0..<0]);
|
||||
sbprintf(&buf, fmt, ..args);
|
||||
res := string_buffer_data(buf);
|
||||
@@ -162,15 +162,15 @@ aprintf :: proc(fmt: string, args: ..any) -> string {
|
||||
|
||||
// bprint* procedures return a string that was allocated with the current context
|
||||
// They must be freed accordingly
|
||||
bprint :: proc(buf: []byte, args: ..any) -> string {
|
||||
bprint :: proc(buf: []u8, args: ..any) -> string {
|
||||
sb := make_string_buffer_from_slice(buf[0..<0..<len(buf)]);
|
||||
return sbprint(&sb, ..args);
|
||||
}
|
||||
bprintln :: proc(buf: []byte, args: ..any) -> string {
|
||||
bprintln :: proc(buf: []u8, args: ..any) -> string {
|
||||
sb := make_string_buffer_from_slice(buf[0..<0..<len(buf)]);
|
||||
return sbprintln(&sb, ..args);
|
||||
}
|
||||
bprintf :: proc(buf: []byte, fmt: string, args: ..any) -> string {
|
||||
bprintf :: proc(buf: []u8, fmt: string, args: ..any) -> string {
|
||||
sb := make_string_buffer_from_slice(buf[0..<0..<len(buf)]);
|
||||
return sbprintf(&sb, fmt, ..args);
|
||||
}
|
||||
@@ -181,7 +181,7 @@ bprintf :: proc(buf: []byte, fmt: string, args: ..any) -> string {
|
||||
|
||||
|
||||
fprint_type :: proc(fd: os.Handle, info: ^TypeInfo) {
|
||||
data: [_BUFFER_SIZE]byte;
|
||||
data: [_BUFFER_SIZE]u8;
|
||||
buf := make_string_buffer_from_slice(data[0..<0]);
|
||||
write_type(&buf, info);
|
||||
os.write(fd, string_buffer_data(buf));
|
||||
@@ -204,6 +204,8 @@ write_type :: proc(buf: ^StringBuffer, ti: ^TypeInfo) {
|
||||
write_string(buf, info.signed ? "i" : "u");
|
||||
write_int(buf, i64(8*info.size), 10);
|
||||
}
|
||||
case Rune:
|
||||
write_string(buf, "rune");
|
||||
case Float:
|
||||
match info.size {
|
||||
case 2: write_string(buf, "f16");
|
||||
@@ -500,7 +502,7 @@ fmt_write_padding :: proc(fi: ^FmtInfo, width: int) {
|
||||
if width <= 0 {
|
||||
return;
|
||||
}
|
||||
pad_byte: byte = '0';
|
||||
pad_byte: u8 = '0';
|
||||
if fi.space {
|
||||
pad_byte = ' ';
|
||||
}
|
||||
@@ -549,7 +551,7 @@ _fmt_int :: proc(fi: ^FmtInfo, u: u128, base: int, is_signed: bool, bit_size: in
|
||||
panic("_fmt_int: unknown base, whoops");
|
||||
}
|
||||
|
||||
buf: [256]byte;
|
||||
buf: [256]u8;
|
||||
start := 0;
|
||||
|
||||
|
||||
@@ -560,7 +562,7 @@ _fmt_int :: proc(fi: ^FmtInfo, u: u128, base: int, is_signed: bool, bit_size: in
|
||||
s := strconv.append_bits(buf[start..<start], u128(u), base, is_signed, bit_size, digits, flags);
|
||||
|
||||
if fi.hash && fi.zero {
|
||||
c: byte;
|
||||
c: u8;
|
||||
match base {
|
||||
case 2: c = 'b';
|
||||
case 8: c = 'o';
|
||||
@@ -583,8 +585,13 @@ _fmt_int :: proc(fi: ^FmtInfo, u: u128, base: int, is_signed: bool, bit_size: in
|
||||
immutable __DIGITS_LOWER := "0123456789abcdefx";
|
||||
immutable __DIGITS_UPPER := "0123456789ABCDEFX";
|
||||
|
||||
fmt_rune :: proc(fi: ^FmtInfo, r: rune) {
|
||||
write_rune(fi.buf, r);
|
||||
fmt_rune :: proc(fi: ^FmtInfo, r: rune, verb: rune) {
|
||||
match verb {
|
||||
case 'c', 'r', 'v':
|
||||
write_rune(fi.buf, r);
|
||||
case:
|
||||
fmt_bad_verb(fi, verb);
|
||||
}
|
||||
}
|
||||
|
||||
fmt_int :: proc(fi: ^FmtInfo, u: u128, is_signed: bool, bit_size: int, verb: rune) {
|
||||
@@ -596,7 +603,7 @@ fmt_int :: proc(fi: ^FmtInfo, u: u128, is_signed: bool, bit_size: int, verb: run
|
||||
case 'x': _fmt_int(fi, u, 16, is_signed, bit_size, __DIGITS_LOWER);
|
||||
case 'X': _fmt_int(fi, u, 16, is_signed, bit_size, __DIGITS_UPPER);
|
||||
case 'c', 'r':
|
||||
fmt_rune(fi, rune(u));
|
||||
fmt_rune(fi, rune(u), verb);
|
||||
case 'U':
|
||||
r := rune(u);
|
||||
if r < 0 || r > utf8.MAX_RUNE {
|
||||
@@ -637,7 +644,7 @@ fmt_float :: proc(fi: ^FmtInfo, v: f64, bit_size: int, verb: rune) {
|
||||
prec = fi.prec;
|
||||
}
|
||||
|
||||
buf: [386]byte;
|
||||
buf: [386]u8;
|
||||
str := strconv.append_float(buf[1..<1], v, 'f', prec, bit_size);
|
||||
str = string(buf[0..len(str)]);
|
||||
if str[1] == '+' || str[1] == '-' {
|
||||
@@ -729,6 +736,7 @@ fmt_enum :: proc(fi: ^FmtInfo, v: any, verb: rune) {
|
||||
ok := false;
|
||||
a := any{v.data, type_info_base(e.base)};
|
||||
match v in a {
|
||||
case rune: i = i128(v);
|
||||
case i8: i = i128(v);
|
||||
case i16: i = i128(v);
|
||||
case i32: i = i128(v);
|
||||
@@ -801,7 +809,7 @@ fmt_value :: proc(fi: ^FmtInfo, v: any, verb: rune) {
|
||||
}
|
||||
write_string(fi.buf, b.names[i]);
|
||||
write_string(fi.buf, " = ");
|
||||
data := ^byte(v.data) + b.offsets[i];
|
||||
data := ^u8(v.data) + b.offsets[i];
|
||||
fmt_arg(fi, any{rawptr(data), b.types[i]}, 'v');
|
||||
}
|
||||
write_byte(fi.buf, '}');
|
||||
@@ -812,6 +820,7 @@ fmt_value :: proc(fi: ^FmtInfo, v: any, verb: rune) {
|
||||
|
||||
case Boolean: fmt_arg(fi, v, verb);
|
||||
case Integer: fmt_arg(fi, v, verb);
|
||||
case Rune: fmt_arg(fi, v, verb);
|
||||
case Float: fmt_arg(fi, v, verb);
|
||||
case Complex: fmt_arg(fi, v, verb);
|
||||
case String: fmt_arg(fi, v, verb);
|
||||
@@ -833,7 +842,7 @@ fmt_value :: proc(fi: ^FmtInfo, v: any, verb: rune) {
|
||||
if i > 0 {
|
||||
write_string(fi.buf, ", ");
|
||||
}
|
||||
data := ^byte(v.data) + i*info.elem_size;
|
||||
data := ^u8(v.data) + i*info.elem_size;
|
||||
fmt_arg(fi, any{rawptr(data), info.elem}, verb);
|
||||
}
|
||||
|
||||
@@ -845,14 +854,14 @@ fmt_value :: proc(fi: ^FmtInfo, v: any, verb: rune) {
|
||||
if i > 0 {
|
||||
write_string(fi.buf, ", ");
|
||||
}
|
||||
data := ^byte(array.data) + i*info.elem_size;
|
||||
data := ^u8(array.data) + i*info.elem_size;
|
||||
fmt_arg(fi, any{rawptr(data), info.elem}, verb);
|
||||
}
|
||||
|
||||
case Slice:
|
||||
write_byte(fi.buf, '[');
|
||||
defer write_byte(fi.buf, ']');
|
||||
slice := ^[]byte(v.data);
|
||||
slice := ^[]u8(v.data);
|
||||
for _, i in slice {
|
||||
if i > 0 {
|
||||
write_string(fi.buf, ", ");
|
||||
@@ -870,7 +879,7 @@ fmt_value :: proc(fi: ^FmtInfo, v: any, verb: rune) {
|
||||
write_string(fi.buf, ", ");
|
||||
}
|
||||
|
||||
data := ^byte(v.data) + i*info.elem_size;
|
||||
data := ^u8(v.data) + i*info.elem_size;
|
||||
fmt_value(fi, any{rawptr(data), info.elem}, verb);
|
||||
}
|
||||
|
||||
@@ -892,7 +901,7 @@ fmt_value :: proc(fi: ^FmtInfo, v: any, verb: rune) {
|
||||
if i > 0 {
|
||||
write_string(fi.buf, ", ");
|
||||
}
|
||||
data := ^byte(entries.data) + i*entry_size;
|
||||
data := ^u8(entries.data) + i*entry_size;
|
||||
|
||||
header := ^__MapEntryHeader(data);
|
||||
if types.is_string(info.key) {
|
||||
@@ -920,7 +929,7 @@ fmt_value :: proc(fi: ^FmtInfo, v: any, verb: rune) {
|
||||
}
|
||||
write_string(fi.buf, info.names[i]);
|
||||
write_string(fi.buf, " = ");
|
||||
data := ^byte(v.data) + info.offsets[i];
|
||||
data := ^u8(v.data) + info.offsets[i];
|
||||
fmt_value(fi, any{rawptr(data), info.types[i]}, 'v');
|
||||
}
|
||||
|
||||
@@ -936,7 +945,7 @@ fmt_value :: proc(fi: ^FmtInfo, v: any, verb: rune) {
|
||||
}
|
||||
write_string(fi.buf, cf.names[i]);
|
||||
write_string(fi.buf, " = ");
|
||||
data := ^byte(v.data) + cf.offsets[i];
|
||||
data := ^u8(v.data) + cf.offsets[i];
|
||||
fmt_value(fi, any{rawptr(data), cf.types[i]}, 'v');
|
||||
}
|
||||
|
||||
@@ -999,8 +1008,9 @@ fmt_arg :: proc(fi: ^FmtInfo, arg: any, verb: rune) {
|
||||
base_arg := arg;
|
||||
base_arg.type_info = type_info_base(base_arg.type_info);
|
||||
match a in base_arg {
|
||||
case any: fmt_arg(fi, a, verb);
|
||||
case any: fmt_arg(fi, a, verb);
|
||||
case bool: fmt_bool(fi, a, verb);
|
||||
case rune: fmt_rune(fi, a, verb);
|
||||
|
||||
case f32: fmt_float(fi, f64(a), 32, verb);
|
||||
case f64: fmt_float(fi, a, 64, verb);
|
||||
|
||||
+8
-8
@@ -1,11 +1,11 @@
|
||||
crc32 :: proc(data: []byte) -> u32 {
|
||||
crc32 :: proc(data: []u8) -> u32 {
|
||||
result := ~u32(0);
|
||||
for b in data {
|
||||
result = result>>8 ~ _crc32_table[(result ~ u32(b)) & 0xff];
|
||||
}
|
||||
return ~result;
|
||||
}
|
||||
crc64 :: proc(data: []byte) -> u64 {
|
||||
crc64 :: proc(data: []u8) -> u64 {
|
||||
result := ~u64(0);
|
||||
for b in data {
|
||||
result = result>>8 ~ _crc64_table[(result ~ u64(b)) & 0xff];
|
||||
@@ -13,7 +13,7 @@ crc64 :: proc(data: []byte) -> u64 {
|
||||
return ~result;
|
||||
}
|
||||
|
||||
fnv32 :: proc(data: []byte) -> u32 {
|
||||
fnv32 :: proc(data: []u8) -> u32 {
|
||||
h: u32 = 0x811c9dc5;
|
||||
for b in data {
|
||||
h = (h * 0x01000193) ~ u32(b);
|
||||
@@ -21,7 +21,7 @@ fnv32 :: proc(data: []byte) -> u32 {
|
||||
return h;
|
||||
}
|
||||
|
||||
fnv64 :: proc(data: []byte) -> u64 {
|
||||
fnv64 :: proc(data: []u8) -> u64 {
|
||||
h: u64 = 0xcbf29ce484222325;
|
||||
for b in data {
|
||||
h = (h * 0x100000001b3) ~ u64(b);
|
||||
@@ -29,7 +29,7 @@ fnv64 :: proc(data: []byte) -> u64 {
|
||||
return h;
|
||||
}
|
||||
|
||||
fnv32a :: proc(data: []byte) -> u32 {
|
||||
fnv32a :: proc(data: []u8) -> u32 {
|
||||
h: u32 = 0x811c9dc5;
|
||||
for b in data {
|
||||
h = (h ~ u32(b)) * 0x01000193;
|
||||
@@ -37,7 +37,7 @@ fnv32a :: proc(data: []byte) -> u32 {
|
||||
return h;
|
||||
}
|
||||
|
||||
fnv64a :: proc(data: []byte) -> u64 {
|
||||
fnv64a :: proc(data: []u8) -> u64 {
|
||||
h: u64 = 0xcbf29ce484222325;
|
||||
for b in data {
|
||||
h = (h ~ u64(b)) * 0x100000001b3;
|
||||
@@ -45,7 +45,7 @@ fnv64a :: proc(data: []byte) -> u64 {
|
||||
return h;
|
||||
}
|
||||
|
||||
murmur32 :: proc(data: []byte) -> u32 {
|
||||
murmur32 :: proc(data: []u8) -> u32 {
|
||||
c1_32: u32 : 0xcc9e2d51;
|
||||
c2_32: u32 : 0x1b873593;
|
||||
|
||||
@@ -95,7 +95,7 @@ murmur32 :: proc(data: []byte) -> u32 {
|
||||
return h1;
|
||||
}
|
||||
|
||||
murmur64 :: proc(data: []byte) -> u64 {
|
||||
murmur64 :: proc(data: []u8) -> u64 {
|
||||
SEED :: 0x9747b28c;
|
||||
|
||||
when size_of(int) == 8 {
|
||||
|
||||
+4
-4
@@ -18,7 +18,7 @@ copy :: proc(dst, src: rawptr, len: int) -> rawptr {
|
||||
copy_non_overlapping :: proc(dst, src: rawptr, len: int) -> rawptr {
|
||||
return __mem_copy_non_overlapping(dst, src, len);
|
||||
}
|
||||
compare :: proc(a, b: []byte) -> int {
|
||||
compare :: proc(a, b: []u8) -> int {
|
||||
return __mem_compare(&a[0], &b[0], min(len(a), len(b)));
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ allocation_header :: proc(data: rawptr) -> ^AllocationHeader {
|
||||
Arena :: struct {
|
||||
backing: Allocator,
|
||||
offset: int,
|
||||
memory: []byte,
|
||||
memory: []u8,
|
||||
temp_count: int,
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ ArenaTempMemory :: struct {
|
||||
|
||||
|
||||
|
||||
init_arena_from_memory :: proc(using a: ^Arena, data: []byte) {
|
||||
init_arena_from_memory :: proc(using a: ^Arena, data: []u8) {
|
||||
backing = Allocator{};
|
||||
memory = data[0..<0];
|
||||
temp_count = 0;
|
||||
@@ -102,7 +102,7 @@ init_arena_from_memory :: proc(using a: ^Arena, data: []byte) {
|
||||
|
||||
init_arena_from_context :: proc(using a: ^Arena, size: int) {
|
||||
backing = context.allocator;
|
||||
memory = make([]byte, size);
|
||||
memory = make([]u8, size);
|
||||
temp_count = 0;
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -23,7 +23,7 @@ Ortho :: proc(left, right, bottom, top, near, far: f64) #foreign lib "gl
|
||||
Color3f :: proc(r, g, b: f32) #foreign lib "glColor3f";
|
||||
Vertex3f :: proc(x, y, z: f32) #foreign lib "glVertex3f";
|
||||
GetError :: proc() -> i32 #foreign lib "glGetError";
|
||||
GetString :: proc(name: i32) -> ^byte #foreign lib "glGetString";
|
||||
GetString :: proc(name: i32) -> ^u8 #foreign lib "glGetString";
|
||||
GetIntegerv :: proc(name: i32, v: ^i32) #foreign lib "glGetIntegerv";
|
||||
TexCoord2f :: proc(x, y: f32) #foreign lib "glTexCoord2f";
|
||||
TexImage2D :: proc(target, level, internal_format,
|
||||
@@ -69,7 +69,7 @@ VertexAttribPointer: proc(index: u32, size, type_: i32, normalized: i32, st
|
||||
EnableVertexAttribArray: proc(index: u32) #cc_c;
|
||||
|
||||
CreateShader: proc(shader_type: i32) -> u32 #cc_c;
|
||||
ShaderSource: proc(shader: u32, count: u32, str: ^^byte, length: ^i32) #cc_c;
|
||||
ShaderSource: proc(shader: u32, count: u32, str: ^^u8, length: ^i32) #cc_c;
|
||||
CompileShader: proc(shader: u32) #cc_c;
|
||||
CreateProgram: proc() -> u32 #cc_c;
|
||||
AttachShader: proc(program, shader: u32) #cc_c;
|
||||
@@ -82,8 +82,8 @@ DeleteProgram: proc(program: u32) #cc_c;
|
||||
|
||||
GetShaderiv: proc(shader: u32, pname: i32, params: ^i32) #cc_c;
|
||||
GetProgramiv: proc(program: u32, pname: i32, params: ^i32) #cc_c;
|
||||
GetShaderInfoLog: proc(shader: u32, max_length: u32, length: ^u32, info_long: ^byte) #cc_c;
|
||||
GetProgramInfoLog: proc(program: u32, max_length: u32, length: ^u32, info_long: ^byte) #cc_c;
|
||||
GetShaderInfoLog: proc(shader: u32, max_length: u32, length: ^u32, info_long: ^u8) #cc_c;
|
||||
GetProgramInfoLog: proc(program: u32, max_length: u32, length: ^u32, info_long: ^u8) #cc_c;
|
||||
|
||||
ActiveTexture: proc(texture: i32) #cc_c;
|
||||
GenerateMipmap: proc(target: i32) #cc_c;
|
||||
@@ -106,7 +106,7 @@ Uniform3f: proc(loc: i32, v0, v1, v2: f32) #cc_c;
|
||||
Uniform4f: proc(loc: i32, v0, v1, v2, v3: f32) #cc_c;
|
||||
UniformMatrix4fv: proc(loc: i32, count: u32, transpose: i32, value: ^f32) #cc_c;
|
||||
|
||||
GetUniformLocation: proc(program: u32, name: ^byte) -> i32 #cc_c;
|
||||
GetUniformLocation: proc(program: u32, name: ^u8) -> i32 #cc_c;
|
||||
|
||||
init :: proc() {
|
||||
set_proc_address :: proc(p: rawptr, name: string) #inline {
|
||||
|
||||
+4
-4
@@ -3,10 +3,10 @@
|
||||
#load "os_linux.odin" when ODIN_OS == "linux";
|
||||
|
||||
write_string :: proc(fd: Handle, str: string) -> (int, Errno) {
|
||||
return write(fd, []byte(str));
|
||||
return write(fd, []u8(str));
|
||||
}
|
||||
|
||||
read_entire_file :: proc(name: string) -> ([]byte, bool) {
|
||||
read_entire_file :: proc(name: string) -> ([]u8, bool) {
|
||||
fd, err := open(name, O_RDONLY, 0);
|
||||
if err != 0 {
|
||||
return nil, false;
|
||||
@@ -22,7 +22,7 @@ read_entire_file :: proc(name: string) -> ([]byte, bool) {
|
||||
return nil, true;
|
||||
}
|
||||
|
||||
data := make([]byte, length);
|
||||
data := make([]u8, length);
|
||||
if data == nil {
|
||||
return nil, false;
|
||||
}
|
||||
@@ -35,7 +35,7 @@ read_entire_file :: proc(name: string) -> ([]byte, bool) {
|
||||
return data[0..<bytes_read], true;
|
||||
}
|
||||
|
||||
write_entire_file :: proc(name: string, data: []byte) -> bool {
|
||||
write_entire_file :: proc(name: string, data: []u8) -> bool {
|
||||
fd, err := open(name, O_WRONLY, 0);
|
||||
if err != 0 {
|
||||
return false;
|
||||
|
||||
+3
-3
@@ -164,12 +164,12 @@ close :: proc(fd: Handle) {
|
||||
_unix_close(fd);
|
||||
}
|
||||
|
||||
read :: proc(fd: Handle, data: []byte) -> (int, Errno) {
|
||||
read :: proc(fd: Handle, data: []u8) -> (int, Errno) {
|
||||
sz := _unix_read(fd, &data[0], len(data));
|
||||
return sz, 0;
|
||||
}
|
||||
|
||||
write :: proc(fd: Handle, data: []byte) -> (int, Errno) {
|
||||
write :: proc(fd: Handle, data: []u8) -> (int, Errno) {
|
||||
sz := _unix_write(fd, &data[0], len(data));
|
||||
return sz, 0;
|
||||
}
|
||||
@@ -213,7 +213,7 @@ access :: proc(path: string, mask: int) -> bool #inline {
|
||||
|
||||
|
||||
|
||||
// read_entire_file :: proc(name: string) -> ([]byte, bool) {
|
||||
// read_entire_file :: proc(name: string) -> ([]u8, bool) {
|
||||
// fd: Handle;
|
||||
// err: Errno;
|
||||
// size: i64;
|
||||
|
||||
+17
-17
@@ -93,8 +93,8 @@ open :: proc(path: string, mode: int, perm: u32) -> (Handle, Errno) {
|
||||
create_mode = win32.OPEN_EXISTING;
|
||||
}
|
||||
|
||||
buf: [300]byte;
|
||||
copy(buf[..], []byte(path));
|
||||
buf: [300]u8;
|
||||
copy(buf[..], []u8(path));
|
||||
|
||||
handle := Handle(win32.create_file_a(&buf[0], access, share_mode, sa, create_mode, win32.FILE_ATTRIBUTE_NORMAL, nil));
|
||||
if handle != INVALID_HANDLE {
|
||||
@@ -109,7 +109,7 @@ close :: proc(fd: Handle) {
|
||||
}
|
||||
|
||||
|
||||
write :: proc(fd: Handle, data: []byte) -> (int, Errno) {
|
||||
write :: proc(fd: Handle, data: []u8) -> (int, Errno) {
|
||||
if len(data) == 0 {
|
||||
return 0, ERROR_NONE;
|
||||
}
|
||||
@@ -136,7 +136,7 @@ write :: proc(fd: Handle, data: []byte) -> (int, Errno) {
|
||||
return int(total_write), ERROR_NONE;
|
||||
}
|
||||
|
||||
read :: proc(fd: Handle, data: []byte) -> (int, Errno) {
|
||||
read :: proc(fd: Handle, data: []u8) -> (int, Errno) {
|
||||
if len(data) == 0 {
|
||||
return 0, ERROR_NONE;
|
||||
}
|
||||
@@ -225,11 +225,11 @@ last_write_time :: proc(fd: Handle) -> FileTime {
|
||||
last_write_time_by_name :: proc(name: string) -> FileTime {
|
||||
last_write_time: win32.Filetime;
|
||||
data: win32.FileAttributeData;
|
||||
buf: [1024]byte;
|
||||
buf: [1024]u8;
|
||||
|
||||
assert(len(buf) > len(name));
|
||||
|
||||
copy(buf[..], []byte(name));
|
||||
copy(buf[..], []u8(name));
|
||||
|
||||
if win32.get_file_attributes_ex_a(&buf[0], win32.GetFileExInfoStandard, &data) != 0 {
|
||||
last_write_time = data.last_write_time;
|
||||
@@ -283,7 +283,7 @@ _alloc_command_line_arguments :: proc() -> []string {
|
||||
wstr_len++;
|
||||
}
|
||||
len := 2*wstr_len-1;
|
||||
buf := make([]byte, len+1);
|
||||
buf := make([]u8, len+1);
|
||||
str := slice_ptr(wstr, wstr_len+1);
|
||||
|
||||
i, j := 0, 0;
|
||||
@@ -293,24 +293,24 @@ _alloc_command_line_arguments :: proc() -> []string {
|
||||
if i+1 > len {
|
||||
return "";
|
||||
}
|
||||
buf[i] = byte(str[j]); i++;
|
||||
buf[i] = u8(str[j]); i++;
|
||||
j++;
|
||||
case str[j] < 0x800:
|
||||
if i+2 > len {
|
||||
return "";
|
||||
}
|
||||
buf[i] = byte(0xc0 + (str[j]>>6)); i++;
|
||||
buf[i] = byte(0x80 + (str[j]&0x3f)); i++;
|
||||
buf[i] = u8(0xc0 + (str[j]>>6)); i++;
|
||||
buf[i] = u8(0x80 + (str[j]&0x3f)); i++;
|
||||
j++;
|
||||
case 0xd800 <= str[j] && str[j] < 0xdc00:
|
||||
if i+4 > len {
|
||||
return "";
|
||||
}
|
||||
c := rune((str[j] - 0xd800) << 10) + rune((str[j+1]) - 0xdc00) + 0x10000;
|
||||
buf[i] = byte(0xf0 + (c >> 18)); i++;
|
||||
buf[i] = byte(0x80 + ((c >> 12) & 0x3f)); i++;
|
||||
buf[i] = byte(0x80 + ((c >> 6) & 0x3f)); i++;
|
||||
buf[i] = byte(0x80 + ((c ) & 0x3f)); i++;
|
||||
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++;
|
||||
j += 2;
|
||||
case 0xdc00 <= str[j] && str[j] < 0xe000:
|
||||
return "";
|
||||
@@ -318,9 +318,9 @@ _alloc_command_line_arguments :: proc() -> []string {
|
||||
if i+3 > len {
|
||||
return "";
|
||||
}
|
||||
buf[i] = 0xe0 + byte (str[j] >> 12); i++;
|
||||
buf[i] = 0x80 + byte((str[j] >> 6) & 0x3f); i++;
|
||||
buf[i] = 0x80 + byte((str[j] ) & 0x3f); i++;
|
||||
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++;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -166,7 +166,7 @@ close :: proc(fd: Handle) {
|
||||
unix_close(fd);
|
||||
}
|
||||
|
||||
write :: proc(fd: Handle, data: []byte) -> (AddressSize, Errno) {
|
||||
write :: proc(fd: Handle, data: []u8) -> (AddressSize, Errno) {
|
||||
assert(fd != -1);
|
||||
|
||||
bytes_written := unix_write(fd, &data[0], len(data));
|
||||
@@ -176,7 +176,7 @@ write :: proc(fd: Handle, data: []byte) -> (AddressSize, Errno) {
|
||||
return bytes_written, 0;
|
||||
}
|
||||
|
||||
read :: proc(fd: Handle, data: []byte) -> (AddressSize, Errno) {
|
||||
read :: proc(fd: Handle, data: []u8) -> (AddressSize, Errno) {
|
||||
assert(fd != -1);
|
||||
|
||||
bytes_read := unix_read(fd, &data[0], len(data));
|
||||
@@ -229,7 +229,7 @@ access :: proc(path: string, mask: int) -> bool #inline {
|
||||
return unix_access(cstr, mask) == 0;
|
||||
}
|
||||
|
||||
// read_entire_file :: proc(name: string) -> ([]byte, bool) {
|
||||
// read_entire_file :: proc(name: string) -> ([]u8, bool) {
|
||||
|
||||
// handle, err := open_simple(name, O_RDONLY);
|
||||
// if(err != 0) {
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ Any :: struct #ordered {
|
||||
}
|
||||
|
||||
String :: struct #ordered {
|
||||
data: ^byte,
|
||||
data: ^u8,
|
||||
len: int,
|
||||
};
|
||||
|
||||
|
||||
+16
-16
@@ -189,21 +189,21 @@ parse_f64 :: proc(s: string) -> f64 {
|
||||
}
|
||||
|
||||
|
||||
append_bool :: proc(buf: []byte, b: bool) -> string {
|
||||
append_bool :: proc(buf: []u8, b: bool) -> string {
|
||||
s := b ? "true" : "false";
|
||||
append(buf, ..[]byte(s));
|
||||
append(buf, ..[]u8(s));
|
||||
return string(buf);
|
||||
}
|
||||
|
||||
append_uint :: proc(buf: []byte, u: u64, base: int) -> string {
|
||||
append_uint :: proc(buf: []u8, u: u64, base: int) -> string {
|
||||
return append_bits(buf, u128(u), base, false, 8*size_of(uint), digits, 0);
|
||||
}
|
||||
append_int :: proc(buf: []byte, i: i64, base: int) -> string {
|
||||
append_int :: proc(buf: []u8, i: i64, base: int) -> string {
|
||||
return append_bits(buf, u128(i), base, true, 8*size_of(int), digits, 0);
|
||||
}
|
||||
itoa :: proc(buf: []byte, i: int) -> string { return append_int(buf, i64(i), 10); }
|
||||
itoa :: proc(buf: []u8, i: int) -> string { return append_int(buf, i64(i), 10); }
|
||||
|
||||
append_float :: proc(buf: []byte, f: f64, fmt: byte, prec, bit_size: int) -> string {
|
||||
append_float :: proc(buf: []u8, f: f64, fmt: u8, prec, bit_size: int) -> string {
|
||||
return string(generic_ftoa(buf, f, fmt, prec, bit_size));
|
||||
}
|
||||
|
||||
@@ -211,7 +211,7 @@ append_float :: proc(buf: []byte, f: f64, fmt: byte, prec, bit_size: int) -> str
|
||||
|
||||
|
||||
DecimalSlice :: struct {
|
||||
digits: []byte,
|
||||
digits: []u8,
|
||||
count: int,
|
||||
decimal_point: int,
|
||||
neg: bool,
|
||||
@@ -228,7 +228,7 @@ _f32_info := Float_Info{23, 8, -127};
|
||||
_f64_info := Float_Info{52, 11, -1023};
|
||||
|
||||
|
||||
generic_ftoa :: proc(buf: []byte, val: f64, fmt: byte, prec, bit_size: int) -> []byte {
|
||||
generic_ftoa :: proc(buf: []u8, val: f64, fmt: u8, prec, bit_size: int) -> []u8 {
|
||||
bits: u64;
|
||||
flt: ^Float_Info;
|
||||
match bit_size {
|
||||
@@ -256,7 +256,7 @@ generic_ftoa :: proc(buf: []byte, val: f64, fmt: byte, prec, bit_size: int) -> [
|
||||
} else {
|
||||
s = "+Inf";
|
||||
}
|
||||
append(buf, ..[]byte(s));
|
||||
append(buf, ..[]u8(s));
|
||||
return buf;
|
||||
|
||||
case 0: // denormalized
|
||||
@@ -300,7 +300,7 @@ generic_ftoa :: proc(buf: []byte, val: f64, fmt: byte, prec, bit_size: int) -> [
|
||||
|
||||
|
||||
|
||||
format_digits :: proc(buf: []byte, shortest: bool, neg: bool, digs: DecimalSlice, prec: int, fmt: byte) -> []byte {
|
||||
format_digits :: proc(buf: []u8, shortest: bool, neg: bool, digs: DecimalSlice, prec: int, fmt: u8) -> []u8 {
|
||||
match fmt {
|
||||
case 'f', 'F':
|
||||
append(buf, neg ? '-' : '+');
|
||||
@@ -321,7 +321,7 @@ format_digits :: proc(buf: []byte, shortest: bool, neg: bool, digs: DecimalSlice
|
||||
if prec > 0 {
|
||||
append(buf, '.');
|
||||
for i in 0..<prec {
|
||||
c: byte = '0';
|
||||
c: u8 = '0';
|
||||
if j := digs.decimal_point + i; 0 <= j && j < digs.count {
|
||||
c = digs.digits[j];
|
||||
}
|
||||
@@ -340,7 +340,7 @@ format_digits :: proc(buf: []byte, shortest: bool, neg: bool, digs: DecimalSlice
|
||||
return buf; // TODO
|
||||
}
|
||||
|
||||
c: [2]byte;
|
||||
c: [2]u8;
|
||||
c[0] = '%';
|
||||
c[1] = fmt;
|
||||
append(buf, ..c[..]);
|
||||
@@ -385,12 +385,12 @@ round_shortest :: proc(d: ^Decimal, mant: u64, exp: int, flt: ^Float_Info) {
|
||||
inclusive := mant%2 == 0;
|
||||
|
||||
for i in 0..<d.count {
|
||||
l: byte = '0'; // lower digit
|
||||
l: u8 = '0'; // lower digit
|
||||
if i < lower.count {
|
||||
l = lower.digits[i];
|
||||
}
|
||||
m := d.digits[i]; // middle digit
|
||||
u: byte = '0'; // upper digit
|
||||
u: u8 = '0'; // upper digit
|
||||
if i < upper.count {
|
||||
u = upper.digits[i];
|
||||
}
|
||||
@@ -454,12 +454,12 @@ is_integer_negative :: proc(u: u128, is_signed: bool, bit_size: int) -> (unsigne
|
||||
return u, neg;
|
||||
}
|
||||
|
||||
append_bits :: proc(buf: []byte, u_: u128, base: int, is_signed: bool, bit_size: int, digits: string, flags: IntFlag) -> string {
|
||||
append_bits :: proc(buf: []u8, u_: u128, base: int, is_signed: bool, bit_size: int, digits: string, flags: IntFlag) -> string {
|
||||
if base < 2 || base > MAX_BASE {
|
||||
panic("strconv: illegal base passed to append_bits");
|
||||
}
|
||||
|
||||
a: [129]byte;
|
||||
a: [129]u8;
|
||||
i := len(a);
|
||||
u, neg := is_integer_negative(u_, is_signed, bit_size);
|
||||
b := u128(base);
|
||||
|
||||
+4
-4
@@ -1,11 +1,11 @@
|
||||
new_c_string :: proc(s: string) -> ^byte {
|
||||
c := make([]byte, len(s)+1);
|
||||
copy(c, []byte(s));
|
||||
new_c_string :: proc(s: string) -> ^u8 {
|
||||
c := make([]u8, len(s)+1);
|
||||
copy(c, []u8(s));
|
||||
c[len(s)] = 0;
|
||||
return &c[0];
|
||||
}
|
||||
|
||||
to_odin_string :: proc(c: ^byte) -> string {
|
||||
to_odin_string :: proc(c: ^u8) -> string {
|
||||
len := 0;
|
||||
for (c+len)^ != 0 {
|
||||
len++;
|
||||
|
||||
+22
-22
@@ -16,26 +16,26 @@ LayerPlaneDescriptor :: struct {
|
||||
size: u16,
|
||||
version: u16,
|
||||
flags: u32,
|
||||
pixel_type: byte,
|
||||
color_bits: byte,
|
||||
red_bits: byte,
|
||||
red_shift: byte,
|
||||
green_bits: byte,
|
||||
green_shift: byte,
|
||||
blue_bits: byte,
|
||||
blue_shift: byte,
|
||||
alpha_bits: byte,
|
||||
alpha_shift: byte,
|
||||
accum_bits: byte,
|
||||
accum_red_bits: byte,
|
||||
accum_green_bits: byte,
|
||||
accum_blue_bits: byte,
|
||||
accum_alpha_bits: byte,
|
||||
depth_bits: byte,
|
||||
stencil_bits: byte,
|
||||
aux_buffers: byte,
|
||||
layer_type: byte,
|
||||
reserved: byte,
|
||||
pixel_type: u8,
|
||||
color_bits: u8,
|
||||
red_bits: u8,
|
||||
red_shift: u8,
|
||||
green_bits: u8,
|
||||
green_shift: u8,
|
||||
blue_bits: u8,
|
||||
blue_shift: u8,
|
||||
alpha_bits: u8,
|
||||
alpha_shift: u8,
|
||||
accum_bits: u8,
|
||||
accum_red_bits: u8,
|
||||
accum_green_bits: u8,
|
||||
accum_blue_bits: u8,
|
||||
accum_alpha_bits: u8,
|
||||
depth_bits: u8,
|
||||
stencil_bits: u8,
|
||||
aux_buffers: u8,
|
||||
layer_type: u8,
|
||||
reserved: u8,
|
||||
transparent: ColorRef,
|
||||
}
|
||||
|
||||
@@ -53,8 +53,8 @@ Glyph_MetricsFloat :: struct {
|
||||
|
||||
CreateContextAttribsARBType :: #type proc(hdc: Hdc, h_share_context: rawptr, attribList: ^i32) -> Hglrc;
|
||||
ChoosePixelFormatARBType :: #type proc(hdc: Hdc, attrib_i_list: ^i32, attrib_f_list: ^f32, max_formats: u32, formats: ^i32, num_formats : ^u32) -> Bool #cc_c;
|
||||
SwapIntervalEXTType :: #type proc(interval : i32) -> bool #cc_c;
|
||||
GetExtensionsStringARBType :: #type proc(Hdc) -> ^byte #cc_c;
|
||||
SwapIntervalEXTType :: #type proc(interval: i32) -> bool #cc_c;
|
||||
GetExtensionsStringARBType :: #type proc(Hdc) -> ^u8 #cc_c;
|
||||
|
||||
|
||||
create_context_attribs_arb: CreateContextAttribsARBType;
|
||||
|
||||
+11
-11
@@ -73,7 +73,7 @@ Point :: struct #ordered {
|
||||
|
||||
WndClassExA :: struct #ordered {
|
||||
size, style: u32,
|
||||
wndproc: WndProc,
|
||||
wnd_proc: WndProc,
|
||||
cls_extra, wnd_extra: i32,
|
||||
instance: Hinstance,
|
||||
icon: Hicon,
|
||||
@@ -140,8 +140,8 @@ FindData :: struct #ordered {
|
||||
file_size_low : u32,
|
||||
reserved0 : u32,
|
||||
reserved1 : u32,
|
||||
file_name : [MAX_PATH]byte,
|
||||
alternate_file_name : [14]byte,
|
||||
file_name : [MAX_PATH]u8,
|
||||
alternate_file_name : [14]u8,
|
||||
}
|
||||
|
||||
|
||||
@@ -225,7 +225,7 @@ read_file :: proc(h: Handle, buf: rawptr, to_read: u32, bytes_read: ^i32, overl
|
||||
write_file :: proc(h: Handle, buf: rawptr, len: i32, written_result: ^i32, overlapped: rawptr) -> Bool #foreign kernel32 "WriteFile";
|
||||
|
||||
get_file_size_ex :: proc(file_handle: Handle, file_size: ^i64) -> Bool #foreign kernel32 "GetFileSizeEx";
|
||||
get_file_attributes_a :: proc(filename: ^byte) -> u32 #foreign kernel32 "GetFileAttributesA";
|
||||
get_file_attributes_a :: proc(filename: ^u8) -> u32 #foreign kernel32 "GetFileAttributesA";
|
||||
get_file_attributes_ex_a :: proc(filename: ^u8, info_level_id: GET_FILEEX_INFO_LEVELS, file_info: rawptr) -> Bool #foreign kernel32 "GetFileAttributesExA";
|
||||
get_file_information_by_handle :: proc(file_handle: Handle, file_info: ^ByHandleFileInformation) -> Bool #foreign kernel32 "GetFileInformationByHandle";
|
||||
|
||||
@@ -234,7 +234,7 @@ set_file_pointer :: proc(file_handle: Handle, distance_to_move: i32, distance_to
|
||||
|
||||
set_handle_information :: proc(obj: Handle, mask, flags: u32) -> Bool #foreign kernel32 "SetHandleInformation";
|
||||
|
||||
find_first_file_a :: proc(file_name : ^byte, data : ^FindData) -> Handle #foreign kernel32 "FindFirstFileA";
|
||||
find_first_file_a :: proc(file_name : ^u8, data : ^FindData) -> Handle #foreign kernel32 "FindFirstFileA";
|
||||
find_next_file_a :: proc(file : Handle, data : ^FindData) -> Bool #foreign kernel32 "FindNextFileA";
|
||||
find_close :: proc(file : Handle) -> Bool #foreign kernel32 "FindClose";
|
||||
|
||||
@@ -312,7 +312,7 @@ Security_Attributes :: struct #ordered {
|
||||
|
||||
INFINITE :: 0xffffffff;
|
||||
|
||||
create_semaphore_a :: proc(attributes: ^Security_Attributes, initial_count, maximum_count: i32, name: ^byte) -> Handle #foreign kernel32 "CreateSemaphoreA";
|
||||
create_semaphore_a :: proc(attributes: ^Security_Attributes, initial_count, maximum_count: i32, name: ^u8) -> Handle #foreign kernel32 "CreateSemaphoreA";
|
||||
release_semaphore :: proc(semaphore: Handle, release_count: i32, previous_count: ^i32) -> Bool #foreign kernel32 "ReleaseSemaphore";
|
||||
wait_for_single_object :: proc(handle: Handle, milliseconds: u32) -> u32 #foreign kernel32 "WaitForSingleObject";
|
||||
|
||||
@@ -383,7 +383,7 @@ get_window_rect :: proc(wnd: Hwnd, rect: ^Rect) -> Bool
|
||||
get_window_long_ptr_a :: proc(wnd: Hwnd, index: i32) -> i64 #foreign user32 "GetWindowLongPtrA";
|
||||
set_window_long_ptr_a :: proc(wnd: Hwnd, index: i32, new: i64) -> i64 #foreign user32 "SetWindowLongPtrA";
|
||||
|
||||
get_window_text :: proc(wnd: Hwnd, str: ^byte, maxCount: i32) -> i32 #foreign user32 "GetWindowText";
|
||||
get_window_text :: proc(wnd: Hwnd, str: ^u8, maxCount: i32) -> i32 #foreign user32 "GetWindowText";
|
||||
|
||||
HIWORD :: proc(wParam: Wparam) -> u16 { return u16((u32(wParam) >> 16) & 0xffff); }
|
||||
HIWORD :: proc(lParam: Lparam) -> u16 { return u16((u32(lParam) >> 16) & 0xffff); }
|
||||
@@ -416,7 +416,7 @@ BitmapInfo :: struct #ordered {
|
||||
}
|
||||
|
||||
|
||||
RgbQuad :: struct #ordered { blue, green, red, reserved: byte }
|
||||
RgbQuad :: struct #ordered { blue, green, red, reserved: u8 }
|
||||
|
||||
BI_RGB :: 0;
|
||||
DIB_RGB_COLORS :: 0x00;
|
||||
@@ -486,18 +486,18 @@ PixelFormatDescriptor :: struct #ordered {
|
||||
stencil_bits,
|
||||
aux_buffers,
|
||||
layer_type,
|
||||
reserved: byte,
|
||||
reserved: u8,
|
||||
|
||||
layer_mask,
|
||||
visible_mask,
|
||||
damage_mask: u32,
|
||||
}
|
||||
|
||||
get_d_c :: proc(h: Hwnd) -> Hdc #foreign user32 "GetDC";
|
||||
get_dc :: proc(h: Hwnd) -> Hdc #foreign user32 "GetDC";
|
||||
set_pixel_format :: proc(hdc: Hdc, pixel_format: i32, pfd: ^PixelFormatDescriptor) -> Bool #foreign gdi32 "SetPixelFormat";
|
||||
choose_pixel_format :: proc(hdc: Hdc, pfd: ^PixelFormatDescriptor) -> i32 #foreign gdi32 "ChoosePixelFormat";
|
||||
swap_buffers :: proc(hdc: Hdc) -> Bool #foreign gdi32 "SwapBuffers";
|
||||
release_d_c :: proc(wnd: Hwnd, hdc: Hdc) -> i32 #foreign user32 "ReleaseDC";
|
||||
release_dc :: proc(wnd: Hwnd, hdc: Hdc) -> i32 #foreign user32 "ReleaseDC";
|
||||
|
||||
|
||||
Proc :: #type proc() #cc_c;
|
||||
|
||||
+21
-21
@@ -38,7 +38,7 @@ immutable accept_ranges := [5]AcceptRange{
|
||||
{0x80, 0x8f},
|
||||
};
|
||||
|
||||
immutable accept_sizes := [256]byte{
|
||||
immutable accept_sizes := [256]u8{
|
||||
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, // 0x00-0x0f
|
||||
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, // 0x10-0x1f
|
||||
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, // 0x20-0x2f
|
||||
@@ -58,17 +58,17 @@ immutable accept_sizes := [256]byte{
|
||||
0x34, 0x04, 0x04, 0x04, 0x44, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, // 0xf0-0xff
|
||||
};
|
||||
|
||||
encode_rune :: proc(r: rune) -> ([4]byte, int) {
|
||||
buf: [4]byte;
|
||||
encode_rune :: proc(r: rune) -> ([4]u8, int) {
|
||||
buf: [4]u8;
|
||||
i := u32(r);
|
||||
mask: byte : 0x3f;
|
||||
mask: u8 : 0x3f;
|
||||
if i <= 1<<7-1 {
|
||||
buf[0] = byte(r);
|
||||
buf[0] = u8(r);
|
||||
return buf, 1;
|
||||
}
|
||||
if i <= 1<<11-1 {
|
||||
buf[0] = 0xc0 | byte(r>>6);
|
||||
buf[1] = 0x80 | byte(r) & mask;
|
||||
buf[0] = 0xc0 | u8(r>>6);
|
||||
buf[1] = 0x80 | u8(r) & mask;
|
||||
return buf, 2;
|
||||
}
|
||||
|
||||
@@ -79,21 +79,21 @@ encode_rune :: proc(r: rune) -> ([4]byte, int) {
|
||||
}
|
||||
|
||||
if i <= 1<<16-1 {
|
||||
buf[0] = 0xe0 | byte(r>>12);
|
||||
buf[1] = 0x80 | byte(r>>6) & mask;
|
||||
buf[2] = 0x80 | byte(r) & mask;
|
||||
buf[0] = 0xe0 | u8(r>>12);
|
||||
buf[1] = 0x80 | u8(r>>6) & mask;
|
||||
buf[2] = 0x80 | u8(r) & mask;
|
||||
return buf, 3;
|
||||
}
|
||||
|
||||
buf[0] = 0xf0 | byte(r>>18);
|
||||
buf[1] = 0x80 | byte(r>>12) & mask;
|
||||
buf[2] = 0x80 | byte(r>>6) & mask;
|
||||
buf[3] = 0x80 | byte(r) & mask;
|
||||
buf[0] = 0xf0 | u8(r>>18);
|
||||
buf[1] = 0x80 | u8(r>>12) & mask;
|
||||
buf[2] = 0x80 | u8(r>>6) & mask;
|
||||
buf[3] = 0x80 | u8(r) & mask;
|
||||
return buf, 4;
|
||||
}
|
||||
|
||||
decode_rune :: proc(s: string) -> (rune, int) #inline { return decode_rune([]byte(s)); }
|
||||
decode_rune :: proc(s: []byte) -> (rune, int) {
|
||||
decode_rune :: proc(s: string) -> (rune, int) #inline { return decode_rune([]u8(s)); }
|
||||
decode_rune :: proc(s: []u8) -> (rune, int) {
|
||||
n := len(s);
|
||||
if n < 1 {
|
||||
return RUNE_ERROR, 0;
|
||||
@@ -132,8 +132,8 @@ decode_rune :: proc(s: []byte) -> (rune, int) {
|
||||
|
||||
|
||||
|
||||
decode_last_rune :: proc(s: string) -> (rune, int) #inline { return decode_last_rune([]byte(s)); }
|
||||
decode_last_rune :: proc(s: []byte) -> (rune, int) {
|
||||
decode_last_rune :: proc(s: string) -> (rune, int) #inline { return decode_last_rune([]u8(s)); }
|
||||
decode_last_rune :: proc(s: []u8) -> (rune, int) {
|
||||
r: rune;
|
||||
size: int;
|
||||
start, end, limit: int;
|
||||
@@ -215,10 +215,10 @@ valid_string :: proc(s: string) -> bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
rune_start :: proc(b: byte) -> bool #inline { return b&0xc0 != 0x80; }
|
||||
rune_start :: proc(b: u8) -> bool #inline { return b&0xc0 != 0x80; }
|
||||
|
||||
rune_count :: proc(s: string) -> int #inline { return rune_count([]byte(s)); }
|
||||
rune_count :: proc(s: []byte) -> int {
|
||||
rune_count :: proc(s: string) -> int #inline { return rune_count([]u8(s)); }
|
||||
rune_count :: proc(s: []u8) -> int {
|
||||
count := 0;
|
||||
n := len(s);
|
||||
|
||||
|
||||
+21
-5
@@ -156,7 +156,7 @@ i64 check_distance_between_types(Checker *c, Operand *operand, Type *type) {
|
||||
if (is_type_typed(dst) && src->kind == Type_Basic) {
|
||||
switch (src->Basic.kind) {
|
||||
case Basic_UntypedInteger:
|
||||
if (is_type_integer(dst)) {
|
||||
if (is_type_integer(dst) || is_type_rune(dst)) {
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
@@ -2102,7 +2102,7 @@ bool check_representable_as_constant(Checker *c, ExactValue in_value, Type *type
|
||||
return in_value.kind == ExactValue_Bool;
|
||||
} else if (is_type_string(type)) {
|
||||
return in_value.kind == ExactValue_String;
|
||||
} else if (is_type_integer(type)) {
|
||||
} else if (is_type_integer(type) || is_type_rune(type)) {
|
||||
ExactValue v = exact_value_to_integer(in_value);
|
||||
if (v.kind != ExactValue_Integer) {
|
||||
return false;
|
||||
@@ -2127,6 +2127,7 @@ bool check_representable_as_constant(Checker *c, ExactValue in_value, Type *type
|
||||
i128 imax = i128_shl(I128_ONE, s-1ll);
|
||||
|
||||
switch (type->Basic.kind) {
|
||||
case Basic_rune:
|
||||
case Basic_i8:
|
||||
case Basic_i16:
|
||||
case Basic_i32:
|
||||
@@ -2212,7 +2213,15 @@ void check_is_expressible(Checker *c, Operand *o, Type *type) {
|
||||
if (!is_type_integer(o->type) && is_type_integer(type)) {
|
||||
error_node(o->expr, "`%s` truncated to `%s`", a, b);
|
||||
} else {
|
||||
error_node(o->expr, "`%s = %lld` overflows `%s`", a, i128_to_i64(o->value.value_integer), b);
|
||||
char buf[127] = {0};
|
||||
String str = {0};
|
||||
i128 i = o->value.value_integer;
|
||||
if (is_type_unsigned(o->type)) {
|
||||
str = u128_to_string(*cast(u128 *)&i, buf, gb_size_of(buf));
|
||||
} else {
|
||||
str = i128_to_string(i, buf, gb_size_of(buf));
|
||||
}
|
||||
error_node(o->expr, "`%s = %.*s` overflows `%s`", a, str, b);
|
||||
}
|
||||
} else {
|
||||
error_node(o->expr, "Cannot convert `%s` to `%s`", a, b);
|
||||
@@ -2623,6 +2632,13 @@ bool check_is_castable_to(Checker *c, Operand *operand, Type *y) {
|
||||
}
|
||||
}
|
||||
|
||||
if (is_type_integer(src) && is_type_rune(dst)) {
|
||||
return true;
|
||||
}
|
||||
if (is_type_rune(src) && is_type_integer(dst)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (is_type_complex(src) && is_type_complex(dst)) {
|
||||
return true;
|
||||
}
|
||||
@@ -4349,7 +4365,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
|
||||
} break;
|
||||
|
||||
case BuiltinProc_slice_to_bytes: {
|
||||
// slice_to_bytes :: proc(a: []T) -> []byte
|
||||
// slice_to_bytes :: proc(a: []T) -> []u8
|
||||
Type *slice_type = base_type(operand->type);
|
||||
if (!is_type_slice(slice_type)) {
|
||||
gbString type_str = type_to_string(operand->type);
|
||||
@@ -4358,7 +4374,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
|
||||
return false;
|
||||
}
|
||||
|
||||
operand->type = t_byte_slice;
|
||||
operand->type = t_u8_slice;
|
||||
operand->mode = Addressing_Value;
|
||||
} break;
|
||||
|
||||
|
||||
+28
-25
@@ -658,13 +658,12 @@ void init_universal_scope(void) {
|
||||
add_global_entity(make_entity_type_name(a, NULL, make_token_ident(basic_types[i].Basic.name), &basic_types[i]));
|
||||
}
|
||||
#if 1
|
||||
for (isize i = 0; i < gb_count_of(basic_type_aliases); i++) {
|
||||
add_global_entity(make_entity_type_name(a, NULL, make_token_ident(basic_type_aliases[i].Basic.name), &basic_type_aliases[i]));
|
||||
}
|
||||
// for (isize i = 0; i < gb_count_of(basic_type_aliases); i++) {
|
||||
// add_global_entity(make_entity_type_name(a, NULL, make_token_ident(basic_type_aliases[i].Basic.name), &basic_type_aliases[i]));
|
||||
// }
|
||||
#else
|
||||
{
|
||||
t_byte = add_global_type_alias(a, str_lit("byte"), &basic_types[Basic_u8]);
|
||||
t_rune = add_global_type_alias(a, str_lit("rune"), &basic_types[Basic_i32]);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -700,7 +699,7 @@ void init_universal_scope(void) {
|
||||
t_i64_ptr = make_type_pointer(a, t_i64);
|
||||
t_i128_ptr = make_type_pointer(a, t_i128);
|
||||
t_f64_ptr = make_type_pointer(a, t_f64);
|
||||
t_byte_slice = make_type_slice(a, t_byte);
|
||||
t_u8_slice = make_type_slice(a, t_u8);
|
||||
t_string_slice = make_type_slice(a, t_string);
|
||||
}
|
||||
|
||||
@@ -1204,33 +1203,35 @@ void init_preload(Checker *c) {
|
||||
|
||||
|
||||
|
||||
if (record->variant_count != 22) {
|
||||
if (record->variant_count != 23) {
|
||||
compiler_error("Invalid `TypeInfo` layout");
|
||||
}
|
||||
t_type_info_named = record->variants[ 1]->type;
|
||||
t_type_info_integer = record->variants[ 2]->type;
|
||||
t_type_info_float = record->variants[ 3]->type;
|
||||
t_type_info_complex = record->variants[ 4]->type;
|
||||
t_type_info_string = record->variants[ 5]->type;
|
||||
t_type_info_boolean = record->variants[ 6]->type;
|
||||
t_type_info_any = record->variants[ 7]->type;
|
||||
t_type_info_pointer = record->variants[ 8]->type;
|
||||
t_type_info_atomic = record->variants[ 9]->type;
|
||||
t_type_info_procedure = record->variants[10]->type;
|
||||
t_type_info_array = record->variants[11]->type;
|
||||
t_type_info_dynamic_array = record->variants[12]->type;
|
||||
t_type_info_slice = record->variants[13]->type;
|
||||
t_type_info_vector = record->variants[14]->type;
|
||||
t_type_info_tuple = record->variants[15]->type;
|
||||
t_type_info_struct = record->variants[16]->type;
|
||||
t_type_info_raw_union = record->variants[17]->type;
|
||||
t_type_info_union = record->variants[18]->type;
|
||||
t_type_info_enum = record->variants[19]->type;
|
||||
t_type_info_map = record->variants[20]->type;
|
||||
t_type_info_bit_field = record->variants[21]->type;
|
||||
t_type_info_rune = record->variants[ 3]->type;
|
||||
t_type_info_float = record->variants[ 4]->type;
|
||||
t_type_info_complex = record->variants[ 5]->type;
|
||||
t_type_info_string = record->variants[ 6]->type;
|
||||
t_type_info_boolean = record->variants[ 7]->type;
|
||||
t_type_info_any = record->variants[ 8]->type;
|
||||
t_type_info_pointer = record->variants[ 9]->type;
|
||||
t_type_info_atomic = record->variants[10]->type;
|
||||
t_type_info_procedure = record->variants[11]->type;
|
||||
t_type_info_array = record->variants[12]->type;
|
||||
t_type_info_dynamic_array = record->variants[13]->type;
|
||||
t_type_info_slice = record->variants[14]->type;
|
||||
t_type_info_vector = record->variants[15]->type;
|
||||
t_type_info_tuple = record->variants[16]->type;
|
||||
t_type_info_struct = record->variants[17]->type;
|
||||
t_type_info_raw_union = record->variants[18]->type;
|
||||
t_type_info_union = record->variants[19]->type;
|
||||
t_type_info_enum = record->variants[20]->type;
|
||||
t_type_info_map = record->variants[21]->type;
|
||||
t_type_info_bit_field = record->variants[22]->type;
|
||||
|
||||
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_rune_ptr = make_type_pointer(c->allocator, t_type_info_rune);
|
||||
t_type_info_float_ptr = make_type_pointer(c->allocator, t_type_info_float);
|
||||
t_type_info_complex_ptr = make_type_pointer(c->allocator, t_type_info_complex);
|
||||
t_type_info_string_ptr = make_type_pointer(c->allocator, t_type_info_string);
|
||||
@@ -2118,12 +2119,14 @@ void check_parsed_files(Checker *c) {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
for (isize i = 0; i < gb_count_of(basic_type_aliases)-1; i++) {
|
||||
Type *t = &basic_type_aliases[i];
|
||||
if (t->Basic.size > 0) {
|
||||
add_type_info_type(c, t);
|
||||
}
|
||||
}
|
||||
*/
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -7526,6 +7526,10 @@ void ir_gen_tree(irGen *s) {
|
||||
ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 2), is_signed);
|
||||
} break;
|
||||
|
||||
case Basic_rune:
|
||||
tag = ir_emit_conv(proc, ti_ptr, t_type_info_rune_ptr);
|
||||
break;
|
||||
|
||||
// case Basic_f16:
|
||||
case Basic_f32:
|
||||
case Basic_f64:
|
||||
|
||||
@@ -193,6 +193,8 @@ void ir_print_type(irFileBuffer *f, irModule *m, Type *t) {
|
||||
case Basic_i128: ir_fprintf(f, "i128"); return;
|
||||
case Basic_u128: ir_fprintf(f, "i128"); return;
|
||||
|
||||
case Basic_rune: ir_fprintf(f, "i32"); return;
|
||||
|
||||
// case Basic_f16: ir_fprintf(f, "half"); return;
|
||||
case Basic_f32: ir_fprintf(f, "float"); return;
|
||||
case Basic_f64: ir_fprintf(f, "double"); return;
|
||||
|
||||
+3
-3
@@ -890,9 +890,9 @@ Token tokenizer_get_token(Tokenizer *t) {
|
||||
case '}': token.kind = Token_CloseBrace; break;
|
||||
case '\\': token.kind = Token_BackSlash; break;
|
||||
|
||||
case '≠': token.kind = Token_NotEq; break;
|
||||
case '≤': token.kind = Token_LtEq; break;
|
||||
case '≥': token.kind = Token_GtEq; break;
|
||||
case 0x2260: token.kind = Token_NotEq; break; // '≠'
|
||||
case 0x2264: token.kind = Token_LtEq; break; // '≤'
|
||||
case 0x2265: token.kind = Token_GtEq; break; // '≥'
|
||||
|
||||
case '%': token.kind = token_kind_dub_eq(t, '%', Token_Mod, Token_ModEq, Token_ModMod, Token_ModModEq); break;
|
||||
|
||||
|
||||
+23
-10
@@ -14,6 +14,8 @@ typedef enum BasicKind {
|
||||
Basic_i128,
|
||||
Basic_u128,
|
||||
|
||||
Basic_rune,
|
||||
|
||||
// Basic_f16,
|
||||
Basic_f32,
|
||||
Basic_f64,
|
||||
@@ -39,7 +41,6 @@ typedef enum BasicKind {
|
||||
Basic_COUNT,
|
||||
|
||||
Basic_byte = Basic_u8,
|
||||
Basic_rune = Basic_i32,
|
||||
} BasicKind;
|
||||
|
||||
typedef enum BasicFlag {
|
||||
@@ -54,8 +55,8 @@ typedef enum BasicFlag {
|
||||
BasicFlag_Untyped = GB_BIT(8),
|
||||
|
||||
BasicFlag_Numeric = BasicFlag_Integer | BasicFlag_Float | BasicFlag_Complex,
|
||||
BasicFlag_Ordered = BasicFlag_Integer | BasicFlag_Float | BasicFlag_String | BasicFlag_Pointer,
|
||||
BasicFlag_ConstantType = BasicFlag_Boolean | BasicFlag_Numeric | BasicFlag_Pointer | BasicFlag_String | BasicFlag_Rune,
|
||||
BasicFlag_Ordered = BasicFlag_Integer | BasicFlag_Float | BasicFlag_String | BasicFlag_Pointer | BasicFlag_Rune,
|
||||
BasicFlag_ConstantType = BasicFlag_Boolean | BasicFlag_Numeric | BasicFlag_String | BasicFlag_Pointer | BasicFlag_Rune,
|
||||
} BasicFlag;
|
||||
|
||||
typedef struct BasicType {
|
||||
@@ -235,6 +236,7 @@ gb_global Type basic_types[] = {
|
||||
{Type_Basic, {Basic_i128, BasicFlag_Integer, 16, STR_LIT("i128")}},
|
||||
{Type_Basic, {Basic_u128, BasicFlag_Integer | BasicFlag_Unsigned, 16, STR_LIT("u128")}},
|
||||
|
||||
{Type_Basic, {Basic_rune, BasicFlag_Integer | BasicFlag_Rune, 4, STR_LIT("rune")}},
|
||||
|
||||
// {Type_Basic, {Basic_f16, BasicFlag_Float, 2, STR_LIT("f16")}},
|
||||
{Type_Basic, {Basic_f32, BasicFlag_Float, 4, STR_LIT("f32")}},
|
||||
@@ -260,10 +262,10 @@ gb_global Type basic_types[] = {
|
||||
{Type_Basic, {Basic_UntypedNil, BasicFlag_Untyped, 0, STR_LIT("untyped nil")}},
|
||||
};
|
||||
|
||||
gb_global Type basic_type_aliases[] = {
|
||||
{Type_Basic, {Basic_byte, BasicFlag_Integer | BasicFlag_Unsigned, 1, STR_LIT("byte")}},
|
||||
{Type_Basic, {Basic_rune, BasicFlag_Integer, 4, STR_LIT("rune")}},
|
||||
};
|
||||
// gb_global Type basic_type_aliases[] = {
|
||||
// // {Type_Basic, {Basic_byte, BasicFlag_Integer | BasicFlag_Unsigned, 1, STR_LIT("byte")}},
|
||||
// // {Type_Basic, {Basic_rune, BasicFlag_Integer, 4, STR_LIT("rune")}},
|
||||
// };
|
||||
|
||||
gb_global Type *t_invalid = &basic_types[Basic_Invalid];
|
||||
gb_global Type *t_bool = &basic_types[Basic_bool];
|
||||
@@ -278,6 +280,8 @@ gb_global Type *t_u64 = &basic_types[Basic_u64];
|
||||
gb_global Type *t_i128 = &basic_types[Basic_i128];
|
||||
gb_global Type *t_u128 = &basic_types[Basic_u128];
|
||||
|
||||
gb_global Type *t_rune = &basic_types[Basic_rune];
|
||||
|
||||
// gb_global Type *t_f16 = &basic_types[Basic_f16];
|
||||
gb_global Type *t_f32 = &basic_types[Basic_f32];
|
||||
gb_global Type *t_f64 = &basic_types[Basic_f64];
|
||||
@@ -301,15 +305,13 @@ gb_global Type *t_untyped_string = &basic_types[Basic_UntypedString];
|
||||
gb_global Type *t_untyped_rune = &basic_types[Basic_UntypedRune];
|
||||
gb_global Type *t_untyped_nil = &basic_types[Basic_UntypedNil];
|
||||
|
||||
gb_global Type *t_byte = &basic_type_aliases[0];
|
||||
gb_global Type *t_rune = &basic_type_aliases[1];
|
||||
|
||||
gb_global Type *t_u8_ptr = NULL;
|
||||
gb_global Type *t_int_ptr = NULL;
|
||||
gb_global Type *t_i64_ptr = NULL;
|
||||
gb_global Type *t_i128_ptr = NULL;
|
||||
gb_global Type *t_f64_ptr = NULL;
|
||||
gb_global Type *t_byte_slice = NULL;
|
||||
gb_global Type *t_u8_slice = NULL;
|
||||
gb_global Type *t_string_slice = NULL;
|
||||
|
||||
|
||||
@@ -323,6 +325,7 @@ gb_global Type *t_type_info_enum_value_ptr = NULL;
|
||||
|
||||
gb_global Type *t_type_info_named = NULL;
|
||||
gb_global Type *t_type_info_integer = NULL;
|
||||
gb_global Type *t_type_info_rune = NULL;
|
||||
gb_global Type *t_type_info_float = NULL;
|
||||
gb_global Type *t_type_info_complex = NULL;
|
||||
gb_global Type *t_type_info_any = NULL;
|
||||
@@ -345,6 +348,7 @@ gb_global Type *t_type_info_bit_field = NULL;
|
||||
|
||||
gb_global Type *t_type_info_named_ptr = NULL;
|
||||
gb_global Type *t_type_info_integer_ptr = NULL;
|
||||
gb_global Type *t_type_info_rune_ptr = NULL;
|
||||
gb_global Type *t_type_info_float_ptr = NULL;
|
||||
gb_global Type *t_type_info_complex_ptr = NULL;
|
||||
gb_global Type *t_type_info_quaternion_ptr = NULL;
|
||||
@@ -646,6 +650,13 @@ bool is_type_unsigned(Type *t) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool is_type_rune(Type *t) {
|
||||
t = core_type(t);
|
||||
if (t->kind == Type_Basic) {
|
||||
return (t->Basic.flags & BasicFlag_Rune) != 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool is_type_numeric(Type *t) {
|
||||
t = core_type(t);
|
||||
if (t->kind == Type_Basic) {
|
||||
@@ -932,6 +943,8 @@ bool is_type_comparable(Type *t) {
|
||||
case Basic_UntypedNil:
|
||||
case Basic_any:
|
||||
return false;
|
||||
case Basic_rune:
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
case Type_Pointer:
|
||||
|
||||
Reference in New Issue
Block a user