-
Notifications
You must be signed in to change notification settings - Fork 1
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
10 changed files
with
130 additions
and
7 deletions.
There are no files selected for viewing
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,13 @@ | ||
use std::fmt::Debug; | ||
use surotto::simple_key; | ||
|
||
use crate::ast; | ||
|
||
use super::name_lookup::ScopeId; | ||
|
||
simple_key!( | ||
pub struct ArchId; | ||
); | ||
|
||
#[derive(Debug)] | ||
pub struct RoughArch<'ast>(pub ScopeId, pub &'ast ast::Arch<'ast>); |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod architectures; | ||
pub mod import_bucket; | ||
pub mod modules; | ||
pub mod name_lookup; | ||
|
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 |
---|---|---|
@@ -0,0 +1,83 @@ | ||
use bumpalo::Bump; | ||
|
||
use crate::{ | ||
ast, | ||
ir::{ | ||
architectures::{ArchId, RoughArch}, | ||
import_bucket::LookupStrategy, | ||
name_lookup::{PostFlattenNameLookup, Resolved, ScopeId}, | ||
registry::{Registry, TypeId}, | ||
}, | ||
message::Message, | ||
MESSAGES, | ||
}; | ||
|
||
use super::refine_types::types::RefinedType; | ||
|
||
pub struct ArchitectureStage<'ir, 'b, 'ast> { | ||
pub arena: &'ir Bump, | ||
pub name_lookup: &'b PostFlattenNameLookup, | ||
pub registry: &'ast Registry<RefinedType<'ir>, RoughArch<'ast>>, | ||
} | ||
|
||
impl<'ir, 'ast> ArchitectureStage<'ir, '_, 'ast> { | ||
pub fn lower(self) { | ||
for (id, arch) in self.registry.architectures.iter() { | ||
self.lower_arch(id, arch) | ||
} | ||
} | ||
|
||
fn lower_arch(&self, id: ArchId, arch: &RoughArch<'ast>) { | ||
let ty = self.lookup_type(arch.0, &arch.1.ty); | ||
println!("Implementing arch '{}' for {:?}", arch.1.name.0.get(), ty); | ||
} | ||
|
||
// TODO: equal to one in `architectures`, fix duplicate pls | ||
fn lookup_type(&self, scope: ScopeId, ty: &ast::Type) -> Option<TypeId> { | ||
let mut lookup_scope = match ty.path.0 .1 { | ||
ast::PathStart::Root => self.name_lookup.root, | ||
ast::PathStart::Local => scope, | ||
}; | ||
|
||
let mut path = ty.path.0 .0.iter().peekable(); | ||
let mut is_start = true; | ||
while let Some(segment) = path.next() { | ||
let is_terminal = path.peek().is_none(); | ||
let segment = segment.0; | ||
|
||
let lookup = self.name_lookup.lookup( | ||
lookup_scope, | ||
&segment, | ||
if is_start { | ||
LookupStrategy::Indirect | ||
} else { | ||
LookupStrategy::Direct | ||
}, | ||
); | ||
match (is_terminal, lookup) { | ||
(false, Some(Resolved::Type(_))) => { | ||
MESSAGES.report(Message::use_continues_after_type(segment.1)); | ||
return None; | ||
} | ||
(false, Some(Resolved::Module(m))) => { | ||
lookup_scope = self.registry.modules[*m].scope; | ||
} | ||
|
||
(true, Some(Resolved::Type(t))) => return Some(*t), | ||
(true, Some(Resolved::Module(_))) => { | ||
MESSAGES.report(Message::wrong_path_end(segment, "Type", "Module")); | ||
return None; | ||
} | ||
|
||
(_, None) => { | ||
MESSAGES.report(Message::could_not_resolve(segment)); | ||
return None; | ||
} | ||
} | ||
|
||
is_start = false; | ||
} | ||
|
||
return None; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -3,3 +3,5 @@ pub mod rough; | |
pub mod flatten_lookup; | ||
|
||
pub mod refine_types; | ||
|
||
pub mod architectures; |
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
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