From 92292c756cf7987acc34984eec15960272e6cae7 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Fri, 8 Jul 2022 22:33:32 +0200 Subject: [PATCH] crates --- Cargo.lock | 11 +++++++++++ Cargo.toml | 2 +- analysis/Cargo.toml | 9 +++++++++ analysis/src/lib.rs | 6 ++++++ codegen_x86/Cargo.toml | 8 ++++++++ codegen_x86/src/lib.rs | 6 ++++++ parser/src/lib.rs | 2 ++ parser/src/parser.rs | 18 +++++++++++++++++- 8 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 analysis/Cargo.toml create mode 100644 analysis/src/lib.rs create mode 100644 codegen_x86/Cargo.toml create mode 100644 codegen_x86/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index b5ee882..342c469 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,6 +17,13 @@ dependencies = [ "memchr", ] +[[package]] +name = "analysis" +version = "0.1.0" +dependencies = [ + "parser", +] + [[package]] name = "autocfg" version = "1.1.0" @@ -56,6 +63,10 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "codegen_x86" +version = "0.1.0" + [[package]] name = "console" version = "0.15.0" diff --git a/Cargo.toml b/Cargo.toml index 2587cc1..c3389ea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -members = [".", "./parser"] +members = [".", "./parser", "./analysis", "./codegen_x86"] [package] name = "uwucc" diff --git a/analysis/Cargo.toml b/analysis/Cargo.toml new file mode 100644 index 0000000..996574f --- /dev/null +++ b/analysis/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "analysis" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +parser = { path = "../parser" } \ No newline at end of file diff --git a/analysis/src/lib.rs b/analysis/src/lib.rs new file mode 100644 index 0000000..756c862 --- /dev/null +++ b/analysis/src/lib.rs @@ -0,0 +1,6 @@ +#![allow(dead_code)] // TODO: no +#![warn(rust_2018_idioms)] + +struct Ctx<'src, P> { + parser: P, +} \ No newline at end of file diff --git a/codegen_x86/Cargo.toml b/codegen_x86/Cargo.toml new file mode 100644 index 0000000..08431c5 --- /dev/null +++ b/codegen_x86/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "codegen_x86" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/codegen_x86/src/lib.rs b/codegen_x86/src/lib.rs new file mode 100644 index 0000000..43e55db --- /dev/null +++ b/codegen_x86/src/lib.rs @@ -0,0 +1,6 @@ +#![allow(dead_code)] // TODO: no +#![warn(rust_2018_idioms)] + +pub fn generate() { + println!("ud2"); +} \ No newline at end of file diff --git a/parser/src/lib.rs b/parser/src/lib.rs index 98d25ee..82be820 100644 --- a/parser/src/lib.rs +++ b/parser/src/lib.rs @@ -12,6 +12,8 @@ mod pre; mod pretty; mod token; +pub use parser::Parser; + pub type Spanned = (T, Span); #[derive(PartialEq, Eq, Clone, Copy, Default)] diff --git a/parser/src/parser.rs b/parser/src/parser.rs index f7df693..fe9fa1d 100644 --- a/parser/src/parser.rs +++ b/parser/src/parser.rs @@ -45,7 +45,7 @@ impl DebugPls for ParserError { type Result = std::result::Result; -struct Parser<'src, I> +pub struct Parser<'src, I> where I: Iterator, Span)>, { @@ -549,6 +549,22 @@ where } } +impl<'src, I> Iterator for Parser<'src, I> +where + I: Iterator, Span)>, + { + type Item = Result>; + + fn next(&mut self) -> Option { + if self.peek_t().is_ok() { + let decl = self.external_declaration(); + Some(decl) + } else { + None + } + } +} + pub fn parse_declarations<'src>( src: impl Iterator, Span)>, ) -> Result>> {