From 56a1548c9a10a2bfc6ddda0e0d28ae0087aa193f Mon Sep 17 00:00:00 2001 From: Jonas Maier <> Date: Sat, 7 Mar 2026 15:42:50 +0100 Subject: reorganize towards function execution --- src/run/mod.rs | 50 ++++++++++++++++++++++++-------------------------- 1 file changed, 24 insertions(+), 26 deletions(-) (limited to 'src/run/mod.rs') diff --git a/src/run/mod.rs b/src/run/mod.rs index f32007e..3b48f75 100644 --- a/src/run/mod.rs +++ b/src/run/mod.rs @@ -66,7 +66,7 @@ impl Executor { (None, None) }; - let dc = self.se.lock().unwrap().dispatch.get(&cmd.cmd[..]); + let dc = get_command_kind(&self.se.lock().unwrap(), &cmd.cmd[..]); match dc { CommandKind::Path(path) => { @@ -147,6 +147,10 @@ impl Executor { threads.push(handle); } + + CommandKind::Fun(ast) => { + todo!() + } } prev_reader = reader; @@ -346,36 +350,30 @@ const BUILTINS: &[&'static dyn Builtin] = &[ &builtin::parse, ]; -pub struct CommandDispatch { - map: HashMap, -} - -impl CommandDispatch { - pub fn new() -> Self { - let mut map = HashMap::new(); - - // builtins - for &b in BUILTINS { - map.insert(b.name().as_bytes().to_vec(), CommandKind::Builtin(b)); - } - - Self { map } - } - - fn get(&self, cmd: &bstr) -> CommandKind { - let path_cmd = CommandKind::Path(PathBuf::from(OsStr::from_bytes(cmd))); - if cmd.contains(&b'/') { - path_cmd - } else if let Some(cmd) = self.map.get(cmd) { - cmd.clone() - } else { - path_cmd - } +pub fn builtin_map() -> HashMap { + let mut map = HashMap::new(); + for &b in BUILTINS { + map.insert(b.name().as_bytes().to_vec(), b); } + map } #[derive(Clone)] pub enum CommandKind { Builtin(&'static dyn Builtin), + Fun(Ast), Path(PathBuf), } + +pub fn get_command_kind(se: &Session, cmd: &bstr) -> CommandKind { + let path_cmd = CommandKind::Path(PathBuf::from(OsStr::from_bytes(cmd))); + if cmd.contains(&b'/') { + path_cmd + } else if let Some(fun) = se.funs.get(cmd) { + CommandKind::Fun(fun.clone()) + } else if let Some(builtin) = se.builtins.get(cmd) { + CommandKind::Builtin(builtin.clone()) + } else { + path_cmd + } +} -- cgit v1.2.3