(&mut self, idx: u32, ty: &'a Type)
| 1388 | } |
| 1389 | |
| 1390 | fn write_decl(&mut self, idx: u32, ty: &'a Type) -> String { |
| 1391 | let mut decl = format!("(type $t{idx}' "); |
| 1392 | match ty { |
| 1393 | Type::Bool |
| 1394 | | Type::S8 |
| 1395 | | Type::U8 |
| 1396 | | Type::S16 |
| 1397 | | Type::U16 |
| 1398 | | Type::S32 |
| 1399 | | Type::U32 |
| 1400 | | Type::S64 |
| 1401 | | Type::U64 |
| 1402 | | Type::Float32 |
| 1403 | | Type::Float64 |
| 1404 | | Type::Char |
| 1405 | | Type::String => unreachable!(), |
| 1406 | |
| 1407 | Type::List(ty) => { |
| 1408 | decl.push_str("(list "); |
| 1409 | self.write_ref(ty, &mut decl); |
| 1410 | decl.push_str(")"); |
| 1411 | } |
| 1412 | Type::Map(key_ty, value_ty) => { |
| 1413 | decl.push_str("(map "); |
| 1414 | self.write_ref(key_ty, &mut decl); |
| 1415 | decl.push_str(" "); |
| 1416 | self.write_ref(value_ty, &mut decl); |
| 1417 | decl.push_str(")"); |
| 1418 | } |
| 1419 | Type::Record(types) => { |
| 1420 | decl.push_str("(record"); |
| 1421 | for (index, ty) in types.iter().enumerate() { |
| 1422 | uwrite!(decl, r#" (field "f{index}" "#); |
| 1423 | self.write_ref(ty, &mut decl); |
| 1424 | decl.push_str(")"); |
| 1425 | } |
| 1426 | decl.push_str(")"); |
| 1427 | } |
| 1428 | Type::Tuple(types) => { |
| 1429 | decl.push_str("(tuple"); |
| 1430 | for ty in types.iter() { |
| 1431 | decl.push_str(" "); |
| 1432 | self.write_ref(ty, &mut decl); |
| 1433 | } |
| 1434 | decl.push_str(")"); |
| 1435 | } |
| 1436 | Type::Variant(types) => { |
| 1437 | decl.push_str("(variant"); |
| 1438 | for (index, ty) in types.iter().enumerate() { |
| 1439 | uwrite!(decl, r#" (case "C{index}""#); |
| 1440 | if let Some(ty) = ty { |
| 1441 | decl.push_str(" "); |
| 1442 | self.write_ref(ty, &mut decl); |
| 1443 | } |
| 1444 | decl.push_str(")"); |
| 1445 | } |
| 1446 | decl.push_str(")"); |
| 1447 | } |
no test coverage detected