Skip to content

Commit

Permalink
SUS can parse templates now
Browse files Browse the repository at this point in the history
  • Loading branch information
VonTum committed Jun 21, 2024
1 parent 62d9a22 commit 5dceb00
Show file tree
Hide file tree
Showing 12 changed files with 246 additions and 98 deletions.
14 changes: 13 additions & 1 deletion src/arena_alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ impl<T, IndexMarker : UUIDMarker> ArenaAllocator<T, IndexMarker> {
pub fn iter_mut<'a>(&'a mut self) -> FlatOptionIteratorMut<'a, T, IndexMarker> {
self.into_iter()
}
pub fn find<F : FnMut(UUID<IndexMarker>, &T) -> bool>(&self, mut predicate : F) -> Option<UUID<IndexMarker>> {
self.iter().find(|(id, v)| predicate(*id, v)).map(|(id, _)| id)
}
}

impl<T, IndexMarker : UUIDMarker> Index<UUID<IndexMarker>> for ArenaAllocator<T, IndexMarker> {
Expand Down Expand Up @@ -322,6 +325,9 @@ impl<T, IndexMarker : UUIDMarker> ArenaVector<T, IndexMarker> {
pub fn iter_mut<'a>(&'a mut self) -> FlatOptionIteratorMut<'a, T, IndexMarker> {
self.into_iter()
}
pub fn find<F : FnMut(UUID<IndexMarker>, &T) -> bool>(&self, mut predicate : F) -> Option<UUID<IndexMarker>> {
self.iter().find(|(id, v)| predicate(*id, v)).map(|(id, _)| id)
}
}

impl<T, IndexMarker : UUIDMarker> Index<UUID<IndexMarker>> for ArenaVector<T, IndexMarker> {
Expand Down Expand Up @@ -474,7 +480,7 @@ pub struct FlatAlloc<T, IndexMarker> {
}

impl<T, IndexMarker : UUIDMarker> FlatAlloc<T, IndexMarker> {
pub fn new() -> Self {
pub const fn new() -> Self {
Self{data : Vec::new(), _ph : PhantomData}
}
pub fn with_capacity(cap : usize) -> Self {
Expand Down Expand Up @@ -507,6 +513,9 @@ impl<T, IndexMarker : UUIDMarker> FlatAlloc<T, IndexMarker> {
pub fn iter_mut<'a>(&'a mut self) -> FlatAllocIterMut<'a, T, IndexMarker> {
self.into_iter()
}
pub fn find<F : FnMut(UUID<IndexMarker>, &T) -> bool>(&self, mut predicate : F) -> Option<UUID<IndexMarker>> {
self.iter().find(|(id, v)| predicate(*id, v)).map(|(id, _)| id)
}
pub fn range_since(&self, id : UUID<IndexMarker>) -> UUIDRange<IndexMarker> {
UUIDRange(id, UUID(self.data.len(), PhantomData))
}
Expand Down Expand Up @@ -539,6 +548,9 @@ impl<T, IndexMarker : UUIDMarker> FlatAlloc<Option<T>, IndexMarker> {
pub fn iter_valids_mut<'a>(&'a mut self) -> FlatOptionIteratorMut<'a, T, IndexMarker> {
FlatOptionIteratorMut{ it: self.data.iter_mut().enumerate(), _ph: PhantomData }
}
pub fn new_nones(size : usize) -> Self {
Self{data : (0..size).into_iter().map(|_| None).collect(), _ph : PhantomData}
}
}

impl<T, IndexMarker : UUIDMarker> Index<UUID<IndexMarker>> for FlatAlloc<T, IndexMarker> {
Expand Down
4 changes: 1 addition & 3 deletions src/dev_aid/lsp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ impl LoadedFileCache {
Self{linker, uris}
}
fn find_uri(&self, uri : &Url) -> Option<FileUUID> {
self.uris.iter()
.find(|(_uuid, uri_found)| **uri_found == *uri)
.map(|(uuid, _uri_found)| uuid)
self.uris.find(|_uuid, uri_found| uri_found == uri)
}
fn update_text(&mut self, uri : Url, new_file_text : String) {
if let Some(found_file_uuid) = self.find_uri(&uri) {
Expand Down
2 changes: 1 addition & 1 deletion src/dev_aid/lsp/tree_walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl<'linker> From<LocationInfo<'linker>> for RefersTo {
LocationInfo::InModule(md_id, md, flat_id, flat_obj) => {
match flat_obj {
InModule::NamedLocal(_) => {
if let Some((port_id, _)) = md.ports.iter().find(|(_, port)| port.declaration_instruction == flat_id) {
if let Some(port_id) = md.ports.find(|_, port| port.declaration_instruction == flat_id) {
result.port = Some((md_id, port_id));
}
result.local = Some((md_id, flat_id));
Expand Down
11 changes: 10 additions & 1 deletion src/flattening/initialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,17 @@ impl<'linker> ModuleInitializationContext<'linker> {

fn finish_gather_decl(&mut self, is_input: bool, cursor: &mut Cursor) {
cursor.field(field!("type"));
let type_span = cursor.span();
let name_span = cursor.field_span(field!("name"), kind!("identifier"));
let name = self.file_text[name_span].to_owned();
self.ports.alloc(Port{name, name_span, is_input, interface : self.current_interface, declaration_instruction : UUID::PLACEHOLDER});
self.ports.alloc(Port{
name,
name_span,
decl_span : Span::new_overarching(type_span, name_span),
is_input,
interface : self.current_interface,
declaration_instruction : UUID::PLACEHOLDER
});
}
}

Expand Down Expand Up @@ -193,6 +201,7 @@ pub fn gather_initial_file_data(mut builder : FileBuilder) {
span,
errors,
resolved_globals,
template_arguments : FlatAlloc::new(), // TODO
after_initial_parse_cp,
after_flatten_cp : None
},
Expand Down
4 changes: 2 additions & 2 deletions src/flattening/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ impl Module {
use std::fmt::Write;
let port = &self.ports[port_id];
let port_direction = if port.is_input {"input"} else {"output"};
let port_decl_instr = self.instructions[port.declaration_instruction].unwrap_wire_declaration();
writeln!(result, "{port_direction} {}", &file_text[port_decl_instr.decl_span]).unwrap()
writeln!(result, "{port_direction} {}", &file_text[port.decl_span]).unwrap()
}
pub fn make_port_info_string(&self, port_id : PortID, file_text : &FileText) -> String {
let mut r = String::new(); self.make_port_info_fmt(port_id, file_text, &mut r); r
Expand Down Expand Up @@ -208,6 +207,7 @@ impl IdentifierType {
pub struct Port {
pub name : String,
pub name_span : Span,
pub decl_span : Span,
pub is_input : bool,
pub interface : DomainID,
/// This is only set after flattening is done. Initially just [UUID::PLACEHOLDER]
Expand Down
Loading

0 comments on commit 5dceb00

Please sign in to comment.