Issues with the micropython.native code generator

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
smurfendrek123
Posts: 6
Joined: Sat Dec 10, 2016 3:46 pm

Issues with the micropython.native code generator

Post by smurfendrek123 » Sat Dec 10, 2016 10:27 pm

Hello everyone

I'm not happy with the speed of my AES implementation (i have to use my own and don't have the time, or knowledge of C to port it to C) so I've resorted to experimenting with the micropython.native code generator, but I'm having some issues.

So my main.py file imports the file Encryption, that file imports Subclasses_Encryption and i added the @micropython.native in some functions in subclasses. But now it's saying that a certain variable (its a matrix called S block) is not defined, while it worked without the @micropython.native.

I did it like this: https://github.com/smurfendrek123/slimm ... enative.py is that the right way to use micropython.native?

If you want the files that import this file, to try it for yourself, ask me and i'll put them all together in a folder.

Thanks

smurfendrek123
Posts: 6
Joined: Sat Dec 10, 2016 3:46 pm

Re: Issues with the micropython.native code generator

Post by smurfendrek123 » Sat Dec 17, 2016 9:34 pm

I got a reply from the kind robert-hh on github, and this was his answer.
@micropython.native code functions seem not to see global symbols. I stumbled over that too. I do not know whether it's a bug. In my case, I just moved that variable into the function using it. That may be possible here too. Otherwise, you could try to supply s_blok and inv_s_block as function parameters.
I will confirm later whether or not this works

smurfendrek123
Posts: 6
Joined: Sat Dec 10, 2016 3:46 pm

Re: Issues with the micropython.native code generator

Post by smurfendrek123 » Sun Dec 18, 2016 12:25 am

Okay, i played around with the native code generator, and it seems that functions using @micropython.native can't use anything outside the function. If you want to call upon another function, you have to add it as an argument, and the same goes for variables.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Issues with the micropython.native code generator

Post by pythoncoder » Sun Dec 18, 2016 5:33 pm

Another approach is to define a class. The native and viper decorators work with methods, which can then access data via self.
Peter Hinch
Index to my micropython libraries.

Post Reply