diff --git a/src/codegen_fallback.rs b/src/codegen_fallback.rs index ee67f65..a38a60c 100644 --- a/src/codegen_fallback.rs +++ b/src/codegen_fallback.rs @@ -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"); diff --git a/src/linker.rs b/src/linker.rs index 22bc4ab..fd5acbc 100644 --- a/src/linker.rs +++ b/src/linker.rs @@ -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!() @@ -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 = self.links.globals.iter().filter_map(|(id,v)| { if let Named::Module(_) = v { Some(id) diff --git a/src/typing.rs b/src/typing.rs index fb7bf57..f54a40b 100644 --- a/src/typing.rs +++ b/src/typing.rs @@ -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)] @@ -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("!") { diff --git a/src/value.rs b/src/value.rs index 8f007a0..59b1c84 100644 --- a/src/value.rs +++ b/src/value.rs @@ -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 { @@ -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 {