Skip to content

Commit

Permalink
CLEANUP: Use GeneralizedGenerated instead of invokelatest (Algebrai…
Browse files Browse the repository at this point in the history
  • Loading branch information
epatters committed Jul 14, 2020
1 parent d1c561a commit d5c8057
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ AutoHashEquals = "15f4f7f2-30c1-5605-9d31-71845cf9641f"
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
Compose = "a81c6b42-2e10-5240-aca2-a61377ecd94b"
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
GeneralizedGenerated = "6b9d7cbe-bcb9-11e9-073f-15a7a543e2eb"
IterativeSolvers = "42fd0dbc-a981-5370-80f2-aaf504508153"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
LabelledArrays = "2ee39098-c373-598a-b85f-a56591580800"
Expand All @@ -34,6 +35,7 @@ AutoHashEquals = "^0"
Compat = "^1, ^2, ^3"
Compose = "^0"
DataStructures = "^0"
GeneralizedGenerated = "^0"
IterativeSolvers = "^0"
JSON = "^0"
LabelledArrays = "^1"
Expand Down
14 changes: 7 additions & 7 deletions src/programs/ParseJuliaPrograms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
module ParseJuliaPrograms
export @program, parse_wiring_diagram

using Base: invokelatest
using Compat
using GeneralizedGenerated: mk_function
using Match

using ...Catlab
Expand All @@ -16,9 +16,9 @@ using ..GenerateJuliaPrograms: make_return_value

""" Parse a wiring diagram from a Julia program.
For the most part, this is standard Julia but we take a few liberties with the
syntax. Products are represented as tuples. So if `x` and `y` are variables of
type \$X\$ and \$Y\$, then `(x,y)` has type \$X \\otimes Y\$. Also, both `()`
For the most part, this is standard Julia code but we take a few liberties with
the syntax. Products are represented as tuples. So if `x` and `y` are variables
of type \$X\$ and \$Y\$, then `(x,y)` has type \$X \\otimes Y\$. Also, both `()`
and `nothing` are interpreted as the monoidal unit \$I\$.
Unlike in standard Julia, the call expressions `f(x,y)` and `f((x,y))` are
Expand All @@ -31,7 +31,7 @@ g(x,y)
```
is equivalent to `g(f(w))`. In standard Julia, at most one of these calls to `g`
would be valid.
would be valid, unless `g` had multiple signatures.
The diagonals (copying and deleting) are implicit in the Julia syntax: copying
is variable reuse and deleting is variable non-use. For the codiagonals (merging
Expand Down Expand Up @@ -86,7 +86,7 @@ function parse_wiring_diagram(pres::Presentation, call::Expr0, body::Expr)::Wiri
kwargs = make_lookup_table(pres, syntax_module, unique_symbols(body))
func_expr = compile_recording_expr(body, args,
kwargs = sort!(collect(keys(kwargs))))
func = parentmodule(syntax_module).eval(func_expr)
func = mk_function(parentmodule(syntax_module), func_expr)

# ...and then evaluate function that records the function calls.
arg_obs = syntax_module.Ob[ last(arg) for arg in parsed_args ]
Expand All @@ -97,7 +97,7 @@ function parse_wiring_diagram(pres::Presentation, call::Expr0, body::Expr)::Wiri
arg_ports = [ Tuple(Port(v_in, OutputPort, i) for i in (stop-len+1):stop)
for (len, stop) in zip(arg_blocks, cumsum(arg_blocks)) ]
recorder = f -> (args...) -> record_call!(diagram, f, args...)
value = invokelatest(func, recorder, arg_ports...; kwargs...)
value = func(recorder, arg_ports...; kwargs...)

# Add outgoing wires for return values.
out_ports = normalize_arguments((value,))
Expand Down

0 comments on commit d5c8057

Please sign in to comment.