diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 471ddec3d2..3a63ba39d1 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -107,6 +107,7 @@ pub fn (p mut Parser) parse_ti() types.TypeIdent { name: 'array_fixed_$elem_ti.type_name' size: fixed_size elem_type_idx: elem_ti.type_idx + elem_is_ptr: elem_ti.is_ptr() } idx := p.table.find_or_register_array_fixed(array_fixed_type) return types.new_ti(._array_fixed, array_fixed_type.name, idx, nr_muls) @@ -117,6 +118,7 @@ pub fn (p mut Parser) parse_ti() types.TypeIdent { array_type := types.Array{ name: 'array_$elem_ti.type_name' elem_type_idx: elem_ti.type_idx + elem_is_ptr: elem_ti.is_ptr() } idx := p.table.find_or_register_array(array_type) return types.new_ti(._array, array_type.name, idx, nr_muls) @@ -145,12 +147,13 @@ pub fn (p mut Parser) parse_ti() types.TypeIdent { return types.new_ti(._placeholder, name, idx, nr_muls) } - // typ := p.table.types[p.tok.lit] - // if isnil(typ.name.str) || typ.name == '' { - // p.error('undefined type `$p.tok.lit`') - // } - // println('RET Typ $typ.name') - // typ + // typ := p.table.find_type(p.tok.lit) or { + // // typ := p.table.types[p.tok.lit] + // // if isnil(typ.name.str) || typ.name == '' { + // p.error('undefined type `$p.tok.lit`') + // exit(0) + // } + // println('RET Typ $typ.name') } } } @@ -193,18 +196,6 @@ pub fn parse_files(paths []string, table &table.Table) []ast.File { return files } -// former get_type() -// pub fn (p mut Parser) parse_ti() types.Type { -// typ := p.table.find_type(p.tok.lit) or { -// // typ := p.table.types[p.tok.lit] -// // if isnil(typ.name.str) || typ.name == '' { -// p.error('undefined type `$p.tok.lit`') -// exit(0) -// } -// p.next() -// return typ -// } - pub fn (p mut Parser) read_first_token() { // need to call next() twice to get peek token and current token p.next() diff --git a/vlib/v/table/table.v b/vlib/v/table/table.v index f901eae5b5..578112757e 100644 --- a/vlib/v/table/table.v +++ b/vlib/v/table/table.v @@ -126,12 +126,17 @@ pub fn (t mut Table) register_struct(typ types.Struct) int { match ex_type { types.Placeholder { // override placeholder - println('placeholder exists: $it.name overidding') + println('overriding type placeholder `$it.name` with struct') t2 = {typ| idx: existing_idx} t.types[existing_idx] = t2 return existing_idx } - else {} + types.Struct { + return existing_idx + } + else { + panic('cannot register type `$typ.name`, another type with this name exists') + } } } // register @@ -219,4 +224,3 @@ pub fn (t mut Table) new_tmp_var() string { t.tmp_cnt++ return 'tmp$t.tmp_cnt' } - diff --git a/vlib/v/types/types.v b/vlib/v/types/types.v index 29a0fef2c4..fc9133b8e3 100644 --- a/vlib/v/types/types.v +++ b/vlib/v/types/types.v @@ -239,6 +239,7 @@ pub: name string elem_type_kind Kind elem_type_idx int + elem_is_ptr bool nr_dims int } @@ -248,6 +249,7 @@ pub: name string elem_type_kind Kind elem_type_idx int + elem_is_ptr bool size int } @@ -276,7 +278,7 @@ pub: pub fn (t Void) str() string { return 'void' } pub fn (t Voidptr) str() string { return 'voidptr' } pub fn (t Charptr) str() string { return 'charptr' } -pub fn (t Byteptr) str() string { return 'Byteptr' } +pub fn (t Byteptr) str() string { return 'byteptr' } pub fn (t Const) str() string { return t.name } pub fn (t Enum) str() string { return t.name } pub fn (t Struct) str() string { return t.name } @@ -296,9 +298,12 @@ pub const ( voidptr_type = Voidptr{} charptr_type = Charptr{} byteptr_type = Byteptr{} + i8_type = Int{8, false} + i16_type = Int{16, false} int_type = Int{32, false} i64_type = Int{64, false} byte_type = Int{8, true} + u16_type = Int{16, true} u32_type = Int{32, true} u64_type = Int{64, true} f32_type = Float{32}