Skip to content

Commit

Permalink
test: Add mlua as unit test tools
Browse files Browse the repository at this point in the history
  • Loading branch information
sbwtw committed May 27, 2024
1 parent a791a83 commit bd61dd0
Show file tree
Hide file tree
Showing 22 changed files with 401 additions and 254 deletions.
87 changes: 86 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ indexmap = "*"
byteorder = "*"
uuid = { version = "*", features = ["v4", "fast-rng", "macro-diagnostics", "serde"] }
inkwell = { version = "*", optional = true, features = ["llvm17-0-no-llvm-linking"] }
mlua = { version = "*", features = ["lua54", "macros", "async"], optional = true }

[dev-dependencies]
tempfile = "*"
Expand All @@ -38,6 +39,7 @@ lalrpop = { version = "*", optional = true }
llvm-sys = { version = "170", optional = true, features = ["prefer-dynamic"] }

[features]
default = ["use_lalrpop"]
default = ["use_lalrpop", "lua_backend"]
use_lalrpop = ["lalrpop", "lalrpop-util"]
llvm_backend = ["inkwell", "llvm-sys"]
lua_backend = ["mlua"]
5 changes: 2 additions & 3 deletions lib/src/ast/function_declaration.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use crate::impl_ast_display;
use crate::prelude::*;
use smallvec::SmallVec;
use std::rc::Rc;

#[derive(Debug)]
pub struct FunctionDeclare {
name: StString,
decl_class: DeclareClass,
return_type: Option<Rc<Box<dyn Type>>>,
parameters: SmallVec<[Rc<Variable>; 8]>,
parameters: SmallVec8<Rc<Variable>>,
}

impl_ast_display!(FunctionDeclare, visit_function_declaration);
Expand All @@ -18,7 +17,7 @@ impl FunctionDeclare {
name: StString,
class: DeclareClass,
ty: Option<Rc<Box<dyn Type>>>,
variables: SmallVec<[Rc<Variable>; 8]>,
variables: SmallVec8<Rc<Variable>>,
) -> Self {
Self {
name,
Expand Down
6 changes: 3 additions & 3 deletions lib/src/ast/if_statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl IfStatement {
condition,
then_controlled: None,
else_controlled: None,
else_if_list: vec![],
else_if_list: Vec::with_capacity(0),
}
}

Expand All @@ -28,7 +28,7 @@ impl IfStatement {
condition,
then_controlled: Some(then_control),
else_controlled: None,
else_if_list: vec![],
else_if_list: Vec::with_capacity(0),
}
}

Expand All @@ -41,7 +41,7 @@ impl IfStatement {
condition,
then_controlled: Some(then_control),
else_controlled: Some(else_control),
else_if_list: vec![],
else_if_list: Vec::with_capacity(0),
}
}

Expand Down
6 changes: 3 additions & 3 deletions lib/src/ast/operator_expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ use std::rc::Rc;
pub struct OperatorExpression {
op: Operator,
ty: Option<Rc<Box<dyn Type>>>,
operands: Vec<Expression>,
operands: SmallVec<[Expression; 2]>,
}

impl_ast_display!(OperatorExpression, visit_operator_expression);
impl_into_expression!(OperatorExpression, |x| Expression::operator(Box::new(x)));

impl OperatorExpression {
pub fn new(op: Operator, operands: Vec<Expression>) -> Self {
pub fn new(op: Operator, operands: SmallVec<[Expression; 2]>) -> Self {
match operands.len() {
1 => debug_assert!(op.is_unary_operator(), "'{:?}' is not a unary operator", op),
2 => debug_assert!(
Expand Down Expand Up @@ -43,7 +43,7 @@ impl OperatorExpression {
self.ty = ty;
}

pub fn operands(&self) -> &Vec<Expression> {
pub fn operands(&self) -> &[Expression] {
&self.operands
}

Expand Down
5 changes: 0 additions & 5 deletions lib/src/ast/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ builtin_type_impl!(struct StringType, TypeClass::String);
#[derive(Debug)]
pub struct UserType {
name: StString,
#[allow(dead_code)]
decl_id: Option<usize>,
class: Option<UserTypeClass>,
attributes: Map<StString, String>,
Expand All @@ -64,7 +63,6 @@ impl UserType {
}
}

#[allow(unused)]
pub fn name(&self) -> &StString {
&self.name
}
Expand Down Expand Up @@ -114,7 +112,6 @@ impl Type for EnumDeclare {
}

#[derive(Debug)]
#[allow(unused)]
pub struct AliasDeclare {
name: StString,
alias: Rc<Box<dyn Type>>,
Expand All @@ -137,7 +134,6 @@ impl Type for AliasDeclare {
}

#[derive(Debug)]
#[allow(unused)]
pub struct StructDeclare {
name: StString,
variables: SmallVec8<Rc<Variable>>,
Expand All @@ -156,7 +152,6 @@ impl StructDeclare {
self.variables.as_slice()
}

#[allow(dead_code)]
pub fn variables_mut(&mut self) -> &mut [Rc<Variable>] {
self.variables.as_mut_slice()
}
Expand Down
1 change: 0 additions & 1 deletion lib/src/ast/variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ pub struct Variable {
}

impl Variable {
#[allow(dead_code)]
pub fn new(name: StString) -> Self {
Self {
name,
Expand Down
Loading

0 comments on commit bd61dd0

Please sign in to comment.