Skip to content

Commit e401791

Browse files
committed
fix: match latest ltk_meta
1 parent bad6a5b commit e401791

File tree

2 files changed

+70
-80
lines changed

2 files changed

+70
-80
lines changed

crates/ltk_ritobin/src/typecheck/name_ext.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
use ltk_meta::BinPropertyKind;
1+
use ltk_meta::PropertyKind;
22

33
pub trait RitobinName: Sized {
44
fn from_ritobin_name(name: &str) -> Option<Self>;
55
fn to_ritobin_name(self) -> &'static str;
66
}
77

8-
impl RitobinName for BinPropertyKind {
8+
impl RitobinName for PropertyKind {
99
fn from_ritobin_name(name: &str) -> Option<Self> {
1010
match name {
1111
"none" => Some(Self::None),

crates/ltk_ritobin/src/typecheck/visitor.rs

Lines changed: 68 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ use std::{
66
use indexmap::IndexMap;
77
use ltk_hash::fnv1a;
88
use ltk_meta::{
9-
value::{
10-
ContainerValue, EmbeddedValue, HashValue, MapValue, OptionalValue, StringValue,
11-
UnorderedContainerValue, Vector2Value, Vector3Value,
12-
},
13-
BinPropertyKind, PropertyValueEnum,
9+
property::{values, NoMeta},
10+
traits::PropertyValueDyn,
11+
PropertyKind, PropertyValueEnum,
1412
};
1513

1614
use crate::{
@@ -306,19 +304,10 @@ impl PropertyValueExt for PropertyValueEnum {
306304
fn rito_type(&self) -> RitoType {
307305
let base = self.kind();
308306
let subtypes = match self {
309-
PropertyValueEnum::Map(MapValue {
310-
key_kind,
311-
value_kind,
312-
..
313-
}) => [Some(*key_kind), Some(*value_kind)],
314-
PropertyValueEnum::UnorderedContainer(UnorderedContainerValue(ContainerValue {
315-
item_kind,
316-
..
317-
})) => [Some(*item_kind), None],
318-
PropertyValueEnum::Container(ContainerValue { item_kind, .. }) => {
319-
[Some(*item_kind), None]
320-
}
321-
PropertyValueEnum::Optional(OptionalValue { kind, .. }) => [Some(*kind), None],
307+
PropertyValueEnum::Map(map) => [Some(map.key_kind()), Some(map.value_kind())],
308+
PropertyValueEnum::UnorderedContainer(values::UnorderedContainer(container))
309+
| PropertyValueEnum::Container(container) => [Some(container.item_kind()), None],
310+
PropertyValueEnum::Optional(optional) => [Some(optional.item_kind()), None],
322311

323312
_ => [None, None],
324313
};
@@ -328,8 +317,8 @@ impl PropertyValueExt for PropertyValueEnum {
328317

329318
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
330319
pub struct RitoType {
331-
pub base: BinPropertyKind,
332-
pub subtypes: [Option<BinPropertyKind>; 2],
320+
pub base: PropertyKind,
321+
pub subtypes: [Option<PropertyKind>; 2],
333322
}
334323

335324
impl Display for RitoType {
@@ -347,39 +336,37 @@ impl Display for RitoType {
347336
}
348337

349338
impl RitoType {
350-
pub fn simple(kind: BinPropertyKind) -> Self {
339+
pub fn simple(kind: PropertyKind) -> Self {
351340
Self {
352341
base: kind,
353342
subtypes: [None, None],
354343
}
355344
}
356345

357-
fn subtype(&self, idx: usize) -> BinPropertyKind {
346+
fn subtype(&self, idx: usize) -> PropertyKind {
358347
self.subtypes[idx].unwrap_or_default()
359348
}
360349

361-
fn value_subtype(&self) -> Option<BinPropertyKind> {
350+
fn value_subtype(&self) -> Option<PropertyKind> {
362351
self.subtypes[1].or(self.subtypes[0])
363352
}
364353

365354
pub fn make_default(&self) -> PropertyValueEnum {
366355
match self.base {
367-
BinPropertyKind::Map => PropertyValueEnum::Map(MapValue {
356+
PropertyKind::Map => PropertyValueEnum::Map(values::Map {
368357
key_kind: self.subtype(0),
369358
value_kind: self.subtype(1),
370359
..Default::default()
371360
}),
372-
BinPropertyKind::UnorderedContainer => {
373-
PropertyValueEnum::UnorderedContainer(UnorderedContainerValue(ContainerValue {
374-
item_kind: self.subtype(0),
375-
..Default::default()
376-
}))
361+
PropertyKind::UnorderedContainer => {
362+
PropertyValueEnum::UnorderedContainer(values::UnorderedContainer(
363+
values::Container::empty_dyn(self.subtype(0)).unwrap_or_default(),
364+
))
377365
}
378-
BinPropertyKind::Container => PropertyValueEnum::Container(ContainerValue {
379-
item_kind: self.subtype(0),
380-
..Default::default()
381-
}),
382-
BinPropertyKind::Optional => PropertyValueEnum::Optional(OptionalValue {
366+
PropertyKind::Container => PropertyValueEnum::Container(
367+
values::Container::empty_dyn(self.subtype(0)).unwrap_or_default(),
368+
),
369+
PropertyKind::Optional => PropertyValueEnum::Optional(values::Optional {
383370
kind: self.subtype(0),
384371
value: None,
385372
}),
@@ -427,7 +414,7 @@ pub fn resolve_rito_type(ctx: &mut Ctx<'_>, tree: &Cst) -> Result<RitoType, Diag
427414
let base_span = base.span;
428415

429416
let base =
430-
BinPropertyKind::from_ritobin_name(&ctx.text[base.span]).ok_or(UnknownType(base.span))?;
417+
PropertyKind::from_ritobin_name(&ctx.text[base.span]).ok_or(UnknownType(base.span))?;
431418

432419
let subtypes = match c
433420
.clone()
@@ -450,7 +437,7 @@ pub fn resolve_rito_type(ctx: &mut Ctx<'_>, tree: &Cst) -> Result<RitoType, Diag
450437
.iter()
451438
.filter_map(|c| c.tree().filter(|t| t.kind == Kind::TypeArg))
452439
.map(|t| {
453-
let resolved = BinPropertyKind::from_ritobin_name(&ctx.text[t.span]);
440+
let resolved = PropertyKind::from_ritobin_name(&ctx.text[t.span]);
454441
if resolved.is_none() {
455442
ctx.diagnostics.push(UnknownType(t.span).unwrap());
456443
}
@@ -492,10 +479,9 @@ pub fn resolve_rito_type(ctx: &mut Ctx<'_>, tree: &Cst) -> Result<RitoType, Diag
492479
pub fn resolve_value(
493480
ctx: &mut Ctx,
494481
tree: &Cst,
495-
kind_hint: Option<BinPropertyKind>,
482+
kind_hint: Option<PropertyKind>,
496483
) -> Result<Option<Spanned<PropertyValueEnum>>, Diagnostic> {
497-
use ltk_meta::value::*;
498-
use BinPropertyKind as K;
484+
use PropertyKind as K;
499485
use PropertyValueEnum as P;
500486

501487
// dbg!(tree, kind_hint);
@@ -540,12 +526,14 @@ pub fn resolve_value(
540526
}
541527
};
542528
match kind_hint {
543-
K::Struct => P::Struct(StructValue {
529+
K::Struct => P::Struct(values::Struct {
544530
class_hash,
531+
meta: NoMeta,
545532
properties: Default::default(),
546533
}),
547-
K::Embedded => P::Embedded(EmbeddedValue(StructValue {
534+
K::Embedded => P::Embedded(values::Embedded(values::Struct {
548535
class_hash,
536+
meta: NoMeta,
549537
properties: Default::default(),
550538
})),
551539
other => {
@@ -698,7 +686,8 @@ pub fn resolve_entry(
698686
};
699687

700688
Ok(IrEntry {
701-
key: PropertyValueEnum::String(StringValue(ctx.text[key.span].into())).with_span(key.span),
689+
key: PropertyValueEnum::String(values::String(ctx.text[key.span].into()))
690+
.with_span(key.span),
702691
value,
703692
})
704693
}
@@ -711,26 +700,26 @@ impl TypeChecker<'_> {
711700
fn merge_ir(&mut self, mut parent: IrItem, child: IrItem) -> IrItem {
712701
match &mut parent.value_mut().inner {
713702
PropertyValueEnum::Container(list)
714-
| PropertyValueEnum::UnorderedContainer(UnorderedContainerValue(list)) => {
703+
| PropertyValueEnum::UnorderedContainer(values::UnorderedContainer(list)) => {
715704
match child {
716705
IrItem::ListItem(IrListItem(value)) => {
717-
let value = match list.item_kind == value.kind() {
718-
true => value.inner, // FIXME: span info inside all containers??
719-
false => {
706+
match list.push(value.inner) {
707+
Ok(_) => {}
708+
Err(ltk_meta::Error::MismatchedContainerTypes { expected, got }) => {
720709
self.ctx.diagnostics.push(
721710
TypeMismatch {
722-
span: value.span,
723-
expected: RitoType::simple(list.item_kind),
711+
span: value.span, // FIXME: span info inside all containers
712+
expected: RitoType::simple(list.item_kind()),
724713
expected_span: None, // TODO: would be nice here
725714
got: RitoType::simple(value.kind()).into(),
726715
}
727716
.unwrap(),
728717
);
729-
list.item_kind.default_value()
730718
}
731-
};
732-
733-
list.items.push(value);
719+
Err(e) => {
720+
todo!("handle unexpected error");
721+
}
722+
}
734723
}
735724
IrItem::Entry(IrEntry { key, value }) => {
736725
eprintln!("list item must be list item");
@@ -739,15 +728,15 @@ impl TypeChecker<'_> {
739728
}
740729
}
741730
PropertyValueEnum::Struct(struct_val)
742-
| PropertyValueEnum::Embedded(EmbeddedValue(struct_val)) => {
731+
| PropertyValueEnum::Embedded(values::Embedded(struct_val)) => {
743732
let IrItem::Entry(IrEntry { key, value }) = child else {
744733
eprintln!("struct item must be entry");
745734
return parent;
746735
};
747736

748737
let key = match key.inner {
749-
PropertyValueEnum::String(StringValue(str)) => fnv1a::hash_lower(&str),
750-
PropertyValueEnum::Hash(HashValue(hash)) => hash,
738+
PropertyValueEnum::String(values::String(str)) => fnv1a::hash_lower(&str),
739+
PropertyValueEnum::Hash(values::Hash(hash)) => hash,
751740
other => {
752741
eprintln!("{other:?} not valid hash");
753742
return parent;
@@ -768,24 +757,23 @@ impl TypeChecker<'_> {
768757
eprintln!("map item must be entry");
769758
return parent;
770759
};
771-
let value = match map_value.value_kind == value.kind() {
772-
true => value.inner, // FIXME: span info inside all containers??
773-
false => {
760+
match map_value.push(key.inner, value.inner) {
761+
Ok(()) => {}
762+
Err(ltk_meta::Error::MismatchedContainerTypes { expected, got }) => {
774763
self.ctx.diagnostics.push(
775764
TypeMismatch {
776765
span: value.span,
777-
expected: RitoType::simple(map_value.value_kind),
766+
expected: RitoType::simple(map_value.value_kind()),
778767
expected_span: None, // TODO: would be nice here
779768
got: RitoType::simple(value.kind()).into(),
780769
}
781770
.unwrap(),
782771
);
783-
map_value.value_kind.default_value()
784772
}
785-
};
786-
map_value
787-
.entries
788-
.insert(ltk_meta::value::PropertyValueUnsafeEq(key.inner), value);
773+
Err(e) => {
774+
todo!("handle unexpected err");
775+
}
776+
}
789777
}
790778
other => {
791779
eprintln!("cant inject into {:?}", other.kind())
@@ -801,10 +789,10 @@ fn populate_vec_or_color(
801789
) -> Result<(), MaybeSpanDiag> {
802790
let resolve_f32 = |n: Spanned<PropertyValueEnum>| -> Result<f32, MaybeSpanDiag> {
803791
match n.inner {
804-
PropertyValueEnum::F32(F32Value(n)) => Ok(n),
792+
PropertyValueEnum::F32(values::F32 { value: n, .. }) => Ok(n),
805793
_ => Err(TypeMismatch {
806794
span: n.span,
807-
expected: RitoType::simple(BinPropertyKind::F32),
795+
expected: RitoType::simple(PropertyKind::F32),
808796
expected_span: None, // TODO: would be nice
809797
got: RitoTypeOrVirtual::RitoType(RitoType::simple(n.inner.kind())),
810798
}
@@ -813,10 +801,10 @@ fn populate_vec_or_color(
813801
};
814802
let resolve_u8 = |n: Spanned<PropertyValueEnum>| -> Result<u8, MaybeSpanDiag> {
815803
match n.inner {
816-
PropertyValueEnum::U8(U8Value(n)) => Ok(n),
804+
PropertyValueEnum::U8(values::U8 { value: n, .. }) => Ok(n),
817805
_ => Err(TypeMismatch {
818806
span: n.span,
819-
expected: RitoType::simple(BinPropertyKind::U8),
807+
expected: RitoType::simple(PropertyKind::U8),
820808
expected_span: None, // TODO: would be nice
821809
got: RitoTypeOrVirtual::RitoType(RitoType::simple(n.inner.kind())),
822810
}
@@ -838,30 +826,29 @@ fn populate_vec_or_color(
838826
Ok(item)
839827
};
840828

841-
use ltk_meta::value::*;
842829
use PropertyValueEnum as V;
843830
let mut span = Span::new(0, 0); // FIXME: get a span in here stat
844831
let expected;
845832
match &mut **target.value_mut() {
846-
V::Vector2(Vector2Value(vec)) => {
833+
V::Vector2(values::Vector2 { value: vec, .. }) => {
847834
vec.x = resolve_f32(get_next(&mut span)?)?;
848835
vec.y = resolve_f32(get_next(&mut span)?)?;
849836
expected = ColorOrVec::Vec2;
850837
}
851-
V::Vector3(Vector3Value(vec)) => {
838+
V::Vector3(values::Vector3 { value: vec, .. }) => {
852839
vec.x = resolve_f32(get_next(&mut span)?)?;
853840
vec.y = resolve_f32(get_next(&mut span)?)?;
854841
vec.z = resolve_f32(get_next(&mut span)?)?;
855842
expected = ColorOrVec::Vec3;
856843
}
857-
V::Vector4(Vector4Value(vec)) => {
844+
V::Vector4(values::Vector4 { value: vec, .. }) => {
858845
vec.x = resolve_f32(get_next(&mut span)?)?;
859846
vec.y = resolve_f32(get_next(&mut span)?)?;
860847
vec.z = resolve_f32(get_next(&mut span)?)?;
861848
vec.w = resolve_f32(get_next(&mut span)?)?;
862849
expected = ColorOrVec::Vec4;
863850
}
864-
V::Color(ColorValue(color)) => {
851+
V::Color(values::Color { value: color, .. }) => {
865852
color.r = resolve_u8(get_next(&mut span)?)?;
866853
color.g = resolve_u8(get_next(&mut span)?)?;
867854
color.b = resolve_u8(get_next(&mut span)?)?;
@@ -918,7 +905,7 @@ impl Visitor for TypeChecker<'_> {
918905

919906
let parent_type = parent.value().rito_type();
920907

921-
use BinPropertyKind as K;
908+
use PropertyKind as K;
922909
match parent_type.base {
923910
K::Container | K::UnorderedContainer => {
924911
let value_type = parent_type
@@ -944,10 +931,10 @@ impl Visitor for TypeChecker<'_> {
944931

945932
let parent_type = parent.value().rito_type();
946933

947-
use BinPropertyKind as K;
934+
use PropertyKind as K;
948935
let color_vec_type = match parent_type.base {
949-
K::Vector2 | K::Vector3 | K::Vector4 => Some(BinPropertyKind::F32),
950-
K::Color => Some(BinPropertyKind::U8),
936+
K::Vector2 | K::Vector3 | K::Vector4 => Some(K::F32),
937+
K::Color => Some(K::U8),
951938
_ => None,
952939
};
953940

@@ -1059,7 +1046,10 @@ impl Visitor for TypeChecker<'_> {
10591046
key:
10601047
Spanned {
10611048
span: key_span,
1062-
inner: PropertyValueEnum::String(StringValue(key)),
1049+
inner:
1050+
PropertyValueEnum::String(values::String {
1051+
value: key, ..
1052+
}),
10631053
},
10641054
value,
10651055
}),

0 commit comments

Comments
 (0)