Skip to content

Commit b54b749

Browse files
attempts at variable dependence failing due to escape issues
1 parent 86600fa commit b54b749

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

src/variables.jl

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,20 +107,30 @@ function _parse_vars(macroname, fun, x)
107107
# z = exp(2)
108108
# end
109109
x = flatten_expr!(x)
110-
for var in x
110+
for _var in x
111+
iscall = typeof(_var) <: Expr && _var.head == :call
112+
@show iscall
113+
if iscall
114+
dependents = Variable[:($(esc(d))) for d in _var.args[2:end]]
115+
var = _var.args[1]
116+
else
117+
dependents = Variable[]
118+
var = _var
119+
end
111120
issym = var isa Symbol
112121
isassign = issym ? false : var.head == :(=)
113122
@assert issym || isassign "@$macroname expects a tuple of expressions!\nE.g. `@$macroname x y z=1`"
114123
if issym
115124
lhs = var
116125
push!(lhss, lhs)
117-
expr = :( $lhs = $fun( Symbol($(String(lhs))) ) )
126+
expr = :( $lhs = $fun( Symbol($(String(lhs))) ,
127+
dependents = $dependents))
118128
end
119129
if isassign
120130
lhs = var.args[1]
121131
rhs = var.args[2]
122132
push!(lhss, lhs)
123-
expr = :( $lhs = $fun( Symbol($(String(lhs))) , $rhs) )
133+
expr = :( $lhs = $fun( Symbol($(String(lhs))) , $rhs))
124134
end
125135
push!(ex.args, expr)
126136
end

test/basic_variables_and_operations.jl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
using SciCompDSL
22
using Base.Test
33

4-
@DVar x y z
54
@IVar t
5+
@DVar x(t)
6+
macroexpand(:(@DVar x(t)))
7+
macroexpand(:(@IVar t))
8+
@DVar x y z
9+
610
@Deriv D'~t # Default of first derivative, Derivative(t,1)
711
@Param σ ρ β
812
@Const c=0
@@ -22,3 +26,11 @@ D*y ~ x*(ρ-z)-sin(y)
2226
@test D*t == Constant(1)
2327
null_op = 0*t
2428
@test simplify_constants(null_op) == Constant(0)
29+
30+
macro escape_all(x...)
31+
:($(esc(x))...)
32+
end
33+
x = 1
34+
y = 2
35+
z = 3
36+
macroexpand(:(@escape_all x y z))

0 commit comments

Comments
 (0)