-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
144 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ pub mod codegen; | |
pub mod driver; | ||
pub mod ir; | ||
pub mod parser; | ||
pub mod repository; | ||
pub mod session; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
BEGIN; | ||
|
||
CREATE TABLE Module ( | ||
name TEXT NOT NULL, | ||
path TEXT NOT NULL, | ||
is_public BOOLEAN NOT NULL, | ||
PRIMARY KEY(name, path) | ||
); | ||
|
||
CREATE TABLE Types ( | ||
name TEXT NOT NULL, | ||
generics TEXT DEFAULT NULL, -- format: json array [of names] | ||
is_struct BOOLEAN NOT NULL DEFAULT FALSE, | ||
is_enum BOOLEAN NOT NULL DEFAULT FALSE, | ||
size INT, | ||
variants TEXT DEFAULT NULL, -- either struct fields or enum variants: json array of names (with generics?) | ||
path TEXT NOT NULL, | ||
PRIMARY KEY(name, path) | ||
); | ||
|
||
CREATE INDEX idx_types_name ON types(name); | ||
|
||
CREATE TABLE Functions ( | ||
name TEXT NOT NULL, | ||
is_extern BOOLEAN NOT NULL, | ||
is_pub BOOLEAN NOT NULL, | ||
path TEXT NOT NULL, | ||
generics TEXT DEFAULT NULL, -- format: json array [of names] | ||
abi TEXT, | ||
body BLOB, | ||
PRIMARY KEY(name, path) | ||
); | ||
|
||
CREATE INDEX idx_functions_name ON functions(name); | ||
|
||
INSERT INTO Types (name, size, path) VALUES ('bool', 1, "std"); | ||
INSERT INTO Types (name, size, path) VALUES ('char', 32, "std"); | ||
INSERT INTO Types (name, size, path) VALUES ('u8', 8, "std"); | ||
INSERT INTO Types (name, size, path) VALUES ('u16', 16, "std"); | ||
INSERT INTO Types (name, size, path) VALUES ('u32', 32, "std"); | ||
INSERT INTO Types (name, size , path) VALUES ('u64', 64, "std"); | ||
INSERT INTO Types (name, size, path) VALUES ('u128', 128, "std"); | ||
INSERT INTO Types (name, size, path) VALUES ('i8', 8, "std"); | ||
INSERT INTO Types (name, size, path) VALUES ('i16', 16, "std"); | ||
INSERT INTO Types (name, size, path) VALUES ('i32', 32, "std"); | ||
INSERT INTO Types (name, size , path) VALUES ('i64', 64, "std"); | ||
INSERT INTO Types (name, size, path) VALUES ('i128', 128, "std"); | ||
|
||
INSERT INTO Types (name, size, path) VALUES ('f32', 32, "std"); | ||
INSERT INTO Types (name, size, path) VALUES ('f64', 64, "std"); | ||
|
||
COMMIT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use rusqlite::{Connection, Result}; | ||
|
||
#[derive(Debug)] | ||
pub struct Repo { | ||
db: Connection, | ||
} | ||
|
||
impl Repo { | ||
pub fn new() -> Result<Self> { | ||
let mut s = Self { | ||
db: Connection::open_in_memory()?, | ||
}; | ||
s.create_tables()?; | ||
Ok(s) | ||
} | ||
|
||
fn create_tables(&self) -> Result<()> { | ||
self.db.execute_batch(include_str!("repo.sql"))?; | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::Repo; | ||
|
||
#[test] | ||
fn create() { | ||
let _repo = Repo::new().unwrap(); | ||
} | ||
} |