(&mut self, ty: &Type, addr: B::Operand, offset: ArchitectureSize)
| 1951 | } |
| 1952 | |
| 1953 | fn write_to_memory(&mut self, ty: &Type, addr: B::Operand, offset: ArchitectureSize) { |
| 1954 | use Instruction::*; |
| 1955 | |
| 1956 | match *ty { |
| 1957 | // Builtin types need different flavors of storage instructions |
| 1958 | // depending on the size of the value written. |
| 1959 | Type::Bool | Type::U8 | Type::S8 => { |
| 1960 | self.lower_and_emit(ty, addr, &I32Store8 { offset }) |
| 1961 | } |
| 1962 | Type::U16 | Type::S16 => self.lower_and_emit(ty, addr, &I32Store16 { offset }), |
| 1963 | Type::U32 | Type::S32 | Type::Char => { |
| 1964 | self.lower_and_emit(ty, addr, &I32Store { offset }) |
| 1965 | } |
| 1966 | Type::U64 | Type::S64 => self.lower_and_emit(ty, addr, &I64Store { offset }), |
| 1967 | Type::F32 => self.lower_and_emit(ty, addr, &F32Store { offset }), |
| 1968 | Type::F64 => self.lower_and_emit(ty, addr, &F64Store { offset }), |
| 1969 | Type::String => self.write_list_to_memory(ty, addr, offset), |
| 1970 | Type::ErrorContext => self.lower_and_emit(ty, addr, &I32Store { offset }), |
| 1971 | |
| 1972 | Type::Id(id) => match &self.resolve.types[id].kind { |
| 1973 | TypeDefKind::Type(t) => self.write_to_memory(t, addr, offset), |
| 1974 | TypeDefKind::List(_) => self.write_list_to_memory(ty, addr, offset), |
| 1975 | // Maps have the same linear memory layout as list<tuple<K, V>>. |
| 1976 | TypeDefKind::Map(_, _) => self.write_list_to_memory(ty, addr, offset), |
| 1977 | |
| 1978 | TypeDefKind::Future(_) | TypeDefKind::Stream(_) | TypeDefKind::Handle(_) => { |
| 1979 | self.lower_and_emit(ty, addr, &I32Store { offset }) |
| 1980 | } |
| 1981 | |
| 1982 | // Decompose the record into its components and then write all |
| 1983 | // the components into memory one-by-one. |
| 1984 | TypeDefKind::Record(record) => { |
| 1985 | self.emit(&RecordLower { |
| 1986 | record, |
| 1987 | ty: id, |
| 1988 | name: self.resolve.types[id].name.as_deref().unwrap(), |
| 1989 | }); |
| 1990 | self.write_fields_to_memory(record.fields.iter().map(|f| &f.ty), addr, offset); |
| 1991 | } |
| 1992 | TypeDefKind::Resource => { |
| 1993 | todo!() |
| 1994 | } |
| 1995 | TypeDefKind::Tuple(tuple) => { |
| 1996 | self.emit(&TupleLower { tuple, ty: id }); |
| 1997 | self.write_fields_to_memory(tuple.types.iter(), addr, offset); |
| 1998 | } |
| 1999 | |
| 2000 | TypeDefKind::Flags(f) => { |
| 2001 | self.lower(ty); |
| 2002 | match f.repr() { |
| 2003 | FlagsRepr::U8 => { |
| 2004 | self.stack.push(addr); |
| 2005 | self.store_intrepr(offset, Int::U8); |
| 2006 | } |
| 2007 | FlagsRepr::U16 => { |
| 2008 | self.stack.push(addr); |
| 2009 | self.store_intrepr(offset, Int::U16); |
| 2010 | } |
no test coverage detected