I have the following code:
import sys def entry_point(argv): sys.exit(1) return 0 def target(*args): return entry_point, None
However, when I run python ./pypy/pypy/translator/goal/translate.py t.py , I get the following error:
... [translation:ERROR] Exception: unexpected prebuilt constant: <built-in function exit> [translation:ERROR] Processing block: [translation:ERROR] block@9 is a <class 'pypy.objspace.flow.flowcontext.SpamBlock'> [translation:ERROR] in (t:3)entry_point [translation:ERROR] containing the following operations: [translation:ERROR] v0 = simple_call((builtin_function_or_method exit), (1)) [translation:ERROR] --end--
Actually there were more mistakes, but I thought this last part mattered. If you think that more of this might be useful, comment and I will edit.
In fact, I get another error when I replace sys.exit with something simpler, like sys.stdout.write.
import sys def entry_point(argv): sys.stdout.write('some mesg\n') return 0 def target(*args): return entry_point, None
gives me:
... [translation:ERROR] AnnotatorError: annotation of v0 degenerated to SomeObject() [translation:ERROR] v0 = getattr((module sys), ('stdout')) [translation:ERROR] [translation:ERROR] In <FunctionGraph of (t:3)entry_point at 0x10d03de10>: [translation:ERROR] Happened at file t.py line 4 [translation:ERROR] [translation:ERROR] ==> sys.stdout.write('some mesg\n') [translation:ERROR] [translation:ERROR] Previous annotation: [translation:ERROR] (none) [translation:ERROR] Processing block: [translation:ERROR] block@3 is a <class 'pypy.objspace.flow.flowcontext.SpamBlock'> [translation:ERROR] in (t:3)entry_point [translation:ERROR] containing the following operations: [translation:ERROR] v0 = getattr((module sys), ('stdout')) [translation:ERROR] v1 = getattr(v0, ('write')) [translation:ERROR] v2 = simple_call(v1, ('some mesg\n')) [translation:ERROR] --end--
Are sys methods simply inaccessible to RPython? It seems strange to me because exit and stdout are so easily accessible in C. However, the error messages look like they might be different, so I could just bark through the wrong tree.
I am currently using this guide to find out exactly what is allowed and not allowed in RPython. Are there any other pretty accessible links that I could use for more information?
math4tots
source share