Skip to content

Commit

Permalink
split linker::get_builtin_uuid
Browse files Browse the repository at this point in the history
  • Loading branch information
VonTum committed Jan 10, 2024
1 parent ada82a6 commit f4ebe5a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/codegen_fallback.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::{iter::zip, ops::Deref};

use crate::{ast::{Module, IdentifierType}, instantiation::{InstantiatedModule, RealWireDataSource, StateInitialValue, ConnectToPathElem}, linker::{NamedUUID, get_builtin_uuid}, typing::ConcreteType, tokenizer::get_token_type_name, flattening::Instantiation, value::Value};
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};

fn get_type_name_size(id : NamedUUID) -> u64 {
if id == get_builtin_uuid("int") {
if id == get_builtin_type("int") {
32 // TODO concrete int sizes
} else if id == get_builtin_uuid("bool") {
} else if id == get_builtin_type("bool") {
1 // TODO concrete int sizes
} else {
println!("TODO Named Structs Size");
Expand Down
13 changes: 9 additions & 4 deletions src/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,16 @@ const BUILTIN_CONSTANTS : [(&'static str, Value); 2] = [
];

// Goes together with Links::new
pub const fn get_builtin_uuid(name : &'static str) -> NamedUUID {
pub const fn get_builtin_type(name : &'static str) -> NamedUUID {
if let Some(is_type) = const_str_position(name, &BUILTIN_TYPES) {
NamedUUID::from_hidden_value(is_type)
} else if let Some(is_constant) = const_str_position_in_tuples(name, &BUILTIN_CONSTANTS) {
} else {
unreachable!()
}
}

pub const fn get_builtin_constant(name : &'static str) -> NamedUUID {
if let Some(is_constant) = const_str_position_in_tuples(name, &BUILTIN_CONSTANTS) {
NamedUUID::from_hidden_value(is_constant + BUILTIN_TYPES.len())
} else {
unreachable!()
Expand Down Expand Up @@ -365,8 +371,7 @@ impl Linker {
}

pub fn recompile_all(&mut self) {
// First create initial flattening for everything, to produce the necessary interfaces

// Flatten all modules
let module_ids : Vec<NamedUUID> = self.links.globals.iter().filter_map(|(id,v)| {
if let Named::Module(_) = v {
Some(id)
Expand Down
10 changes: 5 additions & 5 deletions src/typing.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::ops::Deref;

use crate::{ast::{Operator, Span}, linker::{get_builtin_uuid, NamedUUID, Linker, Linkable}, tokenizer::kw, flattening::FlatID, errors::ErrorCollector, value::Value};
use crate::{ast::{Operator, Span}, linker::{get_builtin_type, NamedUUID, Linker, Linkable}, tokenizer::kw, flattening::FlatID, errors::ErrorCollector, value::Value};

// Types contain everything that cannot be expressed at runtime
#[derive(Debug, Clone)]
Expand Down Expand Up @@ -65,10 +65,10 @@ impl Type {
}


pub const BOOL_TYPE : Type = Type::Named{id : get_builtin_uuid("bool"), span : None};
pub const INT_TYPE : Type = Type::Named{id : get_builtin_uuid("int"), span : None};
pub const BOOL_CONCRETE_TYPE : ConcreteType = ConcreteType::Named(get_builtin_uuid("bool"));
pub const INT_CONCRETE_TYPE : ConcreteType = ConcreteType::Named(get_builtin_uuid("int"));
pub const BOOL_TYPE : Type = Type::Named{id : get_builtin_type("bool"), span : None};
pub const INT_TYPE : Type = Type::Named{id : get_builtin_type("int"), span : None};
pub const BOOL_CONCRETE_TYPE : ConcreteType = ConcreteType::Named(get_builtin_type("bool"));
pub const INT_CONCRETE_TYPE : ConcreteType = ConcreteType::Named(get_builtin_type("int"));

pub fn typecheck_unary_operator(op : Operator, input_typ : &Type, span : Span, linker : &Linker, errors : &ErrorCollector) -> Type {
if op.op_typ == kw("!") {
Expand Down
6 changes: 3 additions & 3 deletions src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::ops::Deref;

use num::BigInt;

use crate::{typing::{Type, ConcreteType, BOOL_TYPE, INT_TYPE}, linker::get_builtin_uuid, ast::Operator, tokenizer::kw};
use crate::{typing::{Type, ConcreteType, BOOL_TYPE, INT_TYPE, INT_CONCRETE_TYPE, BOOL_CONCRETE_TYPE}, ast::Operator, tokenizer::kw};

#[derive(Debug,Clone,PartialEq,Eq)]
pub enum Value {
Expand Down Expand Up @@ -33,8 +33,8 @@ impl Value {
}
pub fn is_of_type(&self, typ : &ConcreteType) -> bool {
match (self, typ) {
(Self::Integer(_), ConcreteType::Named(name)) if *name == get_builtin_uuid("int") => true,
(Self::Bool(_), ConcreteType::Named(name)) if *name == get_builtin_uuid("bool") => true,
(Self::Integer(_), typ) if *typ == INT_CONCRETE_TYPE => true,
(Self::Bool(_), typ) if *typ == BOOL_CONCRETE_TYPE => true,
(Self::Array(arr_slice), ConcreteType::Array(arr_typ_box)) => {
let (arr_content_typ, arr_size_typ) = arr_typ_box.deref();
if arr_slice.len() != *arr_size_typ as usize {
Expand Down

0 comments on commit f4ebe5a

Please sign in to comment.