table: remove fn to set idx & add new derive fn

pull/5231/head
joe-conigliaro 2020-06-06 12:51:36 +10:00
parent 31d03bb113
commit c2fe4ffa85
No known key found for this signature in database
GPG Key ID: C12F7136C08206F1
3 changed files with 8 additions and 10 deletions

View File

@ -1743,8 +1743,7 @@ fn (mut c Checker) stmts(stmts []ast.Stmt) {
pub fn (c &Checker) unwrap_generic(typ table.Type) table.Type { pub fn (c &Checker) unwrap_generic(typ table.Type) table.Type {
if typ.idx() == table.t_type_idx { if typ.idx() == table.t_type_idx {
// return c.cur_generic_type // return c.cur_generic_type
// its more efficient to set the id rather than to copy flags/nr_muls return c.cur_generic_type.derive(typ)
return typ.set_idx(c.cur_generic_type)
} }
return typ return typ
} }

View File

@ -331,8 +331,7 @@ fn (mut g Gen) call_expr(node ast.CallExpr) {
pub fn (g &Gen) unwrap_generic(typ table.Type) table.Type { pub fn (g &Gen) unwrap_generic(typ table.Type) table.Type {
if typ.idx() == table.t_type_idx { if typ.idx() == table.t_type_idx {
// return g.cur_generic_type // return g.cur_generic_type
// its more efficient to set the id rather than to copy flags/nr_muls return g.cur_generic_type.derive(typ)
return typ.set_idx(g.cur_generic_type)
} }
return typ return typ
} }

View File

@ -70,12 +70,6 @@ pub fn (t Type) is_ptr() bool {
return (int(t) >> 16) & 0xff > 0 return (int(t) >> 16) & 0xff > 0
} }
// set idx on `t` and return it
[inline]
pub fn (t Type) set_idx(idx int) Type {
return (((int(t) >> 24) & 0xff) << 24) | (((int(t) >> 16) & 0xff) << 16) | (u16(idx) & 0xffff)
}
// set nr_muls on `t` and return it // set nr_muls on `t` and return it
[inline] [inline]
pub fn (t Type) set_nr_muls(nr_muls int) Type { pub fn (t Type) set_nr_muls(nr_muls int) Type {
@ -129,6 +123,12 @@ pub fn (t Type) has_flag(flag TypeFlag) bool {
return (((int(t) >> 24) & 0xff) >> int(flag)) & 1 == 1 return (((int(t) >> 24) & 0xff) >> int(flag)) & 1 == 1
} }
// copy flags & nr_muls from `t_from` to `t` and return `t`
[inline]
pub fn (t Type) derive(t_from Type) Type {
return (((int(t_from) >> 24) & 0xff) << 24) | (((int(t_from) >> 16) & 0xff) << 16) | (u16(t) & 0xffff)
}
// return new type with TypeSymbol idx set to `idx` // return new type with TypeSymbol idx set to `idx`
[inline] [inline]
pub fn new_type(idx int) Type { pub fn new_type(idx int) Type {