Skip to content

Commit

Permalink
BUG: Appropriately type diagrams created by parse_wiring_diagram.
Browse files Browse the repository at this point in the history
Noticed while fixing #86.
  • Loading branch information
epatters committed Jan 27, 2020
1 parent ccf4a8b commit 1fc4096
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/programs/JuliaPrograms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -253,18 +253,22 @@ function parse_wiring_diagram(pres::Presentation, call::Expr0, body::Expr)::Wiri
_ => error("Argument $arg is not simply typed")
end
end

# FIXME: Presentations should be uniquely associated with syntax systems.
syntax_module = Syntax.syntax_module(first(pres.generators))
signature_module = syntax_module.signature()

# Compile...
args = first.(parsed_args)
kwargs = make_lookup_table(pres, unique_symbols(body))
kwargs = make_lookup_table(pres, syntax_module, unique_symbols(body))
func_expr = compile_recording_expr(body, args,
kwargs = sort!(collect(keys(kwargs))))
func = eval(func_expr)

# ...and then evaluate function that records the function calls.
inputs = last.(parsed_args)
@assert all(has_generator(pres, name) for name in inputs)
diagram = WiringDiagram(inputs, empty(inputs))
diagram = WiringDiagram{signature_module.Hom}(inputs, empty(inputs))
v_in, v_out = input_id(diagram), output_id(diagram)
in_ports = [ Port(v_in, OutputPort, i) for i in eachindex(inputs) ]
recorder = f -> (args...) -> record_call!(diagram, f, args...)
Expand All @@ -285,9 +289,7 @@ end

""" Make a lookup table assigning names to generators or term constructors.
"""
function make_lookup_table(pres::Presentation, names)::Dict{Symbol,Any}
# FIXME: Presentations should be uniquely associated with syntax systems.
syntax_module = Syntax.syntax_module(first(pres.generators))
function make_lookup_table(pres::Presentation, syntax_module::Module, names)
signature = syntax_module.signature().class().signature
terms = Set([ term.name for term in signature.terms ])

Expand Down
1 change: 1 addition & 0 deletions test/programs/JuliaPrograms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ f, g, m, n = generators(C, [:f, :g, :m, :n])

parsed = @parse_wiring_diagram(C, (x::X) -> f(x))
@test parsed == to_wiring_diagram(f)
@test parsed isa WiringDiagram{BiproductCategory.Hom}

# Composition: one-dimensional.

Expand Down

0 comments on commit 1fc4096

Please sign in to comment.