Hi Alex,

> On 9. Aug 2018, at 13:52, Alexander Burger <a...@software-lab.de> wrote:
> 
> Hi Alexander,
> 
>>  struct {
>>    int vla[g()]; // vla-member, int array of size g()
>>  } s; 
>> The patch attached translates all uses of bindFrame as an anonymous struct
>> with a VLA-member to a combination of a regular byte-vla for memory and a
>> bindFrame pointer into that memory.
> 
> Cool! I was under the assumption that clang prohibits dynamically sized arrays
> in general, not just in structures. But when looking at your changes, using
> basically
> 
>   int bndLen = length(y)+2;
>   char fbuf[bindFrameSize(bndLen)];
> 
> instead of
> 
>   struct {  // bindFrame
>      struct bindFrame *link;
>      int i, cnt;
>      struct {any sym; any val;} bnd[length(y)+2];
>   } f;
> 
> I deduce that you still can use an dynamically sized array. After all, 
> length(y)
> is called at runtime.

Yes, that's 100% correct.
There's still a dynamically sized array allocated on the stack used, it's just 
outside of the struct definition.
As long as it's not a member of a struct, VLAs are a regular C99 feature and 
thankfully supported by all major compilers.
Clang also assumes C99 by default, so it works with your Makefiles out of the 
box.

> 
> 
>> This requires the bindFrame uses in question to use indirection, rendering 
>> the
>> patch a bit noisy.
> 
> Yes, and probably some runtime overhead due to the indirection (though the 
> same
> overhead must be there anyway, albeit hidden in the syntax).
> 

To be fair, I have no idea why the generated assembly differs at all.
In my opinion, the data layout should be exactly the same, especially since the 
line
"f.link = Env.bind, Env.bind = (bindFrame*)&f;"
makes the struct visible to outside of the function and so the compiler 
shouldn't reorder fields or promote them to registers in either version of the 
code.

If I can get my hands on a nice PicoLisp benchmark and a linux machine I can 
use for that, I'd be happy to benchmark the whole thing.

> 
> 
>> As far as I'm aware and able to test, the behavior is identical.
> 
> Cool!
> 
> 
>> Overall the code is slightly shorter because the bindFrame struct is not
>> redefined as an anonymous struct 11 times throughout the code.
> 
> Well, but this is only the source code for the definitions, right? I expect it
> does not generate runtime code.
> 
> 
>> I'm not able to fully test everything because I'm struggling with the test
>> suite; I don't know whether this is due to me using macOS or misusing
>> PicoLisp.
> 
> Doesn't this
> 
>   $ ./pil lib/test.l -bye +
> 
> work? Sorry, I don't have a 32-bit system available any more.
> 
> Mike, how about you? I'm sure you are our absolute testing guru! ;)
> 

Unfortunately, that crashes with "abort trap: 6", same for some other tests.
I'll see if I can find out what the issue is there.

> 
>> The patch is generated from the git mirror but applies to the source in 
>> picoLisp-18.6.tgz
>> 
>> I'm happy about all feedback.
> 
> If it runs fine, I could release the patched files.

Sounds fantastic!

Cheers,
- Alex

> 
> ♫ Alex
> 
> -- 
> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


--
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe

Reply via email to