1
0

Fix main function and bench script

This commit is contained in:
Jeff 2024-01-24 18:57:36 -05:00
parent 270c2fd1dc
commit 363ecf444b
4 changed files with 36 additions and 34 deletions

View File

@ -9,9 +9,27 @@
hyperfine \
--shell none \
--parameter-list data_path examples/assets/seaCreatures.json,examples/assets/jq_data.json,dielectron.json \
--parameter-list data_path examples/assets/seaCreatures.json \
--warmup 3 \
"dust -c 'length(from_json(input))' -p {data_path}" \
"dust -c 'length(json:parse(input))' -p {data_path}" \
"jq 'length' {data_path}" \
"node --eval \"require('node:fs').readFile('{data_path}', (err, data)=>{console.log(JSON.parse(data).length)})\"" \
"nu -c 'open {data_path} | length'"
hyperfine \
--shell none \
--parameter-list data_path examples/assets/jq_data.json \
--warmup 3 \
"dust -c 'length(json:parse(input))' -p {data_path}" \
"jq 'length' {data_path}" \
"node --eval \"require('node:fs').readFile('{data_path}', (err, data)=>{console.log(JSON.parse(data).length)})\"" \
"nu -c 'open {data_path} | length'"
hyperfine \
--shell none \
--parameter-list data_path dielectron.json \
--warmup 3 \
"dust -c 'length(json:parse(input))' -p {data_path}" \
"jq 'length' {data_path}" \
"node --eval \"require('node:fs').readFile('{data_path}', (err, data)=>{console.log(JSON.parse(data).length)})\"" \
"nu -c 'open {data_path} | length'"

View File

@ -138,7 +138,7 @@ impl Interpreter {
formatted_source
} else {
"".to_string()
String::with_capacity(0)
}
}
}

View File

@ -51,19 +51,6 @@ fn main() {
env_logger::init();
let args = Args::parse();
if args.path.is_none() && args.command.is_none() {
return run_cli_shell();
}
let source = if let Some(path) = &args.path {
read_to_string(path).unwrap()
} else if let Some(command) = &args.command {
command.clone()
} else {
"".to_string()
};
let context = Map::new();
if let Some(input) = args.input {
@ -80,6 +67,18 @@ fn main() {
.unwrap();
}
if args.path.is_none() && args.command.is_none() {
return run_cli_shell(context);
}
let source = if let Some(path) = &args.path {
read_to_string(path).unwrap()
} else if let Some(command) = args.command {
command
} else {
String::with_capacity(0)
};
let mut interpreter = Interpreter::new(context);
if let Some(CliCommand::Syntax) = args.cli_command {
@ -90,14 +89,14 @@ fn main() {
return;
}
let eval_result = interpreter.run(&source);
if let Some(CliCommand::Format) = args.cli_command {
println!("{}", interpreter.format());
return;
}
let eval_result = interpreter.run(&source);
match eval_result {
Ok(value) => {
if !value.is_none() {
@ -183,8 +182,7 @@ impl Highlighter for DustReadline {
}
}
fn run_cli_shell() {
let context = Map::new();
fn run_cli_shell(context: Map) {
let mut interpreter = Interpreter::new(context);
let mut rl: Editor<DustReadline, DefaultHistory> = Editor::new().unwrap();

View File

@ -94,20 +94,6 @@ impl Map {
Ok(previous)
}
pub fn unset_all(&self) -> Result<()> {
for (_key, (value, r#_type)) in self.variables.write()?.iter_mut() {
*value = Value::none();
}
Ok(())
}
pub fn clear(&self) -> Result<()> {
self.variables.write()?.clear();
Ok(())
}
}
impl Default for Map {