table: register u8 type

pull/10988/head
Alexander Medvednikov 2021-07-29 05:00:03 +03:00
parent a7270148e5
commit 628498e0dc
2 changed files with 15 additions and 7 deletions

View File

@ -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 {

View File

@ -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 {