mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-30 21:01:10 +00:00
Fix some warnings
This commit is contained in:
parent
6726d93f65
commit
2bba7f741c
14 changed files with 64 additions and 35 deletions
|
@ -317,7 +317,7 @@ impl CodeObj {
|
||||||
) -> std::io::Result<()> {
|
) -> std::io::Result<()> {
|
||||||
let mut file = File::create(path)?;
|
let mut file = File::create(path)?;
|
||||||
let mut bytes = Vec::with_capacity(16);
|
let mut bytes = Vec::with_capacity(16);
|
||||||
let python_ver = python_ver.unwrap_or_else(|| detect_magic_number());
|
let python_ver = python_ver.unwrap_or_else(detect_magic_number);
|
||||||
bytes.append(&mut get_magic_num_bytes(python_ver).to_vec());
|
bytes.append(&mut get_magic_num_bytes(python_ver).to_vec());
|
||||||
bytes.append(&mut vec![0; 4]); // padding
|
bytes.append(&mut vec![0; 4]); // padding
|
||||||
bytes.append(&mut get_timestamp_bytes().to_vec());
|
bytes.append(&mut get_timestamp_bytes().to_vec());
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
//! Escape sequences change the color of the terminal
|
//! Escape sequences change the color of the terminal
|
||||||
|
|
||||||
pub const RESET: &'static str = "\x1b[m";
|
pub const RESET: &str = "\x1b[m";
|
||||||
pub const DEEP_RED: &'static str = "\x1b[31m";
|
pub const DEEP_RED: &str = "\x1b[31m";
|
||||||
pub const RED: &'static str = "\x1b[91m";
|
pub const RED: &str = "\x1b[91m";
|
||||||
pub const GREEN: &'static str = "\x1b[92m";
|
pub const GREEN: &str = "\x1b[92m";
|
||||||
pub const YELLOW: &'static str = "\x1b[93m";
|
pub const YELLOW: &str = "\x1b[93m";
|
||||||
pub const BLUE: &'static str = "\x1b[94m";
|
pub const BLUE: &str = "\x1b[94m";
|
||||||
pub const CYAN: &'static str = "\x1b[96m";
|
pub const CYAN: &str = "\x1b[96m";
|
||||||
|
|
|
@ -44,7 +44,7 @@ where
|
||||||
type Item = Vec<I::Item>;
|
type Item = Vec<I::Item>;
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
if let Some(i) = self.combinations.next() {
|
if let Some(i) = self.combinations.next() {
|
||||||
return Some(i);
|
Some(i)
|
||||||
} else {
|
} else {
|
||||||
self.combinations.reset(self.combinations.k() + 1);
|
self.combinations.reset(self.combinations.k() + 1);
|
||||||
self.len -= 1;
|
self.len -= 1;
|
||||||
|
|
|
@ -96,7 +96,7 @@ impl Input {
|
||||||
},
|
},
|
||||||
Self::Pipe(s) | Self::Str(s) => s.split('\n').collect::<Vec<_>>()
|
Self::Pipe(s) | Self::Str(s) => s.split('\n').collect::<Vec<_>>()
|
||||||
[ln_begin - 1..=ln_end - 1]
|
[ln_begin - 1..=ln_end - 1]
|
||||||
.into_iter()
|
.iter()
|
||||||
.map(|s| Str::rc(*s))
|
.map(|s| Str::rc(*s))
|
||||||
.collect(),
|
.collect(),
|
||||||
Self::REPL => stdin::reread_lines(ln_begin, ln_end),
|
Self::REPL => stdin::reread_lines(ln_begin, ln_end),
|
||||||
|
|
|
@ -84,6 +84,7 @@ impl DeserializeError {
|
||||||
|
|
||||||
pub type DeserializeResult<T> = Result<T, DeserializeError>;
|
pub type DeserializeResult<T> = Result<T, DeserializeError>;
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
pub struct Deserializer {
|
pub struct Deserializer {
|
||||||
str_cache: Cache<str>,
|
str_cache: Cache<str>,
|
||||||
arr_cache: Cache<[ValueObj]>,
|
arr_cache: Cache<[ValueObj]>,
|
||||||
|
@ -107,7 +108,7 @@ impl Deserializer {
|
||||||
process::exit(1);
|
process::exit(1);
|
||||||
};
|
};
|
||||||
let codeobj =
|
let codeobj =
|
||||||
CodeObj::from_pyc(&filename[..]).expect(&format!("failed to deserialize {filename}"));
|
CodeObj::from_pyc(&filename[..]).unwrap_or_else(|_| panic!("failed to deserialize {filename}"));
|
||||||
println!("{}", codeobj.code_info());
|
println!("{}", codeobj.code_info());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,7 +242,7 @@ impl Deserializer {
|
||||||
) -> DeserializeResult<Vec<ValueObj>> {
|
) -> DeserializeResult<Vec<ValueObj>> {
|
||||||
match self.deserialize_const(v, python_ver)? {
|
match self.deserialize_const(v, python_ver)? {
|
||||||
ValueObj::Array(arr) => Ok(arr.to_vec()),
|
ValueObj::Array(arr) => Ok(arr.to_vec()),
|
||||||
other => Err(DeserializeError::type_error(&Type::Str, &other.ref_t())),
|
other => Err(DeserializeError::type_error(&Type::Str, other.ref_t())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,18 +253,18 @@ impl Deserializer {
|
||||||
) -> DeserializeResult<RcArray<ValueObj>> {
|
) -> DeserializeResult<RcArray<ValueObj>> {
|
||||||
match self.deserialize_const(v, python_ver)? {
|
match self.deserialize_const(v, python_ver)? {
|
||||||
ValueObj::Array(arr) => Ok(arr),
|
ValueObj::Array(arr) => Ok(arr),
|
||||||
other => Err(DeserializeError::type_error(&Type::Str, &other.ref_t())),
|
other => Err(DeserializeError::type_error(&Type::Str, other.ref_t())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn array_into_const(&mut self, arr: &[ValueObj]) -> ValueObj {
|
pub fn array_into_const(&mut self, arr: &[ValueObj]) -> ValueObj {
|
||||||
self.get_cached_arr(&arr)
|
self.get_cached_arr(arr)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn try_into_str(&mut self, c: ValueObj) -> DeserializeResult<Str> {
|
pub fn try_into_str(&mut self, c: ValueObj) -> DeserializeResult<Str> {
|
||||||
match c {
|
match c {
|
||||||
ValueObj::Str(s) => Ok(s),
|
ValueObj::Str(s) => Ok(s),
|
||||||
other => Err(DeserializeError::type_error(&Type::Str, &other.ref_t())),
|
other => Err(DeserializeError::type_error(&Type::Str, other.ref_t())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -275,14 +276,14 @@ impl Deserializer {
|
||||||
match self.deserialize_const(v, python_ver)? {
|
match self.deserialize_const(v, python_ver)? {
|
||||||
ValueObj::Array(arr) => {
|
ValueObj::Array(arr) => {
|
||||||
let mut strs = Vec::with_capacity(arr.len());
|
let mut strs = Vec::with_capacity(arr.len());
|
||||||
for c in arr.to_vec().into_iter() {
|
for c in arr.iter().cloned() {
|
||||||
strs.push(self.try_into_str(c)?);
|
strs.push(self.try_into_str(c)?);
|
||||||
}
|
}
|
||||||
Ok(strs)
|
Ok(strs)
|
||||||
}
|
}
|
||||||
other => Err(DeserializeError::type_error(
|
other => Err(DeserializeError::type_error(
|
||||||
&Type::array(Type::Str, TyParam::erased(Type::Nat)),
|
&Type::array(Type::Str, TyParam::erased(Type::Nat)),
|
||||||
&other.ref_t(),
|
other.ref_t(),
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -290,7 +291,7 @@ impl Deserializer {
|
||||||
pub fn deserialize_str(&mut self, v: &mut Vec<u8>, python_ver: u32) -> DeserializeResult<Str> {
|
pub fn deserialize_str(&mut self, v: &mut Vec<u8>, python_ver: u32) -> DeserializeResult<Str> {
|
||||||
match self.deserialize_const(v, python_ver)? {
|
match self.deserialize_const(v, python_ver)? {
|
||||||
ValueObj::Str(s) => Ok(s),
|
ValueObj::Str(s) => Ok(s),
|
||||||
other => Err(DeserializeError::type_error(&Type::Str, &other.ref_t())),
|
other => Err(DeserializeError::type_error(&Type::Str, other.ref_t())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -84,6 +84,11 @@ impl<K, V> Dict<K, V> {
|
||||||
self.dict.len()
|
self.dict.len()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn is_empty(&self) -> bool {
|
||||||
|
self.dict.is_empty()
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn capacity(&self) -> usize {
|
pub fn capacity(&self) -> usize {
|
||||||
self.dict.capacity()
|
self.dict.capacity()
|
||||||
|
|
|
@ -359,7 +359,7 @@ pub trait ErrorDisplay {
|
||||||
fn write_to_stderr(&self) {
|
fn write_to_stderr(&self) {
|
||||||
let mut writer = BufWriter::new(stderr());
|
let mut writer = BufWriter::new(stderr());
|
||||||
writer
|
writer
|
||||||
.write(
|
.write_all(
|
||||||
format!(
|
format!(
|
||||||
"{}{}{}: {}{}\n",
|
"{}{}{}: {}{}\n",
|
||||||
self.format_header(),
|
self.format_header(),
|
||||||
|
@ -379,9 +379,9 @@ pub trait ErrorDisplay {
|
||||||
|
|
||||||
/// fmt::Display実装用
|
/// fmt::Display実装用
|
||||||
fn format(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn format(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
write!(
|
writeln!(
|
||||||
f,
|
f,
|
||||||
"{}{}{}: {}{}\n",
|
"{}{}{}: {}{}",
|
||||||
self.format_header(),
|
self.format_header(),
|
||||||
self.format_code_and_pointer(),
|
self.format_code_and_pointer(),
|
||||||
self.core().kind,
|
self.core().kind,
|
||||||
|
|
|
@ -26,5 +26,5 @@ pub fn levenshtein(lhs: &str, rhs: &str) -> usize {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return table[l_len][r_len];
|
table[l_len][r_len]
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,7 +85,7 @@ pub fn fmt_iter_split_with<T: fmt::Display, I: Iterator<Item = T>>(i: I, splitte
|
||||||
|
|
||||||
pub fn fmt_indent(s: String, depth: usize) -> String {
|
pub fn fmt_indent(s: String, depth: usize) -> String {
|
||||||
let indent = " ".repeat(depth);
|
let indent = " ".repeat(depth);
|
||||||
s.split("\n").map(|s| indent.clone() + s).collect()
|
s.split('\n').map(|s| indent.clone() + s).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_hash<T: std::hash::Hash>(t: &T) -> usize {
|
pub fn get_hash<T: std::hash::Hash>(t: &T) -> usize {
|
||||||
|
|
|
@ -13,9 +13,9 @@ pub fn which_python() -> String {
|
||||||
.expect("python not found");
|
.expect("python not found");
|
||||||
let res = String::from_utf8(out.stdout)
|
let res = String::from_utf8(out.stdout)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.replace("\n", "")
|
.replace('\n', "")
|
||||||
.replace("\r", "");
|
.replace('\r', "");
|
||||||
if res == "" {
|
if res.is_empty() {
|
||||||
panic!("python not found");
|
panic!("python not found");
|
||||||
}
|
}
|
||||||
res
|
res
|
||||||
|
|
|
@ -17,7 +17,7 @@ pub enum Str {
|
||||||
impl PartialEq for Str {
|
impl PartialEq for Str {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn eq(&self, other: &Str) -> bool {
|
fn eq(&self, other: &Str) -> bool {
|
||||||
&self[..] == &other[..]
|
self[..] == other[..]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -345,8 +345,8 @@ pub trait Runnable: Sized {
|
||||||
let output = stdout();
|
let output = stdout();
|
||||||
let mut output = BufWriter::new(output.lock());
|
let mut output = BufWriter::new(output.lock());
|
||||||
log!(f output, "{GREEN}[DEBUG] The REPL has started.{RESET}\n");
|
log!(f output, "{GREEN}[DEBUG] The REPL has started.{RESET}\n");
|
||||||
output.write(instance.start_message().as_bytes()).unwrap();
|
output.write_all(instance.start_message().as_bytes()).unwrap();
|
||||||
output.write(instance.ps1().as_bytes()).unwrap();
|
output.write_all(instance.ps1().as_bytes()).unwrap();
|
||||||
output.flush().unwrap();
|
output.flush().unwrap();
|
||||||
let mut lines = String::new();
|
let mut lines = String::new();
|
||||||
loop {
|
loop {
|
||||||
|
@ -359,20 +359,20 @@ pub trait Runnable: Sized {
|
||||||
lines.push_str(&line);
|
lines.push_str(&line);
|
||||||
if expect_block(&line) || line.starts_with(' ') {
|
if expect_block(&line) || line.starts_with(' ') {
|
||||||
lines += "\n";
|
lines += "\n";
|
||||||
output.write(instance.ps2().as_bytes()).unwrap();
|
output.write_all(instance.ps2().as_bytes()).unwrap();
|
||||||
output.flush().unwrap();
|
output.flush().unwrap();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
match instance.eval(mem::take(&mut lines).into()) {
|
match instance.eval(mem::take(&mut lines).into()) {
|
||||||
Ok(out) => {
|
Ok(out) => {
|
||||||
output.write((out + "\n").as_bytes()).unwrap();
|
output.write_all((out + "\n").as_bytes()).unwrap();
|
||||||
output.flush().unwrap();
|
output.flush().unwrap();
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
e.fmt_all_stderr();
|
e.fmt_all_stderr();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
output.write(instance.ps1().as_bytes()).unwrap();
|
output.write_all(instance.ps1().as_bytes()).unwrap();
|
||||||
output.flush().unwrap();
|
output.flush().unwrap();
|
||||||
instance.clear();
|
instance.clear();
|
||||||
}
|
}
|
||||||
|
|
|
@ -293,14 +293,14 @@ impl<T: Clone + HasLevel> Free<T> {
|
||||||
self.0
|
self.0
|
||||||
.borrow()
|
.borrow()
|
||||||
.constraint()
|
.constraint()
|
||||||
.and_then(|c| c.typ().map(|t| t.clone()))
|
.and_then(|c| c.typ().cloned())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn subtype_of(&self) -> Option<Type> {
|
pub fn subtype_of(&self) -> Option<Type> {
|
||||||
self.0
|
self.0
|
||||||
.borrow()
|
.borrow()
|
||||||
.constraint()
|
.constraint()
|
||||||
.and_then(|c| c.super_type().map(|t| t.clone()))
|
.and_then(|c| c.super_type().cloned())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_unbound(&self) -> bool {
|
pub fn is_unbound(&self) -> bool {
|
||||||
|
|
|
@ -17,7 +17,7 @@ use crate::{RcArray, Str};
|
||||||
|
|
||||||
/// 値オブジェクト
|
/// 値オブジェクト
|
||||||
/// コンパイル時評価ができ、シリアライズも可能
|
/// コンパイル時評価ができ、シリアライズも可能
|
||||||
#[derive(Clone, PartialEq)]
|
#[derive(Clone)]
|
||||||
pub enum ValueObj {
|
pub enum ValueObj {
|
||||||
Int(i32),
|
Int(i32),
|
||||||
Nat(u64),
|
Nat(u64),
|
||||||
|
@ -92,6 +92,29 @@ impl Neg for ValueObj {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl PartialEq for ValueObj {
|
||||||
|
fn eq(&self, other: &ValueObj) -> bool {
|
||||||
|
match (self, other) {
|
||||||
|
(Self::Int(i), Self::Int(j)) => i == j,
|
||||||
|
(Self::Nat(n), Self::Nat(m)) => n == m,
|
||||||
|
(Self::Float(fl), Self::Float(fr)) => fl == fr,
|
||||||
|
(Self::Str(s), Self::Str(t)) => s == t,
|
||||||
|
(Self::True, Self::True) => true,
|
||||||
|
(Self::False, Self::False) => true,
|
||||||
|
(Self::Array(arr), Self::Array(arr2)) => arr == arr2,
|
||||||
|
(Self::Dict(dict), Self::Dict(dict2)) => dict == dict2,
|
||||||
|
(Self::Code(code), Self::Code(code2)) => code == code2,
|
||||||
|
(Self::None, Self::None) => true,
|
||||||
|
(Self::Ellipsis, Self::Ellipsis) => true,
|
||||||
|
(Self::NotImplemented, Self::NotImplemented) => true,
|
||||||
|
(Self::NegInf, Self::NegInf) => true,
|
||||||
|
(Self::Inf, Self::Inf) => true,
|
||||||
|
(Self::Illegal, Self::Illegal) => true,
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// FIXME:
|
// FIXME:
|
||||||
impl Hash for ValueObj {
|
impl Hash for ValueObj {
|
||||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue