|
| 1 | +macro yao_code_lowered(ex) |
| 2 | + esc(yao_code_lowered_m(ex)) |
| 3 | +end |
| 4 | + |
| 5 | +macro yao_code_lowered(ctrl, ex) |
| 6 | + esc(yao_code_lowered_m(ctrl, ex)) |
| 7 | +end |
| 8 | + |
| 9 | +macro yao_code_typed(ex) |
| 10 | + esc(yao_code_typed_m(ex)) |
| 11 | +end |
| 12 | + |
| 13 | +macro yao_code_typed(ctrl, ex) |
| 14 | + esc(yao_code_typed_m(ctrl, ex)) |
| 15 | +end |
| 16 | + |
| 17 | +function yao_code_lowered_m(ex) |
| 18 | + @match ex begin |
| 19 | + # apply(reg, gate, locs) |
| 20 | + :($locs => $gate) => quote |
| 21 | + Base.code_lowered( |
| 22 | + $Intrinsics.apply, |
| 23 | + ($YaoCompiler.AnyReg, typeof($gate), typeof($Locations($(locs)))) |
| 24 | + ) |
| 25 | + end |
| 26 | + # apply(reg, gate) |
| 27 | + _ => quote |
| 28 | + Base.code_lowered($Intrinsics.apply, ($YaoCompiler.AnyReg, typeof($ex))) |
| 29 | + end |
| 30 | + end |
| 31 | +end |
| 32 | + |
| 33 | +function yao_code_lowered_m(ctrl, ex) |
| 34 | + @match ex begin |
| 35 | + # apply(reg, gate, locs, ctrl) |
| 36 | + :($locs => $gate) => quote |
| 37 | + Base.code_lowered( |
| 38 | + $Intrinsics.apply, |
| 39 | + ($YaoCompiler.AnyReg, typeof($gate), typeof($Locations($(locs))), typeof($CtrlLocations($ctrl))) |
| 40 | + ) |
| 41 | + end |
| 42 | + _ => error("expect a locs => gate expression") |
| 43 | + end |
| 44 | +end |
| 45 | + |
| 46 | +function yao_code_typed_m(ex) |
| 47 | + @match ex begin |
| 48 | + # apply(reg, gate, locs) |
| 49 | + :($locs => $gate) => quote |
| 50 | + $Base.code_typed( |
| 51 | + $Intrinsics.apply, |
| 52 | + ($YaoCompiler.AnyReg, typeof($gate), typeof($Locations($(locs)))); |
| 53 | + interp=$(YaoInterpreter()) |
| 54 | + ) |
| 55 | + end |
| 56 | + # apply(reg, gate) |
| 57 | + _ => quote |
| 58 | + $Base.code_typed( |
| 59 | + $Intrinsics.apply, ($YaoCompiler.AnyReg, typeof($ex)); |
| 60 | + interp=$(YaoInterpreter()), |
| 61 | + ) |
| 62 | + end |
| 63 | + end |
| 64 | +end |
| 65 | + |
| 66 | +function yao_code_typed_m(ctrl, ex) |
| 67 | + @match ex begin |
| 68 | + # apply(reg, gate, locs, ctrl) |
| 69 | + :($locs => $gate) => quote |
| 70 | + Base.code_typed( |
| 71 | + $Intrinsics.apply, |
| 72 | + ($YaoCompiler.AnyReg, typeof($gate), typeof($Locations($(locs))), typeof($CtrlLocations($ctrl))); |
| 73 | + interp=$(YaoInterpreter()), |
| 74 | + ) |
| 75 | + end |
| 76 | + _ => error("expect a locs => gate expression") |
| 77 | + end |
| 78 | +end |
0 commit comments