Skip to content

Commit

Permalink
Update with dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
mtshiba committed Feb 4, 2023
1 parent 36427cb commit 9d1b4dc
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 41 deletions.
11 changes: 11 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[alias]
r = "run"
rd = "run --features debug"
b = "build"
bd = "build --features debug"
r_re = "run --release"
rd_re = "run --features debug --release"
b_re = "build --release"
bd_re = "build --features debug --release"
i = "install --path ."
di = "install --path . --debug --features debug"
20 changes: 10 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 20 additions & 26 deletions crates/py2erg/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ pub enum ShadowingMode {
///
/// would be converted as follows. This is a mistake.
///
/// ```
/// ```python
/// i = 1
/// i = i2 + 1
/// ```
Expand Down Expand Up @@ -453,7 +453,7 @@ impl ASTConverter {
let method = tmp_expr.clone().attr_expr(
self.convert_ident("__Tuple_getitem__".to_string(), expr.location),
);
let args = Args::new(vec![PosArg::new(Expr::Lit(index))], vec![], None);
let args = Args::new(vec![PosArg::new(Expr::Lit(index))], None, vec![], None);
let tuple_acc = method.call_expr(args);
let body = DefBody::new(EQUAL, Block::new(vec![tuple_acc]), DefId(0));
let def = Expr::Def(Def::new(sig, body));
Expand Down Expand Up @@ -616,13 +616,12 @@ impl ASTConverter {
let sig = LambdaSignature::new(params, None, TypeBoundSpecs::empty());
let else_body =
Lambda::new(sig, Token::DUMMY, Block::new(vec![else_block]), DefId(0));
let args = Args::new(
let args = Args::pos_only(
vec![
PosArg::new(test),
PosArg::new(Expr::Lambda(body)),
PosArg::new(Expr::Lambda(else_body)),
],
vec![],
None,
);
if_acc.call_expr(args)
Expand All @@ -637,7 +636,7 @@ impl ASTConverter {
.into_iter()
.map(|ex| PosArg::new(self.convert_expr(ex)))
.collect::<Vec<_>>();
let args = Args::new(pos_args, vec![], None);
let args = Args::pos_only(pos_args, None);
function.call_expr(args)
}
ExpressionType::Binop { a, op, b } => {
Expand Down Expand Up @@ -713,7 +712,7 @@ impl ASTConverter {
.into_iter()
.map(|ex| PosArg::new(self.convert_expr(ex)))
.collect::<Vec<_>>();
let elems = Args::new(elements, vec![], None);
let elems = Args::pos_only(elements, None);
Expr::Array(Array::Normal(NormalArray::new(l_sqbr, r_sqbr, elems)))
// Self::mutate_expr(arr)
}
Expand All @@ -724,7 +723,7 @@ impl ASTConverter {
.into_iter()
.map(|ex| PosArg::new(self.convert_expr(ex)))
.collect::<Vec<_>>();
let elems = Args::new(elements, vec![], None);
let elems = Args::pos_only(elements, None);
Expr::Set(Set::Normal(NormalSet::new(l_brace, r_brace, elems)))
// Self::mutate_expr(set)
}
Expand Down Expand Up @@ -752,14 +751,14 @@ impl ASTConverter {
.into_iter()
.map(|ex| PosArg::new(self.convert_expr(ex)))
.collect::<Vec<_>>();
let elems = Args::new(elements, vec![], None);
let elems = Args::pos_only(elements, None);
Expr::Tuple(Tuple::Normal(NormalTuple::new(elems)))
}
ExpressionType::Subscript { a, b } => {
let obj = self.convert_expr(*a);
let method =
obj.attr_expr(self.convert_ident("__getitem__".to_string(), expr.location));
let args = Args::new(vec![PosArg::new(self.convert_expr(*b))], vec![], None);
let args = Args::pos_only(vec![PosArg::new(self.convert_expr(*b))], None);
method.call_expr(args)
}
_other => {
Expand Down Expand Up @@ -1003,7 +1002,7 @@ impl ASTConverter {
} else {
vec![]
};
let args = Args::new(pos_args, vec![], None);
let args = Args::pos_only(pos_args, None);
let class_acc = Expr::Accessor(Accessor::Ident(
self.convert_ident("Class".to_string(), loc),
));
Expand Down Expand Up @@ -1125,7 +1124,7 @@ impl ASTConverter {
stmt.location,
));
let args =
Args::new(vec![PosArg::new(Expr::Lit(index))], vec![], None);
Args::pos_only(vec![PosArg::new(Expr::Lit(index))], None);
let tuple_acc = method.call_expr(args);
let body =
DefBody::new(EQUAL, Block::new(vec![tuple_acc]), DefId(0));
Expand Down Expand Up @@ -1270,9 +1269,8 @@ impl ASTConverter {
let block = self.convert_for_body(Some(*target), body);
let for_ident = self.convert_ident("for".to_string(), stmt.location);
let for_acc = Expr::Accessor(Accessor::Ident(for_ident));
for_acc.call_expr(Args::new(
for_acc.call_expr(Args::pos_only(
vec![PosArg::new(iter), PosArg::new(Expr::Lambda(block))],
vec![],
None,
))
}
Expand All @@ -1288,9 +1286,8 @@ impl ASTConverter {
let body = Lambda::new(empty_sig, Token::DUMMY, block, DefId(0));
let while_ident = self.convert_ident("while".to_string(), stmt.location);
let while_acc = Expr::Accessor(Accessor::Ident(while_ident));
while_acc.call_expr(Args::new(
while_acc.call_expr(Args::pos_only(
vec![PosArg::new(test), PosArg::new(Expr::Lambda(body))],
vec![],
None,
))
}
Expand All @@ -1306,20 +1303,18 @@ impl ASTConverter {
let else_block = self.convert_block(orelse, BlockKind::If);
let sig = LambdaSignature::new(params, None, TypeBoundSpecs::empty());
let else_body = Lambda::new(sig, Token::DUMMY, else_block, DefId(0));
let args = Args::new(
let args = Args::pos_only(
vec![
PosArg::new(test),
PosArg::new(Expr::Lambda(body)),
PosArg::new(Expr::Lambda(else_body)),
],
vec![],
None,
);
if_acc.call_expr(args)
} else {
let args = Args::new(
let args = Args::pos_only(
vec![PosArg::new(test), PosArg::new(Expr::Lambda(body))],
vec![],
None,
);
if_acc.call_expr(args)
Expand All @@ -1337,16 +1332,16 @@ impl ASTConverter {
));
let return_acc = self.convert_ident("return".to_string(), stmt.location);
let return_acc = Expr::Accessor(Accessor::attr(func_acc, return_acc));
return_acc.call_expr(Args::new(vec![PosArg::new(value)], vec![], None))
return_acc.call_expr(Args::pos_only(vec![PosArg::new(value)], None))
}
}
StatementType::Assert { test, msg } => {
let test = self.convert_expr(test);
let args = if let Some(msg) = msg {
let msg = self.convert_expr(msg);
Args::new(vec![PosArg::new(test), PosArg::new(msg)], vec![], None)
Args::pos_only(vec![PosArg::new(test), PosArg::new(msg)], None)
} else {
Args::new(vec![PosArg::new(test)], vec![], None)
Args::pos_only(vec![PosArg::new(test)], None)
};
let assert_acc = Expr::Accessor(Accessor::Ident(
self.convert_ident("assert".to_string(), stmt.location),
Expand All @@ -1366,7 +1361,7 @@ impl ASTConverter {
stmt.location.row() as u32,
stmt.location.column() as u32 - 1,
)));
let args = Args::new(vec![PosArg::new(mod_name)], vec![], None);
let args = Args::pos_only(vec![PosArg::new(mod_name)], None);
let call = import_acc.call_expr(args);
let def = if let Some(alias) = name.alias {
self.register_name_info(&alias, NameKind::Variable);
Expand Down Expand Up @@ -1412,7 +1407,7 @@ impl ASTConverter {
stmt.location.row() as u32,
stmt.location.column() as u32 - 1,
)));
let args = Args::new(vec![PosArg::new(mod_name)], vec![], None);
let args = Args::new(vec![PosArg::new(mod_name)], None, vec![], None);
let call = import_acc.call_expr(args);
self.register_name_info(module.as_ref().unwrap(), NameKind::Variable);
let mod_ident = self.convert_ident(module.unwrap(), stmt.location);
Expand Down Expand Up @@ -1487,9 +1482,8 @@ impl ASTConverter {
let body = self.convert_for_body(item.optional_vars, body);
let with_ident = self.convert_ident("with".to_string(), stmt.location);
let with_acc = Expr::Accessor(Accessor::Ident(with_ident));
with_acc.call_expr(Args::new(
with_acc.call_expr(Args::pos_only(
vec![PosArg::new(context_expr), PosArg::new(Expr::Lambda(body))],
vec![],
None,
))
}
Expand Down
7 changes: 4 additions & 3 deletions src/analyze.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use erg_common::config::ErgConfig;
use erg_common::error::{ErrorCore, ErrorKind, MultiErrorDisplay};
use erg_common::style::{BLUE, GREEN, RED, RESET, YELLOW};
use erg_common::style::colors::{BLUE, GREEN, RED, YELLOW};
use erg_common::style::RESET;
use erg_common::traits::{Runnable, Stream};
use erg_common::Str;
use erg_compiler::artifact::{BuildRunnable, Buildable, CompleteArtifact, IncompleteArtifact};
Expand Down Expand Up @@ -56,7 +57,7 @@ impl Runnable for PythonAnalyzer {

impl Buildable for PythonAnalyzer {
fn inherit(cfg: ErgConfig, shared: SharedCompilerResource) -> Self {
let mod_name = Str::rc(cfg.input.file_stem());
let mod_name = Str::rc(&cfg.input.file_stem());
Self {
cfg: cfg.copy(),
checker: ASTLowerer::new_with_cache(cfg, mod_name, shared),
Expand Down Expand Up @@ -104,7 +105,7 @@ impl PythonAnalyzer {
};
let converter = py2erg::ASTConverter::new(self.cfg.copy(), shadowing);
let IncompleteArtifact{ object: Some(erg_module), mut errors, mut warns } = converter.convert_program(py_program) else { unreachable!() };
let erg_ast = AST::new(erg_common::Str::rc(filename), erg_module);
let erg_ast = AST::new(erg_common::Str::rc(&filename), erg_module);
erg_common::log!("AST:\n{erg_ast}");
match self.checker.lower(erg_ast, mode) {
Ok(mut artifact) => {
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub fn parse_args() -> ErgConfig {
break;
}
"-c" | "--code" => {
cfg.input = Input::Str(args.next().expect("the value of `-c` is not passed"));
cfg.input = Input::str(args.next().expect("the value of `-c` is not passed"));
}
"--server" => {
cfg.mode = ErgMode::LanguageServer;
Expand Down Expand Up @@ -58,7 +58,7 @@ For more information try `pylyzer --help`"
_ => {
cfg.input = Input::File(
PathBuf::from_str(&arg[..])
.unwrap_or_else(|_| panic!("invalid file path: {}", arg)),
.unwrap_or_else(|_| panic!("invalid file path: {arg}")),
);
if let Some("--") = args.next().as_ref().map(|s| &s[..]) {
for arg in args {
Expand Down

0 comments on commit 9d1b4dc

Please sign in to comment.