@@ -1618,7 +1618,7 @@ impl QasmCompiler {
1618
1618
}
1619
1619
Type :: Bit ( ..) => build_angle_cast_call_by_name ( "AngleAsResult" , expr, span, span) ,
1620
1620
Type :: BitArray ( ..) => {
1621
- build_angle_cast_call_by_name ( "AngleAsResultArray " , expr, span, span)
1621
+ build_angle_cast_call_by_name ( "AngleAsResultArrayBE " , expr, span, span)
1622
1622
}
1623
1623
Type :: Bool ( ..) => build_angle_cast_call_by_name ( "AngleAsBool" , expr, span, span) ,
1624
1624
_ => err_expr ( span) ,
@@ -1644,21 +1644,18 @@ impl QasmCompiler {
1644
1644
let operand_span = expr. span ;
1645
1645
let name_span = span;
1646
1646
match ty {
1647
- & Type :: Angle ( ..) => {
1647
+ Type :: Angle ( ..) => {
1648
1648
build_angle_cast_call_by_name ( "ResultAsAngle" , expr, name_span, operand_span)
1649
1649
}
1650
- & Type :: Bool ( ..) => {
1650
+ Type :: Bool ( ..) => {
1651
1651
build_convert_cast_call_by_name ( "ResultAsBool" , expr, name_span, operand_span)
1652
1652
}
1653
- & Type :: Float ( ..) => {
1654
- // The spec says that this cast isn't supported, but it
1655
- // casts to other types that case to float. For now, we'll
1656
- // say it is invalid like the spec.
1657
- err_expr ( span)
1653
+ Type :: Float ( ..) => {
1654
+ build_convert_cast_call_by_name ( "ResultAsDouble" , expr, name_span, operand_span)
1658
1655
}
1659
- & Type :: Int ( w, _) | & Type :: UInt ( w, _) => {
1656
+ Type :: Int ( w, _) | Type :: UInt ( w, _) => {
1660
1657
let function = if let Some ( width) = w {
1661
- if width > 64 {
1658
+ if * width > 64 {
1662
1659
"ResultAsBigInt"
1663
1660
} else {
1664
1661
"ResultAsInt"
@@ -1669,6 +1666,16 @@ impl QasmCompiler {
1669
1666
1670
1667
build_convert_cast_call_by_name ( function, expr, name_span, operand_span)
1671
1668
}
1669
+ Type :: BitArray ( size, _) => {
1670
+ let size_expr = build_lit_int_expr ( i64:: from ( * size) , Span :: default ( ) ) ;
1671
+ build_qasmstd_convert_call_with_two_params (
1672
+ "ResultAsResultArrayBE" ,
1673
+ expr,
1674
+ size_expr,
1675
+ name_span,
1676
+ operand_span,
1677
+ )
1678
+ }
1672
1679
_ => err_expr ( span) ,
1673
1680
}
1674
1681
}
@@ -1681,21 +1688,34 @@ impl QasmCompiler {
1681
1688
span : Span ,
1682
1689
) -> qsast:: Expr {
1683
1690
assert ! ( matches!( expr_ty, Type :: BitArray ( _, _) ) ) ;
1691
+ // There is no operand, choosing the span of the node
1692
+ // but we could use the expr span as well.
1693
+ let operand_span = expr. span ;
1694
+ let name_span = span;
1684
1695
1685
- let name_span = expr. span ;
1686
- let operand_span = span;
1687
-
1688
- if !matches ! ( ty, Type :: Int ( ..) | Type :: UInt ( ..) ) {
1689
- return err_expr ( span) ;
1690
- }
1691
- // we know we have a bit array being cast to an int/uint
1692
- // verfiy widths
1693
- let int_width = ty. width ( ) ;
1694
-
1695
- if int_width. is_none ( ) || ( int_width == Some ( size) ) {
1696
- build_convert_cast_call_by_name ( "ResultArrayAsIntBE" , expr, name_span, operand_span)
1697
- } else {
1698
- err_expr ( span)
1696
+ match ty {
1697
+ Type :: Bit ( ..) => build_convert_cast_call_by_name (
1698
+ "ResultArrayAsResultBE" ,
1699
+ expr,
1700
+ name_span,
1701
+ operand_span,
1702
+ ) ,
1703
+ Type :: Bool ( ..) => {
1704
+ build_convert_cast_call_by_name ( "ResultArrayAsBool" , expr, name_span, operand_span)
1705
+ }
1706
+ Type :: Angle ( Some ( width) , _) if * width == size => build_convert_cast_call_by_name (
1707
+ "ResultArrayAsAngleBE" ,
1708
+ expr,
1709
+ name_span,
1710
+ operand_span,
1711
+ ) ,
1712
+ Type :: Int ( Some ( width) , _) | Type :: UInt ( Some ( width) , _) if * width == size => {
1713
+ build_convert_cast_call_by_name ( "ResultArrayAsIntBE" , expr, name_span, operand_span)
1714
+ }
1715
+ Type :: Int ( None , _) | Type :: UInt ( None , _) => {
1716
+ build_convert_cast_call_by_name ( "ResultArrayAsIntBE" , expr, name_span, operand_span)
1717
+ }
1718
+ _ => err_expr ( span) ,
1699
1719
}
1700
1720
}
1701
1721
@@ -1734,6 +1754,16 @@ impl QasmCompiler {
1734
1754
} ;
1735
1755
build_convert_cast_call_by_name ( function, expr, name_span, operand_span)
1736
1756
}
1757
+ Type :: BitArray ( size, _) => {
1758
+ let size_expr = build_lit_int_expr ( i64:: from ( * size) , Span :: default ( ) ) ;
1759
+ build_qasmstd_convert_call_with_two_params (
1760
+ "BoolAsResultArrayBE" ,
1761
+ expr,
1762
+ size_expr,
1763
+ name_span,
1764
+ operand_span,
1765
+ )
1766
+ }
1737
1767
_ => err_expr ( span) ,
1738
1768
}
1739
1769
}
@@ -1776,6 +1806,8 @@ impl QasmCompiler {
1776
1806
span : Span ,
1777
1807
) -> qsast:: Expr {
1778
1808
assert ! ( matches!( expr_ty, Type :: Float ( ..) ) ) ;
1809
+ let name_span = expr. span ;
1810
+ let operand_span = span;
1779
1811
1780
1812
match ty {
1781
1813
& Type :: Complex ( ..) => build_complex_from_expr ( expr) ,
@@ -1818,6 +1850,9 @@ impl QasmCompiler {
1818
1850
span,
1819
1851
)
1820
1852
}
1853
+ & Type :: Bit ( ..) => {
1854
+ build_convert_cast_call_by_name ( "DoubleAsResult" , expr, name_span, operand_span)
1855
+ }
1821
1856
_ => err_expr ( span) ,
1822
1857
}
1823
1858
}
0 commit comments