@@ -48,6 +48,8 @@ function _model_macro(mod, name, expr, isconnector)
4848 eqs = Expr[]
4949 icon = Ref {Union{String, URI}} ()
5050 ps, sps, vs, = [], [], []
51+ c_evts = []
52+ d_evts = []
5153 kwargs = Set ()
5254 where_types = Expr[]
5355
@@ -61,7 +63,7 @@ function _model_macro(mod, name, expr, isconnector)
6163 for arg in expr. args
6264 if arg. head == :macrocall
6365 parse_model! (exprs. args, comps, ext, eqs, icon, vs, ps,
64- sps, dict, mod, arg, kwargs, where_types)
66+ sps, c_evts, d_evts, dict, mod, arg, kwargs, where_types)
6567 elseif arg. head == :block
6668 push! (exprs. args, arg)
6769 elseif arg. head == :if
@@ -116,6 +118,16 @@ function _model_macro(mod, name, expr, isconnector)
116118 isconnector && push! (exprs. args,
117119 :($ Setfield. @set! (var"#___sys___" . connector_type= $ connector_type (var"#___sys___" ))))
118120
121+ ! (c_evts == []) && push! (exprs. args,
122+ :($ Setfield. @set! (var"#___sys___" . continuous_events= $ SymbolicContinuousCallback .([
123+ $ (c_evts... )
124+ ]))))
125+
126+ ! (d_evts == []) && push! (exprs. args,
127+ :($ Setfield. @set! (var"#___sys___" . discrete_events= $ SymbolicDiscreteCallback .([
128+ $ (d_evts... )
129+ ]))))
130+
119131 f = if length (where_types) == 0
120132 :($ (Symbol (:__ , name, :__ ))(; name, $ (kwargs... )) = $ exprs)
121133 else
@@ -124,6 +136,7 @@ function _model_macro(mod, name, expr, isconnector)
124136 :($ (Symbol (:__ , name, :__ ))(; name, $ (kwargs... ))), where_types... )
125137 :($ f_with_where = $ exprs)
126138 end
139+
127140 :($ name = $ Model ($ f, $ dict, $ isconnector))
128141end
129142
@@ -341,7 +354,7 @@ function get_var(mod::Module, b)
341354 end
342355end
343356
344- function parse_model! (exprs, comps, ext, eqs, icon, vs, ps, sps,
357+ function parse_model! (exprs, comps, ext, eqs, icon, vs, ps, sps, c_evts, d_evts,
345358 dict, mod, arg, kwargs, where_types)
346359 mname = arg. args[1 ]
347360 body = arg. args[end ]
@@ -359,6 +372,10 @@ function parse_model!(exprs, comps, ext, eqs, icon, vs, ps, sps,
359372 parse_equations! (exprs, eqs, dict, body)
360373 elseif mname == Symbol (" @constants" )
361374 parse_constants! (exprs, dict, body, mod)
375+ elseif mname == Symbol (" @continuous_events" )
376+ parse_continuous_events! (c_evts, dict, body)
377+ elseif mname == Symbol (" @discrete_events" )
378+ parse_discrete_events! (d_evts, dict, body)
362379 elseif mname == Symbol (" @icon" )
363380 isassigned (icon) && error (" This model has more than one icon." )
364381 parse_icon! (body, dict, icon, mod)
@@ -753,6 +770,24 @@ function parse_equations!(exprs, eqs, dict, body)
753770 end
754771end
755772
773+ function parse_continuous_events! (c_evts, dict, body)
774+ dict[:continuous_events ] = []
775+ Base. remove_linenums! (body)
776+ for arg in body. args
777+ push! (c_evts, arg)
778+ push! (dict[:continuous_events ], readable_code .(c_evts)... )
779+ end
780+ end
781+
782+ function parse_discrete_events! (d_evts, dict, body)
783+ dict[:discrete_events ] = []
784+ Base. remove_linenums! (body)
785+ for arg in body. args
786+ push! (d_evts, arg)
787+ push! (dict[:discrete_events ], readable_code .(d_evts)... )
788+ end
789+ end
790+
756791function parse_icon! (body:: String , dict, icon, mod)
757792 icon_dir = get (ENV , " MTK_ICONS_DIR" , joinpath (DEPOT_PATH [1 ], " mtk_icons" ))
758793 dict[:icon ] = icon[] = if isfile (body)
0 commit comments