Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/ast/structs/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use crate::global::operators::assignment::AssignmentOperator;
use crate::global::operators::{ArithmeticUnaryOperator, UnaryOperator};
use crate::references::reference::ReferenceMutability;
use crate::stdlib::vec::Vec;
use crate::types::type_container::TypeContainer;
use crate::values::core_value::CoreValue;
use crate::values::core_values::decimal::Decimal;
use crate::values::core_values::decimal::typed_decimal::TypedDecimal;
Expand All @@ -29,7 +28,7 @@ pub struct DatexExpression {
pub data: DatexExpressionData,
pub span: Range<usize>,
pub wrapped: Option<usize>, // number of wrapping parentheses
pub ty: Option<TypeContainer>,
pub ty: Option<Type>,
}
impl Default for DatexExpression {
fn default() -> Self {
Expand Down
4 changes: 2 additions & 2 deletions src/ast/structs/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ use core::ops::Range;
use crate::ast::spanned::Spanned;
use crate::ast::structs::ResolvedVariable;
use crate::ast::structs::expression::VariableAccess;
use crate::types::type_container::TypeContainer;
use crate::values::core_values::decimal::Decimal;
use crate::values::core_values::decimal::typed_decimal::TypedDecimal;
use crate::values::core_values::endpoint::Endpoint;
use crate::values::core_values::integer::Integer;
use crate::values::core_values::integer::typed_integer::TypedInteger;
use crate::values::core_values::r#type::Type;
use crate::values::pointer::PointerAddress;

#[derive(Clone, Debug, PartialEq)]
Expand Down Expand Up @@ -92,7 +92,7 @@ pub struct TypeExpression {
pub data: TypeExpressionData,
pub span: Range<usize>,
pub wrapped: Option<usize>, // number of wrapping parentheses
pub ty: Option<TypeContainer>,
pub ty: Option<Type>,
}
impl TypeExpression {
pub fn new(data: TypeExpressionData, span: Range<usize>) -> Self {
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/precompiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ use crate::{
global::operators::{BinaryOperator, binary::ArithmeticOperator},
libs::core::CoreLibPointerId,
references::type_reference::{NominalTypeDeclaration, TypeReference},
types::type_container::TypeContainer,
values::core_values::r#type::Type,
visitor::{
VisitAction,
Expand All @@ -48,6 +47,7 @@ use precompiled_ast::RichAst;
use precompiled_ast::VariableShape;
use scope::NewScopeType;
use scope_stack::PrecompilerScopeStack;
use crate::types::definition::TypeDefinition;

pub struct Precompiler<'a> {
ast_metadata: Rc<RefCell<AstMetadata>>,
Expand Down Expand Up @@ -303,7 +303,7 @@ impl<'a> Precompiler<'a> {
};

// register placeholder ref in metadata
let type_def = TypeContainer::TypeReference(reference.clone());
let type_def = Type::new(TypeDefinition::reference(reference), None);
{
self.ast_metadata
.borrow_mut()
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/precompiler/precompiled_ast.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use crate::stdlib::{cell::RefCell, rc::Rc};
use crate::{
ast::structs::expression::{DatexExpression, VariableKind},
types::type_container::TypeContainer,
};
use core::fmt::Display;
use crate::values::core_values::r#type::Type;

#[derive(Clone, Debug)]
pub struct VariableMetadata {
pub original_realm_index: usize,
pub is_cross_realm: bool,
pub shape: VariableShape,
pub var_type: Option<TypeContainer>,
pub var_type: Option<Type>,
pub name: String,
}

Expand Down
4 changes: 2 additions & 2 deletions src/compiler/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ use crate::compiler::{
CompileOptions, parse_datex_script_to_rich_ast_detailed_errors,
};
use crate::runtime::Runtime;
use crate::types::type_container::TypeContainer;
use crate::values::core_values::r#type::Type;

/// Represents a file in the compiler workspace with its URL, cached content and AST.
pub struct WorkspaceFile {
pub url: Url,
pub content: String,
pub rich_ast: Option<RichAst>,
pub return_type: Option<TypeContainer>,
pub return_type: Option<Type>,
pub errors: Option<DetailedCompilerErrors>,
}

Expand Down
58 changes: 58 additions & 0 deletions src/core_compiler/type_compiler.rs
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!()
Copy link

Copilot AI Nov 26, 2025

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.

Suggested change
_ => unreachable!()
_ => unreachable!("append_type_container: encountered unexpected Type variant. Only variants handled above are expected here. If you see this, Type may have changed or this function is being misused.")

Copilot uses AI. Check for mistakes.
}
}

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_
5 changes: 2 additions & 3 deletions src/core_compiler/value_compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ use core::prelude::rust_2024::*;
use datex_core::utils::buffers::{
append_i32, append_i64, append_i128, append_u16, append_u64,
};
use datex_core::values::core_values::r#type::Type;
use crate::types::type_container::TypeContainer;
use crate::types::definition::TypeDefinition;

/// Compiles a given value container to a DXB body
pub fn compile_value_container(value_container: &ValueContainer) -> Vec<u8> {
Expand Down Expand Up @@ -105,7 +104,7 @@ pub fn append_value(buffer: &mut Vec<u8>, value: &Value) {
}
}

pub fn append_type_cast(buffer: &mut Vec<u8>, ty: &TypeContainer) {
pub fn append_type_cast(buffer: &mut Vec<u8>, ty: &TypeDefinition) {
append_instruction_code(buffer, InstructionCode::TYPED_VALUE);
// TODO
}
Expand Down
14 changes: 3 additions & 11 deletions src/dif/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,7 @@ mod tests {
fn dif_value_serialization() {
let value = DIFValue {
value: DIFValueRepresentation::Null,
ty: Some(
DIFType {
mutability: None,
name: None,
type_definition: DIFTypeDefinition::Unit,
}
.as_container(),
),
ty: Some(DIFTypeDefinition::Unit),
};
let serialized = value.as_json();
println!("Serialized DIFValue: {}", serialized);
Expand All @@ -112,9 +105,8 @@ mod tests {
assert_eq!(dif_value.value, DIFValueRepresentation::Number(42f64));
assert_eq!(
dif_value.ty,
Some(DIFTypeContainer::Reference(
CoreLibPointerId::Integer(Some(IntegerTypeVariant::I32))
.into()
Some(DIFTypeDefinition::Reference(
CoreLibPointerId::Integer(Some(IntegerTypeVariant::I32)).into()
))
);
} else {
Expand Down
6 changes: 4 additions & 2 deletions src/dif/reference.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::dif::r#type::DIFTypeContainer;

Check warning on line 1 in src/dif/reference.rs

View workflow job for this annotation

GitHub Actions / Test

unused import: `crate::dif::r#type::DIFTypeContainer`
use crate::references::reference::mutability_as_int;
use crate::references::reference::{Reference, ReferenceMutability};
use crate::runtime::memory::Memory;
Expand All @@ -6,10 +6,12 @@
use core::prelude::rust_2024::*;
use datex_core::dif::value::DIFValueContainer;
use serde::{Deserialize, Serialize};
use datex_core::dif::r#type::DIFTypeDefinition;

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct DIFReference {
pub value: DIFValueContainer,
pub allowed_type: DIFTypeContainer,
pub allowed_type: DIFTypeDefinition,
#[serde(rename = "mut")]
#[serde(with = "mutability_as_int")]
pub mutability: ReferenceMutability,
Expand All @@ -24,7 +26,7 @@
&reference.value_container(),
memory,
);
let allowed_type = DIFTypeContainer::from_type_container(
let allowed_type = DIFTypeDefinition::from_type_container(
&reference.allowed_type(),
memory,
);
Expand Down
43 changes: 21 additions & 22 deletions src/dif/representation.rs
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};

Check warning on line 3 in src/dif/representation.rs

View workflow job for this annotation

GitHub Actions / Test

unused import: `get_core_lib_type`
use crate::runtime::memory::Memory;
use crate::std_random::RandomState;
use crate::stdlib::boxed::Box;
Expand All @@ -20,12 +20,11 @@
use core::prelude::rust_2024::*;
use core::result::Result;
use indexmap::IndexMap;
use log::info;

Check warning on line 23 in src/dif/representation.rs

View workflow job for this annotation

GitHub Actions / Test

unused import: `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)]
Expand Down Expand Up @@ -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 {
Expand All @@ -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(
Expand All @@ -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()),
Expand All @@ -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()),
Expand All @@ -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) => {
Copy link

Copilot AI Nov 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function parameter is type_definition: &DIFTypeDefinition but the match arms reference DIFTypeContainer. This appears to be incorrect - should be matching on DIFTypeDefinition variants instead.

Copilot uses AI. Check for mistakes.
if let Ok(core_lib_ptr_id) = CoreLibPointerId::try_from(r) {
match core_lib_ptr_id {
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -241,7 +240,7 @@
DIFTypeRepresentation::Array(
arr.iter()
.map(|v| {
DIFTypeContainer::from_type_container(v, memory)
DIFType::from_type(v, memory)
})
.collect(),
)
Expand All @@ -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,
),
)
Expand Down Expand Up @@ -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);
}
Expand All @@ -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));
Expand Down
Loading
Loading