diff --git a/src/printing.jl b/src/printing.jl index 290732c..2d1715b 100644 --- a/src/printing.jl +++ b/src/printing.jl @@ -43,3 +43,23 @@ function Base.show(io::IO, ::Type{T}) where {name,T<:GenericRoutine{name}} mod === Main || print(io, mod, ".") print(io, name, ")") end + +function Base.show(io::IO, op::Operation) + print(io, routine_name(op.parent)) + print(io, "(") + join(io, op.args, ", ") + print(io, ")") +end + +function Base.show(io::IO, ::MIME"text/plain", g::Gate) + print(io, g.locations, " => ", g.operation) +end + +Base.show(io::IO, g::Chain) = show(io, MIME"text/plain"(), g) + +function Base.show(io::IO, ::MIME"text/plain", g::Chain) + print(io, "Chain(") + join(io, g.args, ", ") + print(io, ")") +end + diff --git a/test/runtests.jl b/test/runtests.jl index 95a2eb9..93d4549 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -3,11 +3,26 @@ using MLStyle using YaoHIR using Test -@testset "YaoHIR.jl" begin - # Write your tests here. +module TestIntrinsic +using YaoHIR: @intrinsic + +@intrinsic X +@intrinsic R(theta::T) where {T <: Real} + end -using YaoHIR: intrinsic_m -intrinsic_m(:X) -intrinsic_m(:(Rx(theta::T) where {T <: Real})) -Chain([Gate(YaoHIR.X, Locations(1)), ]) \ No newline at end of file +@test YaoHIR.routine_name(TestIntrinsic.X) == :X +@test YaoHIR.routine_name(TestIntrinsic.R(1.0)) == :R +@test TestIntrinsic.R(1.0).theta == 1.0 + +display(YaoHIR.X) +display(YaoHIR.Rx(1.0)) +display(YaoHIR.Operation(YaoHIR.X, 2.0)) + +circ = Chain( + Gate(YaoHIR.X, Locations(1)), + Core.SSAValue(1), + Ctrl(Gate(Core.SSAValue(1), Locations(3)), CtrlLocations(2)) +) + +print(circ_1)