-
-
Notifications
You must be signed in to change notification settings - Fork 1
Major refactoring of Type / DIF Type structs #512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
benStre
wants to merge
10
commits into
feat/variant-access
Choose a base branch
from
feat/refactor-type-architecture
base: feat/variant-access
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8974fc6
:boom: refactoring (WIP)
benStre a7115bf
refactoring on types (WIP)
jonasstrehle 0fa8006
refactoring on types (WIP)
jonasstrehle 929c5fd
refactoring on types (WIP)
jonasstrehle 24d3e3b
refactoring on types (WIP)
jonasstrehle b3637c7
refactoring on types (WIP)
jonasstrehle 46085f4
refactoring on types (WIP)
jonasstrehle 27256d1
refactoring on types (WIP) [17 test failing]
jonasstrehle ea08dbc
fix type matching tests
benStre 0f2bc13
remove debug log, all tests passed
benStre File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 +1,59 @@ | ||
| use crate::values::core_values::r#type::Type; | ||
| /// Compiles a given type container to a DXB body | ||
| pub fn compile_type_container(ty: &Type) -> Vec<u8> { | ||
| let mut buffer = Vec::with_capacity(256); | ||
| append_type_container(&mut buffer, ty); | ||
|
|
||
| buffer | ||
| } | ||
|
|
||
| /*** | ||
|
|
||
| $123123123 | ||
| "txt" | ||
| $x = () | ||
|
|
||
| */ | ||
|
|
||
| pub fn append_type_container( | ||
| buffer: &mut Vec<u8>, | ||
| ty: &Type, | ||
| ) { | ||
| match ty { | ||
| // TypeContainer::Type(ty) => append_type(buffer, ty), | ||
| // // nominal type (e.g. integer, User) | ||
| // TypeContainer::TypeReference(reference) => { | ||
| // // add CREATE_REF/CREATE_REF_MUT instruction | ||
| // if reference.mutability() == ReferenceMutability::Mutable { | ||
| // append_instruction_code( | ||
| // buffer, | ||
| // InstructionCode::CREATE_REF_MUT, | ||
| // ); | ||
| // } else { | ||
| // append_instruction_code(buffer, InstructionCode::CREATE_REF); | ||
| // } | ||
| // // insert pointer id + value or only id | ||
| // // add pointer to memory if not there yet | ||
| // append_value(buffer, &reference.collapse_to_value().borrow()) | ||
| // } | ||
| _ => unreachable!() | ||
| } | ||
| } | ||
|
|
||
| pub fn append_type(buffer: &mut Vec<u8>, ty: &Type) { | ||
|
|
||
| // INSTRUCTION | ||
| // &mut (integer + js.undefed) | ||
| // function (x: null) { | ||
| // | ||
| // } | ||
| // | ||
| // match &ty.type_definition { | ||
| // TypeDefinition::MarkedType(ty) => { | ||
| // // ... | ||
| // } | ||
| // _ => todo!() | ||
| // } | ||
| } | ||
|
|
||
| // pub fn get_type_definition_ | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,6 +1,6 @@ | ||
| use crate::dif::r#type::{DIFTypeContainer, DIFTypeDefinition}; | ||
| use crate::dif::r#type::{DIFType, DIFTypeContainer, DIFTypeDefinition}; | ||
| use crate::dif::value::{DIFReferenceNotFoundError, DIFValueContainer}; | ||
| use crate::libs::core::{CoreLibPointerId, get_core_lib_type}; | ||
| use crate::libs::core::{CoreLibPointerId, get_core_lib_type, get_core_lib_type_definition}; | ||
| use crate::runtime::memory::Memory; | ||
| use crate::std_random::RandomState; | ||
| use crate::stdlib::boxed::Box; | ||
|
|
@@ -20,12 +20,11 @@ | |
| use core::prelude::rust_2024::*; | ||
| use core::result::Result; | ||
| use indexmap::IndexMap; | ||
| use log::info; | ||
| use ordered_float::OrderedFloat; | ||
| use serde::de::{MapAccess, SeqAccess, Visitor}; | ||
| use serde::ser::{SerializeMap, SerializeSeq}; | ||
| use serde::{Deserialize, Deserializer, Serialize, Serializer, de}; | ||
| use datex_core::types::type_container::TypeContainer; | ||
| use crate::values::core_values::map::Map; | ||
|
|
||
| #[derive(Clone, Debug, PartialEq)] | ||
|
|
@@ -55,11 +54,11 @@ | |
| /// Represents a number in DIF. | ||
| Number(f64), | ||
| /// Represents a array of DIF values. | ||
| Array(Vec<DIFTypeContainer>), | ||
| Array(Vec<DIFType>), | ||
| /// Represents a map of DIF values. | ||
| Map(Vec<(DIFTypeContainer, DIFTypeContainer)>), | ||
| Map(Vec<(DIFType, DIFType)>), | ||
| /// Represents a struct value in DIF. | ||
| Object(Vec<(String, DIFTypeContainer)>), | ||
| Object(Vec<(String, DIFType)>), | ||
| } | ||
|
|
||
| impl DIFValueRepresentation { | ||
|
|
@@ -72,27 +71,27 @@ | |
| Ok(match self { | ||
| DIFValueRepresentation::Null => Value::null(), | ||
| DIFValueRepresentation::String(str) => Value { | ||
| actual_type: Box::new(get_core_lib_type( | ||
| actual_type: Box::new(get_core_lib_type_definition( | ||
| CoreLibPointerId::Text, | ||
| )), | ||
| inner: CoreValue::Text(str.clone().into()), | ||
| }, | ||
| DIFValueRepresentation::Boolean(b) => Value { | ||
| actual_type: Box::new(get_core_lib_type( | ||
| actual_type: Box::new(get_core_lib_type_definition( | ||
| CoreLibPointerId::Boolean, | ||
| )), | ||
| inner: CoreValue::Boolean((*b).into()), | ||
| }, | ||
| DIFValueRepresentation::Number(n) => Value { | ||
| actual_type: Box::new(get_core_lib_type( | ||
| actual_type: Box::new(get_core_lib_type_definition( | ||
| CoreLibPointerId::Decimal(Some(DecimalTypeVariant::F64)), | ||
| )), | ||
| inner: CoreValue::TypedDecimal(TypedDecimal::F64( | ||
| OrderedFloat::from(*n), | ||
| )), | ||
| }, | ||
| DIFValueRepresentation::Array(array) => Value { | ||
| actual_type: Box::new(get_core_lib_type( | ||
| actual_type: Box::new(get_core_lib_type_definition( | ||
| CoreLibPointerId::List, | ||
| )), | ||
| inner: CoreValue::List( | ||
|
|
@@ -112,7 +111,7 @@ | |
| ); | ||
| } | ||
| Value { | ||
| actual_type: Box::new(get_core_lib_type( | ||
| actual_type: Box::new(get_core_lib_type_definition( | ||
| CoreLibPointerId::Map, | ||
| )), | ||
| inner: CoreValue::Map(map.into()), | ||
|
|
@@ -127,7 +126,7 @@ | |
| ); | ||
| } | ||
| Value { | ||
| actual_type: Box::new(get_core_lib_type( | ||
| actual_type: Box::new(get_core_lib_type_definition( | ||
| CoreLibPointerId::Map, | ||
| )), | ||
| inner: CoreValue::Map(core_map.into()), | ||
|
|
@@ -145,10 +144,10 @@ | |
| /// Returns an error if a reference cannot be resolved. | ||
| pub fn to_value_with_type( | ||
| &self, | ||
| type_container: &DIFTypeContainer, | ||
| type_definition: &DIFTypeDefinition, | ||
| memory: &RefCell<Memory>, | ||
| ) -> Result<Value, DIFReferenceNotFoundError> { | ||
| Ok(match type_container { | ||
| Ok(match type_definition { | ||
| DIFTypeContainer::Reference(r) => { | ||
|
||
| if let Ok(core_lib_ptr_id) = CoreLibPointerId::try_from(r) { | ||
| match core_lib_ptr_id { | ||
|
|
@@ -193,7 +192,7 @@ | |
| let val = self.to_default_value(memory)?; | ||
| let ty = dif_type.to_type(memory); | ||
| Value { | ||
| actual_type: Box::new(TypeContainer::Type(ty)), | ||
| actual_type: Box::new(ty), | ||
| ..val | ||
| } | ||
| } | ||
|
|
@@ -241,7 +240,7 @@ | |
| DIFTypeRepresentation::Array( | ||
| arr.iter() | ||
| .map(|v| { | ||
| DIFTypeContainer::from_type_container(v, memory) | ||
| DIFType::from_type(v, memory) | ||
| }) | ||
| .collect(), | ||
| ) | ||
|
|
@@ -252,10 +251,10 @@ | |
| .iter() | ||
| .map(|(k, v)| { | ||
| ( | ||
| DIFTypeContainer::from_type_container( | ||
| DIFType::from_type( | ||
| k, memory, | ||
| ), | ||
| DIFTypeContainer::from_type_container( | ||
| DIFType::from_type( | ||
| v, memory, | ||
| ), | ||
| ) | ||
|
|
@@ -481,13 +480,13 @@ | |
| A: SeqAccess<'de>, | ||
| { | ||
| let first_entry = seq | ||
| .next_element::<DeserializeMapOrArray<DIFTypeContainer>>( | ||
| .next_element::<DeserializeMapOrArray<DIFType>>( | ||
| )?; | ||
| match first_entry { | ||
| Some(DeserializeMapOrArray::ArrayEntry(first)) => { | ||
| let mut elements = vec![first]; | ||
| while let Some(elem) = | ||
| seq.next_element::<DIFTypeContainer>()? | ||
| seq.next_element::<DIFType>()? | ||
| { | ||
| elements.push(elem); | ||
| } | ||
|
|
@@ -496,8 +495,8 @@ | |
| Some(DeserializeMapOrArray::MapEntry(k, v)) => { | ||
| let mut elements = vec![(k, v)]; | ||
| while let Some((k, v)) = seq.next_element::<( | ||
| DIFTypeContainer, | ||
| DIFTypeContainer, | ||
| DIFType, | ||
| DIFType, | ||
| )>( | ||
| )? { | ||
| elements.push((k, v)); | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
unreachable!()without explanation in a match arm makes it unclear what cases should never occur. Consider using a more descriptive panic message or documenting why this is unreachable.