Stefan Behnel wrote:
> Dag Sverre Seljebotn wrote:
>> A way to get around this would be to split generate_result_code. So 
>> mainly my proposal, but with this modification:
>>
>> self.subexpr.preparation_code(code)
>> tmp = code.funcstate.allocate_temp(...)
>> self.subexpr.store_result_code(tmp, code)
> 
> That's something I thought about, too. Most of the time, within an
> expression, all you really want is to say "do whatever it takes to
> calculate the result, and then put it *here*", where 'here' may be a temp
> or a name.

How about using a dedicated Target class and writing code like this:

    target = code.new_temp_target(some_type)
    # or, when targeting a name rather than a temp
    target = code.new_target(some_cname, needs_xdecref=True)
    # or maybe even
    target = code.new_target(some_entry, needs_xdecref=True)

and then you'd call

    something.generate_result_code(code, target)

which would do

    code.put_incref("source")
    target.assign_from("source")
    # or
    code.put_incref("source")
    target.assign_from("source", source_type=some_ext_type)

and let 'target' do what's needed in terms of casting the source and
(x)decrefing the target before the assignment.

For disposal, you would call

    target.free()

which would free the temp (if it holds one). I could also imagine writing

    target.decref_clear()

or something in that line.

The "code.new_target()" bit could even be a bit smart and decide based on
the flow control mechanism if an (x)decref is needed for a name when no
needs_decref or needs_xdecref keywords are passed.

What do you think?

Stefan
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to