Move Constant to Value
This commit is contained in:
parent
2710a43bb2
commit
56943d612a
@ -9,8 +9,8 @@ use crate::{
|
|||||||
Literal, Node, Statement, UnaryOperator,
|
Literal, Node, Statement, UnaryOperator,
|
||||||
},
|
},
|
||||||
vm::{
|
vm::{
|
||||||
Constant, Instruction, Prototype,
|
Instruction, Prototype,
|
||||||
value::{LuaBool, LuaInteger},
|
value::{Constant, LuaBool, LuaInteger},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -56,7 +56,7 @@ pub enum CompilationError {
|
|||||||
pub struct CompilationUnit {
|
pub struct CompilationUnit {
|
||||||
pub instructions: Vec<vm::Instruction>,
|
pub instructions: Vec<vm::Instruction>,
|
||||||
pub state: compile::State,
|
pub state: compile::State,
|
||||||
pub constants: Vec<vm::Constant>,
|
pub constants: Vec<vm::value::Constant>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Debug for CompilationUnit {
|
impl Debug for CompilationUnit {
|
||||||
|
|||||||
@ -1,42 +1,15 @@
|
|||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
use std::{cell::RefCell, collections::HashMap, fmt::Debug, hash::Hash, rc::Rc};
|
use std::{cell::RefCell, collections::HashMap, fmt::Debug, rc::Rc};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
CompilationUnit,
|
CompilationUnit,
|
||||||
ast::{BinaryOperator, UnaryOperator},
|
ast::{BinaryOperator, UnaryOperator},
|
||||||
vm::value::{IndexableValue, LuaBool, LuaInteger, VMFloat, Value},
|
vm::value::{Constant, IndexableValue, LuaInteger, Value},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub mod value;
|
pub mod value;
|
||||||
|
|
||||||
#[derive(Clone, Hash, PartialEq, Eq)]
|
|
||||||
pub enum Constant {
|
|
||||||
String(String),
|
|
||||||
Float(VMFloat),
|
|
||||||
Integer(LuaInteger),
|
|
||||||
Bool(LuaBool),
|
|
||||||
Nil,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<&str> for Constant {
|
|
||||||
fn from(value: &str) -> Self {
|
|
||||||
Constant::String(value.to_owned())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Debug for Constant {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
match self {
|
|
||||||
Self::String(arg0) => f.debug_tuple("String").field(arg0).finish(),
|
|
||||||
Self::Float(arg0) => f.debug_tuple("Float").field(&arg0.lua_number()).finish(),
|
|
||||||
Self::Integer(arg0) => f.debug_tuple("Integer").field(arg0).finish(),
|
|
||||||
Self::Bool(arg0) => f.debug_tuple("Boolean").field(arg0).finish(),
|
|
||||||
Self::Nil => f.debug_tuple("Nil").finish(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
pub enum Instruction {
|
pub enum Instruction {
|
||||||
/// R(A) := R(B)
|
/// R(A) := R(B)
|
||||||
|
|||||||
@ -87,6 +87,32 @@ impl<T: RustFunction + 'static> From<T> for Value {
|
|||||||
Self::RustFunction(Rc::new(RefCell::new(value)))
|
Self::RustFunction(Rc::new(RefCell::new(value)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[derive(Clone, Hash, PartialEq, Eq)]
|
||||||
|
pub enum Constant {
|
||||||
|
String(String),
|
||||||
|
Float(VMFloat),
|
||||||
|
Integer(LuaInteger),
|
||||||
|
Bool(LuaBool),
|
||||||
|
Nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&str> for Constant {
|
||||||
|
fn from(value: &str) -> Self {
|
||||||
|
Constant::String(value.to_owned())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Debug for Constant {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
Self::String(arg0) => f.debug_tuple("String").field(arg0).finish(),
|
||||||
|
Self::Float(arg0) => f.debug_tuple("Float").field(&arg0.lua_number()).finish(),
|
||||||
|
Self::Integer(arg0) => f.debug_tuple("Integer").field(arg0).finish(),
|
||||||
|
Self::Bool(arg0) => f.debug_tuple("Boolean").field(arg0).finish(),
|
||||||
|
Self::Nil => f.debug_tuple("Nil").finish(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub enum Value {
|
pub enum Value {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user