Reorganize repository into a workspace

This commit is contained in:
Joel Wejdenstål 2022-06-16 18:26:02 +02:00
parent de7d775648
commit f8f58d70e0
No known key found for this signature in database
GPG key ID: DF03CEFBB1A915AA
40 changed files with 76 additions and 55 deletions

View file

@ -1,26 +1,5 @@
[package]
name = "zaia"
version = "0.1.0"
edition = "2021"
[dependencies]
logos = "0.12.0"
ariadne = "0.1.5"
cstree = "0.11.0"
hexponent = "0.3.1"
[dev-dependencies]
insta = "1.14.0"
paste = "1.0.7"
criterion = "0.3.5"
[profile.bench]
debug = true
[[bench]]
name = "parse"
harness = false
[[bench]]
name = "load"
harness = false
[workspace]
members = [
"crates/zaia",
"crates/zaia-cli",
]

View file

@ -1,9 +0,0 @@
# Zaia
Zaia is a dialect of the Lua language that is designed to be easy and flexible,
promoting integration and extensibility within modern software.
## License
Zaia is licensed under the Apache v2.0 license.
See the `LICENSE` file for more information.

View file

@ -0,0 +1,8 @@
[package]
name = "zaia-cli"
version = "0.1.0"
edition = "2021"
[dependencies]
zaia = { path = "../zaia" }
clap = { version = "3.2.5", features = ["derive"] }

View file

@ -0,0 +1,18 @@
use std::path::PathBuf;
use clap::Parser;
use zaia::Lua;
use std::fs;
#[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)]
struct Args {
file: PathBuf,
}
fn main() {
let args = Args::parse();
let source = fs::read_to_string(&args.file).unwrap();
let mut lua = Lua::new();
let script = lua.load(&source);
lua.execute(&script).unwrap();
}

23
crates/zaia/Cargo.toml Normal file
View file

@ -0,0 +1,23 @@
[package]
name = "zaia"
version = "0.1.0"
edition = "2021"
[dependencies]
logos = "0.12.0"
ariadne = "0.1.5"
cstree = "0.11.0"
hexponent = "0.3.1"
[dev-dependencies]
insta = "1.14.0"
paste = "1.0.7"
criterion = "0.3.5"
[[bench]]
name = "parse"
harness = false
[[bench]]
name = "load"
harness = false

View file

@ -1,10 +1,10 @@
use std::fs;
use criterion::{black_box, criterion_group, criterion_main, Criterion, Throughput};
use zaia::engine::Lua;
use zaia::Lua;
fn criterion_benchmark(c: &mut Criterion) {
let source = fs::read_to_string("test-files/if.lua").unwrap();
let source = fs::read_to_string("../../test-files/if.lua").unwrap();
{
let mut group = c.benchmark_group("load");
let mut deferred = Vec::new();

View file

@ -6,7 +6,7 @@ use logos::Logos;
use zaia::parser::{kind::SyntaxKind, parse};
fn criterion_benchmark(c: &mut Criterion) {
let source = fs::read_to_string("test-files/mixed.lua").unwrap();
let source = fs::read_to_string("../../test-files/mixed.lua").unwrap();
{
let mut group = c.benchmark_group("lex");
let mut deferred = Vec::new();

View file

@ -1010,8 +1010,8 @@ mod tests {
};
}
test!(function, "test-files/function.lua");
test!(if, "test-files/if.lua");
test!(op_prec, "test-files/op_prec.lua");
test!(nbody, "test-files/nbody.lua");
test!(function, "../../test-files/function.lua");
test!(if, "../../test-files/if.lua");
test!(op_prec, "../../test-files/op_prec.lua");
test!(nbody, "../../test-files/nbody.lua");
}

View file

@ -6,7 +6,7 @@ mod gc;
pub mod value;
mod vm;
use std::cell::RefCell;
mod api;
pub mod api;
use std::{
collections::HashMap,
@ -15,7 +15,7 @@ use std::{
pub use error::Error;
use gc::{Heap, ObjectPtr};
pub use value::{ByteString, Function, Table2, Userdata, Value, ValueType};
use value::{Table2, Value};
use vm::{Chunk, VM};
use super::parser::{parse, syntax};
@ -48,7 +48,7 @@ impl Lua {
}
}
pub fn load(&mut self, code: &str) -> Rc<ScriptData> {
pub fn load(&mut self, code: &str) -> Script {
let (syntax_tree, reports) = parse(&mut self.cache, code);
assert!(reports.is_empty());
let root = syntax::Root::new(syntax_tree).unwrap();
@ -77,7 +77,7 @@ impl Lua {
self.script_id += 1;
let data = Rc::new(data);
self.scripts.insert(data.id, Rc::downgrade(&data));
data
Script { data, referenced: Rc::clone(&self.referenced) }
}
pub fn execute(&mut self, script: &Script) -> Result<api::Value, Error> {

View file

@ -1,5 +1,7 @@
#![feature(hash_raw_entry)]
#![allow(dead_code)]
pub mod engine;
mod engine;
pub mod parser;
pub use engine::{Lua, Script, api::{Value, Table}};

View file

@ -83,12 +83,12 @@ mod tests {
};
}
test!(function, "test-files/function.lua");
test!(op_prec, "test-files/op_prec.lua");
test!(if, "test-files/if.lua");
test!(declare, "test-files/declare.lua");
test!(literal, "test-files/literal.lua");
test!(comment, "test-files/comment.lua");
test!(mixed, "test-files/mixed.lua");
test!(nbody, "test-files/nbody.lua");
test!(function, "../../test-files/function.lua");
test!(op_prec, "../../test-files/op_prec.lua");
test!(if, "../../test-files/if.lua");
test!(declare, "../../test-files/declare.lua");
test!(literal, "../../test-files/literal.lua");
test!(comment, "../../test-files/comment.lua");
test!(mixed, "../../test-files/mixed.lua");
test!(nbody, "../../test-files/nbody.lua");
}