Skip to content

Commit

Permalink
shin-asm: start implementing hir lowering
Browse files Browse the repository at this point in the history
  • Loading branch information
DCNick3 committed Aug 31, 2023
1 parent a5d5f5f commit dc8cfb0
Show file tree
Hide file tree
Showing 22 changed files with 894 additions and 276 deletions.
111 changes: 96 additions & 15 deletions Cargo.lock

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

5 changes: 3 additions & 2 deletions shin-asm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ assert_matches = "1.5.0"

rustc-hash = "1.1.0"
smol_str = "0.2.0"
internment = { version = "0.7.0", features = ["arena"] }
la-arena = "0.3.1"

unicode-xid = "0.2.4"
unic-emoji-char = "0.9.0"
Expand All @@ -30,11 +30,12 @@ drop_bomb = "0.1.5"
rowan = "0.15.11"
text-size = "1.1.0"
salsa = { git = "https://github.com/salsa-rs/salsa.git", rev = "d4a94fbf07bb837f3d9d0a4caa5db4d5db29243f", package = "salsa-2022" }
miette = "5.9.0"
miette = "5.10.0"

[dev-dependencies]
test-generator = { git = "https://github.com/JamesGuthrie/test-generator.git", rev = "82e799979980962aec1aa324ec6e0e4cad781f41" }
expect-test = "1.4.1"
miette = { version = "5.10.0", features = ["fancy"] }

[build-dependencies]
build-deps = "0.1.4"
78 changes: 78 additions & 0 deletions shin-asm/src/db/diagnostics.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,72 @@
use crate::db::file::File;
use crate::db::in_file::InFile;
use crate::db::Db;
use std::fmt;
use std::fmt::{Debug, Display};

use miette::NamedSource;
use std::sync::Arc;

#[salsa::accumulator]
pub struct Diagnostics(InFile<Arc<miette::Report>>);

struct DiagnosticWithSourceCode {
error: Arc<miette::Report>,
source_code: NamedSource,
}

impl Debug for DiagnosticWithSourceCode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Debug::fmt(&self.error, f)
}
}

impl Display for DiagnosticWithSourceCode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Display::fmt(&self.error, f)
}
}

impl std::error::Error for DiagnosticWithSourceCode {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
self.error.source()
}
}

impl miette::Diagnostic for DiagnosticWithSourceCode {
fn code<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
self.error.code()
}

fn severity(&self) -> Option<miette::Severity> {
self.error.severity()
}

fn help<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
self.error.help()
}

fn url<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
self.error.url()
}

fn source_code(&self) -> Option<&dyn miette::SourceCode> {
Some(&self.source_code)
}

fn labels<'a>(&'a self) -> Option<Box<dyn Iterator<Item = miette::LabeledSpan> + 'a>> {
self.error.labels()
}

fn related<'a>(&'a self) -> Option<Box<dyn Iterator<Item = &'a dyn miette::Diagnostic> + 'a>> {
self.error.related()
}

fn diagnostic_source(&self) -> Option<&dyn miette::Diagnostic> {
self.error.diagnostic_source()
}
}

impl Diagnostics {
pub fn emit(
db: &dyn Db,
Expand All @@ -18,4 +78,22 @@ impl Diagnostics {
InFile::new(file, Arc::new(miette::Report::new(diagnostic))),
)
}

pub fn with_source(
db: &dyn Db,
diagnostics: Vec<InFile<Arc<miette::Report>>>,
) -> Vec<miette::Report> {
diagnostics
.into_iter()
.map(|diag| {
let path = diag.file.path(db);
let source_code = diag.file.contents(db).clone();

miette::Report::new(DiagnosticWithSourceCode {
error: diag.value.clone(),
source_code: NamedSource::new(path, source_code),
})
})
.collect()
}
}
2 changes: 0 additions & 2 deletions shin-asm/src/db/in_file.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use crate::db::file::File;
use crate::db::Db;
use crate::syntax;
use either::Either;

/// `InFile<T>` stores a value of `T` inside a particular file/syntax tree.
Expand Down
10 changes: 5 additions & 5 deletions shin-asm/src/db/items.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::db::in_file::InFile;
use crate::db::symbols::DefRefId;
use crate::syntax::ast;
use crate::syntax::ptr::AstPtr;
use smol_str::SmolStr;
// use crate::db::in_file::InFile;
// use crate::db::symbols::DefRefId;
// use crate::syntax::ast;
// use crate::syntax::ptr::AstPtr;
// use smol_str::SmolStr;

// // #[salsa::tracked]
// pub enum Item {
Expand Down
Loading

0 comments on commit dc8cfb0

Please sign in to comment.