[pypy-dev] IRC metting on translator
Armin Rigo
arigo at tunes.org
Wed May 25 19:48:06 CEST 2005
Hi,
Attached, some logs of the screen session. Probably doesn't make sense
without the IRC log as well, and even so.
1. playing in the interactive Python prompt with lltypes to build a
list-like implementation
2. a "to-do" roadmap, mainly about how to implement various RPython
types in low-level types
3. more playing about function pointers, and how they could be used
to call external functions in libraries (thus going in the good
direction to help with this general problem that we have never
investigated in-depth). (Pasted at the end of 1. above).
A bientot,
Armin
-------------- next part --------------
******************************************************************************
Python 2.3.5 (#1, Feb 20 2005, 11:38:51)
[GCC 3.4.3 20050110 (Gentoo Linux 3.4.3.20050110, ssp-3.4.3.20050110-0,
pie-8.7
on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from pypy.rpython import rtyper
>>> from pypy.rpython import rlist
>>> from pypy.rpython.rlist import *
>>> ll_newlist
<function ll_newlist at 0x2a96d4ce60>
>>> from pypy.annotation.model import *
>>> from pypy.annotation.listdef import *
>>> s_list = SomeList(ListDef(None, s_item=SomeInteger()))
>>> s_list
SomeList(listdef=<SomeInteger(nonneg=False, unsigned=False)>)
>>> s_list.lowleveltype()
<ptr(gc) to GcStruct list { items: ptr(gc) to GcArray of { item: Signed
} }>
>>> s_list.lowleveltype() == s_list.lowleveltype()
True
>>> LISTPTR = s_list.lowleveltype()
>>> ll_newlist(LISTPTR, 5)
<_ptrtype to struct list { items=... }>
>>> ptr = _
>>> ptr.items
<_ptrtype to array [ {item=0}, {item=0}, {item=0}, {item=0}, {item=0} ]>
>>> ptr.items[0]
<_ptrtype to struct <arrayitem> { item=0 }>
>>> LISTPTR
<ptr(gc) to GcStruct list { items: ptr(gc) to GcArray of { item: Signed
} }>
>>> LISTPTR.TO
<GcStruct list { items: ptr(gc) to GcArray of { item: Signed } }>
>>> LISTPTR.TO.items
<ptr(gc) to GcArray of { item: Signed }>
>>> LISTPTR.TO.items.OF
Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: '_PtrType' object has no attribute 'OF'
>>> LISTPTR.TO.items.TO
<GcArray of { item: Signed }>
>>> LISTPTR.TO.items.TO.OF
<Struct <arrayitem> { item: Signed }>
>>> ptr # attributes are the fields of the structure it points to
<_ptrtype to struct list { items=... }>
>>> ptr.items
<_ptrtype to array [ {item=0}, {item=0}, {item=0}, {item=0}, {item=0} ]>
>>> # that's a pointer to an array
...
>>> ptr.items[0]
<_ptrtype to struct <arrayitem> { item=0 }>
>>> ptr.items[0].item
0
>>> ptr.items[0].item = 42
>>> ptr.items
<_ptrtype to array [ {item=42}, {item=0}, {item=0}, {item=0}, {item=0}
]>
>>> # pointer to an array in the sense of the produces structure?
KeyboardInterrupt
>>> # for example, to resize a list, we would do something like:
...
>>> LISTPTR
<ptr(gc) to GcStruct list { items: ptr(gc) to GcArray of { item: Signed
} }>
>>> LISTPTR.TO
<GcStruct list { items: ptr(gc) to GcArray of { item: Signed } }>
>>> LISTPTR.TO.items
<ptr(gc) to GcArray of { item: Signed }>
>>> LISTPTR.TO.items.TO
<GcArray of { item: Signed }>
>>> LISTARRAY = _
>>> malloc(LISTARRAY, 6)
<_ptrtype to array [ {item=0}, {item=0}, {item=0}, {item=0}, {item=0},
{item=0} ]>
>>> newitems = _
>>> newitems[0].item = ptr.items[0].item
>>> # etc in a for loop
...
>>> newitems
<_ptrtype to array [ {item=42}, {item=0}, {item=0}, {item=0}, {item=0},
{item=0} ]>
>>> ptr.items = newitems # point to the new array, forget the old one
>>> ptr
<_ptrtype to struct list { items=... }>
>>> ptr.items
<_ptrtype to array [ {item=42}, {item=0}, {item=0}, {item=0}, {item=0},
{item=0} ]>
>>>
******************************************************************************
>>> F = FuncType([Signed, Signed], Signed)
>>> F
<Func ( Signed, Signed ) -> Signed>
>>> functionptr(F, 'externalname') # (TYPE, name)
<_ptrtype to func externalname>
>>> # a pointer to a function which has a name, and nothing more
...
>>> # maybe with more explicit flags:
>>> f = functionptr(F, 'sin', external='math')
>>> f._obj.external
'math'
>>> # so the code generators would know to try to find the given C
function
... # from the given library (the details are very backend-specificm
though).
...
>>> # note that at the moment we're generating direct_call() operations
... # where the first argument is such a functionptr, but with
... # a graph=... attribute.
-------------- next part --------------
* annotator/rtyper interface about specializations introduced
by the annotator
* low-level implementation of the RPython types:
- int and bool
- float
- list and list-iterators
* consider optimizing lists whose length never changes
- dict
* string-keyed dicts
* immutable dicts with general keys
- string
- tuples
- rpython object system (classes+instances)
* instances are GcStruct with the instance fields found by annot.
* subclassing: instance of subclass starts with an inlined
GcStruct containing the parent part of the instance
* instances have a pointer to a "vtable"
* one global vtable per class, a Struct with the class fields
found by annotation (methods are just class fields, of
type 'function pointer')
* subclassing: the vtable starts with an inlined Struct of the
same type as the base class' vtable
* probably special treatment and placement for constructor/__init__
* optimization: de-virtualize method calls when possible, i.e.
when a call can only go to one possible method
- conversions
(- issues with PBCs, need to advance further to discover exactly
what is entailed)
* write a ll-graph interpreter for testing.
* complete translator/c:
- incref, decref, free, deallocators
- exception handling, a la CPython for now
* genllvm:
- add support for new ll types
- add support for garbage collection (probably reference counting for
starters)
-
More information about the pypy-dev
mailing list