mirror of
https://github.com/erg-lang/erg.git
synced 2025-10-02 13:41:10 +00:00
Implement helper methods for AST/HIR construction
This commit is contained in:
parent
ae15f95191
commit
a0714b218c
8 changed files with 114 additions and 70 deletions
|
@ -185,7 +185,7 @@ impl<'a> Linker<'a> {
|
|||
let module_type =
|
||||
Expr::Accessor(Accessor::private_with_line(Str::ever("#ModuleType"), line));
|
||||
let args = Args::new(vec![PosArg::new(mod_name.clone())], None, vec![], None);
|
||||
let block = Block::new(vec![Expr::Call(Call::new(module_type, None, args))]);
|
||||
let block = Block::new(vec![module_type.call_expr(args)]);
|
||||
let tmp =
|
||||
Identifier::private_with_line(Str::from(fresh_varname()), expr.ln_begin().unwrap());
|
||||
let mod_def = Expr::Def(Def::new(
|
||||
|
@ -194,9 +194,9 @@ impl<'a> Linker<'a> {
|
|||
));
|
||||
let module = Expr::Accessor(Accessor::Ident(tmp));
|
||||
let __dict__ = Identifier::public("__dict__");
|
||||
let m_dict = Expr::Accessor(Accessor::attr(module.clone(), __dict__));
|
||||
let m_dict = module.clone().attr_expr(__dict__);
|
||||
let locals = Expr::Accessor(Accessor::public_with_line(Str::ever("locals"), line));
|
||||
let locals_call = Expr::Call(Call::new(locals, None, Args::empty()));
|
||||
let locals_call = locals.call_expr(Args::empty());
|
||||
let args = Args::new(vec![PosArg::new(locals_call)], None, vec![], None);
|
||||
let mod_update = Expr::Call(Call::new(
|
||||
m_dict.clone(),
|
||||
|
@ -210,7 +210,7 @@ impl<'a> Linker<'a> {
|
|||
vec![],
|
||||
None,
|
||||
);
|
||||
let exec_code = Expr::Call(Call::new(exec, None, args));
|
||||
let exec_code = exec.call_expr(args);
|
||||
let compound = Block::new(vec![mod_def, mod_update, exec_code, module]);
|
||||
*expr = Expr::Compound(compound);
|
||||
}
|
||||
|
@ -256,15 +256,13 @@ impl<'a> Linker<'a> {
|
|||
args.insert_pos(0, PosArg::new(mod_name));
|
||||
let line = expr.ln_begin().unwrap_or(0);
|
||||
for attr in comps {
|
||||
*expr = Expr::Accessor(Accessor::attr(
|
||||
// instead of mem::take(),
|
||||
mem::replace(expr, Expr::Code(Block::empty())),
|
||||
*expr = mem::replace(expr, Expr::Code(Block::empty())).attr_expr(
|
||||
Identifier::public_with_line(
|
||||
Token::dummy(),
|
||||
Str::rc(attr.as_os_str().to_str().unwrap()),
|
||||
line,
|
||||
),
|
||||
));
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue