mirror of
https://github.com/erg-lang/erg.git
synced 2025-10-02 21:44:34 +00:00
fix: eliminate todo!
s
This commit is contained in:
parent
2e8810f10d
commit
f1c44175f7
2 changed files with 59 additions and 41 deletions
|
@ -1199,9 +1199,18 @@ impl Context {
|
||||||
namespace: &Context,
|
namespace: &Context,
|
||||||
) -> TyCheckResult<VarInfo> {
|
) -> TyCheckResult<VarInfo> {
|
||||||
erg_common::debug_power_assert!(args.len() == 2);
|
erg_common::debug_power_assert!(args.len() == 2);
|
||||||
let cont = Str::rc(binop_to_dname(op.inspect()));
|
let Some(cont) = binop_to_dname(op.inspect()) else {
|
||||||
|
return Err(TyCheckError::no_var_error(
|
||||||
|
self.cfg.input.clone(),
|
||||||
|
line!() as usize,
|
||||||
|
op.loc(),
|
||||||
|
namespace.caused_by(),
|
||||||
|
op.inspect(),
|
||||||
|
None,
|
||||||
|
).into());
|
||||||
|
};
|
||||||
// not a `Token::from_str(op.kind, cont)` because ops are defined as symbols
|
// not a `Token::from_str(op.kind, cont)` because ops are defined as symbols
|
||||||
let symbol = Token::symbol_with_loc(cont, Location::concat(&args[0], &args[1]));
|
let symbol = Token::symbol_with_loc(Str::rc(cont), Location::concat(&args[0], &args[1]));
|
||||||
let ident = Identifier::private_from_token(symbol.clone());
|
let ident = Identifier::private_from_token(symbol.clone());
|
||||||
let t = self
|
let t = self
|
||||||
.rec_get_var_info(&ident, AccessKind::Name, input, namespace)
|
.rec_get_var_info(&ident, AccessKind::Name, input, namespace)
|
||||||
|
@ -1244,7 +1253,16 @@ impl Context {
|
||||||
namespace: &Context,
|
namespace: &Context,
|
||||||
) -> TyCheckResult<VarInfo> {
|
) -> TyCheckResult<VarInfo> {
|
||||||
erg_common::debug_power_assert!(args.len() == 1);
|
erg_common::debug_power_assert!(args.len() == 1);
|
||||||
let cont = unaryop_to_dname(op.inspect());
|
let Some(cont) = unaryop_to_dname(op.inspect()) else {
|
||||||
|
return Err(TyCheckError::no_var_error(
|
||||||
|
self.cfg.input.clone(),
|
||||||
|
line!() as usize,
|
||||||
|
op.loc(),
|
||||||
|
namespace.caused_by(),
|
||||||
|
op.inspect(),
|
||||||
|
None,
|
||||||
|
).into());
|
||||||
|
};
|
||||||
let symbol = Token::symbol(cont);
|
let symbol = Token::symbol(cont);
|
||||||
let ident = Identifier::private_from_token(symbol.clone());
|
let ident = Identifier::private_from_token(symbol.clone());
|
||||||
let vi = self
|
let vi = self
|
||||||
|
|
|
@ -78,50 +78,50 @@ pub fn ordinal_num(n: usize) -> String {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// dname is for "double under name"
|
/// dname is for "double under name"
|
||||||
pub fn binop_to_dname(op: &str) -> &str {
|
pub fn binop_to_dname(op: &str) -> Option<&str> {
|
||||||
match op {
|
match op {
|
||||||
"+" => "__add__",
|
"+" => Some("__add__"),
|
||||||
"-" => "__sub__",
|
"-" => Some("__sub__"),
|
||||||
"*" => "__mul__",
|
"*" => Some("__mul__"),
|
||||||
"/" => "__div__",
|
"/" => Some("__div__"),
|
||||||
"//" => "__floordiv__",
|
"//" => Some("__floordiv__"),
|
||||||
"**" => "__pow__",
|
"**" => Some("__pow__"),
|
||||||
"%" => "__mod__",
|
"%" => Some("__mod__"),
|
||||||
"@" => "__matmul__",
|
"@" => Some("__matmul__"),
|
||||||
".." => "__rng__",
|
".." => Some("__rng__"),
|
||||||
"<.." => "__lorng__",
|
"<.." => Some("__lorng__"),
|
||||||
"..<" => "__rorng__",
|
"..<" => Some("__rorng__"),
|
||||||
"<..<" => "__orng__",
|
"<..<" => Some("__orng__"),
|
||||||
"&&" | "&" | "and" => "__and__",
|
"&&" | "&" | "and" => Some("__and__"),
|
||||||
"||" | "|" | "or" => "__or__",
|
"||" | "|" | "or" => Some("__or__"),
|
||||||
"^^" | "^" => "__xor__",
|
"^^" | "^" => Some("__xor__"),
|
||||||
"as" => "__as__",
|
"as" => Some("__as__"),
|
||||||
// l in r, l notin r -> r contains l, not(r contains l)
|
// l in r, l notin r -> r contains l, not(r contains l)
|
||||||
"contains" => "__contains__",
|
"contains" => Some("__contains__"),
|
||||||
"subof" => "__subof__",
|
"subof" => Some("__subof__"),
|
||||||
"supof" => "__supof__",
|
"supof" => Some("__supof__"),
|
||||||
"is!" => "__is__!",
|
"is!" => Some("__is__!"),
|
||||||
"isnot!" => "__isnot__!",
|
"isnot!" => Some("__isnot__!"),
|
||||||
"==" => "__eq__",
|
"==" => Some("__eq__"),
|
||||||
"!=" => "__ne__",
|
"!=" => Some("__ne__"),
|
||||||
"<" => "__lt__",
|
"<" => Some("__lt__"),
|
||||||
"<=" => "__le__",
|
"<=" => Some("__le__"),
|
||||||
">" => "__gt__",
|
">" => Some("__gt__"),
|
||||||
">=" => "__ge__",
|
">=" => Some("__ge__"),
|
||||||
"<<" => "__lshift__",
|
"<<" => Some("__lshift__"),
|
||||||
">>" => "__rshift__",
|
">>" => Some("__rshift__"),
|
||||||
other => todo!("no such binary operator: {other}"),
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn unaryop_to_dname(op: &str) -> &str {
|
pub fn unaryop_to_dname(op: &str) -> Option<&str> {
|
||||||
match op {
|
match op {
|
||||||
"+" => "__pos__",
|
"+" => Some("__pos__"),
|
||||||
"-" => "__neg__",
|
"-" => Some("__neg__"),
|
||||||
"~" => "__invert__",
|
"~" => Some("__invert__"),
|
||||||
"!" => "__mutate__",
|
"!" => Some("__mutate__"),
|
||||||
"..." => "__spread__",
|
"..." => Some("__spread__"),
|
||||||
other => todo!("no such unary operator: {other}"),
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue