ho il seguente codice:RPython metodi sys non funzionano
import sys
def entry_point(argv):
sys.exit(1)
return 0
def target(*args):
return entry_point, None
Tuttavia, quando corro python ./pypy/pypy/translator/goal/translate.py t.py
ottengo il seguente errore:
...
[translation:ERROR] Exception: unexpected prebuilt constant: <built-in function exit>
[translation:ERROR] Processing block:
[translation:ERROR] [email protected] 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--
C'era in realtà più per l'errore, ma Pensavo che solo quest'ultima parte fosse pertinente. Se pensi che potrebbe esserti utile, ti preghiamo di commentare e io modificherò.
In effetti, ottengo un altro errore quando sostituisco sys.exit con qualcosa di ancora più semplice come sys.stdout.write.
import sys
def entry_point(argv):
sys.stdout.write('some mesg\n')
return 0
def target(*args):
return entry_point, None
mi da:
...
[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] [email protected] 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--
sono metodi sys semplicemente off limits per RPython? Sembra strano per me perché exit e stdout sono così prontamente disponibili in C. Tuttavia, i messaggi di errore sembrano simili a cose diverse, quindi potrei semplicemente abbaiare dall'albero sbagliato.
Attualmente sto usando la guida this per capire approssimativamente cosa è permesso e non permesso in RPython. Ci sono altri riferimenti piuttosto accessibili che potrei usare per maggiori informazioni?
Mi spiace non posso aiutare ulteriormente, ma permettimi di far notare che l'ultimo esempio è sbagliato che dovresti sostituire: 'sys.std.write' di' sys.stdout.write', non c'è 'sys.std 'in python. – mouad
@mouad Grazie per avermelo fatto notare. Ho provato di nuovo e pubblicato il messaggio di errore aggiornato. – math4tots