diff --git a/.gitignore b/.gitignore index d01bd1a..ccc6284 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,6 @@ Cargo.lock # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. -#.idea/ \ No newline at end of file +#.idea/ + +.vscode \ No newline at end of file diff --git a/rasynth/Cargo.toml b/rasynth/Cargo.toml index f9a6214..f3c8c5e 100644 --- a/rasynth/Cargo.toml +++ b/rasynth/Cargo.toml @@ -1,12 +1,14 @@ [package] name = "rasynth" version = "0.1.0" +authors = ["wheatfox "] edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[build-dependencies] # <-- We added this and everything after! +[build-dependencies] lalrpop = "0.20.2" [dependencies] +env_logger = "0.11.5" +graph = "0.3.1" lalrpop-util = { version = "0.20.2", features = ["lexer", "unicode"] } +log = "0.4.22" diff --git a/rasynth/src/ast.rs b/rasynth/src/ast.rs index a70276e..27045b5 100644 --- a/rasynth/src/ast.rs +++ b/rasynth/src/ast.rs @@ -12,18 +12,24 @@ pub enum Numeric { } #[derive(Debug, Clone)] -pub enum LetDefine { +pub enum LetDef { Let(String, Expr), } #[derive(Debug, Clone)] -pub enum BoxDefine { - Box(String, Vec, Vec), +pub enum BoxWire { + Boxw(String, Vec), } #[derive(Debug, Clone)] -pub enum Statement { - LetDefine(LetDefine), +pub enum BoxDef { + Box(String, Vec, Vec), +} + +#[derive(Debug, Clone)] +pub enum Stmt { + LetDef(LetDef), + BoxWire(BoxWire), } #[derive(Debug, Clone)] @@ -48,4 +54,9 @@ impl Type { _ => None, } } -} \ No newline at end of file +} + +#[derive(Debug, Clone)] +pub enum TopDef { + Boxes(Vec), +} diff --git a/rasynth/src/graph.rs b/rasynth/src/graph.rs new file mode 100644 index 0000000..e99c240 --- /dev/null +++ b/rasynth/src/graph.rs @@ -0,0 +1,26 @@ +use crate::ast; +use log::*; +use std::sync::Mutex; + +pub static FLOW_GRAPH: Mutex> = Mutex::new(None); + +#[derive(Debug)] +pub struct FlowGraph { + pub timestamp: u64, + pub ast: Mutex>, +} + +impl FlowGraph { + pub fn new(ast: Option) -> Self { + FlowGraph { + timestamp: std::time::SystemTime::now() + .duration_since(std::time::UNIX_EPOCH) + .unwrap() + .as_secs(), + ast: Mutex::new(ast), + } + } + pub fn generate(&self) { + info!("Generating Graph..."); + } +} diff --git a/rasynth/src/main.rs b/rasynth/src/main.rs index 85649ac..cf9513c 100644 --- a/rasynth/src/main.rs +++ b/rasynth/src/main.rs @@ -1,11 +1,42 @@ +use env_logger::Env; use lalrpop_util::lalrpop_mod; +use log::*; use std::fs; + pub mod ast; +pub mod graph; lalrpop_mod!(pub raslisp); // synthesized by LALRPOP fn main() { - let test1 = fs::read_to_string("../test/test.raslisp").unwrap(); - let r = raslisp::BoxDefineParser::new().parse(&test1).unwrap(); - println!("{:?}", r); + let env = Env::default() + .filter_or("MY_LOG_LEVEL", "trace") + .write_style_or("MY_LOG_STYLE", "always"); + env_logger::init_from_env(env); + + info!("RASLISP Interpreter, version {}", env!("CARGO_PKG_VERSION")); + info!("Author: {}", env!("CARGO_PKG_AUTHORS")); + + let input_file = "../test/osc1.raslisp"; + info!("Input Top File Path: {}", input_file); + let test1 = fs::read_to_string(input_file).expect("Unable to read file"); + + let r = raslisp::TopParser::new().parse(&test1).unwrap(); + info!("AST Parsed Successfully!"); + + graph::FLOW_GRAPH + .lock() + .unwrap() + .replace(graph::FlowGraph::new(Some(r))); + + graph::FLOW_GRAPH + .lock() + .unwrap() + .as_ref() + .unwrap() + .generate(); + + info!("Graph: {:?}", graph::FLOW_GRAPH.lock().unwrap()); + + info!("Goodbye!"); } diff --git a/rasynth/src/raslisp.lalrpop b/rasynth/src/raslisp.lalrpop index 36cf814..b3a34e4 100644 --- a/rasynth/src/raslisp.lalrpop +++ b/rasynth/src/raslisp.lalrpop @@ -3,21 +3,46 @@ use crate::ast::*; grammar; -pub BoxDefine: BoxDefine = { - "(" "box" "(" ")" ")" => BoxDefine::Box(name, ports, body), +match { + r"\s*" => { }, + r";[^\n\r]*[\n\r]*" => { }, +} else { + _ +} + +pub Top: TopDef = { + => TopDef::Boxes(bs), +}; + +pub Boxes: Vec = { + => vec![b], + => { + let mut v = bs; + v.insert(0, b); + v + }, +}; + +pub BoxDef: BoxDef = { + "(" "box" "(" ")" ")" => BoxDef::Box(name, ports, body), }; -pub Exprs: Vec = { - => vec![s], - => { +pub Stmts: Vec = { + => vec![s], + => { let mut v = ss; v.insert(0, s); v }, }; -pub Statement: Statement = { - => Statement::LetDefine(ld), +pub Exprs: Vec = { + => vec![s], + => { + let mut v = ss; + v.insert(0, s); + v + }, }; pub PortVec: Vec = { @@ -34,8 +59,15 @@ pub Port: Port = { "out" ":" => Port::Out(name, ty), }; -pub LetDefine: LetDefine = { - "(" "let" ")" => LetDefine::Let(name, expr), +pub Stmt: Stmt = { + => Stmt::LetDef(ld), + => Stmt::BoxWire(bw), +}; +pub BoxWire: BoxWire = { + "[" "]" => BoxWire::Boxw(name, exprs), +}; +pub LetDef: LetDef = { + "(" "let" ")" => LetDef::Let(name, expr), }; pub Expr: Expr = { => Expr::NodeIdent(ni), diff --git a/test/osc1.raslisp b/test/osc1.raslisp index 3f42dfb..4e10b61 100644 --- a/test/osc1.raslisp +++ b/test/osc1.raslisp @@ -1,19 +1,20 @@ -[box osc1 ( +(box osc1 ( in freq: float in amp: float in wav_sel: i32 out raw_wav: float ) - (let sin1 (sinwave 128)) // sin1: waveform - (let sample (idx sin1 65)) // get sin1[65]'s sample value - (let raw_wav amp * sample) -] + (let sin1 (sinwave 128)) ; sin1: waveform + (let sample (idx sin1 65)) ; get sin1[65]'s sample value + (let raw_wav (* amp sample)) +) -[box main ( +(box main ( out stereo_L: float out stereo_R: float ) - [osc1 osc1_out_raw] - (let stereo_L = osc1_out_raw) - (let stereo_R = osc1_out_raw) -] \ No newline at end of file + (let amp (* 50 2)) + [osc1 440 amp 0 osc1_out_raw] + (let stereo_L osc1_out_raw) + (let stereo_R osc1_out_raw) +) \ No newline at end of file diff --git a/test/test.raslisp b/test/test.raslisp index 4467c92..cece1ec 100644 --- a/test/test.raslisp +++ b/test/test.raslisp @@ -2,5 +2,14 @@ in in1: float out out1: float ) - (let out1 (+ in1 1)) + (let out1 (+ in1 1)) ; comment test +) + +(box main ( + out L: float + out R: float +) + [test1 1 out1] + (let L out1) + (let R out1) ) \ No newline at end of file