v2: reorder types idxs, > string defined with v struct. rm unresovled

pull/3790/head
joe-conigliaro 2020-02-20 11:39:59 +11:00
parent d2cb5ad725
commit aab1045045
3 changed files with 15 additions and 29 deletions

View File

@ -35,16 +35,16 @@ pub const (
f64_type_idx = 14 f64_type_idx = 14
char_type_idx = 15 char_type_idx = 15
bool_type_idx = 16 bool_type_idx = 16
none_type_idx = 17
// advanced / defined from v structs // advanced / defined from v structs
string_type_idx = 17 string_type_idx = 18
array_type_idx = 18 array_type_idx = 19
map_type_idx = 19 map_type_idx = 20
none_type_idx = 20
) )
pub const ( pub const (
builtin_type_names = ['void', 'voidptr', 'charptr', 'byteptr', 'i8', 'i16', 'int', 'i64', 'u16', 'u32', 'u64', builtin_type_names = ['void', 'voidptr', 'charptr', 'byteptr', 'i8', 'i16', 'int', 'i64', 'u16', 'u32', 'u64',
'f32', 'f64', 'string', 'char', 'byte', 'bool', 'struct', 'array', 'array_fixed', 'map', 'f32', 'f64', 'string', 'char', 'byte', 'bool', 'none', 'array', 'array_fixed', 'map', 'struct',
'mapnode', 'ustring'] 'mapnode', 'ustring']
) )
@ -73,16 +73,15 @@ pub enum Kind {
f64 f64
char char
bool bool
none_
string string
struct_
array array
array_fixed array_fixed
map map
struct_
multi_return multi_return
sum_type sum_type
alias alias
unresolved
none_
} }
[inline] [inline]
@ -226,6 +225,10 @@ pub fn (t mut Table) register_builtin_type_symbols() {
kind: .bool kind: .bool
name: 'bool' name: 'bool'
}) })
t.register_type_symbol(TypeSymbol{
kind: .none_
name: 'none'
})
t.register_type_symbol(TypeSymbol{ t.register_type_symbol(TypeSymbol{
kind: .string kind: .string
name: 'string' name: 'string'
@ -238,10 +241,6 @@ pub fn (t mut Table) register_builtin_type_symbols() {
kind: .map kind: .map
name: 'map' name: 'map'
}) })
t.register_type_symbol(TypeSymbol{
kind: .none_
name: 'none'
})
// TODO: remove // TODO: remove
t.register_type_symbol(TypeSymbol{ t.register_type_symbol(TypeSymbol{
parent_idx: map_type_idx parent_idx: map_type_idx
@ -267,9 +266,6 @@ pub fn (t &TypeSymbol) is_number() bool {
pub fn (k Kind) str() string { pub fn (k Kind) str() string {
k_str := match k { k_str := match k {
.unresolved{
'unresolved'
}
.placeholder{ .placeholder{
'placeholder' 'placeholder'
} }
@ -327,6 +323,9 @@ pub fn (k Kind) str() string {
.bool{ .bool{
'bool' 'bool'
} }
.none_{
'none'
}
.array{ .array{
'array' 'array'
} }

View File

@ -187,14 +187,7 @@ pub fn (t &Table) find_type(name string) ?TypeSymbol {
[inline] [inline]
pub fn (t &Table) get_type_symbol(typ Type) &TypeSymbol { pub fn (t &Table) get_type_symbol(typ Type) &TypeSymbol {
idx := type_idx(typ) idx := type_idx(typ)
if idx < 0 { if idx > 0 {
unresolved_idx := -idx
return &TypeSymbol{
kind: .unresolved
name: 'unresolved-$unresolved_idx'
}
}
else if idx > 0 {
return &t.types[idx] return &t.types[idx]
} }
// this should never happen // this should never happen

View File

@ -57,12 +57,6 @@ pub fn new_type_ptr(idx, nr_muls int) Type {
return idx<<i16(16) | nr_muls return idx<<i16(16) | nr_muls
} }
// true if the type of unresolved expression
[inline]
pub fn type_is_unresolved(t Type) bool {
return type_idx(t) < 0
}
pub const ( pub const (
void_type = new_type(void_type_idx) void_type = new_type(void_type_idx)
voidptr_type = new_type(voidptr_type_idx) voidptr_type = new_type(voidptr_type_idx)