Tôi muốn biên dịch một số mã python sử dụng trình biên dịch rpython của Pypy. Một ví dụ đồ chơi rất đơn giản mà không làm bất cứ điều gì:Làm thế nào để khởi tạo một tập hợp() trong mã được biên dịch như rpython của pypy?
def main(argv):
a = []
b = set(a)
print b
return 0
def target(driver,args):
return main,None
Nếu tôi biên dịch nó như:
python2.6 ~/Downloads/pypy-1.4.1-src/pypy/translator/goal/translate.py --output trypy trypy.py
Nó không biên dịch, chứ không phải chỉ dừng với lỗi cái gì đó như thế này:
[translation:ERROR] AttributeError': 'FrozenDesc' object has no attribute 'rowkey'
[translation:ERROR] .. v1 = simple_call((type set), v0)
[translation:ERROR] .. '(trypy:3)main'
[translation:ERROR] Processing block:
[translation:ERROR] [email protected] is a <class 'pypy.objspace.flow.flowcontext.SpamBlock'>
[translation:ERROR] in (trypy:3)main
[translation:ERROR] containing the following operations:
[translation:ERROR] v0 = newlist()
[translation:ERROR] v1 = simple_call((type set), v0)
[translation:ERROR] v2 = str(v1)
[translation:ERROR] v3 = simple_call((function rpython_print_item), v2)
[translation:ERROR] v4 = simple_call((function rpython_print_newline))
[translation:ERROR] --end--
Nếu tôi lấy hàm set() hoạt động. Làm thế nào để bạn sử dụng bộ trong rpython?
Dường như là sự cố với PyPy chứ không phải mã của bạn. – orlp
Bạn đã thử 'b = set()' chưa? Sau đó, 'b.add (x)' nếu cần? – TryPyPy
Vì vậy, có vẻ như một trong những không sử dụng bộ trong RPython ... Tốt dicts cũ nên làm các trick, phải không? – TryPyPy