Skip to content

Commit

Permalink
Split Linker IDs in distinct categories
Browse files Browse the repository at this point in the history
  • Loading branch information
VonTum committed Jan 18, 2024
1 parent 1cf53b8 commit f932b4a
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 192 deletions.
4 changes: 2 additions & 2 deletions src/codegen_fallback.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::{iter::zip, ops::Deref};

use crate::{ast::{Module, IdentifierType}, instantiation::{InstantiatedModule, RealWireDataSource, StateInitialValue, ConnectToPathElem}, linker::{NamedUUID, get_builtin_type}, typing::ConcreteType, tokenizer::get_token_type_name, flattening::Instantiation, value::Value};
use crate::{ast::{Module, IdentifierType}, instantiation::{InstantiatedModule, RealWireDataSource, StateInitialValue, ConnectToPathElem}, linker::{get_builtin_type, TypeUUID}, typing::ConcreteType, tokenizer::get_token_type_name, flattening::Instantiation, value::Value};

fn get_type_name_size(id : NamedUUID) -> u64 {
fn get_type_name_size(id : TypeUUID) -> u64 {
if id == get_builtin_type("int") {
32 // TODO concrete int sizes
} else if id == get_builtin_type("bool") {
Expand Down
13 changes: 6 additions & 7 deletions src/dev_aid/syntax_highlighting.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

use std::{ops::Range, path::PathBuf};

use crate::{ast::*, tokenizer::*, parser::*, linker::{FileData, NamedUUID, Named, Linkable, Linker, FileUUIDMarker, FileUUID}, arena_alloc::ArenaVector, flattening::{Instantiation, WireSource}};
use crate::{ast::*, tokenizer::*, parser::*, linker::{FileData, Linker, FileUUIDMarker, FileUUID, NameElem}, arena_alloc::ArenaVector, flattening::{Instantiation, WireSource}};

use ariadne::FileCache;
use console::Style;
Expand Down Expand Up @@ -108,11 +108,11 @@ fn set_span_name_color(span : Span, typ : IDEIdentifierType, result : &mut [IDET
result[tok_idx].typ = IDETokenType::Identifier(typ);
}
}
fn walk_name_color(all_objects : &[NamedUUID], linker : &Linker, result : &mut [IDEToken]) {
fn walk_name_color(all_objects : &[NameElem], linker : &Linker, result : &mut [IDEToken]) {
for obj_uuid in all_objects {
let object = &linker.globals[*obj_uuid];
let ide_typ = match object {
Named::Module(module) => {
let (ide_typ, link_info) = match obj_uuid {
NameElem::Module(id) => {
let module = &linker.modules[*id];
for (_id, item) in &module.flattened.instantiations {
match item {
Instantiation::Wire(w) => {
Expand Down Expand Up @@ -149,12 +149,11 @@ fn walk_name_color(all_objects : &[NamedUUID], linker : &Linker, result : &mut [
Instantiation::IfStatement(_) | Instantiation::ForStatement(_) => {}
}
}
IDEIdentifierType::Interface
(IDEIdentifierType::Interface, &module.link_info)
}
_other => {todo!("Name Color for non-modules not implemented")}
};

let link_info = object.get_link_info().unwrap();
set_span_name_color(link_info.name_span, ide_typ, result);
}
}
Expand Down
28 changes: 13 additions & 15 deletions src/flattening.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{ops::{Deref, Range}, iter::zip, cell::RefCell};

use crate::{
ast::{Span, Module, Expression, SpanExpression, LocalOrGlobal, Operator, AssignableExpression, SpanAssignableExpression, Statement, CodeBlock, IdentifierType, TypeExpression, DeclIDMarker, DeclID, SpanTypeExpression},
linker::{Linker, NamedUUID, FileUUID, GlobalResolver, ResolvedGlobals, Named, NamedConstant},
linker::{Linker, FileUUID, GlobalResolver, ResolvedGlobals, NamedConstant, ConstantUUID, ModuleUUID, NameElem},
errors::{ErrorCollector, error_info}, arena_alloc::{UUID, UUIDMarker, FlatAlloc, UUIDRange}, typing::{Type, typecheck_unary_operator, get_binary_operator_types, typecheck, typecheck_is_array_indexer, BOOL_TYPE, INT_TYPE}, value::Value
};

Expand Down Expand Up @@ -48,7 +48,7 @@ pub enum WireSource {
BinaryOp{op : Operator, left : FlatID, right : FlatID},
ArrayAccess{arr : FlatID, arr_idx : FlatID},
Constant(Value),
NamedConstant(NamedUUID),
NamedConstant(ConstantUUID),
}

impl WireSource {
Expand Down Expand Up @@ -93,7 +93,7 @@ impl WireDeclaration {

#[derive(Debug)]
pub struct SubModuleInstance {
pub module_uuid : NamedUUID,
pub module_uuid : ModuleUUID,
pub name : Box<str>,
pub typ_span : Span,
pub is_remote_declaration : bool,
Expand Down Expand Up @@ -194,7 +194,7 @@ impl<'inst, 'l, 'm, 'resolved> FlatteningContext<'inst, 'l, 'm, 'resolved> {
fn map_to_type(&mut self, type_expr : &SpanTypeExpression) -> Type {
match &type_expr.0 {
TypeExpression::Named => {
if let Some(typ_id) = &self.linker.try_get_type(type_expr.1, &self.errors) {
if let Some(typ_id) = &self.linker.resolve_type(type_expr.1, &self.errors) {
Type::Named{id : *typ_id, span : Some(type_expr.1)}
} else {
Type::Error
Expand All @@ -220,10 +220,9 @@ impl<'inst, 'l, 'm, 'resolved> FlatteningContext<'inst, 'l, 'm, 'resolved> {

if ONLY_ALLOW_TYPES {
if let TypeExpression::Named = &decl.typ.0 {
if let Some(possible_module_ref) = self.linker.resolve_global(decl.typ.1, &self.errors) {
if let Some(md) = &self.linker.is_module(possible_module_ref) {
return self.alloc_module_interface(decl.name.clone(), md,possible_module_ref, decl.typ.1)
}
if let Some(NameElem::Module(module_id)) = self.linker.try_resolve_global(decl.typ.1) {
let md = &self.linker.get_module(module_id);
return self.alloc_module_interface(decl.name.clone(), md, module_id, decl.typ.1)
}
}
}
Expand Down Expand Up @@ -252,7 +251,7 @@ impl<'inst, 'l, 'm, 'resolved> FlatteningContext<'inst, 'l, 'm, 'resolved> {
self.flatten_declaration::<false>(*decl_id, read_only)
}).collect()
}
fn alloc_module_interface(&mut self, name : Box<str>, module : &Module, module_uuid : NamedUUID, typ_span : Span) -> FlatID {
fn alloc_module_interface(&mut self, name : Box<str>, module : &Module, module_uuid : ModuleUUID, typ_span : Span) -> FlatID {
let mut nested_context = FlatteningContext {
decl_to_flat_map: module.declarations.iter().map(|_| None).collect(),
instantiations: self.instantiations,
Expand Down Expand Up @@ -281,10 +280,9 @@ impl<'inst, 'l, 'm, 'resolved> FlatteningContext<'inst, 'l, 'm, 'resolved> {
self.decl_to_flat_map[*l].unwrap()
}
Expression::Named(LocalOrGlobal::Global(ref_span)) => {
let module_ref = self.linker.resolve_global(*ref_span, &self.errors)?;

let dependency = self.linker.try_get_module(*ref_span, &self.errors)?;
self.alloc_module_interface(dependency.link_info.name.clone(), dependency, module_ref, *name_expr_span)
let module_id = self.linker.resolve_module(*ref_span, &self.errors)?;
let md = self.linker.get_module(module_id);
self.alloc_module_interface(md.link_info.name.clone(), md, module_id, *name_expr_span)
}
_other => {
self.errors.error_basic(*name_expr_span, "Function call name cannot be an expression");
Expand Down Expand Up @@ -336,7 +334,7 @@ impl<'inst, 'l, 'm, 'resolved> FlatteningContext<'inst, 'l, 'm, 'resolved> {
(decl.identifier_type == IdentifierType::Generative, WireSource::WireRead(from_wire))
}
Expression::Named(LocalOrGlobal::Global(ref_span)) => {
let cst = self.linker.try_get_constant(*ref_span, &self.errors)?;
let cst = self.linker.resolve_constant(*ref_span, &self.errors)?;
(true, WireSource::NamedConstant(cst))
}
Expression::Constant(cst) => {
Expand Down Expand Up @@ -627,7 +625,7 @@ impl FlattenedModule {
value.get_type_of_constant()
}
&WireSource::NamedConstant(id) => {
let Named::Constant(NamedConstant::Builtin{name:_, typ, val:_}) = &linker.globals[id] else {unreachable!()};
let NamedConstant::Builtin{name:_, typ, val:_} = &linker.constants[id];
typ.clone()
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/instantiation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{rc::Rc, ops::Deref, cell::RefCell};

use num::BigInt;

use crate::{arena_alloc::{UUID, UUIDMarker, FlatAlloc, UUIDRange}, ast::{Operator, IdentifierType, Span}, typing::{ConcreteType, Type, BOOL_CONCRETE_TYPE, INT_CONCRETE_TYPE}, flattening::{FlatID, Instantiation, FlatIDMarker, ConnectionWritePathElement, WireSource, WireInstance, Connection, ConnectionWritePathElementComputed, FlattenedModule, FlatIDRange}, errors::ErrorCollector, linker::{Linker, NamedConstant, Named}, value::{Value, compute_unary_op, compute_binary_op}, tokenizer::kw};
use crate::{arena_alloc::{UUID, UUIDMarker, FlatAlloc, UUIDRange}, ast::{Operator, IdentifierType, Span}, typing::{ConcreteType, Type, BOOL_CONCRETE_TYPE, INT_CONCRETE_TYPE}, flattening::{FlatID, Instantiation, FlatIDMarker, ConnectionWritePathElement, WireSource, WireInstance, Connection, ConnectionWritePathElementComputed, FlattenedModule, FlatIDRange}, errors::ErrorCollector, linker::{Linker, NamedConstant}, value::{Value, compute_unary_op, compute_binary_op}, tokenizer::kw};

pub mod latency;

Expand Down Expand Up @@ -304,7 +304,7 @@ impl<'fl, 'l> InstantiationContext<'fl, 'l> {
}
WireSource::Constant(value) => value.clone(),
WireSource::NamedConstant(id) => {
let Named::Constant(NamedConstant::Builtin{name:_, typ:_, val}) = &self.linker.globals[*id] else {unreachable!()};
let NamedConstant::Builtin{name:_, typ:_, val} = &self.linker.constants[*id];
val.clone()
}
})
Expand Down
Loading

0 comments on commit f932b4a

Please sign in to comment.