Skip to content

Commit 115916b

Browse files
committed
fixed errors
1 parent 310a6da commit 115916b

File tree

19 files changed

+90
-1550
lines changed

19 files changed

+90
-1550
lines changed

anathema-runtime/src/runtime/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::time::{Duration, Instant};
33

44
use anathema_backend::{Backend, WidgetCycle};
55
use anathema_geometry::Size;
6-
use anathema_state::{Changes, StateId, States, clear_all_changes, clear_all_subs, drain_changes};
6+
use anathema_state::{clear_all_changes, clear_all_subs, drain_changes, Changes, StateId, States};
77
use anathema_store::tree::root_node;
88
use anathema_templates::blueprints::Blueprint;
99
use anathema_templates::{Document, Globals};
@@ -17,8 +17,8 @@ use anathema_widgets::layout::{LayoutCtx, Viewport};
1717
use anathema_widgets::query::Children;
1818
use anathema_widgets::tabindex::{Index, TabIndex};
1919
use anathema_widgets::{
20-
Component, Components, Factory, FloatingWidgets, GlyphMap, WidgetContainer, WidgetId, WidgetKind, WidgetTree,
21-
eval_blueprint, update_widget,
20+
eval_blueprint, update_widget, Component, Components, Factory, FloatingWidgets, GlyphMap, WidgetContainer,
21+
WidgetId, WidgetKind, WidgetTree,
2222
};
2323
use flume::Receiver;
2424
use notify::RecommendedWatcher;

anathema-state/src/store/values.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -131,18 +131,6 @@ pub(crate) fn drop_value(key: ValueKey) -> OwnedValue {
131131
value
132132
}
133133

134-
pub(crate) fn copy_val<T: 'static + Copy>(key: OwnedKey) -> T {
135-
OWNED
136-
.with(|owned| {
137-
owned.with(key, |val| {
138-
let val: &dyn std::any::Any = &val.val;
139-
let val = val.downcast_ref::<T>();
140-
*val.expect("the value type is determined by the wrapping Value<T> and should not change")
141-
})
142-
})
143-
.expect("the value is assumed to not be checked out or borrowed")
144-
}
145-
146134
// /// This should only be used for debugging.
147135
// pub fn dump_state() -> String {
148136
// use std::fmt::Write;

anathema-state/src/value/mod.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ pub use self::list::List;
1212
pub use self::map::Map;
1313
pub use self::maybe::{Maybe, Nullable};
1414
use crate::states::State;
15-
use crate::store::subscriber::{SubKey, subscribe, unsubscribe};
15+
use crate::store::subscriber::{subscribe, unsubscribe, SubKey};
1616
use crate::store::values::{
17-
OwnedValue, copy_val, drop_value, get_unique, make_shared, new_value, return_owned, return_shared, try_make_shared,
17+
drop_value, get_unique, make_shared, new_value, return_owned, return_shared, try_make_shared, OwnedValue,
1818
};
19-
use crate::store::watchers::{Watcher, monitor, queue_monitor};
20-
use crate::store::{ValueKey, changed};
19+
use crate::store::watchers::{monitor, queue_monitor, Watcher};
20+
use crate::store::{changed, ValueKey};
2121
use crate::{Change, Subscriber};
2222

2323
mod list;
@@ -157,11 +157,9 @@ impl<T: State> Value<T> {
157157
}
158158

159159
/// Copy the inner value from the owned value.
160-
///
161-
/// This does not copy any auxillary data attached to the key
162160
impl<T: State + Copy> Value<T> {
163161
pub fn copy_value(&self) -> T {
164-
copy_val(self.key.owned())
162+
*self.to_ref()
165163
}
166164
}
167165

anathema-store/src/storage/strings.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,9 @@ impl Display for StringId {
6262
write!(f, "<sid {}>", self.0)
6363
}
6464
}
65+
66+
impl From<usize> for StringId {
67+
fn from(value: usize) -> Self {
68+
Self(value)
69+
}
70+
}

anathema-templates/src/components.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use anathema_store::smallmap::SmallMap;
66
use anathema_store::stack::Stack;
77
use anathema_store::storage::Storage;
88

9-
use crate::Lexer;
109
use crate::blueprints::Blueprint;
1110
use crate::error::{Error, Result};
1211
use crate::statements::eval::Scope;
@@ -15,6 +14,7 @@ use crate::statements::{Context, Statements};
1514
use crate::strings::{StringId, Strings};
1615
use crate::token::Tokens;
1716
use crate::variables::Variables;
17+
use crate::Lexer;
1818

1919
pub trait ToSourceKind {
2020
fn to_path(self) -> SourceKind;
@@ -75,7 +75,6 @@ impl From<&str> for SourceKind {
7575
pub(crate) enum ComponentSource {
7676
File { path: PathBuf, template: String },
7777
InMemory(String),
78-
Empty,
7978
}
8079

8180
#[derive(Debug, Copy, Clone, PartialEq)]
@@ -102,6 +101,13 @@ impl SlabIndex for ComponentBlueprintId {
102101
}
103102
}
104103

104+
#[cfg(test)]
105+
impl From<u32> for ComponentBlueprintId {
106+
fn from(value: u32) -> Self {
107+
Self(value)
108+
}
109+
}
110+
105111
impl From<ComponentBlueprintId> for Index {
106112
fn from(value: ComponentBlueprintId) -> Self {
107113
value.0.into()
@@ -126,12 +132,6 @@ pub(crate) struct ComponentTemplates {
126132
}
127133

128134
impl ComponentTemplates {
129-
pub fn debug_bs(&self) {
130-
for (a, (b, c)) in self.components.iter() {
131-
eprintln!("{b:?}");
132-
}
133-
}
134-
135135
pub(crate) fn new() -> Self {
136136
Self {
137137
dependencies: Stack::empty(),
@@ -147,10 +147,6 @@ impl ComponentTemplates {
147147
*k
148148
}
149149

150-
pub(crate) fn insert_id(&mut self, name: StringId) -> ComponentBlueprintId {
151-
self.components.push(name, ComponentSource::Empty)
152-
}
153-
154150
pub(crate) fn insert(&mut self, ident: StringId, template: ComponentSource) -> ComponentBlueprintId {
155151
self.components.insert(ident, template)
156152
}
@@ -174,7 +170,6 @@ impl ComponentTemplates {
174170
let template = match component_src {
175171
ComponentSource::File { template, .. } => template,
176172
ComponentSource::InMemory(template) => template,
177-
ComponentSource::Empty => return Err(Error::MissingComponent(ident)),
178173
};
179174

180175
// NOTE
@@ -211,7 +206,6 @@ impl ComponentTemplates {
211206
self.components.iter().filter_map(|(_, (_, src))| match src {
212207
ComponentSource::File { path, .. } => Some(path),
213208
ComponentSource::InMemory(_) => None,
214-
ComponentSource::Empty => None,
215209
})
216210
}
217211

@@ -221,7 +215,7 @@ impl ComponentTemplates {
221215
ComponentSource::File { path, template } => {
222216
*template = read_to_string(path)?;
223217
}
224-
ComponentSource::InMemory(_) | ComponentSource::Empty => (),
218+
ComponentSource::InMemory(_) => (),
225219
}
226220
}
227221
Ok(())

anathema-templates/src/error/parse.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ impl Display for ParseError {
6363
ParseErrorKind::UnexpectedEof => "unexpected end of file".into(),
6464
ParseErrorKind::TrailingPipe => "trailing pipe character".into(),
6565
ParseErrorKind::InvalidDedent => "dedent does not match previous indentation levels".into(),
66-
ParseErrorKind::InvalidOperator(_op) => "invalid operator: {op}".into(),
67-
ParseErrorKind::UnexpectedToken(_msg) => "unexpected token: {msg}".into(),
68-
ParseErrorKind::UnregisteredComponent(name) => "unregistered component: {name}".into(),
66+
ParseErrorKind::InvalidOperator(op) => format!("invalid operator: {op}"),
67+
ParseErrorKind::UnexpectedToken(msg) => format!("unexpected token: {msg}"),
68+
ParseErrorKind::UnregisteredComponent(name) => format!("unregistered component: {name}"),
6969
ParseErrorKind::InvalidKey => todo!(),
7070
};
7171

anathema-templates/src/statements/mod.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use anathema_store::smallmap::SmallMap;
22

3-
use crate::ComponentBlueprintId;
43
use crate::blueprints::Blueprint;
54
use crate::components::{AssocEventMapping, ComponentTemplates};
65
use crate::error::Result;
76
use crate::expressions::Expression;
87
use crate::strings::{StringId, Strings};
98
use crate::variables::Variables;
9+
use crate::ComponentBlueprintId;
1010

1111
mod const_eval;
1212
pub(crate) mod eval;
@@ -229,17 +229,21 @@ mod test {
229229
}
230230
}
231231

232-
pub(crate) fn component(id: ComponentBlueprintId) -> Statement {
233-
Statement::Component(id)
232+
pub(crate) fn component(id: u32) -> Statement {
233+
let comp_id = ComponentBlueprintId::from(id);
234+
Statement::Component(comp_id)
234235
}
235236

236237
pub(crate) fn slot(id: usize) -> Statement {
237238
let id = StringId::from_usize(id);
238239
Statement::ComponentSlot(id.into())
239240
}
240241

241-
pub(crate) fn associated_fun(internal: StringId, external: StringId) -> Statement {
242-
Statement::AssociatedFunction { internal, external }
242+
pub(crate) fn associated_fun(internal: usize, external: usize) -> Statement {
243+
Statement::AssociatedFunction(AssocEventMapping {
244+
internal: internal.into(),
245+
external: external.into(),
246+
})
243247
}
244248

245249
pub(crate) fn node(id: usize) -> Statement {

anathema-templates/src/statements/parser.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,9 @@ mod test {
560560

561561
fn parse(src: &str) -> Vec<Result<Statement>> {
562562
let mut strings = Strings::new();
563+
let x_id = strings.push("x");
563564
let mut components = ComponentTemplates::new();
565+
components.insert(x_id, crate::components::ComponentSource::InMemory(String::new()));
564566
let lexer = Lexer::new(src, &mut strings);
565567
let tokens = Tokens::new(lexer.collect::<Result<Vec<_>>>().unwrap(), src.len());
566568
let parser = Parser::new(tokens, &mut strings, src, &mut components);
@@ -582,13 +584,13 @@ mod test {
582584
#[test]
583585
fn parse_single_instruction() {
584586
let actual = parse_ok("a").remove(0);
585-
assert_eq!(node(1), actual);
587+
assert_eq!(node(2), actual);
586588
}
587589

588590
#[test]
589591
fn parse_attributes() {
590592
let src = "a [a: a]";
591-
let expected = vec![node(1), load_attrib(1, ident("a")), eof()];
593+
let expected = vec![node(2), load_attrib(2, ident("a")), eof()];
592594

593595
let actual = parse_ok(src);
594596
assert_eq!(expected, actual);
@@ -597,7 +599,7 @@ mod test {
597599
#[test]
598600
fn parse_text() {
599601
let src = "a 'a' \n\n//some comments \n ";
600-
let expected = vec![node(1), load_value(strlit("a")), eof()];
602+
let expected = vec![node(2), load_value(strlit("a")), eof()];
601603

602604
let actual = parse_ok(src);
603605
assert_eq!(expected, actual);
@@ -613,15 +615,15 @@ mod test {
613615
a
614616
";
615617
let expected = vec![
616-
node(1),
617-
scope_start(),
618618
node(2),
619619
scope_start(),
620620
node(3),
621+
scope_start(),
622+
node(4),
621623
scope_end(),
622-
node(2),
624+
node(3),
623625
scope_end(),
624-
node(1),
626+
node(2),
625627
eof(),
626628
];
627629

@@ -634,11 +636,11 @@ mod test {
634636
c
635637
";
636638
let expected = vec![
637-
node(1),
638-
scope_start(),
639639
node(2),
640640
scope_start(),
641641
node(3),
642+
scope_start(),
643+
node(4),
642644
scope_end(),
643645
scope_end(),
644646
eof(),
@@ -699,7 +701,7 @@ mod test {
699701

700702
assert_eq!(statements.remove(0), if_stmt(ident("data")));
701703
assert_eq!(statements.remove(0), scope_start());
702-
assert_eq!(statements.remove(0), node(2));
704+
assert_eq!(statements.remove(0), node(1));
703705
assert_eq!(statements.remove(0), scope_end());
704706
}
705707

@@ -715,7 +717,7 @@ mod test {
715717

716718
assert_eq!(statements.remove(0), if_stmt(*ident("data")));
717719
assert_eq!(statements.remove(0), scope_start());
718-
assert_eq!(statements.remove(0), node(2));
720+
assert_eq!(statements.remove(0), node(1));
719721
assert_eq!(statements.remove(0), scope_end());
720722
assert_eq!(statements.remove(0), else_stmt());
721723
assert_eq!(statements.remove(0), scope_start());
@@ -737,7 +739,7 @@ mod test {
737739

738740
assert_eq!(statements.remove(0), if_stmt(ident("data")));
739741
assert_eq!(statements.remove(0), scope_start());
740-
assert_eq!(statements.remove(0), node(2));
742+
assert_eq!(statements.remove(0), node(1));
741743
assert_eq!(statements.remove(0), scope_end());
742744
assert_eq!(statements.remove(0), if_else(ident("data")));
743745
assert_eq!(statements.remove(0), scope_start());
@@ -751,11 +753,11 @@ mod test {
751753

752754
#[test]
753755
fn parse_component() {
754-
let src = "@mycomp";
756+
let src = "@x";
755757
let mut statements = parse_ok(src);
756758
assert_eq!(statements.remove(0), component(0));
757759

758-
let src = "@mycomp state";
760+
let src = "@x state";
759761
let mut statements = parse_ok(src);
760762
assert_eq!(statements.remove(0), component(0));
761763
assert_eq!(statements.remove(0), load_value(ident("state")));
@@ -765,7 +767,7 @@ mod test {
765767
fn parse_component_slot() {
766768
let src = "$slot";
767769
let mut statements = parse_ok(src);
768-
assert_eq!(statements.remove(0), slot(1));
770+
assert_eq!(statements.remove(0), slot(2));
769771
}
770772

771773
#[test]
@@ -810,7 +812,7 @@ mod test {
810812
fn parse_text_with_multiple_values() {
811813
let src = "a 'a' 'b'";
812814
let mut statements = parse_ok(src);
813-
assert_eq!(statements.remove(0), node(1));
815+
assert_eq!(statements.remove(0), node(2));
814816
assert_eq!(
815817
statements.remove(0),
816818
load_value(text_segments([strlit("a"), strlit("b")]))

0 commit comments

Comments
 (0)