[Python-ideas] Jump to function as an an alternative to call function

Jacob Solinsky jacobsolinsky at gmail.com
Thu Aug 16 17:37:19 EDT 2018


So when getx is executed inside a let form, if it tries to read/write the
value of X it interacts with the X entry in the let form's symbol table
before moving to find X in the global environment, right? That is similar
to what I was trying to accomplish in python, but with the local symbol
table of the calling function rather than a let form.

I think the way a "jump to" function rather than a "call function" would be
implemented would be by removing the prologue and epilogue of the
function's compiled code. Something vaguely like this:

def foo(a,b):
    c = bar(d =3)%
    return c+2

def bar(d)
     a += 2
     e = 4
     return a + b + d +e

foo(7, 2)

Here would be the symbol table

Scope Foo
__________
a: fp - 1
b: fp - 2
d: fp - 3
e: fp - 5
c: fp - 4

The interpreter would have to recognize that bar was being jumped to rather
than called and thus inject bar's arguments and variable declarations and
return value (if assigned to) into foo's stack frame.

The translation of the above code would be this (I apologize for the
strange pseudoassembly, I don't know any of those languages on a more than
cursory level. The below code is obviously very slow, each variable read
from the memory and written to memory at every step, with no storage of
local variables in registers.) The "return c+2" statement is changed from a
return into a c += 2 assignment in the calling function.

PUSH fp, returnregister # preserve old value in return register
PUSH -1(fp), 7 # load a
PUSH -2(fp),  2 # load b
PUSH -3(fp), 3 # load d
PUSH -4(fp), 0 # initialize c
ADDI -1(fp), -1(fp), 2 # a += 2
PUSH -5(fp), 4 # load e
ADD -4(fp), -1(fp), -2(fp) # c = a + b + d + e
ADD -4(fp), -4(fp), -5(fp) # c = a + d + d + e continued
ADDI returnregister, -4(fp), 2 # return c + 2











On Thu, 16 Aug 2018, 14:44 Jonathan Fine, <jfine2358 at gmail.com> wrote:

> Hi Jacob
>
> I'm finding the python-ideas list a bit noisy, so I'm sending this
> off-list.
>
> I've found
>
>
> https://www.gnu.org/software/emacs/manual/html_node/elisp/Dynamic-Binding.html
>
> https://www.gnu.org/software/emacs/manual/html_node/elisp/Variable-Scoping.html
>
> Please confirm that this is at least close to what you want, to be
> able to program your problem efficiently.
>
> Meanwhile, I'm thinking about how your algorithm might be expressed in
> Python.
>
> --
> Jonathan
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180816/fed91245/attachment-0001.html>


More information about the Python-ideas mailing list