diff --git a/vlib/v/ast/types.v b/vlib/v/ast/types.v index 67aa88a22a..aab47f53e7 100644 --- a/vlib/v/ast/types.v +++ b/vlib/v/ast/types.v @@ -398,11 +398,14 @@ pub const ( int_literal_type_idx = 26 thread_type_idx = 27 error_type_idx = 28 + u8_type_idx = 29 ) pub const ( integer_type_idxs = [i8_type_idx, i16_type_idx, int_type_idx, i64_type_idx, - byte_type_idx, u16_type_idx, u32_type_idx, u64_type_idx, int_literal_type_idx, rune_type_idx] + byte_type_idx, u8_type_idx, u16_type_idx, u32_type_idx, u64_type_idx, int_literal_type_idx, + rune_type_idx, + ] signed_integer_type_idxs = [i8_type_idx, i16_type_idx, int_type_idx, i64_type_idx] unsigned_integer_type_idxs = [byte_type_idx, u16_type_idx, u32_type_idx, u64_type_idx] float_type_idxs = [f32_type_idx, f64_type_idx, float_literal_type_idx] @@ -424,6 +427,7 @@ pub const ( i16_type = new_type(i16_type_idx) i64_type = new_type(i64_type_idx) byte_type = new_type(byte_type_idx) + u8_type = new_type(u8_type_idx) u16_type = new_type(u16_type_idx) u32_type = new_type(u32_type_idx) u64_type = new_type(u64_type_idx) @@ -457,10 +461,11 @@ pub fn merge_types(params ...[]Type) []Type { } pub const ( + // must be in the same order as the idx consts above builtin_type_names = ['void', 'voidptr', 'charptr', 'byteptr', 'i8', 'i16', 'int', 'i64', 'u16', 'u32', 'u64', 'int_literal', 'f32', 'f64', 'float_literal', 'string', 'char', 'byte', 'bool', 'none', 'array', 'array_fixed', 'map', 'chan', 'any', 'struct', 'mapnode', 'size_t', 'rune', - 'thread', 'Error'] + 'thread', 'Error', 'u8'] ) pub struct MultiReturn { @@ -494,6 +499,7 @@ pub enum Kind { int i64 byte + u8 u16 u32 u64 @@ -664,6 +670,7 @@ pub fn (mut t Table) register_builtin_type_symbols() { } ) t.register_type_symbol(kind: .interface_, name: 'IError', cname: 'IError', mod: 'builtin') + t.register_type_symbol(kind: .u8, name: 'u8', cname: 'u8', mod: 'builtin') } [inline] @@ -719,6 +726,7 @@ pub fn (k Kind) str() string { .i16 { 'i16' } .i64 { 'i64' } .byte { 'byte' } + .u8 { 'u8' } .u16 { 'u16' } .u32 { 'u32' } .u64 { 'u64' } @@ -917,7 +925,7 @@ pub fn (t &Table) type_to_str_using_aliases(typ Type, import_aliases map[string] .int_literal, .float_literal { res = sym.name } - .i8, .i16, .int, .i64, .byte, .u16, .u32, .u64, .f32, .f64, .char, .rune, .string, .bool, + .i8, .i16, .int, .i64, .byte, .u8, .u16, .u32, .u64, .f32, .f64, .char, .rune, .string, .bool, .none_, .byteptr, .voidptr, .charptr { // primitive types if sym.kind == .byteptr { diff --git a/vlib/v/gen/js/builtin_types.v b/vlib/v/gen/js/builtin_types.v index 87b9ab77c7..6fb9115f0e 100644 --- a/vlib/v/gen/js/builtin_types.v +++ b/vlib/v/gen/js/builtin_types.v @@ -19,8 +19,8 @@ fn (mut g JsGen) to_js_typ_val(t ast.Type) string { mut styp := '' mut prefix := if g.file.mod.name == 'builtin' { 'new ' } else { '' } match sym.kind { - .i8, .i16, .int, .i64, .byte, .u16, .u32, .u64, .f32, .f64, .int_literal, .float_literal, - .size_t { + .i8, .i16, .int, .i64, .byte, .u8, .u16, .u32, .u64, .f32, .f64, .int_literal, + .float_literal, .size_t { styp = '$prefix${g.sym_to_js_typ(sym)}(0)' } .bool { @@ -132,8 +132,8 @@ pub fn (mut g JsGen) typ(t ast.Type) string { .byteptr, .charptr { styp = '${g.sym_to_js_typ(sym)}' } - .i8, .i16, .int, .i64, .byte, .u16, .u32, .u64, .f32, .f64, .int_literal, .float_literal, - .size_t { + .i8, .i16, .int, .i64, .byte, .u8, .u16, .u32, .u64, .f32, .f64, .int_literal, + .float_literal, .size_t { styp = '${g.sym_to_js_typ(sym)}' } .bool {