Fix polymorphic element types usage; Empty union as opaque type

This commit is contained in:
Ginger Bill
2017-07-20 19:40:51 +01:00
parent 13bc6eeea4
commit 9a3b4167bb
14 changed files with 228 additions and 170 deletions
+13 -1
View File
@@ -314,7 +314,6 @@ copy :: proc(dst, src: $T/[]$E) -> int #cc_contextless {
}
append :: proc(array: ^$T/[]$E, args: ...E) -> int #cc_contextless {
if array == nil do return 0;
@@ -356,6 +355,19 @@ append :: proc(array: ^$T/[dynamic]$E, args: ...E) -> int {
return len(array);
}
append :: proc(array: ^$T/[]u8, args: ...string) -> int {
for arg in args {
append(array, ...cast([]u8)arg);
}
return len(array);
}
append :: proc(array: ^$T/[dynamic]u8, args: ...string) -> int {
for arg in args {
append(array, ...cast([]u8)arg);
}
return len(array);
}
pop :: proc(array: ^$T/[]$E) -> E #cc_contextless {
if array == nil do return E{};
assert(len(array) > 0);
+12 -5
View File
@@ -186,7 +186,8 @@ write_type :: proc(buf: ^StringBuffer, ti: ^TypeInfo) {
case ti == type_info_of(int): write_string(buf, "int");
case ti == type_info_of(uint): write_string(buf, "uint");
case:
write_string(buf, info.signed ? "i" : "u");
if info.signed do write_byte(buf, 'i');
else do write_byte(buf, 'u');
write_int(buf, i64(8*ti.size), 10);
}
case Rune:
@@ -424,7 +425,9 @@ fmt_bad_verb :: proc(using fi: ^FmtInfo, verb: rune) {
fmt_bool :: proc(using fi: ^FmtInfo, b: bool, verb: rune) {
match verb {
case 't', 'v':
write_string(buf, b ? "true" : "false");
s := "false";
if b do s = "true";
write_string(buf, s);
case:
fmt_bad_verb(fi, verb);
}
@@ -434,7 +437,8 @@ fmt_bool :: proc(using fi: ^FmtInfo, b: bool, verb: rune) {
fmt_write_padding :: proc(fi: ^FmtInfo, width: int) {
if width <= 0 do return;
pad_byte: u8 = fi.space ? ' ' : '0';
pad_byte: u8 = '0';
if fi.space do pad_byte = ' ';
for _ in 0..width {
write_byte(fi.buf, pad_byte);
@@ -569,7 +573,8 @@ fmt_float :: proc(fi: ^FmtInfo, v: f64, bit_size: int, verb: rune) {
// case 'f', 'F', 'v':
case 'f', 'F', 'v':
prec: int = fi.prec_set ? fi.prec : 3;
prec: int = 3;
if fi.prec_set do prec = fi.prec;
buf: [386]u8;
str := strconv.append_float(buf[1..1], v, 'f', prec, bit_size);
@@ -617,7 +622,9 @@ fmt_string :: proc(fi: ^FmtInfo, s: string, verb: rune) {
for i in 0..len(s) {
if i > 0 && space do write_byte(fi.buf, ' ');
_fmt_int(fi, u128(s[i]), 16, false, 8, verb == 'x' ? __DIGITS_LOWER : __DIGITS_UPPER);
char_set := __DIGITS_UPPER;
if verb == 'x' do char_set = __DIGITS_LOWER;
_fmt_int(fi, u128(s[i]), 16, false, 8, char_set);
}
case:
+14 -11
View File
@@ -54,8 +54,8 @@ unlerp :: proc(a, b, x: f32) -> (t: f32) do return (x-a)/(b-a);
unlerp :: proc(a, b, x: f64) -> (t: f64) do return (x-a)/(b-a);
sign :: proc(x: f32) -> f32 do return x >= 0 ? +1 : -1;
sign :: proc(x: f64) -> f64 do return x >= 0 ? +1 : -1;
sign :: proc(x: f32) -> f32 { if x >= 0 do return +1; return -1; }
sign :: proc(x: f64) -> f64 { if x >= 0 do return +1; return -1; }
@@ -75,14 +75,14 @@ copy_sign :: proc(x, y: f64) -> f64 {
return transmute(f64, ix);
}
round :: proc(x: f32) -> f32 do return x >= 0 ? floor(x + 0.5) : ceil(x - 0.5);
round :: proc(x: f64) -> f64 do return x >= 0 ? floor(x + 0.5) : ceil(x - 0.5);
round :: proc(x: f32) -> f32 { if x >= 0 do return floor(x + 0.5); return ceil(x - 0.5); }
round :: proc(x: f64) -> f64 { if x >= 0 do return floor(x + 0.5); return ceil(x - 0.5); }
floor :: proc(x: f32) -> f32 do return x >= 0 ? f32(i64(x)) : f32(i64(x-0.5)); // TODO: Get accurate versions
floor :: proc(x: f64) -> f64 do return x >= 0 ? f64(i64(x)) : f64(i64(x-0.5)); // TODO: Get accurate versions
floor :: proc(x: f32) -> f32 { if x >= 0 do f32(i64(x)) return f32(i64(x-0.5)); } // TODO: Get accurate versions
floor :: proc(x: f64) -> f64 { if x >= 0 do f64(i64(x)) return f64(i64(x-0.5)); } // TODO: Get accurate versions
ceil :: proc(x: f32) -> f32 do return x < 0 ? f32(i64(x)) : f32(i64(x+1)); // TODO: Get accurate versions
ceil :: proc(x: f64) -> f64 do return x < 0 ? f64(i64(x)) : f64(i64(x+1)); // TODO: Get accurate versions
ceil :: proc(x: f32) -> f32 { if x < 0 do f32(i64(x)) return f32(i64(x+1)); }// TODO: Get accurate versions
ceil :: proc(x: f64) -> f64 { if x < 0 do f64(i64(x)) return f64(i64(x+1)); }// TODO: Get accurate versions
remainder :: proc(x, y: f32) -> f32 do return x - round(x/y) * y;
remainder :: proc(x, y: f64) -> f64 do return x - round(x/y) * y;
@@ -133,17 +133,20 @@ norm :: proc(v: $T/[vector 4]$E) -> T do return v / mag(v);
norm0 :: proc(v: $T/[vector 2]$E) -> T {
m := mag(v);
return m == 0 ? 0 : v/m;
if m == 0 do return 0;
return v/m;
}
norm0 :: proc(v: $T/[vector 3]$E) -> T {
m := mag(v);
return m == 0 ? 0 : v/m;
if m == 0 do return 0;
return v/m;
}
norm0 :: proc(v: $T/[vector 4]$E) -> T {
m := mag(v);
return m == 0 ? 0 : v/m;
if m == 0 do return 0;
return v/m;
}
+20 -24
View File
@@ -67,7 +67,8 @@ parse_i128 :: proc(s: string) -> i128 {
value += v;
}
return neg ? -value : value;
if neg do return -value;
return value;
}
parse_u128 :: proc(s: string) -> u128 {
@@ -91,19 +92,15 @@ parse_u128 :: proc(s: string) -> u128 {
value: u128;
for r in s {
if r == '_' {
continue;
}
if r == '_' do continue;
v := u128(_digit_value(r));
if v >= base {
break;
}
if v >= base do break;
value *= base;
value += u128(v);
}
return neg ? -value : value;
if neg do return -value;
return value;
}
@@ -127,6 +124,7 @@ parse_f64 :: proc(s: string) -> f64 {
for ; i < len(s); i += 1 {
r := rune(s[i]);
if r == '_' do continue;
v := _digit_value(r);
if v >= 10 do break;
value *= 10;
@@ -139,13 +137,10 @@ parse_f64 :: proc(s: string) -> f64 {
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 += f64(v)/pow10;
pow10 *= 10;
}
@@ -165,13 +160,10 @@ parse_f64 :: proc(s: string) -> f64 {
exp: u32 = 0;
for ; i < len(s); i += 1 {
r := rune(s[i]);
if r == '_' {
continue;
}
if r == '_' do continue;
d := u32(_digit_value(r));
if d >= 10 {
break;
}
if d >= 10 do break;
exp = exp * 10 + d;
}
if exp > 308 { exp = 308; }
@@ -181,13 +173,17 @@ parse_f64 :: proc(s: string) -> f64 {
for exp > 0 { scale *= 10; exp -= 1; }
}
return sign * (frac ? (value/scale) : (value*scale));
if frac do return sign * (value/scale);
return sign * (value*scale);
}
append_bool :: proc(buf: []u8, b: bool) -> string {
s := b ? "true" : "false";
append(&buf, ...cast([]u8)s);
if b {
append(&buf, "true");
} else {
append(&buf, "false");
}
return string(buf);
}