Hi Seo,

Sanghyeon Seo wrote:
Is there some documentation on oopspec attribute? How one may use it
in the backend?

I think there are no docs about the oopspec attribute. Armin wrote these lines some time ago to respond to the same question:

"""
The oopspec string tells what is the "abstract" list operation that this
particular ll_*() function implement.  For example:

    def ll_prepend(l, newitem):
        ...
    ll_prepend.oopspec = 'list.insert(l, 0, newitem)'

means that ll_prepend() is equivalent to an insert with the index set to
zero.  In the stirng, the pseudo-arguments between the ( ) are either
real argument names of the ll_ function, or constants.

So for example, if a backend has got its own way to implement the
insert() calls in general, it could figure out from the oopspec that the
ll_prepend() helper can be replaced by a custom stub invoking the
backend's own version of insertion with an index of 0.  That's
essentially what the JIT does -- see handle_highlevel_operation() in
jit/hintannotator/model.py.
"""

The CLI backend uses the oopspec attribute for replacing calls to selected low-level helpers with native builtin methods; the code is still very experimental since it doesn't parse the argument line: it simply forwards the call using the first parameter as the target object and subsequent parameters as method's arguments. By now the only recognized oopspec is 'list.append' (i.e., ll_append) that is translated to the 'Add' method.

If you want to look at my code see translator/cli/oopspec.py and the _Call.render method in translator/cli/metavm.py; at the moment I put these files in the cli/ directory, but they are general enough to be shared among multiple backends (metavm would be useful only for backends emitting bytecode, so not for gencl nor gensqueak, I guess).

The rationale behind this is that this way a backend can quickly gain full list support by simply supply basic operations such as ll_getitem_fast & Co; then each backend can choose what operation to optimize based on their knowledge of the target system.

Btw, I have a doubt about oopspec, too: Armin told that the 'oopspec' specifies the "abstract" operation that each ll_* helper implements; does this abstract operation have to be one of standard list methods or can I add new operations? I was thinking to add a 'll_remove_range' or similar to be used by other helpers such as delslice and company; this way backends can replace ll_remove_range with their almost-surely-present equivalent without having to care about python-specific logic such as slices or so.

ciao Anto
_______________________________________________
pypy-dev@codespeak.net
http://codespeak.net/mailman/listinfo/pypy-dev

Reply via email to