From 363ecf444b0178b8b228108030ce6a370424dd4a Mon Sep 17 00:00:00 2001 From: Jeff Date: Wed, 24 Jan 2024 18:57:36 -0500 Subject: [PATCH] Fix main function and bench script --- scripts/bench.fish | 22 ++++++++++++++++++++-- src/interpret.rs | 2 +- src/main.rs | 32 +++++++++++++++----------------- src/value/map.rs | 14 -------------- 4 files changed, 36 insertions(+), 34 deletions(-) diff --git a/scripts/bench.fish b/scripts/bench.fish index 99633e8..47c86b0 100755 --- a/scripts/bench.fish +++ b/scripts/bench.fish @@ -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'" diff --git a/src/interpret.rs b/src/interpret.rs index 8c564fd..f2130fc 100644 --- a/src/interpret.rs +++ b/src/interpret.rs @@ -138,7 +138,7 @@ impl Interpreter { formatted_source } else { - "".to_string() + String::with_capacity(0) } } } diff --git a/src/main.rs b/src/main.rs index 573f3dc..0425a71 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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 = Editor::new().unwrap(); diff --git a/src/value/map.rs b/src/value/map.rs index 3e91ac9..73d7357 100644 --- a/src/value/map.rs +++ b/src/value/map.rs @@ -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 {