mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-30 12:51:10 +00:00
Remove SubrSignature::t
This commit is contained in:
parent
78432c6906
commit
4c171db645
5 changed files with 54 additions and 19 deletions
|
@ -2376,14 +2376,15 @@ impl PyCodeGenerator {
|
||||||
log!(info "entered {}", fn_name!());
|
log!(info "entered {}", fn_name!());
|
||||||
let line = sig.ln_begin().unwrap();
|
let line = sig.ln_begin().unwrap();
|
||||||
let class_name = sig.ident().inspect();
|
let class_name = sig.ident().inspect();
|
||||||
let ident = Identifier::public_with_line(DOT, Str::ever("__init__"), line);
|
let mut ident = Identifier::public_with_line(DOT, Str::ever("__init__"), line);
|
||||||
|
ident.vi.t = __new__.clone();
|
||||||
let param_name = fresh_varname();
|
let param_name = fresh_varname();
|
||||||
let param = VarName::from_str_and_line(Str::from(param_name.clone()), line);
|
let param = VarName::from_str_and_line(Str::from(param_name.clone()), line);
|
||||||
let param = NonDefaultParamSignature::new(ParamPattern::VarName(param), None);
|
let param = NonDefaultParamSignature::new(ParamPattern::VarName(param), None);
|
||||||
let self_param = VarName::from_str_and_line(Str::ever("self"), line);
|
let self_param = VarName::from_str_and_line(Str::ever("self"), line);
|
||||||
let self_param = NonDefaultParamSignature::new(ParamPattern::VarName(self_param), None);
|
let self_param = NonDefaultParamSignature::new(ParamPattern::VarName(self_param), None);
|
||||||
let params = Params::new(vec![self_param, param], None, vec![], None);
|
let params = Params::new(vec![self_param, param], None, vec![], None);
|
||||||
let subr_sig = SubrSignature::new(ident, params, __new__.clone());
|
let subr_sig = SubrSignature::new(ident, params);
|
||||||
let mut attrs = vec![];
|
let mut attrs = vec![];
|
||||||
match __new__.non_default_params().unwrap()[0].typ() {
|
match __new__.non_default_params().unwrap()[0].typ() {
|
||||||
// namedtupleは仕様上::xなどの名前を使えない
|
// namedtupleは仕様上::xなどの名前を使えない
|
||||||
|
@ -2431,11 +2432,12 @@ impl PyCodeGenerator {
|
||||||
log!(info "entered {}", fn_name!());
|
log!(info "entered {}", fn_name!());
|
||||||
let class_ident = sig.ident();
|
let class_ident = sig.ident();
|
||||||
let line = sig.ln_begin().unwrap();
|
let line = sig.ln_begin().unwrap();
|
||||||
let ident = Identifier::public_with_line(DOT, Str::ever("new"), line);
|
let mut ident = Identifier::public_with_line(DOT, Str::ever("new"), line);
|
||||||
|
ident.vi.t = __new__;
|
||||||
let param_name = fresh_varname();
|
let param_name = fresh_varname();
|
||||||
let param = VarName::from_str_and_line(Str::from(param_name.clone()), line);
|
let param = VarName::from_str_and_line(Str::from(param_name.clone()), line);
|
||||||
let param = NonDefaultParamSignature::new(ParamPattern::VarName(param), None);
|
let param = NonDefaultParamSignature::new(ParamPattern::VarName(param), None);
|
||||||
let sig = SubrSignature::new(ident, Params::new(vec![param], None, vec![], None), __new__);
|
let sig = SubrSignature::new(ident, Params::new(vec![param], None, vec![], None));
|
||||||
let arg = PosArg::new(Expr::Accessor(Accessor::private_with_line(
|
let arg = PosArg::new(Expr::Accessor(Accessor::private_with_line(
|
||||||
Str::from(param_name),
|
Str::from(param_name),
|
||||||
line,
|
line,
|
||||||
|
|
|
@ -686,8 +686,11 @@ impl Context {
|
||||||
self.deref_tyvar(mem::take(var.ref_mut_t()), Covariant, var.loc())?;
|
self.deref_tyvar(mem::take(var.ref_mut_t()), Covariant, var.loc())?;
|
||||||
}
|
}
|
||||||
hir::Signature::Subr(subr) => {
|
hir::Signature::Subr(subr) => {
|
||||||
subr.t =
|
*subr.ref_mut_t() = self.deref_tyvar(
|
||||||
self.deref_tyvar(mem::take(&mut subr.t), Covariant, subr.loc())?;
|
mem::take(subr.ref_mut_t()),
|
||||||
|
Covariant,
|
||||||
|
subr.loc(),
|
||||||
|
)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for chunk in attr.body.block.iter_mut() {
|
for chunk in attr.body.block.iter_mut() {
|
||||||
|
@ -738,8 +741,11 @@ impl Context {
|
||||||
self.deref_tyvar(mem::take(var.ref_mut_t()), Covariant, var.loc())?;
|
self.deref_tyvar(mem::take(var.ref_mut_t()), Covariant, var.loc())?;
|
||||||
}
|
}
|
||||||
hir::Signature::Subr(subr) => {
|
hir::Signature::Subr(subr) => {
|
||||||
subr.t =
|
*subr.ref_mut_t() = self.deref_tyvar(
|
||||||
self.deref_tyvar(mem::take(&mut subr.t), Covariant, subr.loc())?;
|
mem::take(subr.ref_mut_t()),
|
||||||
|
Covariant,
|
||||||
|
subr.loc(),
|
||||||
|
)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for chunk in def.body.block.iter_mut() {
|
for chunk in def.body.block.iter_mut() {
|
||||||
|
|
|
@ -437,6 +437,11 @@ impl Identifier {
|
||||||
self.name.inspect()
|
self.name.inspect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// show dot + name (no qual_name & type)
|
||||||
|
pub fn show(&self) -> String {
|
||||||
|
format!("{}{}", fmt_option!(self.dot), self.name)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn is_procedural(&self) -> bool {
|
pub fn is_procedural(&self) -> bool {
|
||||||
self.name.is_procedural()
|
self.name.is_procedural()
|
||||||
}
|
}
|
||||||
|
@ -1366,22 +1371,45 @@ impl Params {
|
||||||
pub struct SubrSignature {
|
pub struct SubrSignature {
|
||||||
pub ident: Identifier,
|
pub ident: Identifier,
|
||||||
pub params: Params,
|
pub params: Params,
|
||||||
pub t: Type,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NestedDisplay for SubrSignature {
|
impl NestedDisplay for SubrSignature {
|
||||||
fn fmt_nest(&self, f: &mut fmt::Formatter<'_>, _level: usize) -> fmt::Result {
|
fn fmt_nest(&self, f: &mut fmt::Formatter<'_>, _level: usize) -> fmt::Result {
|
||||||
write!(f, "{}{} (: {})", self.ident, self.params, self.t,)
|
write!(
|
||||||
|
f,
|
||||||
|
"{}{} (: {})",
|
||||||
|
self.ident.show(),
|
||||||
|
self.params,
|
||||||
|
self.ident.t()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl_display_from_nested!(SubrSignature);
|
impl_display_from_nested!(SubrSignature);
|
||||||
impl_locational!(SubrSignature, ident, params);
|
impl_locational!(SubrSignature, ident, params);
|
||||||
impl_t!(SubrSignature);
|
|
||||||
|
impl HasType for SubrSignature {
|
||||||
|
#[inline]
|
||||||
|
fn ref_t(&self) -> &Type {
|
||||||
|
self.ident.ref_t()
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
fn ref_mut_t(&mut self) -> &mut Type {
|
||||||
|
self.ident.ref_mut_t()
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
fn signature_t(&self) -> Option<&Type> {
|
||||||
|
self.ident.signature_t()
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
fn signature_mut_t(&mut self) -> Option<&mut Type> {
|
||||||
|
self.ident.signature_mut_t()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl SubrSignature {
|
impl SubrSignature {
|
||||||
pub const fn new(ident: Identifier, params: Params, t: Type) -> Self {
|
pub const fn new(ident: Identifier, params: Params) -> Self {
|
||||||
Self { ident, params, t }
|
Self { ident, params }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_procedural(&self) -> bool {
|
pub fn is_procedural(&self) -> bool {
|
||||||
|
|
|
@ -988,8 +988,9 @@ impl ASTLowerer {
|
||||||
id,
|
id,
|
||||||
found_body_t,
|
found_body_t,
|
||||||
)?;
|
)?;
|
||||||
let ident = hir::Identifier::bare(sig.ident.dot, sig.ident.name);
|
let mut ident = hir::Identifier::bare(sig.ident.dot, sig.ident.name);
|
||||||
let sig = hir::SubrSignature::new(ident, params, t);
|
ident.vi.t = t;
|
||||||
|
let sig = hir::SubrSignature::new(ident, params);
|
||||||
let body = hir::DefBody::new(body.op, block, body.id);
|
let body = hir::DefBody::new(body.op, block, body.id);
|
||||||
Ok(hir::Def::new(hir::Signature::Subr(sig), body))
|
Ok(hir::Def::new(hir::Signature::Subr(sig), body))
|
||||||
}
|
}
|
||||||
|
@ -1019,7 +1020,7 @@ impl ASTLowerer {
|
||||||
);
|
);
|
||||||
let block = self.lower_block(body.block)?;
|
let block = self.lower_block(body.block)?;
|
||||||
let ident = hir::Identifier::bare(sig.ident.dot, sig.ident.name);
|
let ident = hir::Identifier::bare(sig.ident.dot, sig.ident.name);
|
||||||
let sig = hir::SubrSignature::new(ident, params, Type::Failure);
|
let sig = hir::SubrSignature::new(ident, params);
|
||||||
let body = hir::DefBody::new(body.op, block, body.id);
|
let body = hir::DefBody::new(body.op, block, body.id);
|
||||||
Ok(hir::Def::new(hir::Signature::Subr(sig), body))
|
Ok(hir::Def::new(hir::Signature::Subr(sig), body))
|
||||||
}
|
}
|
||||||
|
|
|
@ -155,9 +155,7 @@ impl Runnable for DummyVM {
|
||||||
.to_string(),
|
.to_string(),
|
||||||
);
|
);
|
||||||
if let Some(Expr::Def(def)) = last {
|
if let Some(Expr::Def(def)) = last {
|
||||||
res.push_str(&format!(" ({}: ", def.sig.ident()));
|
res.push_str(&format!(" ({})", def.sig.ident()));
|
||||||
res.push_str(&def.sig.t().to_string());
|
|
||||||
res.push(')');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(res)
|
Ok(res)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue