Move value to vm/value

This commit is contained in:
Sofia 2026-03-20 18:16:07 +02:00
parent 139887fd73
commit 2710a43bb2
6 changed files with 12 additions and 10 deletions

View File

@ -1,14 +1,13 @@
use ferrite_lua::{ use ferrite_lua::{
compile, compile,
value::{self, RustFunction}, vm::{RuntimeError, VirtualMachine, value},
vm::{self, RuntimeError, VirtualMachine},
}; };
static TEST: &str = include_str!("../examples/test.lua"); static TEST: &str = include_str!("../examples/test.lua");
#[derive(Debug, PartialEq, Eq)] #[derive(Debug, PartialEq, Eq)]
pub struct Max; pub struct Max;
impl RustFunction for Max { impl value::RustFunction for Max {
fn execute(&self, parameters: Vec<value::Value>) -> Result<Vec<value::Value>, RuntimeError> { fn execute(&self, parameters: Vec<value::Value>) -> Result<Vec<value::Value>, RuntimeError> {
let lhs = parameters.get(0).cloned().unwrap_or(value::Value::Nil); let lhs = parameters.get(0).cloned().unwrap_or(value::Value::Nil);
let rhs = parameters.get(1).cloned().unwrap_or(value::Value::Nil); let rhs = parameters.get(1).cloned().unwrap_or(value::Value::Nil);
@ -24,7 +23,7 @@ impl RustFunction for Max {
} }
#[derive(Debug, PartialEq, Eq)] #[derive(Debug, PartialEq, Eq)]
pub struct Print; pub struct Print;
impl RustFunction for Print { impl value::RustFunction for Print {
fn execute(&self, parameters: Vec<value::Value>) -> Result<Vec<value::Value>, RuntimeError> { fn execute(&self, parameters: Vec<value::Value>) -> Result<Vec<value::Value>, RuntimeError> {
println!("{:?}", parameters); println!("{:?}", parameters);
Ok(Vec::new()) Ok(Vec::new())

View File

@ -5,7 +5,7 @@ use crate::{
Parse, TokenRange, TokenStream, TokenStreamError, Parse, TokenRange, TokenStream, TokenStreamError,
lexer::{Keyword, Position, Token}, lexer::{Keyword, Position, Token},
}, },
value::{LuaFloat, LuaInteger}, vm::value::{LuaFloat, LuaInteger},
}; };
#[derive(Debug, Clone)] #[derive(Debug, Clone)]

View File

@ -8,8 +8,10 @@ use crate::{
AccessModifier, BinaryOperator, Block, Expression, ExpressionList, IdentOrEllipsis, AccessModifier, BinaryOperator, Block, Expression, ExpressionList, IdentOrEllipsis,
Literal, Node, Statement, UnaryOperator, Literal, Node, Statement, UnaryOperator,
}, },
value::{LuaBool, LuaInteger}, vm::{
vm::{Constant, Instruction, Prototype}, Constant, Instruction, Prototype,
value::{LuaBool, LuaInteger},
},
}; };
#[derive(Clone, Debug)] #[derive(Clone, Debug)]

View File

@ -1,6 +1,6 @@
//! Usage example: //! Usage example:
//! ```rust //! ```rust
//! use ferrite_lua::{compile, vm, value}; //! use ferrite_lua::{compile, vm::{self, value}};
//! //!
//! #[derive(Debug, PartialEq, Eq)] //! #[derive(Debug, PartialEq, Eq)]
//! pub struct Print; //! pub struct Print;
@ -42,7 +42,6 @@ use crate::{
mod ast; mod ast;
mod compile; mod compile;
mod token_stream; mod token_stream;
pub mod value;
pub mod vm; pub mod vm;
#[derive(Error, Debug)] #[derive(Error, Debug)]

View File

@ -5,9 +5,11 @@ use std::{cell::RefCell, collections::HashMap, fmt::Debug, hash::Hash, rc::Rc};
use crate::{ use crate::{
CompilationUnit, CompilationUnit,
ast::{BinaryOperator, UnaryOperator}, ast::{BinaryOperator, UnaryOperator},
value::{IndexableValue, LuaBool, LuaInteger, VMFloat, Value}, vm::value::{IndexableValue, LuaBool, LuaInteger, VMFloat, Value},
}; };
pub mod value;
#[derive(Clone, Hash, PartialEq, Eq)] #[derive(Clone, Hash, PartialEq, Eq)]
pub enum Constant { pub enum Constant {
String(String), String(String),