v: small fixes typo & register struct & and add array elem pointer

pull/3334/head
joe-conigliaro 2020-01-05 21:52:03 +11:00 committed by Alexander Medvednikov
parent 2061394ad7
commit 5a6f9024d3
3 changed files with 22 additions and 22 deletions

View File

@ -107,6 +107,7 @@ pub fn (p mut Parser) parse_ti() types.TypeIdent {
name: 'array_fixed_$elem_ti.type_name' name: 'array_fixed_$elem_ti.type_name'
size: fixed_size size: fixed_size
elem_type_idx: elem_ti.type_idx 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) idx := p.table.find_or_register_array_fixed(array_fixed_type)
return types.new_ti(._array_fixed, array_fixed_type.name, idx, nr_muls) 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{ array_type := types.Array{
name: 'array_$elem_ti.type_name' name: 'array_$elem_ti.type_name'
elem_type_idx: elem_ti.type_idx elem_type_idx: elem_ti.type_idx
elem_is_ptr: elem_ti.is_ptr()
} }
idx := p.table.find_or_register_array(array_type) idx := p.table.find_or_register_array(array_type)
return types.new_ti(._array, array_type.name, idx, nr_muls) 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) return types.new_ti(._placeholder, name, idx, nr_muls)
} }
// typ := p.table.types[p.tok.lit] // typ := p.table.find_type(p.tok.lit) or {
// if isnil(typ.name.str) || typ.name == '' { // // typ := p.table.types[p.tok.lit]
// p.error('undefined type `$p.tok.lit`') // // if isnil(typ.name.str) || typ.name == '' {
// } // p.error('undefined type `$p.tok.lit`')
// println('RET Typ $typ.name') // exit(0)
// typ // }
// println('RET Typ $typ.name')
} }
} }
} }
@ -193,18 +196,6 @@ pub fn parse_files(paths []string, table &table.Table) []ast.File {
return files 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() { pub fn (p mut Parser) read_first_token() {
// need to call next() twice to get peek token and current token // need to call next() twice to get peek token and current token
p.next() p.next()

View File

@ -126,12 +126,17 @@ pub fn (t mut Table) register_struct(typ types.Struct) int {
match ex_type { match ex_type {
types.Placeholder { types.Placeholder {
// override placeholder // override placeholder
println('placeholder exists: $it.name overidding') println('overriding type placeholder `$it.name` with struct')
t2 = {typ| idx: existing_idx} t2 = {typ| idx: existing_idx}
t.types[existing_idx] = t2 t.types[existing_idx] = t2
return existing_idx return existing_idx
} }
else {} types.Struct {
return existing_idx
}
else {
panic('cannot register type `$typ.name`, another type with this name exists')
}
} }
} }
// register // register
@ -219,4 +224,3 @@ pub fn (t mut Table) new_tmp_var() string {
t.tmp_cnt++ t.tmp_cnt++
return 'tmp$t.tmp_cnt' return 'tmp$t.tmp_cnt'
} }

View File

@ -239,6 +239,7 @@ pub:
name string name string
elem_type_kind Kind elem_type_kind Kind
elem_type_idx int elem_type_idx int
elem_is_ptr bool
nr_dims int nr_dims int
} }
@ -248,6 +249,7 @@ pub:
name string name string
elem_type_kind Kind elem_type_kind Kind
elem_type_idx int elem_type_idx int
elem_is_ptr bool
size int size int
} }
@ -276,7 +278,7 @@ pub:
pub fn (t Void) str() string { return 'void' } pub fn (t Void) str() string { return 'void' }
pub fn (t Voidptr) str() string { return 'voidptr' } pub fn (t Voidptr) str() string { return 'voidptr' }
pub fn (t Charptr) str() string { return 'charptr' } 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 Const) str() string { return t.name }
pub fn (t Enum) str() string { return t.name } pub fn (t Enum) str() string { return t.name }
pub fn (t Struct) str() string { return t.name } pub fn (t Struct) str() string { return t.name }
@ -296,9 +298,12 @@ pub const (
voidptr_type = Voidptr{} voidptr_type = Voidptr{}
charptr_type = Charptr{} charptr_type = Charptr{}
byteptr_type = Byteptr{} byteptr_type = Byteptr{}
i8_type = Int{8, false}
i16_type = Int{16, false}
int_type = Int{32, false} int_type = Int{32, false}
i64_type = Int{64, false} i64_type = Int{64, false}
byte_type = Int{8, true} byte_type = Int{8, true}
u16_type = Int{16, true}
u32_type = Int{32, true} u32_type = Int{32, true}
u64_type = Int{64, true} u64_type = Int{64, true}
f32_type = Float{32} f32_type = Float{32}