@@ -55,6 +55,7 @@ import System;
5555import NFTyping.ExpOrigin ;
5656import SCode ;
5757import NFPrefixes.Variability ;
58+ import EvalFunctionExt = NFEvalFunctionExt ;
5859
5960encapsulated package ReplTree
6061 import BaseAvlTree ;
@@ -149,22 +150,29 @@ protected
149150 String name, lang;
150151 ComponentRef output_ref;
151152 Option < SCode . Annotation > ann;
153+ list< Expression > ext_args;
152154algorithm
153- Sections . EXTERNAL (name = name, outputRef = output_ref, language = lang, ann = ann) :=
155+ Sections . EXTERNAL (name = name, args = ext_args, outputRef = output_ref, language = lang, ann = ann) :=
154156 Class . getSections(InstNode . getClass(fn. node));
155157
156158 if lang == "builtin" then
157159 // Functions defined as 'external "builtin"', delegate to Ceval.
158160 result := Ceval . evalBuiltinCall(fn, args, NFCeval . EvalTarget . IGNORE_ERRORS ());
159161 elseif isKnownExternalFunc(name, ann) then
160162 // External functions that we know how to evaluate without generating code.
163+ // TODO: Move this to EvalFunctionExt and unify evaluateKnownExternal and
164+ // evaluateExternal2. This requires handling of outputRef though.
161165 result := evaluateKnownExternal(name, args);
162166 else
163- // External functions that we would need to generate code for and execute.
164- Error . assertion(false , getInstanceName() +
165- " failed on " + Absyn . pathString(fn. path) +
166- ", evaluation of userdefined external functions not yet implemented" , sourceInfo());
167- fail();
167+ try
168+ result := evaluateExternal2(name, fn, args, ext_args);
169+ else
170+ // External functions that we would need to generate code for and execute.
171+ Error . assertion(false , getInstanceName() +
172+ " failed on " + Absyn . pathString(fn. path) +
173+ ", evaluation of userdefined external functions not yet implemented" , sourceInfo());
174+ fail();
175+ end try ;
168176 end if ;
169177end evaluateExternal;
170178
@@ -452,6 +460,7 @@ algorithm
452460 assignVariable(lhsExp, Ceval . evalExp(rhsExp));
453461end evaluateAssignment;
454462
463+ public
455464function assignVariable
456465 input Expression variable;
457466 input Expression value;
@@ -493,6 +502,7 @@ algorithm
493502 end match;
494503end assignVariable;
495504
505+ protected
496506function assignSubscriptedVariable
497507 input Mutable < Expression > variable;
498508 input list< Subscript > subscripts;
@@ -878,7 +888,7 @@ algorithm
878888 then
879889 Expression . INTEGER (0 );
880890
881- case ("ModelicaString_compare " , {Expression . STRING (s1), Expression . STRING (s2), Expression . BOOLEAN (b)})
891+ case ("ModelicaStrings_compare " , {Expression . STRING (s1), Expression . STRING (s2), Expression . BOOLEAN (b)})
882892 algorithm
883893 i := ModelicaExternalC . Strings_compare (s1, s2, b);
884894 then
@@ -943,5 +953,43 @@ algorithm
943953 end match;
944954end evaluateOpenModelicaRegex;
945955
956+ function evaluateExternal2
957+ input String name;
958+ input Function fn;
959+ input list< Expression > args;
960+ input list< Expression > extArgs;
961+ output Expression result;
962+ protected
963+ ReplTree . Tree repl;
964+ list< Expression > ext_args;
965+ algorithm
966+ repl := createReplacements(fn, args);
967+ ext_args := list(Expression . map(e, function applyReplacements2(repl = repl)) for e in extArgs);
968+ evaluateExternal3(name, ext_args);
969+ result := createResult(repl, fn. outputs);
970+ end evaluateExternal2;
971+
972+ function evaluateExternal3
973+ input String name;
974+ input list< Expression > args;
975+ algorithm
976+ () := match name
977+ case "dgeev" algorithm EvalFunctionExt . Lapack_dgeev (args); then ();
978+ case "dgegv" algorithm EvalFunctionExt . Lapack_dgegv (args); then ();
979+ case "dgels" algorithm EvalFunctionExt . Lapack_dgels (args); then ();
980+ case "dgelsx" algorithm EvalFunctionExt . Lapack_dgelsx (args); then ();
981+ case "dgesv" algorithm EvalFunctionExt . Lapack_dgesv (args); then ();
982+ case "dgglse" algorithm EvalFunctionExt . Lapack_dgglse (args); then ();
983+ case "dgtsv" algorithm EvalFunctionExt . Lapack_dgtsv (args); then ();
984+ case "dgbsv" algorithm EvalFunctionExt . Lapack_dgtsv (args); then ();
985+ case "dgesvd" algorithm EvalFunctionExt . Lapack_dgesvd (args); then ();
986+ case "dgetrf" algorithm EvalFunctionExt . Lapack_dgetrf (args); then ();
987+ case "dgetrs" algorithm EvalFunctionExt . Lapack_dgetrs (args); then ();
988+ case "dgetri" algorithm EvalFunctionExt . Lapack_dgetri (args); then ();
989+ case "dgeqpf" algorithm EvalFunctionExt . Lapack_dgeqpf (args); then ();
990+ case "dorgqr" algorithm EvalFunctionExt . Lapack_dorgqr (args); then ();
991+ end match;
992+ end evaluateExternal3;
993+
946994annotation(__OpenModelica_Interface= "frontend" );
947995end NFEvalFunction ;
0 commit comments