Supported modules

swtjingle

New member
I tried against a script I have downloaded but I get an error: can not import module `struct`: file 'struct.py' is not found
I wonder if such cpython module can be supported?

As a side note: I got security messages when registering, I wonder if this site could use https?
 

alextretyak

Administrator
Staff member
The current development of transpiler Python → 11l → C++ is task-driven, i.e. the transpiler is extended by specific tasks solving (at the present moment mainly from Rosetta Code).

Can you provide your source file wholly or code sample that you want to compile?


P.S. I added support of int.from_bytes() recently [I've just updated 11l.tar.xz] for this code to work:
Python:
file_bytes = open(bmp_file_name, 'rb').read()
image_width = int.from_bytes(file_bytes[18:22], 'little')
 

alextretyak

Administrator
Staff member
Does this converter has performance issues?
If so:
1. Can you provide .exs file for testing?
2. Have you tried PyPy for better performance?
 

swtjingle

New member
I'm not interested to fix it, I did some workaround for testing but I'm only interested to port it to c++ (a partial rewrite was done but it would be nice have some conversion as reference if possible).
Here 2 exs files for testing.
 

Attachments

swtjingle

New member
In the end I just wanted to know if it were possible to support the struct module without having you to deal with the rest of the implementation code of the script.
 

alextretyak

Administrator
Staff member
I have updated transpiler Python → 11l → C++, and made some modifications to exs2sfz.py file, so it can be successfully compiled.

Also I performed some performance tests.
Here is the results for NaturalKit.exs:
Time (in milliseconds)Factor (relative to CPython)
CPython 2381x
PyPy3.7-v7.3.2-win328420.28x
Cython 3.0a61991.2x
Python → 11l → C++ 327.4x

[However tested source file was slightly modified: function locate() was changed to always return empty string. (Anyway this function is very inefficient and should be rewritten.)]

if it were possible to support the struct module
As I said above, the current development process is task-driven. (And I hope it remains so in the foreseeable future.) The reason of this is to keep language [11l] and transpilers [Python → 11l and 11l → C++] as small as possible.

So now I will reject all such generic suggestions as ‘support the struct module’. Because I read this as ‘support the struct module entirely’. So, what should I do? Just go through whole struct module documentation and implement every feature of it?
I dislike this approach. Instead I'd like to implement only really needed features for some practical tasks.

So, I have implemented a small part of the struct module: struct.unpack_from() (for exs2sfz.py) and struct.unpack() (to support code from here) with types `i`, `I`, `h`, `H`, `b`, `B` and little/big-endian byte order support.
What else do you need in the struct module?
 
Last edited:

swtjingle

New member
Great! Thanks a lot! This is just a one time case to be able to debug some details of that code that should be rewritten in c++, so I don't really expect anything else, so do what you think will be more appropriated in a general context and in line with your project.
 
Top