diff --git a/muse-lang/src/vm.rs b/muse-lang/src/vm.rs index 2ca12bb..1625634 100644 --- a/muse-lang/src/vm.rs +++ b/muse-lang/src/vm.rs @@ -137,7 +137,7 @@ impl Vm { /// This function does not actually execute any code. A call to /// [`resume`](Self::resume)/[`resume_async`](Self::resume_async) is needed /// to begin executing the function call. - pub fn prepare(&self, code: &Code, guard: &mut CollectionGuard) -> Result<(), ExecutionError> { + pub fn prepare(&self, code: &Code, guard: &mut CollectionGuard) -> Result<(), Fault> { self.context(guard).prepare(code) } @@ -151,7 +151,7 @@ impl Vm { function: &Rooted, arity: Arity, guard: &mut CollectionGuard, - ) -> Result<(), ExecutionError> { + ) -> Result<(), Fault> { self.context(guard).prepare_call(function, arity) } @@ -225,7 +225,7 @@ impl Vm { &'context self, code: &Code, guard: &'context mut CollectionGuard<'guard>, - ) -> Result, ExecutionError> { + ) -> Result, Fault> { MaybeOwnedContext::Owned(self.context(guard)).execute_async(code) } @@ -649,7 +649,7 @@ impl<'context, 'guard> VmContext<'context, 'guard> { /// This function does not actually execute any code. A call to /// [`resume`](Self::resume)/[`resume_async`](Self::resume_async) is needed /// to begin executing the function call. - pub fn prepare(&mut self, code: &Code) -> Result<(), ExecutionError> { + pub fn prepare(&mut self, code: &Code) -> Result<(), Fault> { let code = self.push_code(code, None); self.prepare_owned(code) } @@ -725,18 +725,18 @@ impl<'context, 'guard> VmContext<'context, 'guard> { self.resume_until(Instant::now() + duration) } - fn prepare_owned(&mut self, code: CodeIndex) -> Result<(), ExecutionError> { + fn prepare_owned(&mut self, code: CodeIndex) -> Result<(), Fault> { let vm = self.vm(); vm.frames[vm.current_frame].code = Some(code); vm.frames[vm.current_frame].instruction = 0; - self.allocate(self.code[code.0].code.data.stack_requirement) - .map_err(|err| ExecutionError::new(err, self))?; + self.allocate(self.code[code.0].code.data.stack_requirement)?; Ok(()) } fn execute_owned(&mut self, code: CodeIndex) -> Result { - self.prepare_owned(code)?; + self.prepare_owned(code) + .map_err(|err| ExecutionError::new(err, self))?; self.resume() } @@ -747,7 +747,8 @@ impl<'context, 'guard> VmContext<'context, 'guard> { code: &Code, ) -> Result, ExecutionError> { let code = self.push_code(code, None); - self.prepare_owned(code)?; + self.prepare_owned(code) + .map_err(|err| ExecutionError::new(err, self))?; Ok(ExecuteAsync(MaybeOwnedContext::Borrowed(self))) } @@ -800,15 +801,9 @@ impl<'context, 'guard> VmContext<'context, 'guard> { /// This function does not actually execute any code. A call to /// [`resume`](Self::resume)/[`resume_async`](Self::resume_async) is needed /// to begin executing the function call. - pub fn prepare_call( - &mut self, - function: &Rooted, - arity: Arity, - ) -> Result<(), ExecutionError> { + pub fn prepare_call(&mut self, function: &Rooted, arity: Arity) -> Result<(), Fault> { let Some(body) = function.body(arity) else { - return Err(ExecutionError::Exception( - Fault::IncorrectNumberOfArguments.as_exception(self), - )); + return Err(Fault::IncorrectNumberOfArguments); }; let code = self.push_code(body, Some(function)); self.prepare_owned(code) @@ -2879,7 +2874,7 @@ impl<'vm, 'context, 'guard> MaybeOwnedContext<'vm, 'context, 'guard> { pub fn execute_async( mut self, code: &Code, - ) -> Result, ExecutionError> { + ) -> Result, Fault> { let code = self.push_code(code, None); self.prepare_owned(code)?; diff --git a/muse-reactor/src/lib.rs b/muse-reactor/src/lib.rs index 3f20c88..f9be1ae 100644 --- a/muse-reactor/src/lib.rs +++ b/muse-reactor/src/lib.rs @@ -123,13 +123,12 @@ impl Builder { } } - pub fn unit(self) -> Builder { - assert!( - self.vm_source.is_none(), - "new_vm must be invoked after unit() to ensure the correct ReactorHandle type" - ); + pub fn new_vm(self, new_vm: F) -> Builder + where + F: NewVm, + { Builder { - vm_source: None, + vm_source: Some(Arc::new(new_vm)), threads: self.threads, thread_name: self.thread_name, work_queue_limit: self.work_queue_limit, @@ -152,14 +151,6 @@ where self } - pub fn new_vm(mut self, new_vm: F) -> Self - where - F: NewVm, - { - self.vm_source = Some(Arc::new(new_vm)); - self - } - pub fn finish(self) -> ReactorHandle { let (sender, receiver) = if let Some(limit) = self.work_queue_limit { flume::bounded(limit) @@ -1269,6 +1260,8 @@ impl Clone for ReactorHandle { } } +impl ContainsNoRefs for ReactorHandle where Work: WorkUnit {} + #[derive(Debug)] struct SharedReactorData { shutdown: AtomicBool, @@ -1516,6 +1509,8 @@ pub struct BudgetPoolId(NonZeroUsize); pub struct BudgetPoolHandle(Arc>); +impl ContainsNoRefs for BudgetPoolHandle where Work: WorkUnit {} + struct BudgetPoolHandleData { pool: ReactorBudgetPool, reactor: ReactorHandle,