Skip to content

Commit

Permalink
compiler db
Browse files Browse the repository at this point in the history
  • Loading branch information
edg-l committed Jan 27, 2025
1 parent 3f514ef commit adca994
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 1 deletion.
58 changes: 57 additions & 1 deletion Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ serde = { version = "1.0.217", features = ["derive"] }
toml = "0.8.19"
test-case = "3.3.1"

rusqlite = { version = "0.33.0", features = ["bundled"] }

[build-dependencies]
lalrpop = "0.22.0"

Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ pub mod codegen;
pub mod driver;
pub mod ir;
pub mod parser;
pub mod repository;
pub mod session;
52 changes: 52 additions & 0 deletions src/repo.sql
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;
32 changes: 32 additions & 0 deletions src/repository.rs
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();
}
}

0 comments on commit adca994

Please sign in to comment.