[PATCH v4] algol68: Add allocation function for leaf objects

Pietro Monteiro pietro@sociotechnical.xyz
Fri Jan 16 04:31:04 GMT 2026


On Thu, Jan 15, 2026, at 10:09 PM, Jose E. Marchesi wrote:
...

>> +  a68_libcall_fn libcall
>> +    = (HAS_REFS (m) || IS_REF (m)) ? A68_LIBCALL_MALLOC_LEAF : A68_LIBCALL_MALLOC;
>
> Can't this just be:
>
>       HAS_REFS (m) ? A68_LIBCALL_MALLOC_LEAF : A68_LIBCALL_MALLOC

Yep, REF modes get has_refs set to true on creation.
...

>> +  if (IS_ROW (m) || IS_FLEX (m))
>> +    {
>> +      for (MOID_T *s = SUB (m); s != NO_MOID; s = SUB (s))
>> +	{
>> +	  HAS_REFS (s) = is_mode_has_ref (s);
>> +	  has_ref |= HAS_REFS (s);
>> +	}
>
> Isn't this doing lots of redundant work?
>
> What about:
>
>   if (IS_ROW (m) || IS_FLEX (m))
>     HAS_REFS (m) = is_mode_has_ref (SUB (m));
>   else if
>   ...
>
> ?

Yes, we don't need to  manually recurse into the mode. Hopefully GCC will turn this into a tail-call.

...
>>  static void
>> @@ -1185,6 +1215,10 @@ compute_derived_modes (MODULE_T *mod)
>>    for (z = TOP_MOID (mod); z != NO_MOID; FORWARD (z))
>>      HAS_ROWS (z) = is_mode_has_row (z);
>>  
>> +  /* Find out what modes contain refs.  */
>> +  for (z = TOP_MOID (mod); z != NO_MOID; FORWARD (z))
>> +    HAS_REFS (z) = is_mode_has_ref (z);
>> +
>
> Surely these two loops can be merged in one?

How about the one below?
 
>>    /* Check flexible modes.  */
>>    for (z = TOP_MOID (mod); z != NO_MOID; FORWARD (z))
>>      {

Thanks again,
pietro


More information about the Algol68 mailing list