Skip to content

Commit 33b9173

Browse files
committed
Tidy up remaining documentation and remove unnecessary dependency.
1 parent 5547ac7 commit 33b9173

File tree

2 files changed

+17
-20
lines changed

2 files changed

+17
-20
lines changed

Project.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ DiffRules = "b552c78f-8df3-52c6-915a-8e097449b14b"
1212
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
1313
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
1414
GeneralizedGenerated = "6b9d7cbe-bcb9-11e9-073f-15a7a543e2eb"
15-
JuliaVariables = "b14d175d-62b4-44ba-8fb7-3064adc8c3ec"
1615
Latexify = "23fbe1c1-3f47-55db-b15f-69d7ec21a316"
1716
LightGraphs = "093fc24a-ae57-5d10-9952-331d41423f4d"
1817
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
@@ -36,7 +35,6 @@ DiffEqJump = "6.7.5"
3635
DiffRules = "0.1, 1.0"
3736
DocStringExtensions = "0.7, 0.8"
3837
GeneralizedGenerated = "0.1.4, 0.2"
39-
JuliaVariables = "0.2.0"
4038
Latexify = "0.11, 0.12, 0.13"
4139
LightGraphs = "1.3"
4240
MacroTools = "0.5"

src/function_registration.jl

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ ModelingToolkit IR. Example:
1010
```
1111
1212
registers `f` as a possible two-argument function.
13-
14-
NOTE: If registering outside of ModelingToolkit (i.e. in your own package),
15-
this should be done at runtime (e.g. in a package `__init__()`, or inside a
16-
method that is called at runtime and not during precompile) to ensure that
17-
any generated functions will use your registered method. See
18-
`inject_registered_module_functions()`.
1913
"""
2014
macro register(sig)
2115
splitsig = splitdef(:($sig = nothing))
@@ -94,24 +88,29 @@ Base.:^(x::Expression,y::T) where T <: Rational = Operation(Base.:^, Expression[
9488
Base.getindex(x::Operation,i::Int64) = Operation(getindex,[x,i])
9589
Base.one(::Operation) = 1
9690

91+
# Ensure that Operations that get @registered from outside the ModelingToolkit
92+
# module can work without having to bring in the associated function into the
93+
# ModelingToolkit namespace. We basically store information about functions
94+
# registered at runtime in a ModelingToolkit variable,
95+
# `registered_external_functions`. It's not pretty, but we are limited by the
96+
# way GeneralizedGenerated builds a function (adding "ModelingToolkit" to every
97+
# function call).
9798
# ---
98-
# Ensure that Operations that get @registered from outside the ModelingToolkit module can work without
99-
# having to bring in the associated function into the ModelingToolkit namespace.
100-
# We basically store information about functions registered at runtime in a ModelingToolkit variable,
101-
# `registered_external_functions`. It's not pretty, but we are limited by the way GeneralizedGenerated
102-
# builds a function (adding "ModelingToolkit" to every function call).
103-
# ---
104-
import JuliaVariables
10599
const registered_external_functions = Dict{Symbol,Module}()
106100
function inject_registered_module_functions(expr)
107101
MacroTools.postwalk(expr) do x
108-
MacroTools.@capture(x, f_(xs__)) # We need to find all function calls in the expression.
109-
# If the function call has been converted to a JuliaVariables.Var and matches
110-
# one of the functions we've registered...
102+
# We need to find all function calls in the expression...
103+
MacroTools.@capture(x, f_(xs__))
104+
111105
if !isnothing(f) && f isa Expr && f.head == :. && f.args[2] isa QuoteNode
112-
f_name = f.args[2].value
106+
# If the function call matches any of the functions we've
107+
# registered, set the calling module (which is probably
108+
# "ModelingToolkit") to the module it is registered to.
109+
f_name = f.args[2].value # function name
113110
f.args[1] = get(registered_external_functions, f_name, f.args[1])
114111
end
115-
return x # Make sure we rebuild the expression as is.
112+
113+
# Make sure we rebuild the expression as is.
114+
return x
116115
end
117116
end

0 commit comments

Comments
 (0)