remove u8 and i32 aliases

pull/1819/head
Alexander Medvednikov 2019-09-01 22:37:22 +03:00
parent d078aa360b
commit 3bd7bcfac3
7 changed files with 27 additions and 51 deletions

View File

@ -124,8 +124,8 @@ string res = tos2("");
fn is_js_prim(typ string) bool {
return typ == 'int' || typ == 'string' ||
typ == 'bool' || typ == 'f32' || typ == 'f64' ||
typ == 'i8' || typ == 'i16' || typ == 'i32' || typ == 'i64' ||
typ == 'u8' || typ == 'u16' || typ == 'u32' || typ == 'u64'
typ == 'i8' || typ == 'i16' || typ == 'i64' ||
typ == 'u16' || typ == 'u32' || typ == 'u64'
}
fn (p mut Parser) decode_array(array_type string) string {

View File

@ -195,7 +195,7 @@ fn (t &Table) debug_fns() string {
// fn (types array_Type) print_to_file(f string) {
// }
const (
number_types = ['number', 'int', 'i8', 'u8', 'i16', 'u16', 'i32', 'u32', 'byte', 'i64', 'u64', 'f32', 'f64']
number_types = ['number', 'int', 'i8', 'i16', 'u16', 'u32', 'byte', 'i64', 'u64', 'f32', 'f64']
float_types = ['f32', 'f64']
)
@ -218,12 +218,10 @@ fn new_table(obfuscate bool) *Table {
t.register_type('int')
t.register_type('size_t')
t.register_type_with_parent('i8', 'int')
t.register_type_with_parent('u8', 'u32')
t.register_type_with_parent('byte', 'int')
t.register_type_with_parent('i16', 'int')
t.register_type_with_parent('u16', 'u32')
t.register_type_with_parent('i32', 'int')
t.register_type_with_parent('u32', 'int')
t.register_type_with_parent('byte', 'int')
t.register_type_with_parent('i64', 'int')
t.register_type_with_parent('u64', 'u32')
t.register_type('byteptr')
@ -650,9 +648,7 @@ fn type_default(typ string) string {
case 'string': return 'tos((byte *)"", 0)'
case 'i8': return '0'
case 'i16': return '0'
case 'i32': return '0'
case 'i64': return '0'
case 'u8': return '0'
case 'u16': return '0'
case 'u32': return '0'
case 'u64': return '0'
@ -760,14 +756,14 @@ fn (table &Table) cgen_name_type_pair(name, typ string) string {
fn is_valid_int_const(val, typ string) bool {
x := val.int()
switch typ {
case 'byte', 'u8': return 0 <= x && x <= math.MaxU8
case 'u8': return 0 <= x && x <= math.MaxU8
case 'u16': return 0 <= x && x <= math.MaxU16
//case 'u32': return 0 <= x && x <= math.MaxU32
//case 'u64': return 0 <= x && x <= math.MaxU64
//////////////
case 'i8': return math.MinI8 <= x && x <= math.MaxI8
case 'i16': return math.MinI16 <= x && x <= math.MaxI16
case 'int', 'i32': return math.MinI32 <= x && x <= math.MaxI32
case 'int': return math.MinI32 <= x && x <= math.MaxI32
//case 'i64':
//x64 := val.i64()
//return i64(-(1<<63)) <= x64 && x64 <= i64((1<<63)-1)
@ -810,8 +806,8 @@ fn (p mut Parser) typ_to_fmt(typ string, level int) string {
case 'string': return '%.*s'
//case 'bool': return '%.*s'
case 'ustring': return '%.*s'
case 'byte', 'bool', 'int', 'char', 'byte', 'i32', 'i16', 'i8': return '%d'
case 'u8', 'u16', 'u32': return '%u'
case 'byte', 'bool', 'int', 'char', 'byte', 'i16', 'i8': return '%d'
case 'u16', 'u32': return '%u'
case 'f64', 'f32': return '%f'
case 'i64': return '%lld'
case 'u64': return '%llu'

View File

@ -80,6 +80,7 @@ pub fn (nn u32) str() string {
return tos(buf + max - len, len)
}
/*
pub fn (nn u8) str() string {
mut n := nn
if n == u8(0) {
@ -97,6 +98,7 @@ pub fn (nn u8) str() string {
}
return tos(buf + max - len, len)
}
*/
pub fn (nn i64) str() string {
mut n := nn

View File

@ -15,8 +15,8 @@ fn test_str_methods() {
assert i8(-1).str() == '-1'
assert i16(1).str() == '1'
assert i16(-1).str() == '-1'
assert i32(1).str() == '1'
assert i32(-1).str() == '-1'
assert int(1).str() == '1'
assert int(-1).str() == '-1'
assert i64(1).str() == '1'
assert i64(-1).str() == '-1'

View File

@ -102,14 +102,6 @@ fn test_various_map_value() {
m4['test'] = i16(0)
assert m4['test'] == i16(0)
mut m5 := map[string]i32
m5['test'] = i32(0)
assert m5['test'] == i32(0)
mut m6 := map[string]u8
m6['test'] = u8(0)
assert m6['test'] == u8(0)
mut m7 := map[string]u16
m7['test'] = u16(0)
assert m7['test'] == u16(0)

View File

@ -132,9 +132,6 @@ pub fn (s string) int() int {
return C.atoi(s.str)
}
pub fn (s string) i32() i32 {
return C.atol(s.str)
}
pub fn (s string) i64() i64 {
return C.atoll(s.str)

View File

@ -35,13 +35,6 @@ fn jsdecode_i16(root *C.cJSON) i16 {
return i16(root.valueint)
}
fn jsdecode_i32(root *C.cJSON) i32 {
if isnil(root) {
return i32(0)
}
return i32(root.valueint)
}
fn jsdecode_i64(root *C.cJSON) i64 {
if isnil(root) {
return i64(0)
@ -49,11 +42,11 @@ fn jsdecode_i64(root *C.cJSON) i64 {
return i64(root.valuedouble) //i64 is double in C
}
fn jsdecode_u8(root *C.cJSON) u8 {
fn jsdecode_byte(root *C.cJSON) byte {
if isnil(root) {
return u8(0)
return byte(0)
}
return u8(root.valueint)
return byte(root.valueint)
}
fn jsdecode_u16(root *C.cJSON) u16 {
@ -124,15 +117,11 @@ fn jsencode_i16(val i16) *C.cJSON {
return C.cJSON_CreateNumber(val)
}
fn jsencode_i32(val i32) *C.cJSON {
return C.cJSON_CreateNumber(val)
}
fn jsencode_i64(val i64) *C.cJSON {
return C.cJSON_CreateNumber(val)
}
fn jsencode_u8(val u8) *C.cJSON {
fn jsencode_byte(val byte) *C.cJSON {
return C.cJSON_CreateNumber(val)
}