-
-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Python Path for Windows #533
base: main
Are you sure you want to change the base?
Conversation
b659dfc
to
019a6b6
Compare
I looked into the cause of the test error, and it seems that it may not be a problem with the Python interpreter selection. Traceback (most recent call last):
File "<string>", line 1, in <module>
File "examples/helloworld.er", line -1, in <module>
UnicodeEncodeError: 'cp932' codec can't encode character '\u03ac' in position 3: illegal multibyte sequence I don't remember seeing this error when I wrote this test, but this output may have been obtained as a result of several improvements to make the test results readable.
In fact, the test passed when I deleted everything except alphabets and hiragana. |
8d570ee
to
2febb71
Compare
@@ -1,3 +1,6 @@ | |||
sys = pyimport "sys" | |||
sys.stdout.reconfigure!(encoding:="utf-8") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is inconvenient that multilingual support is only available if the user sets it up using sys.stdout.reconfigure!
, so I think it would be better to include a process to embed this code when generating the code.
For example, Erg embeds a code in the bytecode that passes its own standard API path and loads it. Using this as a reference, it is possible to call sys.stdout.reconfigure
first.
erg/crates/erg_compiler/codegen.rs
Lines 3929 to 3953 in b2fb80c
fn load_prelude_py(&mut self) { | |
self.emit_global_import_items( | |
Identifier::static_public("sys"), | |
vec![( | |
Identifier::static_public("path"), | |
Some(Identifier::private("#path")), | |
)], | |
); | |
self.emit_load_name_instr(Identifier::private("#path")); | |
self.emit_load_method_instr(Identifier::static_public("append"), BoundAttr); | |
self.emit_load_const(erg_core_path().to_str().unwrap()); | |
self.emit_call_instr(1, BoundAttr); | |
self.stack_dec(); | |
self.emit_pop_top(); | |
let erg_std_mod = Identifier::static_public("_erg_std_prelude"); | |
// escaping | |
self.emit_global_import_items( | |
erg_std_mod.clone(), | |
vec![( | |
Identifier::static_public("contains_operator"), | |
Some(Identifier::private("#contains_operator")), | |
)], | |
); | |
self.emit_import_all_instr(erg_std_mod); | |
} |
Changes proposed in this PR:
@mtshiba