Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

External function annotations assumptions #3133

Open
adrpo opened this issue Mar 9, 2022 · 2 comments
Open

External function annotations assumptions #3133

adrpo opened this issue Mar 9, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@adrpo
Copy link
Collaborator

adrpo commented Mar 9, 2022

The spec: https://specification.modelica.org/master/functions.html#annotations-for-external-libraries-and-include-files
says that annotations: Library, LibraryDirectory, Include and IncludeDirectory can all specify either a scalar value or an array of values.

Why do we have this restriction? All the tools should be able to support constants in these annotations.

It prevents writing flexible packages such as:
https://github.com/adrpo/OMCallPython/tree/ConfigurePython
using constants:

package Py
  constant PyIncludePath = "";
  constant PyLib = "";

 class PythonLibraryHandle
      extends ExternalObject;
  
      function constructor "External object constructor that loads the python dll"
        input String pyLibPath = PyLib;
        output PythonLibraryHandle pyHandle;

        external "C" pyHandle = omc_PyLibLoad(pyLibPath) annotation (
          IncludeDirectory = {"modelica://OMCallPython/Resources/C-Sources", PyIncludePath},
          Include = "#include \"OMCallPython.h\"");
      end constructor;
 ...
end Py;

model Test
  // here we could even call some functions to fetch these values from some environment variables
  package ConfiguredPy = Py(PyIncludePath = "E:/bin/py64/include", PyLib = "E:/bin/py64/python3.dll");
  ....
  ConfiguredPy.PythonLibraryHandle pyHandle = ConfiguredPy.PythonLibraryHandle();
end Test;
@HansOlsson HansOlsson added the enhancement New feature or request label Mar 9, 2022
@HansOlsson
Copy link
Collaborator

It's an interesting enhancement, but I see a number of practical issues:

  • All tools do currently not support this.
  • It seems to open up rather wild ideas with string-handling for the Include-directive.
  • It seems necessary to also concatenate constant string arrays, and not only constant string values.
  • Using functions to extract them from environment variables mean that we first run some functions to generate includes for other functions that we can then run, it seems that can in turn be used for the next function ...

@adrpo
Copy link
Collaborator Author

adrpo commented Mar 9, 2022

It's an interesting enhancement, but I see a number of practical issues:

  • All tools do currently not support this.

They do, at least in graphical user annotations.

  • It seems to open up rather wild ideas with string-handling for the Include-directive.

Sure, but much more flexibility.

  • It seems necessary to also concatenate constant string arrays, and not only constant string values.

True

  • Using functions to extract them from environment variables mean that we first run some functions to generate includes for other functions that we can then run, it seems that can in turn be used for the next function ...

One could easy add a getEnvironmentVariable operator to the Modelica Specification. You already have that in the MSL: Modelica.Utilities.System.getEnvironmentVariable. But yes, you could cascade functions like that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants