@@ -248,6 +248,8 @@ pub(crate) fn build_expr_array_expr(values: Vec<qsc_ast::ast::Expr>, span: Span)
248
248
}
249
249
}
250
250
251
+ // This will be used to compile arrays in the near future.
252
+ #[ allow( dead_code) ]
251
253
pub ( crate ) fn build_default_result_array_expr ( len : usize , span : Span ) -> Expr {
252
254
let exprs: Vec < _ > = ( 0 ..len)
253
255
. map ( |_| Box :: new ( build_lit_result_expr ( ast:: Result :: Zero , Span :: default ( ) ) ) )
@@ -363,35 +365,6 @@ pub(crate) fn build_binary_expr(
363
365
}
364
366
}
365
367
366
- pub ( crate ) fn is_complex_binop_supported ( op : qsc_ast:: ast:: BinOp ) -> bool {
367
- matches ! (
368
- op,
369
- ast:: BinOp :: Add | ast:: BinOp :: Sub | ast:: BinOp :: Mul | ast:: BinOp :: Div | ast:: BinOp :: Exp
370
- )
371
- }
372
-
373
- pub ( crate ) fn build_complex_binary_expr (
374
- is_assignment : bool ,
375
- qsop : ast:: BinOp ,
376
- lhs : ast:: Expr ,
377
- rhs : ast:: Expr ,
378
- span : Span ,
379
- ) -> ast:: Expr {
380
- let name = match qsop {
381
- ast:: BinOp :: Add => "PlusC" ,
382
- ast:: BinOp :: Sub => "MinusC" ,
383
- ast:: BinOp :: Mul => "TimesC" ,
384
- ast:: BinOp :: Div => "DividedByC" ,
385
- ast:: BinOp :: Exp => "PowC" ,
386
- _ => unreachable ! ( "Unsupported complex binary operation" ) ,
387
- } ;
388
-
389
- if is_assignment {
390
- unreachable ! ( "Unsupported complex binary operation" ) ;
391
- }
392
- build_math_call_from_exprs ( name, vec ! [ lhs, rhs] , span)
393
- }
394
-
395
368
pub ( crate ) fn build_math_call_from_exprs ( name : & str , exprs : Vec < Expr > , span : Span ) -> Expr {
396
369
let alloc_ident = Ident {
397
370
name : Rc :: from ( name) ,
@@ -942,14 +915,6 @@ pub(crate) fn build_wrapped_block_expr(block: Block) -> Expr {
942
915
}
943
916
}
944
917
945
- pub ( crate ) fn build_stmt_wrapped_block_expr ( stmt : Stmt ) -> Block {
946
- Block {
947
- id : NodeId :: default ( ) ,
948
- span : stmt. span ,
949
- stmts : Box :: new ( [ Box :: new ( stmt) ] ) ,
950
- }
951
- }
952
-
953
918
pub ( crate ) fn build_expr_wrapped_block_expr ( expr : Expr ) -> Block {
954
919
Block {
955
920
id : NodeId :: default ( ) ,
@@ -1185,14 +1150,6 @@ pub(crate) fn build_top_level_ns_with_items<S: AsRef<str>>(
1185
1150
} )
1186
1151
}
1187
1152
1188
- pub ( crate ) fn build_top_level_ns_with_item < S : AsRef < str > > (
1189
- whole_span : Span ,
1190
- ns : S ,
1191
- entry : ast:: Item ,
1192
- ) -> TopLevelNode {
1193
- build_top_level_ns_with_items ( whole_span, ns, vec ! [ entry] )
1194
- }
1195
-
1196
1153
pub ( crate ) fn build_operation_with_stmts < S : AsRef < str > > (
1197
1154
name : S ,
1198
1155
input_pats : Vec < Pat > ,
@@ -1459,200 +1416,6 @@ pub(crate) fn build_barrier_call(span: Span) -> Stmt {
1459
1416
build_stmt_semi_from_expr ( expr)
1460
1417
}
1461
1418
1462
- pub ( crate ) fn build_gate_decl (
1463
- name : String ,
1464
- cargs : Vec < ( String , Ty , Pat ) > ,
1465
- qargs : Vec < ( String , Ty , Pat ) > ,
1466
- body : Option < Block > ,
1467
- name_span : Span ,
1468
- body_span : Span ,
1469
- gate_span : Span ,
1470
- ) -> Stmt {
1471
- let args = cargs
1472
- . into_iter ( )
1473
- . chain ( qargs)
1474
- . map ( |( _, _, pat) | Box :: new ( pat) )
1475
- . collect :: < Vec < _ > > ( ) ;
1476
-
1477
- let lo = args
1478
- . iter ( )
1479
- . min_by_key ( |x| x. span . lo )
1480
- . map ( |x| x. span . lo )
1481
- . unwrap_or_default ( ) ;
1482
-
1483
- let hi = args
1484
- . iter ( )
1485
- . max_by_key ( |x| x. span . hi )
1486
- . map ( |x| x. span . hi )
1487
- . unwrap_or_default ( ) ;
1488
-
1489
- let input_pat_kind = if args. len ( ) > 1 {
1490
- PatKind :: Tuple ( args. into_boxed_slice ( ) )
1491
- } else {
1492
- PatKind :: Paren ( args[ 0 ] . clone ( ) )
1493
- } ;
1494
-
1495
- let input_pat = Pat {
1496
- kind : Box :: new ( input_pat_kind) ,
1497
- span : Span { lo, hi } ,
1498
- ..Default :: default ( )
1499
- } ;
1500
- let body = CallableBody :: Block ( Box :: new ( body. unwrap_or_else ( || Block {
1501
- id : NodeId :: default ( ) ,
1502
- span : body_span,
1503
- stmts : Box :: new ( [ ] ) ,
1504
- } ) ) ) ;
1505
- let decl = CallableDecl {
1506
- id : NodeId :: default ( ) ,
1507
- span : name_span,
1508
- kind : CallableKind :: Operation ,
1509
- name : Box :: new ( Ident {
1510
- name : name. into ( ) ,
1511
- ..Default :: default ( )
1512
- } ) ,
1513
- generics : Box :: new ( [ ] ) ,
1514
- input : Box :: new ( input_pat) ,
1515
- output : Box :: new ( build_path_ident_ty ( "Unit" ) ) ,
1516
- functors : None ,
1517
- body : Box :: new ( body) ,
1518
- } ;
1519
- let item = Item {
1520
- span : gate_span,
1521
- kind : Box :: new ( ast:: ItemKind :: Callable ( Box :: new ( decl) ) ) ,
1522
- ..Default :: default ( )
1523
- } ;
1524
-
1525
- Stmt {
1526
- kind : Box :: new ( StmtKind :: Item ( Box :: new ( item) ) ) ,
1527
- span : gate_span,
1528
- ..Default :: default ( )
1529
- }
1530
- }
1531
-
1532
- #[ allow( clippy:: too_many_arguments, clippy:: too_many_lines) ]
1533
- pub ( crate ) fn build_lambda < S : AsRef < str > > (
1534
- name : S ,
1535
- cargs : Vec < ( String , Ty , Pat ) > ,
1536
- qargs : Vec < ( String , Ty , Pat ) > ,
1537
- body : Option < Block > ,
1538
- name_span : Span ,
1539
- body_span : Span ,
1540
- gate_span : Span ,
1541
- return_type : Option < Ty > ,
1542
- kind : CallableKind ,
1543
- ) -> Stmt {
1544
- let args = cargs
1545
- . into_iter ( )
1546
- . chain ( qargs)
1547
- . map ( |( name, ty, pat) | ( name, ty, pat. span ) )
1548
- . collect :: < Vec < _ > > ( ) ;
1549
-
1550
- let lo = args
1551
- . iter ( )
1552
- . min_by_key ( |( _, _, span) | span. lo )
1553
- . map ( |( _, _, span) | span. lo )
1554
- . unwrap_or_default ( ) ;
1555
-
1556
- let hi = args
1557
- . iter ( )
1558
- . max_by_key ( |( _, _, span) | span. hi )
1559
- . map ( |( _, _, span) | span. hi )
1560
- . unwrap_or_default ( ) ;
1561
-
1562
- let name_args = args
1563
- . iter ( )
1564
- . map ( |( name, _, span) | Pat {
1565
- kind : Box :: new ( PatKind :: Bind (
1566
- Box :: new ( Ident {
1567
- span : * span,
1568
- name : Rc :: from ( name. as_ref ( ) ) ,
1569
- ..Default :: default ( )
1570
- } ) ,
1571
- None ,
1572
- ) ) ,
1573
- ..Default :: default ( )
1574
- } )
1575
- . map ( Box :: new)
1576
- . collect :: < Vec < _ > > ( ) ;
1577
- let input_pat = if args. len ( ) == 1 {
1578
- ast:: Pat {
1579
- kind : Box :: new ( ast:: PatKind :: Paren ( name_args[ 0 ] . clone ( ) ) ) ,
1580
- span : Span { lo, hi } ,
1581
- ..Default :: default ( )
1582
- }
1583
- } else {
1584
- ast:: Pat {
1585
- kind : Box :: new ( PatKind :: Tuple ( name_args. into_boxed_slice ( ) ) ) ,
1586
- span : Span { lo, hi } ,
1587
- ..Default :: default ( )
1588
- }
1589
- } ;
1590
-
1591
- let block_expr = build_wrapped_block_expr ( body. map_or_else (
1592
- || Block {
1593
- id : NodeId :: default ( ) ,
1594
- span : body_span,
1595
- stmts : Box :: new ( [ ] ) ,
1596
- } ,
1597
- |block| block,
1598
- ) ) ;
1599
- let lambda_expr = Expr {
1600
- id : NodeId :: default ( ) ,
1601
- kind : Box :: new ( ExprKind :: Lambda (
1602
- kind,
1603
- Box :: new ( input_pat) ,
1604
- Box :: new ( block_expr) ,
1605
- ) ) ,
1606
- span : gate_span,
1607
- } ;
1608
- let ty_args = args. iter ( ) . map ( |( _, ty, _) | ty. clone ( ) ) . collect :: < Vec < _ > > ( ) ;
1609
- let input_ty = if args. len ( ) == 1 {
1610
- ast:: Ty {
1611
- kind : Box :: new ( ast:: TyKind :: Paren ( Box :: new ( ty_args[ 0 ] . clone ( ) ) ) ) ,
1612
- ..Default :: default ( )
1613
- }
1614
- } else {
1615
- ast:: Ty {
1616
- kind : Box :: new ( ast:: TyKind :: Tuple ( ty_args. into_boxed_slice ( ) ) ) ,
1617
- ..Default :: default ( )
1618
- }
1619
- } ;
1620
- let return_type = if let Some ( ty) = return_type {
1621
- ty
1622
- } else {
1623
- build_path_ident_ty ( "Unit" )
1624
- } ;
1625
-
1626
- let lambda_ty = ast:: Ty {
1627
- kind : Box :: new ( ast:: TyKind :: Arrow (
1628
- kind,
1629
- Box :: new ( input_ty) ,
1630
- Box :: new ( return_type) ,
1631
- None ,
1632
- ) ) ,
1633
- ..Default :: default ( )
1634
- } ;
1635
- Stmt {
1636
- span : gate_span,
1637
- kind : Box :: new ( StmtKind :: Local (
1638
- Mutability :: Immutable ,
1639
- Box :: new ( Pat {
1640
- kind : Box :: new ( PatKind :: Bind (
1641
- Box :: new ( Ident {
1642
- span : name_span,
1643
- name : Rc :: from ( name. as_ref ( ) ) ,
1644
- ..Default :: default ( )
1645
- } ) ,
1646
- Some ( Box :: new ( lambda_ty) ) ,
1647
- ) ) ,
1648
- ..Default :: default ( )
1649
- } ) ,
1650
- Box :: new ( lambda_expr) ,
1651
- ) ) ,
1652
- ..Default :: default ( )
1653
- }
1654
- }
1655
-
1656
1419
#[ allow( clippy:: too_many_arguments, clippy:: too_many_lines) ]
1657
1420
pub ( crate ) fn build_function_or_operation (
1658
1421
name : String ,
0 commit comments