@@ -130,36 +130,53 @@ end evaluateExp;
130130function evaluateExpTraverser
131131 input Expression exp;
132132 input Boolean changed;
133+ input Boolean isExternalArg = false ;
133134 output Expression outExp;
134135 output Boolean outChanged;
135136protected
136137 Expression e;
138+ ComponentRef cref;
139+ Type ty;
137140algorithm
138- (e, outChanged) := Expression . mapFoldShallow(exp, evaluateExpTraverser, false );
139-
140- outExp := match e
141+ outExp := match exp
141142 case Expression . CREF ()
142143 algorithm
143- if ComponentRef . nodeVariability(e. cref) <= Variability . STRUCTURAL_PARAMETER then
144+ (outExp as Expression . CREF (cref = cref, ty = ty), outChanged) := Expression . mapFoldShallow(exp,
145+ function evaluateExpTraverser(isExternalArg = false ), false );
146+
147+ // Evaluate constants and structural parameters, except for arrays that
148+ // are used as arguments to an external function.
149+
150+ // TODO: The runtime doesn't handle array literals well when used as
151+ // arguments of external functions, since it sometimes tries to
152+ // write to them (e.g. when trying to pack them). Until that's
153+ // fixed we keep them as they are here.
154+ if ComponentRef . nodeVariability(cref) <= Variability . STRUCTURAL_PARAMETER and
155+ not (isExternalArg and Type . isArray(ty)) then
144156 // Evaluate all constants and structural parameters.
145- outExp := Ceval . evalCref(e . cref, e , Ceval . EvalTarget . IGNORE_ERRORS (), evalSubscripts = false );
157+ outExp := Ceval . evalCref(cref, outExp , Ceval . EvalTarget . IGNORE_ERRORS (), evalSubscripts = false );
146158 outChanged := true ;
147159 elseif outChanged then
148160 // If the cref's subscripts changed, recalculate its type.
149- outExp := Expression . CREF (ComponentRef . getSubscriptedType(e. cref), e. cref);
150- else
151- outExp := e;
161+ outExp := Expression . CREF (ComponentRef . getSubscriptedType(cref), cref);
152162 end if ;
153163 then
154164 outExp;
155165
156166 case Expression . CALL ()
157167 algorithm
158- evaluateFunction(Call . typedFunction(e. call));
168+ (outExp, outChanged) := Expression . mapFoldShallow(exp,
169+ function evaluateExpTraverser(isExternalArg = Call . isExternal(exp. call)), false );
170+ evaluateFunction(Call . typedFunction(exp. call));
159171 then
160- e ;
172+ outExp ;
161173
162- else if outChanged then Expression . retype(e) else e;
174+ else
175+ algorithm
176+ (outExp, outChanged) := Expression . mapFoldShallow(exp,
177+ function evaluateExpTraverser(isExternalArg = false ), false );
178+ then
179+ if outChanged then Expression . retype(outExp) else outExp;
163180 end match;
164181
165182 outChanged := changed or outChanged;
0 commit comments