mirror of
https://github.com/erg-lang/erg.git
synced 2025-10-03 14:04:33 +00:00
chore: use ArcArray
instead of Vec
This commit is contained in:
parent
4ac6276ba9
commit
41bf14629b
4 changed files with 23 additions and 16 deletions
|
@ -276,29 +276,30 @@ impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
|
||||||
lsp_log!("packages must be an array: {pkgs}");
|
lsp_log!("packages must be an array: {pkgs}");
|
||||||
return cfg;
|
return cfg;
|
||||||
};
|
};
|
||||||
|
let mut packages = vec![];
|
||||||
for rec in arr.iter() {
|
for rec in arr.iter() {
|
||||||
let ast::Expr::Record(rec) = rec else {
|
let ast::Expr::Record(rec) = rec else {
|
||||||
lsp_log!("packages must be records: {rec}");
|
lsp_log!("packages must be records: {rec}");
|
||||||
return cfg;
|
break;
|
||||||
};
|
};
|
||||||
let Some(ast::Expr::Literal(name)) =
|
let Some(ast::Expr::Literal(name)) =
|
||||||
rec.get("name").and_then(|name| name.body.block.first())
|
rec.get("name").and_then(|name| name.body.block.first())
|
||||||
else {
|
else {
|
||||||
return cfg;
|
break;
|
||||||
};
|
};
|
||||||
let name = name.token.content.replace('\"', "");
|
let name = name.token.content.replace('\"', "");
|
||||||
let Some(ast::Expr::Literal(as_name)) = rec
|
let Some(ast::Expr::Literal(as_name)) = rec
|
||||||
.get("as_name")
|
.get("as_name")
|
||||||
.and_then(|as_name| as_name.body.block.first())
|
.and_then(|as_name| as_name.body.block.first())
|
||||||
else {
|
else {
|
||||||
return cfg;
|
break;
|
||||||
};
|
};
|
||||||
let as_name = as_name.token.content.replace('\"', "");
|
let as_name = as_name.token.content.replace('\"', "");
|
||||||
let Some(ast::Expr::Literal(version)) = rec
|
let Some(ast::Expr::Literal(version)) = rec
|
||||||
.get("version")
|
.get("version")
|
||||||
.and_then(|version| version.body.block.first())
|
.and_then(|version| version.body.block.first())
|
||||||
else {
|
else {
|
||||||
return cfg;
|
break;
|
||||||
};
|
};
|
||||||
let version = version.token.content.replace('\"', "");
|
let version = version.token.content.replace('\"', "");
|
||||||
let path = rec.get("path").and_then(|path| {
|
let path = rec.get("path").and_then(|path| {
|
||||||
|
@ -314,8 +315,9 @@ impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
|
||||||
version.leak(),
|
version.leak(),
|
||||||
path.map(|p| &*p.leak()),
|
path.map(|p| &*p.leak()),
|
||||||
);
|
);
|
||||||
cfg.packages.push(package);
|
packages.push(package);
|
||||||
}
|
}
|
||||||
|
cfg.packages = Arc::from(packages);
|
||||||
cfg
|
cfg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ use crate::levenshtein::get_similar_name;
|
||||||
use crate::normalize_path;
|
use crate::normalize_path;
|
||||||
use crate::python_util::{detect_magic_number, get_python_version, PythonVersion};
|
use crate::python_util::{detect_magic_number, get_python_version, PythonVersion};
|
||||||
use crate::serialize::{get_magic_num_from_bytes, get_ver_from_magic_num};
|
use crate::serialize::{get_magic_num_from_bytes, get_ver_from_magic_num};
|
||||||
|
use crate::ArcArray;
|
||||||
|
|
||||||
#[cfg(not(feature = "pylib"))]
|
#[cfg(not(feature = "pylib"))]
|
||||||
use erg_proc_macros::{new, pyclass, pymethods};
|
use erg_proc_macros::{new, pyclass, pymethods};
|
||||||
|
@ -167,8 +168,8 @@ pub struct ErgConfig {
|
||||||
/// needed for `jupyter-erg`
|
/// needed for `jupyter-erg`
|
||||||
pub ps1: &'static str,
|
pub ps1: &'static str,
|
||||||
pub ps2: &'static str,
|
pub ps2: &'static str,
|
||||||
pub runtime_args: Vec<&'static str>,
|
pub runtime_args: ArcArray<&'static str>,
|
||||||
pub packages: Vec<Package>,
|
pub packages: ArcArray<Package>,
|
||||||
pub effect_check: bool,
|
pub effect_check: bool,
|
||||||
pub ownership_check: bool,
|
pub ownership_check: bool,
|
||||||
}
|
}
|
||||||
|
@ -194,8 +195,8 @@ impl Default for ErgConfig {
|
||||||
verbose: 1,
|
verbose: 1,
|
||||||
ps1: ">>> ",
|
ps1: ">>> ",
|
||||||
ps2: "... ",
|
ps2: "... ",
|
||||||
runtime_args: vec![],
|
runtime_args: ArcArray::from([]),
|
||||||
packages: vec![],
|
packages: ArcArray::from([]),
|
||||||
effect_check: true,
|
effect_check: true,
|
||||||
ownership_check: true,
|
ownership_check: true,
|
||||||
}
|
}
|
||||||
|
@ -269,13 +270,15 @@ impl ErgConfig {
|
||||||
let mut args = env::args();
|
let mut args = env::args();
|
||||||
args.next(); // "ergc"
|
args.next(); // "ergc"
|
||||||
let mut cfg = Self::default();
|
let mut cfg = Self::default();
|
||||||
|
let mut runtime_args: Vec<&'static str> = vec![];
|
||||||
|
let mut packages = vec![];
|
||||||
// not `for` because we need to consume the next argument
|
// not `for` because we need to consume the next argument
|
||||||
while let Some(arg) = args.next() {
|
while let Some(arg) = args.next() {
|
||||||
match &arg[..] {
|
match &arg[..] {
|
||||||
/* Options */
|
/* Options */
|
||||||
"--" => {
|
"--" => {
|
||||||
for arg in args {
|
for arg in args {
|
||||||
cfg.runtime_args.push(Box::leak(arg.into_boxed_str()));
|
runtime_args.push(Box::leak(arg.into_boxed_str()));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -332,7 +335,7 @@ impl ErgConfig {
|
||||||
.next()
|
.next()
|
||||||
.expect("`version` of `--use-package` is not passed")
|
.expect("`version` of `--use-package` is not passed")
|
||||||
.into_boxed_str();
|
.into_boxed_str();
|
||||||
cfg.packages.push(Package::new(
|
packages.push(Package::new(
|
||||||
Box::leak(name),
|
Box::leak(name),
|
||||||
Box::leak(as_name),
|
Box::leak(as_name),
|
||||||
Box::leak(version),
|
Box::leak(version),
|
||||||
|
@ -356,7 +359,7 @@ impl ErgConfig {
|
||||||
.next()
|
.next()
|
||||||
.expect("`path` of `--use-package` is not passed")
|
.expect("`path` of `--use-package` is not passed")
|
||||||
.into_boxed_str();
|
.into_boxed_str();
|
||||||
cfg.packages.push(Package::new(
|
packages.push(Package::new(
|
||||||
Box::leak(name),
|
Box::leak(name),
|
||||||
Box::leak(as_name),
|
Box::leak(as_name),
|
||||||
Box::leak(version),
|
Box::leak(version),
|
||||||
|
@ -505,7 +508,7 @@ USAGE:
|
||||||
cfg.mode = mode;
|
cfg.mode = mode;
|
||||||
if cfg.mode == ErgMode::Pack {
|
if cfg.mode == ErgMode::Pack {
|
||||||
for arg in args {
|
for arg in args {
|
||||||
cfg.runtime_args.push(Box::leak(arg.into_boxed_str()));
|
runtime_args.push(Box::leak(arg.into_boxed_str()));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -517,7 +520,7 @@ USAGE:
|
||||||
match args.next().as_ref().map(|s| &s[..]) {
|
match args.next().as_ref().map(|s| &s[..]) {
|
||||||
Some("--") => {
|
Some("--") => {
|
||||||
for arg in args {
|
for arg in args {
|
||||||
cfg.runtime_args.push(Box::leak(arg.into_boxed_str()));
|
runtime_args.push(Box::leak(arg.into_boxed_str()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(some) => {
|
Some(some) => {
|
||||||
|
@ -543,6 +546,8 @@ USAGE:
|
||||||
};
|
};
|
||||||
cfg.input = input;
|
cfg.input = input;
|
||||||
}
|
}
|
||||||
|
cfg.runtime_args = ArcArray::from(runtime_args);
|
||||||
|
cfg.packages = ArcArray::from(packages);
|
||||||
cfg
|
cfg
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ impl _Compiler {
|
||||||
#[new]
|
#[new]
|
||||||
fn new(deps: Vec<Package>) -> Self {
|
fn new(deps: Vec<Package>) -> Self {
|
||||||
let cfg = ErgConfig {
|
let cfg = ErgConfig {
|
||||||
packages: deps,
|
packages: erg_common::ArcArray::from(deps),
|
||||||
..ErgConfig::default()
|
..ErgConfig::default()
|
||||||
};
|
};
|
||||||
Self {
|
Self {
|
||||||
|
|
|
@ -448,7 +448,7 @@ impl PackageManagerRunner {
|
||||||
.stdin(Stdio::inherit())
|
.stdin(Stdio::inherit())
|
||||||
.stdout(Stdio::inherit())
|
.stdout(Stdio::inherit())
|
||||||
.stderr(Stdio::inherit())
|
.stderr(Stdio::inherit())
|
||||||
.args(&cfg.runtime_args)
|
.args(cfg.runtime_args.as_ref())
|
||||||
.output()
|
.output()
|
||||||
{
|
{
|
||||||
Ok(out) => ExitStatus::new(out.status.code().unwrap_or(0), 0, 0),
|
Ok(out) => ExitStatus::new(out.status.code().unwrap_or(0), 0, 0),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue