Open MarkusOlssonModelon opened 3 years ago
The functiongetMemory
should not be declared as impure, but it should be handled in another way.
Basically the function getMemory
is intended to be behave in a pure way; and it is primarily used with tables given in the library.
Looking at it once more I think that purity is the least of our concerns.
Superficially it seems to do the following:
Fill a logical table with binary values, 0, 1, 2, ... 2^(n_addr)-1, with n_data bits from left-to-right, stored as L.'0', L.'1' (and L.'X' for the left-over bits).
For some reason that is done using an external table which makes it impure, and fails to handle n_addr>4 and if n_data>4 the rest of the bits are left-over bits.
So, if we don't change the external table, I would have the following questions:
If the intent is to provide a different external table the obvious improvement would be to have a table in Modelica instead, so that you don't have to set n_addr, n_data, and external table separately.
And note that this is just how the memory is initialized (the RAM-model allows writing as well). Assuming that the models are useful I would believe it would make more sense to have a selectable memory-initialization-function; like generalization of current one, fill with some value (it seems the original model just filled with 'U' - as the start-value), or user-selectable.
I have found an issue in
Modelica.Electrical.Digital.Interfaces.MemoryBase.getMemory
. It contains a function call toModelica.Utilities.Streams.readLine
which is an impure function, butgetMemory
is not declared as impure.I suggest adding the impure prefix to
getMemory
. This will also require changes inModelica.Electrical.Digital.Memories.DLATRAM
andModelica.Electrical.Digital.Memories.DLATROM
since they contain calls togetMemory
. For that I think the simplest solution is to change the if-statements surrounding the calls to when-statements.