From 40b947a1a930c342bd1893e87f3d51cae7d7b61a Mon Sep 17 00:00:00 2001 From: Vincent Hanquez Date: Mon, 18 Dec 2023 17:11:54 +0800 Subject: [PATCH] remove exec's value now --- werbolg-exec/src/exec.rs | 17 +++++++- werbolg-exec/src/lib.rs | 4 +- werbolg-exec/src/value.rs | 82 --------------------------------------- 3 files changed, 17 insertions(+), 86 deletions(-) delete mode 100644 werbolg-exec/src/value.rs diff --git a/werbolg-exec/src/exec.rs b/werbolg-exec/src/exec.rs index 0b3ce77..05e9e36 100644 --- a/werbolg-exec/src/exec.rs +++ b/werbolg-exec/src/exec.rs @@ -1,11 +1,26 @@ use crate::Valuable; -use super::NIFCall; use super::{ExecutionError, ExecutionMachine}; use werbolg_compile::{CallArity, Instruction, InstructionAddress, LocalStackSize}; use werbolg_core as ir; use werbolg_core::ValueFun; +/// Native Implemented Function +pub struct NIF<'m, L, T, V> { + pub name: &'static str, + pub call: NIFCall<'m, L, T, V>, +} + +/// 2 Variants of Native calls +/// +/// * "Pure" function that don't have access to the execution machine +/// * "Mut" function that have access to the execution machine and have more power / responsability. +pub enum NIFCall<'m, L, T, V> { + Pure(fn(&[V]) -> Result), + Mut(fn(&mut ExecutionMachine<'m, L, T, V>, &[V]) -> Result), +} + +/// Execute the module, calling function identified by FunId, with the arguments in parameters pub fn exec<'module, L, T, V: Valuable>( em: &mut ExecutionMachine<'module, L, T, V>, call: ir::FunId, diff --git a/werbolg-exec/src/lib.rs b/werbolg-exec/src/lib.rs index 68e6e05..031a608 100644 --- a/werbolg-exec/src/lib.rs +++ b/werbolg-exec/src/lib.rs @@ -13,13 +13,11 @@ use werbolg_core as ir; mod exec; mod valuable; -mod value; use alloc::{string::String, vec::Vec}; pub use valuable::{Valuable, ValueKind}; -pub use value::{NIFCall, NIF}; -pub use exec::{exec, exec_continue, step}; +pub use exec::{exec, exec_continue, step, NIFCall, NIF}; pub struct ExecutionEnviron<'m, L, T, V> { pub nifs: IdVec>, diff --git a/werbolg-exec/src/value.rs b/werbolg-exec/src/value.rs deleted file mode 100644 index 6b5cc0c..0000000 --- a/werbolg-exec/src/value.rs +++ /dev/null @@ -1,82 +0,0 @@ -//! Execution machine value - define the Value type - -use super::{ExecutionError, ExecutionMachine}; -/* -use alloc::rc::Rc; -use core::any::Any; -use core::cell::RefCell; -*/ - -/// Native Implemented Function -pub struct NIF<'m, L, T, V> { - pub name: &'static str, - pub call: NIFCall<'m, L, T, V>, -} - -/// 2 Variants of Native calls -/// -/// * "Pure" function that don't have access to the execution machine -/// * "Mut" function that have access to the execution machine and have more power / responsability. -pub enum NIFCall<'m, L, T, V> { - Pure(fn(&[V]) -> Result), - Mut(fn(&mut ExecutionMachine<'m, L, T, V>, &[V]) -> Result), -} - -/* -#[derive(Clone)] -pub struct Opaque(Rc); - -impl Opaque { - pub fn new(t: T) -> Self { - Self(Rc::new(t)) - } - - pub fn downcast_ref(&self) -> Result<&T, ExecutionError> { - self.0 - .downcast_ref() - .ok_or(ExecutionError::OpaqueTypeTypeInvalid { - got_type_id: self.0.type_id(), - }) - } -} - -#[derive(Clone)] -pub struct OpaqueMut(Rc>); - -impl OpaqueMut { - pub fn new(t: T) -> Self { - Self(Rc::new(RefCell::new(t))) - } - - pub fn on_mut(&self, f: F) -> Result<(), ExecutionError> - where - T: Any + Send + Sync, - F: FnOnce(&mut T) -> Result<(), ExecutionError>, - { - let b = self.0.as_ref(); - - let mut cell = b.borrow_mut(); - let r = cell - .downcast_mut() - .ok_or(ExecutionError::OpaqueTypeTypeInvalid { - got_type_id: self.0.type_id(), - })?; - - f(r) - } -} - -impl core::fmt::Debug for Opaque { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - let ty = self.0.type_id(); - f.debug_tuple("Opaque").field(&ty).finish() - } -} - -impl core::fmt::Debug for OpaqueMut { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - let ty = self.0.type_id(); - f.debug_tuple("OpaqueMut").field(&ty).finish() - } -} -*/