From 1bec604657e0d2a03e654bec79f8bf3320c89c56 Mon Sep 17 00:00:00 2001 From: Ryan Daum Date: Sun, 22 Dec 2024 23:53:29 -0500 Subject: [PATCH] Use List instead of Vec throughout Should reduce copies on verb dispatch. --- crates/common/src/var/list.rs | 24 ++++-- crates/daemon/src/rpc_server.rs | 6 +- crates/kernel/benches/vm_benches.rs | 6 +- crates/kernel/src/builtins/bf_list_sets.rs | 4 +- crates/kernel/src/builtins/bf_maps.rs | 2 +- crates/kernel/src/builtins/bf_num.rs | 17 +++-- crates/kernel/src/builtins/bf_objects.rs | 14 ++-- crates/kernel/src/builtins/bf_server.rs | 9 ++- crates/kernel/src/builtins/bf_strings.rs | 2 +- crates/kernel/src/builtins/bf_values.rs | 2 +- crates/kernel/src/builtins/mod.rs | 4 +- crates/kernel/src/tasks/mod.rs | 10 +-- crates/kernel/src/tasks/scheduler.rs | 5 +- crates/kernel/src/tasks/scheduler_client.rs | 6 +- crates/kernel/src/tasks/task.rs | 6 +- crates/kernel/src/tasks/vm_host.rs | 4 +- crates/kernel/src/vm/activation.rs | 16 ++-- crates/kernel/src/vm/mod.rs | 5 +- crates/kernel/src/vm/vm_call.rs | 6 +- crates/kernel/src/vm/vm_test.rs | 82 ++++++++++----------- crates/kernel/tests/textdump.rs | 4 +- crates/kernel/testsuite/common/mod.rs | 4 +- 22 files changed, 128 insertions(+), 110 deletions(-) diff --git a/crates/common/src/var/list.rs b/crates/common/src/var/list.rs index 26657c9f..2e02805d 100644 --- a/crates/common/src/var/list.rs +++ b/crates/common/src/var/list.rs @@ -26,6 +26,7 @@ use num_traits::ToPrimitive; use std::cmp::max; use std::fmt::{Debug, Formatter}; use std::hash::Hash; +use std::ops::Index; #[derive(Clone)] pub struct List(Box>); @@ -42,7 +43,7 @@ impl List { } pub fn iter(&self) -> impl Iterator + '_ { - (0..self.len()).map(move |i| self.index(i).unwrap()) + self.0.iter().cloned() } /// Remove the first found instance of `item` from the list. @@ -225,6 +226,19 @@ impl Sequence for List { } } +impl Into for List { + fn into(self) -> Var { + Var::from_variant(Variant::List(self)) + } +} + +impl Index for List { + type Output = Var; + + fn index(&self, index: usize) -> &Self::Output { + &self.0[index] + } +} impl PartialEq for List { fn eq(&self, other: &Self) -> bool { if self.len() != other.len() { @@ -233,8 +247,8 @@ impl PartialEq for List { // elements comparison for i in 0..self.len() { - let a = self.index(i).unwrap(); - let b = other.index(i).unwrap(); + let a = Sequence::index(self, i).unwrap(); + let b = Sequence::index(other, i).unwrap(); if a != b { return false; } @@ -260,8 +274,8 @@ impl Ord for List { // elements comparison for i in 0..self.len() { - let a = self.index(i).unwrap(); - let b = other.index(i).unwrap(); + let a = Sequence::index(self, i).unwrap(); + let b = Sequence::index(other, i).unwrap(); match a.cmp(&b) { std::cmp::Ordering::Equal => continue, x => return x, diff --git a/crates/daemon/src/rpc_server.rs b/crates/daemon/src/rpc_server.rs index c7bd9735..441396d6 100644 --- a/crates/daemon/src/rpc_server.rs +++ b/crates/daemon/src/rpc_server.rs @@ -36,9 +36,9 @@ use moor_values::model::{Named, ObjectRef, PropFlag, ValSet, VerbFlag}; use moor_values::tasks::SchedulerError::CommandExecutionError; use moor_values::tasks::{CommandError, NarrativeEvent, SchedulerError, TaskId}; use moor_values::util::parse_into_words; -use moor_values::Variant; use moor_values::SYSTEM_OBJECT; use moor_values::{v_obj, v_str, Symbol}; +use moor_values::{List, Variant}; use moor_values::{Obj, Var}; use rpc_common::DaemonToClientReply::{LoginResult, NewConnection}; use rpc_common::{ @@ -869,7 +869,7 @@ impl RpcServer { player, &ObjectRef::Id(handler_object.clone()), connected_verb, - vec![v_obj(player.clone())], + List::mk_list(&[v_obj(player.clone())]), "".to_string(), &SYSTEM_OBJECT, session, @@ -1038,7 +1038,7 @@ impl RpcServer { connection, object, verb, - args, + List::mk_list(&args), "".to_string(), &SYSTEM_OBJECT, session, diff --git a/crates/kernel/benches/vm_benches.rs b/crates/kernel/benches/vm_benches.rs index 133da2de..1c24ea87 100644 --- a/crates/kernel/benches/vm_benches.rs +++ b/crates/kernel/benches/vm_benches.rs @@ -35,7 +35,7 @@ use moor_values::model::{BinaryType, VerbFlag}; use moor_values::model::{WorldState, WorldStateSource}; use moor_values::tasks::AbortLimitReason; use moor_values::util::BitEnum; -use moor_values::{v_obj, Symbol}; +use moor_values::{v_obj, List, Symbol}; use moor_values::{AsByteBuffer, Var, NOTHING, SYSTEM_OBJECT}; fn create_db() -> TxDB { @@ -51,7 +51,7 @@ fn create_db() -> TxDB { pub fn prepare_call_verb( world_state: &mut dyn WorldState, verb_name: &str, - args: Vec, + args: List, max_ticks: usize, ) -> VmHost { let mut vm_host = VmHost::new(0, 20, max_ticks, Duration::from_secs(15)); @@ -95,7 +95,7 @@ fn prepare_vm_execution( BinaryType::LambdaMoo18X, ) .unwrap(); - let vm_host = prepare_call_verb(tx.as_mut(), "test", vec![], max_ticks); + let vm_host = prepare_call_verb(tx.as_mut(), "test", List::mk_list(&[]), max_ticks); assert_eq!(tx.commit().unwrap(), CommitResult::Success); vm_host } diff --git a/crates/kernel/src/builtins/bf_list_sets.rs b/crates/kernel/src/builtins/bf_list_sets.rs index 270dc5df..a96b3fd3 100644 --- a/crates/kernel/src/builtins/bf_list_sets.rs +++ b/crates/kernel/src/builtins/bf_list_sets.rs @@ -109,7 +109,7 @@ fn bf_listset(bf_args: &mut BfCallState<'_>) -> Result { } let index = bf_args.args[2].clone(); let value = bf_args.args[1].clone(); - let list = &mut bf_args.args[0]; + let list = bf_args.args[0].clone(); if list.type_code() != VarType::TYPE_LIST { return Err(BfErr::Code(E_TYPE)); } @@ -124,7 +124,7 @@ fn bf_setadd(bf_args: &mut BfCallState<'_>) -> Result { return Err(BfErr::Code(E_ARGS)); } let value = bf_args.args[1].clone(); - let list = &mut bf_args.args[0]; + let list = bf_args.args[0].clone(); let Variant::List(list) = list.variant() else { return Err(BfErr::Code(E_TYPE)); }; diff --git a/crates/kernel/src/builtins/bf_maps.rs b/crates/kernel/src/builtins/bf_maps.rs index 36f76b66..9bc7a94e 100644 --- a/crates/kernel/src/builtins/bf_maps.rs +++ b/crates/kernel/src/builtins/bf_maps.rs @@ -15,9 +15,9 @@ use crate::bf_declare; use crate::builtins::{BfCallState, BfErr, BfRet, BuiltinFunction}; use moor_compiler::offset_for_builtin; -use moor_values::Associative; use moor_values::Error::{E_ARGS, E_RANGE, E_TYPE}; use moor_values::{v_bool, v_list, Var, Variant}; +use moor_values::{Associative, Sequence}; /// Returns a copy of map with the value corresponding to key removed. If key is not a valid key, then E_RANGE is raised. fn bf_mapdelete(bf_args: &mut BfCallState<'_>) -> Result { if bf_args.args.len() != 2 { diff --git a/crates/kernel/src/builtins/bf_num.rs b/crates/kernel/src/builtins/bf_num.rs index 8370a56c..65d8ad80 100644 --- a/crates/kernel/src/builtins/bf_num.rs +++ b/crates/kernel/src/builtins/bf_num.rs @@ -16,8 +16,8 @@ use rand::Rng; use moor_compiler::offset_for_builtin; use moor_values::Error::{E_ARGS, E_INVARG, E_TYPE}; -use moor_values::Variant; use moor_values::{v_float, v_int, v_str}; +use moor_values::{Sequence, Variant}; use crate::bf_declare; use crate::builtins::BfRet::Ret; @@ -74,12 +74,15 @@ fn bf_random(bf_args: &mut BfCallState<'_>) -> Result { } let mut rng = rand::thread_rng(); - match &bf_args.args.first().map(|var| var.variant()) { - Some(Variant::Int(i)) if *i > 0 => Ok(Ret(v_int(rng.gen_range(1..=*i)))), - Some(Variant::Int(_)) => Err(BfErr::Code(E_INVARG)), - None => Ok(Ret(v_int(rng.gen_range(1..=2147483647)))), - _ => Err(BfErr::Code(E_TYPE)), - } + bf_args + .args + .is_empty() + .then_some(Ok(Ret(v_int(rng.gen_range(1..=2147483647))))) + .unwrap_or_else(|| match &bf_args.args[0].variant() { + Variant::Int(i) if *i > 0 => Ok(Ret(v_int(rng.gen_range(1..=*i)))), + Variant::Int(_) => Err(BfErr::Code(E_INVARG)), + _ => Err(BfErr::Code(E_TYPE)), + }) } bf_declare!(random, bf_random); diff --git a/crates/kernel/src/builtins/bf_objects.rs b/crates/kernel/src/builtins/bf_objects.rs index 9b665147..accd4677 100644 --- a/crates/kernel/src/builtins/bf_objects.rs +++ b/crates/kernel/src/builtins/bf_objects.rs @@ -21,10 +21,10 @@ use moor_values::model::WorldStateError; use moor_values::model::{ObjFlag, ValSet}; use moor_values::util::BitEnum; use moor_values::Error::{E_ARGS, E_INVARG, E_NACC, E_PERM, E_TYPE}; -use moor_values::Variant; use moor_values::{v_bool, v_int, v_none, v_obj, v_str}; use moor_values::{v_list, Sequence, Symbol}; use moor_values::{v_list_iter, NOTHING}; +use moor_values::{List, Variant}; use crate::bf_declare; use crate::builtins::BfRet::{Ret, VmInstr}; @@ -167,7 +167,7 @@ fn bf_create(bf_args: &mut BfCallState<'_>) -> Result { location: v_obj(new_obj.clone()), this: v_obj(new_obj), player: bf_args.exec_state.top().player.clone(), - args: vec![], + args: List::mk_list(&[]), argstr: "".to_string(), caller: bf_args.exec_state.top().this.clone(), }, @@ -278,7 +278,7 @@ fn bf_recycle(bf_args: &mut BfCallState<'_>) -> Result { location: v_obj(obj.clone()), this: v_obj(obj), player: bf_args.exec_state.top().player.clone(), - args: Vec::new(), + args: List::mk_list(&[]), argstr: "".to_string(), caller: bf_args.exec_state.top().this.clone(), }, @@ -347,7 +347,7 @@ fn bf_recycle(bf_args: &mut BfCallState<'_>) -> Result { location: v_obj(head_obj.clone()), this: v_obj(head_obj.clone()), player: bf_args.exec_state.top().player.clone(), - args: vec![v_obj(obj)], + args: List::mk_list(&[v_obj(obj)]), argstr: "".to_string(), caller: bf_args.exec_state.top().this.clone(), }, @@ -449,7 +449,7 @@ fn bf_move(bf_args: &mut BfCallState<'_>) -> Result { location: v_obj(whereto.clone()), this: v_obj(whereto.clone()), player: bf_args.exec_state.top().player.clone(), - args: vec![v_obj(what)], + args: List::mk_list(&[v_obj(what)]), argstr: "".to_string(), caller: bf_args.exec_state.top().this.clone(), }, @@ -527,7 +527,7 @@ fn bf_move(bf_args: &mut BfCallState<'_>) -> Result { location: v_obj(original_location.clone()), this: v_obj(original_location), player: bf_args.exec_state.top().player.clone(), - args: vec![v_obj(what)], + args: List::mk_list(&[v_obj(what)]), argstr: "".to_string(), caller: bf_args.exec_state.top().this.clone(), }, @@ -574,7 +574,7 @@ fn bf_move(bf_args: &mut BfCallState<'_>) -> Result { location: v_obj(whereto.clone()), this: v_obj(whereto), player: bf_args.exec_state.top().player.clone(), - args: vec![v_obj(what)], + args: List::mk_list(&[v_obj(what)]), argstr: "".to_string(), caller: bf_args.exec_state.top().this.clone(), }, diff --git a/crates/kernel/src/builtins/bf_server.rs b/crates/kernel/src/builtins/bf_server.rs index 550df7bf..4fb6f683 100644 --- a/crates/kernel/src/builtins/bf_server.rs +++ b/crates/kernel/src/builtins/bf_server.rs @@ -25,10 +25,10 @@ use moor_compiler::{offset_for_builtin, ArgCount, ArgType, Builtin, BUILTINS}; use moor_values::model::{ObjFlag, WorldStateError}; use moor_values::tasks::NarrativeEvent; use moor_values::Error::{E_ARGS, E_INVARG, E_INVIND, E_PERM, E_TYPE}; -use moor_values::Symbol; use moor_values::Variant; use moor_values::{v_bool, v_int, v_list, v_none, v_obj, v_str, v_string, Var}; use moor_values::{v_list_iter, Error}; +use moor_values::{Sequence, Symbol}; use crate::bf_declare; use crate::builtins::BfRet::{Ret, VmInstr}; @@ -657,7 +657,10 @@ fn bf_call_function(bf_args: &mut BfCallState<'_>) -> Result { }; // Arguments are everything left, if any. - let args = &bf_args.args[1..]; + let (_, args) = bf_args.args.pop_front().map_err(|_| BfErr::Code(E_ARGS))?; + let Variant::List(arguments) = args.variant() else { + return Err(BfErr::Code(E_TYPE)); + }; // Find the function id for the given function name. let func_name = Symbol::mk_case_insensitive(func_name.as_string().as_str()); @@ -668,7 +671,7 @@ fn bf_call_function(bf_args: &mut BfCallState<'_>) -> Result { // Then ask the scheduler to run the function as a continuation of what we're doing now. Ok(VmInstr(ExecutionResult::ContinueBuiltin { builtin, - arguments: args[..].to_vec(), + arguments: arguments.clone(), })) } bf_declare!(call_function, bf_call_function); diff --git a/crates/kernel/src/builtins/bf_strings.rs b/crates/kernel/src/builtins/bf_strings.rs index 865adef4..61ced71f 100644 --- a/crates/kernel/src/builtins/bf_strings.rs +++ b/crates/kernel/src/builtins/bf_strings.rs @@ -18,8 +18,8 @@ use rand::Rng; use moor_compiler::offset_for_builtin; use moor_values::Error::{E_ARGS, E_INVARG, E_TYPE}; -use moor_values::Variant; use moor_values::{v_int, v_str, v_string}; +use moor_values::{Sequence, Variant}; use crate::bf_declare; use crate::builtins::BfRet::Ret; diff --git a/crates/kernel/src/builtins/bf_values.rs b/crates/kernel/src/builtins/bf_values.rs index ac7a7995..108ea414 100644 --- a/crates/kernel/src/builtins/bf_values.rs +++ b/crates/kernel/src/builtins/bf_values.rs @@ -38,7 +38,7 @@ bf_declare!(typeof, bf_typeof); fn bf_tostr(bf_args: &mut BfCallState<'_>) -> Result { let mut result = String::new(); - for arg in &bf_args.args { + for arg in bf_args.args.iter() { match arg.variant() { Variant::None => result.push_str("None"), Variant::Int(i) => result.push_str(&i.to_string()), diff --git a/crates/kernel/src/builtins/mod.rs b/crates/kernel/src/builtins/mod.rs index a4866d22..6a33bb75 100644 --- a/crates/kernel/src/builtins/mod.rs +++ b/crates/kernel/src/builtins/mod.rs @@ -20,10 +20,10 @@ use moor_compiler::{BuiltinId, BUILTINS}; use moor_values::model::Perms; use moor_values::model::WorldState; use moor_values::model::WorldStateError; -use moor_values::Error; use moor_values::Obj; use moor_values::Symbol; use moor_values::Var; +use moor_values::{Error, List}; use crate::builtins::bf_list_sets::register_bf_list_sets; use crate::builtins::bf_maps::register_bf_maps; @@ -92,7 +92,7 @@ pub struct BfCallState<'a> { /// The name of the invoked function. pub(crate) name: Symbol, /// Arguments passed to the function. - pub(crate) args: Vec, + pub(crate) args: List, /// The current execution state of this task in this VM, including the stack /// so that BFs can inspect and manipulate it. pub(crate) exec_state: &'a mut VMExecState, diff --git a/crates/kernel/src/tasks/mod.rs b/crates/kernel/src/tasks/mod.rs index e9c7d62f..61dd62cc 100644 --- a/crates/kernel/src/tasks/mod.rs +++ b/crates/kernel/src/tasks/mod.rs @@ -18,7 +18,7 @@ use std::time::SystemTime; use bincode::{Decode, Encode}; use moor_compiler::Program; -use moor_values::Obj; +use moor_values::{List, Obj}; use moor_values::{Symbol, Var}; pub use crate::tasks::tasks_db::{NoopTasksDb, TasksDb, TasksDbError}; @@ -84,7 +84,7 @@ pub struct VerbCall { pub location: Var, pub this: Var, pub player: Obj, - pub args: Vec, + pub args: List, pub argstr: String, pub caller: Var, } @@ -133,8 +133,8 @@ pub mod vm_test_utils { use moor_compiler::Program; use moor_values::model::WorldState; - use moor_values::SYSTEM_OBJECT; use moor_values::{v_obj, Symbol}; + use moor_values::{List, SYSTEM_OBJECT}; use moor_values::{Obj, Var}; use crate::builtins::BuiltinRegistry; @@ -210,7 +210,7 @@ pub mod vm_test_utils { session: Arc, builtins: Arc, verb_name: &str, - args: Vec, + args: List, ) -> ExecResult { execute(world_state, session, builtins, |world_state, vm_host| { let verb_name = Symbol::mk_case_insensitive(verb_name); @@ -338,7 +338,7 @@ pub enum TaskStart { player: Obj, vloc: Var, verb: Symbol, - args: Vec, + args: List, argstr: String, }, /// The scheduler is telling the task to run a task that was forked from another task. diff --git a/crates/kernel/src/tasks/scheduler.rs b/crates/kernel/src/tasks/scheduler.rs index c1c20aa3..dc64fb03 100644 --- a/crates/kernel/src/tasks/scheduler.rs +++ b/crates/kernel/src/tasks/scheduler.rs @@ -56,7 +56,7 @@ use moor_values::tasks::{ AbortLimitReason, CommandError, SchedulerError, TaskId, VerbProgramError, }; use moor_values::Error::{E_INVARG, E_INVIND, E_PERM}; -use moor_values::{v_err, v_int, v_none, v_obj, v_string, Symbol, Var}; +use moor_values::{v_err, v_int, v_none, v_obj, v_string, List, Symbol, Var}; use moor_values::{AsByteBuffer, SYSTEM_OBJECT}; use moor_values::{Obj, Variant}; @@ -483,7 +483,8 @@ impl Scheduler { session, reply, } => { - let args = command.into_iter().map(v_string).collect::>(); + let args = command.into_iter().map(v_string); + let args = List::from_iter(args); let task_start = Arc::new(TaskStart::StartVerb { player: player.clone(), vloc: v_obj(handler_object), diff --git a/crates/kernel/src/tasks/scheduler_client.rs b/crates/kernel/src/tasks/scheduler_client.rs index 4ff53eee..28a3e5ba 100644 --- a/crates/kernel/src/tasks/scheduler_client.rs +++ b/crates/kernel/src/tasks/scheduler_client.rs @@ -20,7 +20,7 @@ use uuid::Uuid; use moor_compiler::{compile, Program}; use moor_values::model::{ObjectRef, PropDef, PropPerms, VerbDef, VerbDefs}; -use moor_values::{Obj, Symbol, Var}; +use moor_values::{List, Obj, Symbol, Var}; use crate::config::FeaturesConfig; use crate::tasks::sessions::Session; @@ -78,7 +78,7 @@ impl SchedulerClient { player: &Obj, vloc: &ObjectRef, verb: Symbol, - args: Vec, + args: List, argstr: String, perms: &Obj, session: Arc, @@ -370,7 +370,7 @@ pub enum SchedulerClientMsg { player: Obj, vloc: ObjectRef, verb: Symbol, - args: Vec, + args: List, argstr: String, perms: Obj, session: Arc, diff --git a/crates/kernel/src/tasks/task.rs b/crates/kernel/src/tasks/task.rs index 08cd6f14..d6fdbae4 100644 --- a/crates/kernel/src/tasks/task.rs +++ b/crates/kernel/src/tasks/task.rs @@ -41,7 +41,7 @@ use moor_values::tasks::CommandError; use moor_values::tasks::CommandError::PermissionDenied; use moor_values::tasks::TaskId; use moor_values::util::parse_into_words; -use moor_values::{v_int, v_str}; +use moor_values::{v_int, v_str, List}; use moor_values::{v_obj, Obj}; use moor_values::{Symbol, Variant}; use moor_values::{NOTHING, SYSTEM_OBJECT}; @@ -475,7 +475,7 @@ impl Task { } Ok(verb_info) => { let arguments = parse_into_words(command); - let args = arguments.iter().map(|s| v_str(s)).collect::>(); + let args = List::from_iter(arguments.iter().map(|s| v_str(s))); let verb_call = VerbCall { verb_name: Symbol::mk("do_command"), location: v_obj(handler_object.clone()), @@ -578,7 +578,7 @@ impl Task { location: v_obj(target.clone()), this: v_obj(target), player: player.clone(), - args: parsed_command.args.clone(), + args: List::mk_list(&parsed_command.args), argstr: parsed_command.argstr.clone(), caller: v_obj(player.clone()), }; diff --git a/crates/kernel/src/tasks/vm_host.rs b/crates/kernel/src/tasks/vm_host.rs index fc54befe..853d21b0 100644 --- a/crates/kernel/src/tasks/vm_host.rs +++ b/crates/kernel/src/tasks/vm_host.rs @@ -29,11 +29,11 @@ use moor_compiler::{compile, CompileOptions}; use moor_values::model::{BinaryType, ObjFlag}; use moor_values::model::{VerbDef, WorldState}; use moor_values::tasks::{AbortLimitReason, Exception, TaskId}; -use moor_values::AsByteBuffer; use moor_values::Error::E_MAXREC; use moor_values::Obj; use moor_values::Var; use moor_values::{v_none, Symbol}; +use moor_values::{AsByteBuffer, List}; use crate::builtins::BuiltinRegistry; use crate::config::FeaturesConfig; @@ -500,7 +500,7 @@ impl VmHost { pub fn reset_time(&mut self) { self.vm_exec_state.start_time = Some(SystemTime::now()); } - pub fn args(&self) -> &Vec { + pub fn args(&self) -> &List { &self.vm_exec_state.top().args } } diff --git a/crates/kernel/src/vm/activation.rs b/crates/kernel/src/vm/activation.rs index 7c635bfd..878d2960 100644 --- a/crates/kernel/src/vm/activation.rs +++ b/crates/kernel/src/vm/activation.rs @@ -27,11 +27,11 @@ use moor_values::model::VerbArgsSpec; use moor_values::model::VerbDef; use moor_values::model::{BinaryType, VerbFlag}; use moor_values::util::BitEnum; -use moor_values::NOTHING; +use moor_values::Obj; use moor_values::{v_empty_list, v_int, v_obj, v_str, v_string, Var, VarType}; use moor_values::{v_empty_str, Error}; -use moor_values::{v_list, Obj}; use moor_values::{AsByteBuffer, Symbol}; +use moor_values::{List, NOTHING}; use crate::vm::moo_frame::MooStackFrame; use crate::vm::vm_call::VerbProgram; @@ -54,7 +54,7 @@ pub(crate) struct Activation { /// The object that is the 'player' role; that is, the active user of this task. pub(crate) player: Obj, /// The arguments to the verb or bf being called. - pub(crate) args: Vec, + pub(crate) args: List, /// The name of the verb that is currently being executed. pub(crate) verb_name: Symbol, /// The extended information about the verb that is currently being executed. @@ -104,7 +104,7 @@ impl Decode for Activation { frame, this, player, - args, + args: List::mk_list(&args), verb_name, verbdef, permissions, @@ -131,7 +131,7 @@ impl<'de> BorrowDecode<'de> for Activation { frame, this, player, - args, + args: List::mk_list(&args), verb_name, verbdef, permissions, @@ -245,7 +245,7 @@ impl Activation { GlobalName::verb, v_str(verb_call_request.call.verb_name.as_str()), ); - frame.set_global_variable(GlobalName::args, v_list(&verb_call_request.call.args)); + frame.set_global_variable(GlobalName::args, verb_call_request.call.args.clone().into()); // From the command, if any... if let Some(ref command) = verb_call_request.command { @@ -337,7 +337,7 @@ impl Activation { verbdef, verb_name: *EVAL_SYMBOL, command: None, - args: vec![], + args: List::mk_list(&[]), permissions, } } @@ -345,7 +345,7 @@ impl Activation { pub fn for_bf_call( bf_id: BuiltinId, bf_name: Symbol, - args: Vec, + args: List, _verb_flags: BitEnum, player: Obj, ) -> Self { diff --git a/crates/kernel/src/vm/mod.rs b/crates/kernel/src/vm/mod.rs index 953885d0..8a2d4410 100644 --- a/crates/kernel/src/vm/mod.rs +++ b/crates/kernel/src/vm/mod.rs @@ -121,10 +121,7 @@ pub enum ExecutionResult { /// Request dispatch of a new task as a fork DispatchFork(Option, Option, Offset), /// Request dispatch of a builtin function with the given arguments. - ContinueBuiltin { - builtin: BuiltinId, - arguments: Vec, - }, + ContinueBuiltin { builtin: BuiltinId, arguments: List }, /// Request that this task be suspended for a duration of time. /// This leads to the task performing a commit, being suspended for a delay, and then being /// resumed under a new transaction. diff --git a/crates/kernel/src/vm/vm_call.rs b/crates/kernel/src/vm/vm_call.rs index 17118e5a..0ef883ff 100644 --- a/crates/kernel/src/vm/vm_call.rs +++ b/crates/kernel/src/vm/vm_call.rs @@ -43,9 +43,9 @@ lazy_static! { static ref ERROR_SYM: Symbol = Symbol::mk("error"); } -pub(crate) fn args_literal(args: &[Var]) -> String { +pub(crate) fn args_literal(args: &List) -> String { args.iter() - .map(to_literal) + .map(|v| to_literal(&v)) .collect::>() .join(", ") } @@ -287,7 +287,7 @@ impl VMExecState { pub(crate) fn call_builtin_function( &mut self, bf_id: BuiltinId, - args: Vec, + args: List, exec_args: &VmExecParams, world_state: &mut dyn WorldState, session: Arc, diff --git a/crates/kernel/src/vm/vm_test.rs b/crates/kernel/src/vm/vm_test.rs index cead85f8..a0967c46 100644 --- a/crates/kernel/src/vm/vm_test.rs +++ b/crates/kernel/src/vm/vm_test.rs @@ -121,7 +121,7 @@ mod tests { session, Arc::new(BuiltinRegistry::new()), "test", - vec![], + List::mk_list(&[]), ); assert_eq!(result, Ok(v_none())); } @@ -143,7 +143,7 @@ mod tests { session, Arc::new(BuiltinRegistry::new()), "test", - vec![], + List::mk_list(&[]), ); assert_eq!(result, Ok(v_str("e"))); @@ -174,7 +174,7 @@ mod tests { session, Arc::new(BuiltinRegistry::new()), "test", - vec![], + List::mk_list(&[]), ); assert_eq!(result, Ok(v_str("ell"))); @@ -198,7 +198,7 @@ mod tests { session, Arc::new(BuiltinRegistry::new()), "test", - vec![], + List::mk_list(&[]), ); assert_eq!(result, Ok(v_int(222))); @@ -233,7 +233,7 @@ mod tests { session, Arc::new(BuiltinRegistry::new()), "test", - vec![], + List::mk_list(&[]), ); assert_eq!(result, Ok(v_list(&[222.into(), 333.into()]))); } @@ -282,7 +282,7 @@ mod tests { session, Arc::new(BuiltinRegistry::new()), "test", - vec![], + List::mk_list(&[]), ); assert_eq!(result, Ok(v_list(&[111.into(), 321.into(), 123.into()]))); } @@ -300,7 +300,7 @@ mod tests { session, Arc::new(BuiltinRegistry::new()), "test", - vec![], + List::mk_list(&[]), ); assert_eq!(result, Ok(v_list(&[2.into(), 3.into(), 4.into()]))); } @@ -320,7 +320,7 @@ mod tests { session, Arc::new(BuiltinRegistry::new()), "test", - vec![], + List::mk_list(&[]), ); assert_eq!(result, Ok(v_int(1))); } @@ -365,7 +365,7 @@ mod tests { session, Arc::new(BuiltinRegistry::new()), "test", - vec![], + List::mk_list(&[]), ); assert_eq!(result, Ok(v_str("manbozorian"))); } @@ -401,7 +401,7 @@ mod tests { session, Arc::new(BuiltinRegistry::new()), "test", - vec![], + List::mk_list(&[]), ); assert_eq!(result, Ok(v_int(666))); } @@ -442,7 +442,7 @@ mod tests { session, Arc::new(BuiltinRegistry::new()), "test_call_verb", - vec![], + List::mk_list(&[]), ); assert_eq!(result, Ok(v_int(666))); @@ -469,7 +469,7 @@ mod tests { session, Arc::new(BuiltinRegistry::new()), "test", - vec![], + List::mk_list(&[]), ); assert_eq!(result, Ok(v_int(3))); } @@ -485,7 +485,7 @@ mod tests { session, Arc::new(BuiltinRegistry::new()), "test", - vec![], + List::mk_list(&[]), ); assert_eq!(result, Ok(v_int(75))); } @@ -501,7 +501,7 @@ mod tests { session, Arc::new(BuiltinRegistry::new()), "test", - vec![], + List::mk_list(&[]), ); assert_eq!(result, Ok(v_int(50))); @@ -517,7 +517,7 @@ mod tests { session, Arc::new(BuiltinRegistry::new()), "test", - vec![], + List::mk_list(&[]), ); assert_eq!(result, Ok(v_int(50))); @@ -546,7 +546,7 @@ mod tests { session, Arc::new(BuiltinRegistry::new()), "test", - vec![], + List::mk_list(&[]), ); assert_eq!(result, Ok(v_int(50))); @@ -574,7 +574,7 @@ mod tests { session, Arc::new(BuiltinRegistry::new()), "test", - vec![], + List::mk_list(&[]), ); assert_eq!(result, Ok(v_list(&[v_int(3), v_int(2), v_int(1)]))); @@ -600,7 +600,7 @@ mod tests { session, Arc::new(BuiltinRegistry::new()), "test", - vec![], + List::mk_list(&[]), ); assert_eq!(result, Ok(v_int(6))); @@ -628,7 +628,7 @@ mod tests { session, builtin_registry, "test", - vec![v_obj(SYSTEM_OBJECT), v_objid(32)], + List::mk_list(&[v_obj(SYSTEM_OBJECT), v_objid(32)]), ); assert_eq!(result, Ok(v_int(0))); @@ -648,7 +648,7 @@ mod tests { session.clone(), builtin_registry, "test", - vec![], + List::mk_list(&[]), ); assert_eq!(result, Ok(v_int(5))); } @@ -667,7 +667,7 @@ mod tests { session.clone(), builtin_registry, "test", - vec![], + List::mk_list(&[]), ); assert_eq!(result, Ok(v_str("ello world"))); } @@ -685,7 +685,7 @@ mod tests { session.clone(), builtin_registry, "test", - vec![], + List::mk_list(&[]), ); assert_eq!(result, Ok(v_int(666))); } @@ -705,7 +705,7 @@ mod tests { session.clone(), builtin_registry, "test", - vec![], + List::mk_list(&[]), ); assert_eq!(result, Ok(v_none())); } @@ -745,7 +745,7 @@ mod tests { session.clone(), builtin_registry, "test", - vec![], + List::mk_list(&[]), ); assert_eq!(result, Ok(v_str("should reach here"))); } @@ -766,7 +766,7 @@ mod tests { session.clone(), builtin_registry, "test", - vec![], + List::mk_list(&[]), ); assert_eq!(result, Ok(v_str("ello world"))); } @@ -783,7 +783,7 @@ mod tests { session.clone(), builtin_registry, "test", - vec![], + List::mk_list(&[]), ); assert_eq!(result, Ok(v_int(333))); } @@ -808,7 +808,7 @@ mod tests { session.clone(), builtin_registry, "test", - vec![], + List::mk_list(&[]), ); assert_eq!(result, Ok(v_int(42))); } @@ -834,7 +834,7 @@ mod tests { session.clone(), builtin_registry, "test", - vec![], + List::mk_list(&[]), ); assert_eq!(result, Ok(v_int(52))); } @@ -860,7 +860,7 @@ mod tests { session.clone(), builtin_registry, "test", - vec![], + List::mk_list(&[]), ); assert_eq!(result, Ok(v_list(&[v_int(42), v_int(66)]))); } @@ -890,7 +890,7 @@ mod tests { session.clone(), builtin_registry, "test", - vec![], + List::mk_list(&[]), ); assert_eq!(result, Ok(v_list(&[v_int(42), v_int(13), v_int(99)]))); } @@ -917,7 +917,7 @@ mod tests { session.clone(), builtin_registry, "test", - vec![], + List::mk_list(&[]), ); assert_eq!(result, Ok(v_list(&[v_int(5), v_int(3)]))); } @@ -941,7 +941,7 @@ mod tests { session.clone(), builtin_registry, "test", - vec![], + List::mk_list(&[]), ); assert_eq!(result, Ok(v_list(&[v_int(5), v_int(3)]))); } @@ -965,7 +965,7 @@ mod tests { session.clone(), builtin_registry, "test", - vec![], + List::mk_list(&[]), ); assert_eq!(result, Ok(v_list(&[v_int(5), v_int(3)]))); } @@ -991,7 +991,7 @@ mod tests { session.clone(), builtin_registry, "test", - vec![], + List::mk_list(&[]), ); assert_eq!(result, Ok(v_list(&[v_int(5), v_int(3)]))); } @@ -1011,7 +1011,7 @@ mod tests { session.clone(), builtin_registry, "test", - vec![], + List::mk_list(&[]), ); assert_eq!(result, Ok(v_int(42))); } @@ -1033,7 +1033,7 @@ mod tests { session.clone(), builtin_registry, "test", - vec![], + List::mk_list(&[]), ); assert_eq!(result, Ok(v_list(&[v_int(2), v_int(3)]))); } @@ -1146,7 +1146,7 @@ mod tests { session, Arc::new(BuiltinRegistry::new()), "test", - vec![], + List::mk_list(&[]), ); assert_eq!(result, Ok(expected_result)); } @@ -1161,7 +1161,7 @@ mod tests { session, Arc::new(BuiltinRegistry::new()), "test", - vec![], + List::mk_list(&[]), ); assert_eq!( result, @@ -1179,7 +1179,7 @@ mod tests { session, Arc::new(BuiltinRegistry::new()), "test", - vec![], + List::mk_list(&[]), ); assert_eq!( result.unwrap(), @@ -1202,7 +1202,7 @@ mod tests { session, Arc::new(BuiltinRegistry::new()), "test", - vec![], + List::mk_list(&[]), ); assert_eq!(result.unwrap(), v_str("123")); } @@ -1217,7 +1217,7 @@ mod tests { session, Arc::new(BuiltinRegistry::new()), "test", - vec![], + List::mk_list(&[]), ); assert_eq!(result.unwrap(), v_int(2)); } diff --git a/crates/kernel/tests/textdump.rs b/crates/kernel/tests/textdump.rs index 0ccff802..3e931fb6 100644 --- a/crates/kernel/tests/textdump.rs +++ b/crates/kernel/tests/textdump.rs @@ -15,12 +15,12 @@ #[cfg(test)] mod test { use semver::Version; + use similar_asserts; use std::collections::BTreeSet; use std::fs::File; use std::io::{BufReader, Read}; use std::path::PathBuf; use std::sync::Arc; - use similar_asserts; use moor_compiler::Program; use moor_db::loader::LoaderInterface; @@ -256,7 +256,7 @@ mod test { let output = write_textdump(db, "** LambdaMOO Database, Format Version 1 **"); - similar_asserts::assert_eq!(&input, &output,""); + similar_asserts::assert_eq!(&input, &output, ""); } #[test] diff --git a/crates/kernel/testsuite/common/mod.rs b/crates/kernel/testsuite/common/mod.rs index c05b28ba..637be878 100644 --- a/crates/kernel/testsuite/common/mod.rs +++ b/crates/kernel/testsuite/common/mod.rs @@ -35,9 +35,9 @@ use moor_values::model::Named; use moor_values::model::VerbArgsSpec; use moor_values::model::WorldStateSource; use moor_values::model::{BinaryType, VerbFlag}; -use moor_values::Obj; use moor_values::Symbol; use moor_values::{AsByteBuffer, SYSTEM_OBJECT}; +use moor_values::{List, Obj}; #[allow(dead_code)] pub fn testsuite_dir() -> PathBuf { @@ -116,7 +116,7 @@ pub fn run_as_verb(db: &dyn Database, expression: &str) -> ExecResult { Arc::new(NoopClientSession::new()), builtin_registry, &verb_uuid, - vec![], + List::mk_list(&[]), ); state.commit().unwrap(); result