compiler - how to emit mp_store_name in functions

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
jickster
Posts: 629
Joined: Thu Sep 07, 2017 8:57 pm

compiler - how to emit mp_store_name in functions

Post by jickster » Mon May 28, 2018 4:13 am

I'm trying to induce the compiler to emit mp_store_name() inside a function but I cannot

Code: Select all

def f1():
	a = [22]
	b = [a,a]
	c = (a, b)
	return 0


b = f1()
Why won't f1() contain mp_store_name() and how do I get it to contain mp_store_name()

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

Re: compiler - how to emit mp_store_name in functions

Post by pythoncoder » Mon May 28, 2018 5:59 am

I'm guessing wildly here but is it something to do with locals being on the stack?
Peter Hinch
Index to my micropython libraries.

jickster
Posts: 629
Joined: Thu Sep 07, 2017 8:57 pm

compiler - how to emit mp_store_name in functions

Post by jickster » Mon May 28, 2018 6:00 am

pythoncoder wrote:I'm guessing wildly here but is it something to do with locals being on the stack?
How do I get them to not be on the stack?

Do I need to return from a builtin?


Sent from my iPhone using Tapatalk

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

Re: compiler - how to emit mp_store_name in functions

Post by pythoncoder » Mon May 28, 2018 6:05 am

I have little knowledge of compilers but my guess is that if the variables were global or if the function returned a local it might be called (they can obviously no longer live on the stack after a function return).
Peter Hinch
Index to my micropython libraries.

stijn
Posts: 735
Joined: Thu Apr 24, 2014 9:13 am

Re: compiler - how to emit mp_store_name in functions

Post by stijn » Mon May 28, 2018 9:09 am

Look for the references to mp_store_name in the code: it is only used for the MP_BC_STORE_NAME bytecode or when importing modules. And MP_BC_STORE_NAME is only emitted in mp_emit_bc_store_global (so will only be called for f1 and b in your code). I don't think there's a way to get mp_emit_bc_store_global to be called from within a function, but just importing modules in a function is possible so use that as a solution.

Post Reply