This commit is contained in:
Shunsuke Shibayama 2022-12-19 21:02:01 +09:00
parent debd544fdb
commit ec4d668189
5 changed files with 25 additions and 20 deletions

View file

@ -58,5 +58,5 @@ bd_zh_cn_re = "build --features debug --features simplified_chinese --release"
bd_zh_tw_re = "build --features debug --features traditional_chinese --release"
# static linking to libc
[target.'cfg(unix)']
rustflags = ["-C", "target-feature=+crt-static"]
# [target.'cfg(unix)']
# rustflags = ["-C", "target-feature=+crt-static"]

View file

@ -328,6 +328,7 @@ impl PyCodeGenerator {
#[inline]
fn edit_code(&mut self, idx: usize, arg: usize) {
log!(err "editing: {idx} {arg}");
match u8::try_from(arg) {
Ok(u8code) => {
*self.mut_cur_block_codeobj().code.get_mut(idx).unwrap() = u8code;
@ -660,14 +661,6 @@ impl PyCodeGenerator {
.local_search(&escaped, Name)
.unwrap_or_else(|| self.register_name(escaped));
let instr = self.select_load_instr(name.kind, Name);
/*let null_idx = self.cur_block_codeobj().code.len() - 2;
if instr == LOAD_GLOBAL
&& self.cur_block_codeobj().code.get(null_idx) == Some(&(Opcode311::PUSH_NULL as u8))
{
self.mut_cur_block_codeobj().code.pop();
self.mut_cur_block_codeobj().code.pop();
self.mut_cur_block().lasti -= 2;
}*/
self.write_instr(instr);
self.write_arg(name.idx);
self.stack_inc();
@ -2879,8 +2872,11 @@ impl PyCodeGenerator {
let freevars_len = self.cur_block_codeobj().freevars.len();
if freevars_len > 0 {
self.mut_cur_block_codeobj().flags += CodeObjFlags::Nested as u32;
if self.py_version.minor >= Some(11) {
self.edit_code(idx_copy_free_vars + 1, freevars_len);
}
} else if self.py_version.minor >= Some(11) {
// cancel copying
let code = self.cur_block_codeobj().code.get(idx_copy_free_vars);
debug_assert_eq!(code, Some(&(Opcode311::COPY_FREE_VARS as u8)));
self.edit_code(idx_copy_free_vars, CommonOpcode::NOP as usize);

View file

@ -313,7 +313,7 @@ impl CodeObj {
pub fn into_bytes(self, python_ver: PythonVersion) -> Vec<u8> {
let mut bytes = vec![DataTypePrefix::Code as u8];
bytes.append(&mut self.argcount.to_le_bytes().to_vec());
if python_ver.minor >= Some(10) {
if python_ver.minor >= Some(8) {
bytes.append(&mut self.posonlyargcount.to_le_bytes().to_vec());
}
bytes.append(&mut self.kwonlyargcount.to_le_bytes().to_vec());

View file

@ -1,6 +1,7 @@
use std::fs::remove_file;
use std::io::{Read, Write};
use std::net::{Ipv4Addr, SocketAddrV4, TcpListener, TcpStream};
use std::process;
use std::thread::sleep;
use std::time::Duration;
@ -94,7 +95,10 @@ impl Runnable for DummyVM {
fn finish(&mut self) {
if let Some(stream) = &mut self.stream {
stream.write_all("exit".as_bytes()).unwrap();
if let Err(err) = stream.write_all("exit".as_bytes()) {
eprintln!("Write error: {err}");
process::exit(1);
}
let mut buf = [0; 1024];
match stream.read(&mut buf) {
Result::Ok(n) => {
@ -103,8 +107,9 @@ impl Runnable for DummyVM {
println!("The REPL server is closed.");
}
}
Result::Err(e) => {
panic!("{}", format!("Read error: {e}"));
Result::Err(err) => {
eprintln!("Read error: {err}");
process::exit(1);
}
}
remove_file("o.pyc").unwrap_or(());
@ -156,15 +161,17 @@ impl Runnable for DummyVM {
}
s.to_string()
}
Result::Err(e) => {
Result::Err(err) => {
self.finish();
panic!("{}", format!("Read error: {e}"));
eprintln!("Read error: {err}");
process::exit(1);
}
}
}
Result::Err(e) => {
Result::Err(err) => {
self.finish();
panic!("{}", format!("Sending error: {e}"))
eprintln!("Sending error: {err}");
process::exit(1);
}
};
if res.ends_with("None") {

View file

@ -70,7 +70,9 @@ fn _exec_vm(file_path: &'static str) -> Result<i32, CompileErrors> {
} else {
Some("python3")
};
// cfg.target_version = Some(PythonVersion::new(3, Some(10), Some(6))); // your Python's version
// cfg.target_version = Some(PythonVersion::new(3, Some(8), Some(10))); // your Python's version
// cfg.py_magic_num = Some(3413); // in (most) 3.8.x
// cfg.target_version = Some(PythonVersion::new(3, Some(10), Some(6)));
// cfg.py_magic_num = Some(3439); // in (most) 3.10.x
cfg.target_version = Some(PythonVersion::new(3, Some(11), Some(0)));
cfg.py_magic_num = Some(3495); // in 3.11.0