Closed Candoran2 closed 1 year ago
Could we not store arg and make the expressions use arg[0] if they get #ARG#?
Could we not store arg and make the expressions use arg[0] if they get #ARG#?
You mean always store arg as a tuple?
You mean always store arg as a tuple?
Yeah
It's possible, I didn't think of that option. Three reasons why not to do it would be:
Of course that's at the detriment of consistency in how we treat arg (single number vs consistently a tuple), so as usual there's a trade-off.
In python objects and classes are both objects. However, this is not the case in all languages. I would therefore like to restrict template to be limited to types (including templates itself). However, in certain cases template is used as a way to pass a second object. In order to allow for this, I have changed
arg
(andtemplate
, though it wasn't strictly necessary) to allow for the passing of multiple objects.This is accomplished through attributes starting at
arg1
up toarg<n>
, on the field. A type that uses multiple args must haveargs="<n>"
denoted on the type, where<n>
is the number of args that it uses. In the generated code, these are passed as a tuple in the same place as thearg
parameter. It is also still stored asarg
, but it is also accessible through the propertyarg_<i>
. This is equivalent toarg[i - 1]
. Template is treated the same way.Example: type:
used in field:
The choice to (re)use the existing
arg
parameter on the types is to keep the function signatures and field definitions consistent across all types, rather than having to somehow check how many args and templates are passed. The choice to allow accessing the elements of arg through properties is to make the code generation easier - otherwise it would require either implementation of square brackets in the Expression class, or modification of thename_attribute
function to make it less universally applicable. As a side-effect, it also makes it very clear upon reading the generated class whether they use multiple args or not.As it is, I have not yet changed types other than the one in nif.xml to make use of these multiple args. I thought it useful to first check that there were no unforeseen changes beforehand.
Other changes
append
andextend
methods for it (the latter two are not yet tested).math.prod
use. The README promises compatibility with python 3.7. Since 3.7 does not contain math.prod, I created the same function on the Array class.