From f23662c1f9e1f839e2d11e0f90e0aee8c3349fb7 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Sun, 9 Jan 2022 11:58:58 +0100 Subject: [PATCH] change abi the thing C++ is afraid of --- src/bytecode.rs | 24 +++++++++++++----------- src/compile.rs | 2 +- src/lib.rs | 6 +++--- src/vm.rs | 5 ++--- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/bytecode.rs b/src/bytecode.rs index 531eb0b..c45ef6d 100644 --- a/src/bytecode.rs +++ b/src/bytecode.rs @@ -41,18 +41,20 @@ //! returned value. //! //! ```text -//! old stack offset ╮ old *mut FnBlock ╮ ╭ Parameters ╮ ╭ local -//! v v v v v -//! ───────┬─────────────┬────────────┬──────────┬─────────┬──────────┬─────────╮ -//! Num(6) │ NativeU(20) │ NativeU(4) │ Ptr │ Num(5) │ Num(6) │ Num(5) │ -//! ───────┴─────────────┴────────────┴──────────┴─────────┴──────────┴─────────╯ -//! ^ ╰──────────────────────────────────────────────────────────────────── current stack frame -//! │ ^ ^ -//! ╰─ old local ╰╮ ╰─ old PC +//! old stack offset─╮ +//! ╭─Parameters─╮ │ old FnBlock index─╮ local─╮ +//! v v v v v +//! ───────┬─────────┬──────────┬─────────────┬────────────┬────────────┬─────────╮ +//! Num(6) │ Num(5) │ Num(6) │ NativeU(20) │ NativeU(4) │ NativeU(1) │ Num(5) │ +//! ───────┴─────────┴──────────┴─────────────┴────────────┴────────────┴─────────╯ +//! ^ ╰────────────────────────────────────────────────────────────────── current stack frame +//! │ ^ +//! ╰─ old local ╰─old PC +//! +//! ^ +//! Vm ╰────────────╮ //! │ -//! │ -//! Vm │ -//! Current stack offset ╯ +//! Current stack offset─╯ //! //! ``` diff --git a/src/compile.rs b/src/compile.rs index 0e6fce5..3f24b79 100644 --- a/src/compile.rs +++ b/src/compile.rs @@ -152,7 +152,7 @@ impl<'bc, 'gc> Compiler<'bc, 'gc> { Ok(()) } - fn compile_fn_decl(&mut self, decl: &FnDecl) -> CResult { + fn compile_fn_decl(&mut self, _: &FnDecl) -> CResult { todo!() } diff --git a/src/lib.rs b/src/lib.rs index b85f553..4418001 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ -#![deny(clippy::disallowed_type)] +#![deny(clippy::disallowed_types)] mod ast; mod bytecode; @@ -18,14 +18,14 @@ pub use lex::*; pub use parse::*; #[cfg(not(feature = "fxhash"))] -#[allow(clippy::disallowed_type)] +#[allow(clippy::disallowed_types)] type HashMap = std::collections::HashMap; #[cfg(feature = "fxhash")] type HashMap = rustc_hash::FxHashMap; #[cfg(not(feature = "fxhash"))] -#[allow(clippy::disallowed_type)] +#[allow(clippy::disallowed_types)] type HashSet = std::collections::HashSet; #[cfg(feature = "fxhash")] diff --git a/src/vm.rs b/src/vm.rs index 220b22e..afabe25 100644 --- a/src/vm.rs +++ b/src/vm.rs @@ -14,6 +14,7 @@ pub fn execute<'bc>( cfg: &mut Config, ) -> Result<(), VmError> { let mut vm = Vm { + blocks: bytecode, current: bytecode.first().ok_or("no bytecode found")?, pc: 0, stack: Vec::with_capacity(1024 << 5), @@ -42,8 +43,6 @@ pub enum Value { Object(Object), /// A value that is stored by the vm for bookkeeping and should never be accessed for anything else NativeU(usize), - /// A function - Fn(Ptr), } #[derive(Debug, Clone, Copy)] @@ -61,6 +60,7 @@ const FALSE: Value = Value::Bool(false); struct Vm<'bc, 'io> { // -- global + blocks: &'bc [FnBlock<'bc>], _alloc: RtAlloc, stack: Vec, stdout: &'io mut dyn Write, @@ -241,7 +241,6 @@ impl Display for Value { Value::Array => todo!(), Value::Object(_) => todo!(), Value::NativeU(_) => panic!("Called display on native value!"), - Value::Fn(_) => f.write_str("[function]"), } } }