2022-05-08 23:30:49 +02:00
|
|
|
|
use {
|
|
|
|
|
crate::{
|
2023-02-13 18:39:45 +01:00
|
|
|
|
type_system::{Context, TypeTerm, ReprTree},
|
|
|
|
|
editors::{
|
|
|
|
|
char::*,
|
|
|
|
|
list::*,
|
|
|
|
|
integer::*,
|
2023-02-20 03:40:37 +01:00
|
|
|
|
product::*
|
2023-02-13 18:39:45 +01:00
|
|
|
|
},
|
2023-02-24 19:26:46 +01:00
|
|
|
|
tree::{NestedNode},
|
2023-02-13 18:39:45 +01:00
|
|
|
|
diagnostics::{Diagnostics},
|
2023-02-20 03:40:37 +01:00
|
|
|
|
type_system::{MorphismTypePattern},
|
2022-05-08 23:30:49 +02:00
|
|
|
|
},
|
2022-06-19 23:13:21 +02:00
|
|
|
|
std::sync::{Arc, RwLock},
|
2023-02-13 18:39:45 +01:00
|
|
|
|
cgmath::Point2
|
2022-05-08 23:30:49 +02:00
|
|
|
|
};
|
|
|
|
|
|
2023-01-02 13:18:55 +01:00
|
|
|
|
pub fn init_mem_ctx(parent: Arc<RwLock<Context>>) -> Arc<RwLock<Context>> {
|
|
|
|
|
let ctx = Arc::new(RwLock::new(Context::with_parent(Some(parent))));
|
|
|
|
|
|
2023-02-18 04:15:47 +01:00
|
|
|
|
ctx.write().unwrap().add_node_ctor(
|
|
|
|
|
"Vec", Arc::new(
|
|
|
|
|
|ctx: Arc<RwLock<Context>>, ty: TypeTerm, depth: usize| {
|
|
|
|
|
match ty {
|
|
|
|
|
TypeTerm::Type {
|
|
|
|
|
id: _, args
|
|
|
|
|
} => {
|
|
|
|
|
if args.len() > 0 {
|
2023-02-20 03:40:37 +01:00
|
|
|
|
let buf = r3vi::buffer::vec::VecBuffer::<char>::new();
|
2023-02-18 04:15:47 +01:00
|
|
|
|
let data = ReprTree::new_leaf(
|
|
|
|
|
ctx.read().unwrap().type_term_from_str("( Char )").unwrap(),
|
|
|
|
|
buf.get_port().into()
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
Some(
|
|
|
|
|
NestedNode::new(depth)
|
|
|
|
|
.set_ctx(ctx)
|
|
|
|
|
.set_data(data)
|
|
|
|
|
.set_editor(Arc::new(RwLock::new(buf)))
|
|
|
|
|
)
|
|
|
|
|
} else {
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_ => None
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
);
|
2023-01-02 13:18:55 +01:00
|
|
|
|
|
|
|
|
|
ctx
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-19 01:45:57 +01:00
|
|
|
|
pub fn init_editor_ctx(parent: Arc<RwLock<Context>>) -> Arc<RwLock<Context>> {
|
2022-12-18 01:39:01 +01:00
|
|
|
|
let ctx = Arc::new(RwLock::new(Context::with_parent(Some(parent))));
|
2022-11-18 00:21:29 +01:00
|
|
|
|
|
2023-02-17 00:59:07 +01:00
|
|
|
|
ctx.write().unwrap().add_node_ctor(
|
2022-11-19 01:45:57 +01:00
|
|
|
|
"Char", Arc::new(
|
2022-12-18 01:39:01 +01:00
|
|
|
|
|ctx: Arc<RwLock<Context>>, _ty: TypeTerm, _depth: usize| {
|
2023-02-18 04:15:47 +01:00
|
|
|
|
Some(CharEditor::new_node(ctx))
|
2022-11-18 00:21:29 +01:00
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
);
|
2023-03-25 08:56:38 +01:00
|
|
|
|
|
2023-02-26 19:41:10 +01:00
|
|
|
|
ctx.write().unwrap().add_list_typename("Seq".into());
|
2023-02-13 18:39:45 +01:00
|
|
|
|
ctx.write().unwrap().add_list_typename("Sequence".into());
|
2023-03-25 08:56:38 +01:00
|
|
|
|
ctx.write().unwrap().add_list_typename("SepSeq".into());
|
|
|
|
|
ctx.write().unwrap().add_typename("NestedNode".into());
|
2022-11-19 01:45:57 +01:00
|
|
|
|
|
2023-03-25 08:56:38 +01:00
|
|
|
|
ListEditor::init_ctx( &ctx );
|
2022-11-18 00:21:29 +01:00
|
|
|
|
|
2023-02-13 18:39:45 +01:00
|
|
|
|
ctx.write().unwrap().add_list_typename("Symbol".into());
|
2023-02-17 00:59:07 +01:00
|
|
|
|
let pattern = MorphismTypePattern {
|
2023-02-20 03:40:37 +01:00
|
|
|
|
src_tyid: ctx.read().unwrap().get_typeid("List"),
|
2023-02-17 00:59:07 +01:00
|
|
|
|
dst_tyid: ctx.read().unwrap().get_typeid("Symbol").unwrap()
|
|
|
|
|
};
|
|
|
|
|
ctx.write().unwrap().add_morphism(pattern,
|
|
|
|
|
Arc::new(
|
2023-02-18 04:15:47 +01:00
|
|
|
|
|mut node, _dst_type:_| {
|
2023-03-25 08:56:38 +01:00
|
|
|
|
PTYListController::for_node( &mut node, None, None );
|
|
|
|
|
PTYListStyle::for_node( &mut node, ("","","") );
|
|
|
|
|
Some(node)
|
2023-02-17 00:59:07 +01:00
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
ctx.write().unwrap().add_node_ctor(
|
|
|
|
|
"Symbol", Arc::new(
|
|
|
|
|
|ctx: Arc<RwLock<Context>>, dst_typ: TypeTerm, depth: usize| {
|
|
|
|
|
let mut node = Context::make_node(
|
|
|
|
|
&ctx,
|
2023-05-19 11:26:05 +02:00
|
|
|
|
(&ctx, "( List Char )").into(),
|
2023-02-18 04:15:47 +01:00
|
|
|
|
depth+1
|
2023-02-17 00:59:07 +01:00
|
|
|
|
).unwrap();
|
|
|
|
|
|
2023-02-18 04:15:47 +01:00
|
|
|
|
node = node.morph(dst_typ);
|
2023-02-13 18:39:45 +01:00
|
|
|
|
|
|
|
|
|
Some(node)
|
2022-11-18 00:21:29 +01:00
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
);
|
2022-11-19 01:45:57 +01:00
|
|
|
|
|
2023-02-13 18:39:45 +01:00
|
|
|
|
ctx.write().unwrap().add_list_typename("String".into());
|
2023-02-18 04:15:47 +01:00
|
|
|
|
let pattern = MorphismTypePattern {
|
2023-02-20 03:40:37 +01:00
|
|
|
|
src_tyid: ctx.read().unwrap().get_typeid("List"),
|
2023-02-18 04:15:47 +01:00
|
|
|
|
dst_tyid: ctx.read().unwrap().get_typeid("String").unwrap()
|
|
|
|
|
};
|
|
|
|
|
ctx.write().unwrap().add_morphism(pattern,
|
|
|
|
|
Arc::new(
|
|
|
|
|
|mut node, _dst_type:_| {
|
2023-03-25 08:56:38 +01:00
|
|
|
|
PTYListController::for_node( &mut node, None, Some('\"') );
|
|
|
|
|
PTYListStyle::for_node( &mut node, ("\"","","\"") );
|
2023-02-18 04:15:47 +01:00
|
|
|
|
Some(node)
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
2023-02-17 00:59:07 +01:00
|
|
|
|
ctx.write().unwrap().add_node_ctor(
|
2022-11-19 01:45:57 +01:00
|
|
|
|
"String", Arc::new(
|
2023-02-18 04:15:47 +01:00
|
|
|
|
|ctx: Arc<RwLock<Context>>, dst_typ: TypeTerm, depth: usize| {
|
|
|
|
|
let mut node = Context::make_node(
|
|
|
|
|
&ctx,
|
|
|
|
|
TypeTerm::Type {
|
2023-03-25 08:56:38 +01:00
|
|
|
|
id: ctx.read().unwrap().get_fun_typeid("List").unwrap(),
|
2023-02-18 04:15:47 +01:00
|
|
|
|
args: vec![
|
2023-03-02 03:43:38 +01:00
|
|
|
|
TypeTerm::new(ctx.read().unwrap().get_typeid("Char").unwrap()).into()
|
2023-02-18 04:15:47 +01:00
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
depth+1
|
|
|
|
|
).unwrap();
|
|
|
|
|
|
|
|
|
|
node = node.morph(dst_typ);
|
2023-02-13 18:39:45 +01:00
|
|
|
|
|
|
|
|
|
Some(node)
|
2022-11-18 00:21:29 +01:00
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
);
|
2023-02-20 03:40:37 +01:00
|
|
|
|
/*
|
2023-02-13 18:39:45 +01:00
|
|
|
|
ctx.write().unwrap().add_list_typename("TypeTerm".into());
|
2023-02-17 00:59:07 +01:00
|
|
|
|
ctx.write().unwrap().add_node_ctor(
|
2022-11-19 01:45:57 +01:00
|
|
|
|
"TypeTerm", Arc::new(
|
2022-12-18 01:39:01 +01:00
|
|
|
|
|ctx: Arc<RwLock<Context>>, _ty: TypeTerm, depth: usize| {
|
2023-02-18 04:15:47 +01:00
|
|
|
|
Some(TypeTermEditor::new(ctx, depth).into_node(depth))
|
2022-11-18 00:21:29 +01:00
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
);
|
2023-02-20 03:40:37 +01:00
|
|
|
|
*/
|
2023-02-13 18:39:45 +01:00
|
|
|
|
ctx.write().unwrap().add_typename("TerminalEvent".into());
|
2022-11-19 01:45:57 +01:00
|
|
|
|
ctx
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn init_math_ctx(parent: Arc<RwLock<Context>>) -> Arc<RwLock<Context>> {
|
2022-12-18 01:39:01 +01:00
|
|
|
|
let ctx = Arc::new(RwLock::new(Context::with_parent(Some(parent))));
|
2022-11-19 01:45:57 +01:00
|
|
|
|
|
2022-12-18 01:20:17 +01:00
|
|
|
|
ctx.write().unwrap().add_typename("MachineInt".into());
|
2023-02-13 18:39:45 +01:00
|
|
|
|
ctx.write().unwrap().add_typename("u32".into());
|
2023-02-26 19:41:10 +01:00
|
|
|
|
ctx.write().unwrap().add_typename("LittleEndian".into());
|
2022-11-19 01:45:57 +01:00
|
|
|
|
ctx.write().unwrap().add_typename("BigEndian".into());
|
2022-12-19 11:26:07 +01:00
|
|
|
|
|
2023-02-17 00:59:07 +01:00
|
|
|
|
ctx.write().unwrap().add_node_ctor(
|
2022-12-19 11:26:07 +01:00
|
|
|
|
"Digit", Arc::new(
|
2023-02-18 04:15:47 +01:00
|
|
|
|
|ctx: Arc<RwLock<Context>>, ty: TypeTerm, depth: usize| {
|
2022-12-19 11:26:07 +01:00
|
|
|
|
match ty {
|
|
|
|
|
TypeTerm::Type {
|
|
|
|
|
id: _, args
|
|
|
|
|
} => {
|
|
|
|
|
if args.len() > 0 {
|
2023-03-02 03:43:38 +01:00
|
|
|
|
match (args[0].0)[0] {
|
2022-12-19 11:26:07 +01:00
|
|
|
|
TypeTerm::Num(radix) => {
|
2023-03-02 03:43:38 +01:00
|
|
|
|
let node = DigitEditor::new(ctx.clone(), radix as u32).into_node(depth);
|
2022-12-19 11:26:07 +01:00
|
|
|
|
Some(
|
2023-02-13 18:39:45 +01:00
|
|
|
|
node
|
2022-12-19 11:26:07 +01:00
|
|
|
|
)
|
|
|
|
|
},
|
|
|
|
|
_ => None
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_ => None
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
);
|
2023-02-13 18:39:45 +01:00
|
|
|
|
|
|
|
|
|
ctx.write().unwrap().add_list_typename("PosInt".into());
|
2023-02-18 04:15:47 +01:00
|
|
|
|
let pattern = MorphismTypePattern {
|
2023-02-20 03:40:37 +01:00
|
|
|
|
src_tyid: ctx.read().unwrap().get_typeid("List"),
|
2023-02-18 04:15:47 +01:00
|
|
|
|
dst_tyid: ctx.read().unwrap().get_typeid("PosInt").unwrap()
|
|
|
|
|
};
|
|
|
|
|
ctx.write().unwrap().add_morphism(pattern,
|
|
|
|
|
Arc::new(
|
|
|
|
|
|mut node, dst_type| {
|
2023-07-03 12:32:03 +02:00
|
|
|
|
let depth = node.depth.get();
|
|
|
|
|
let editor = node.editor.get().unwrap().downcast::<RwLock<ListEditor>>().unwrap();
|
2023-02-18 04:15:47 +01:00
|
|
|
|
|
2023-02-20 03:40:37 +01:00
|
|
|
|
// todo: check src_type parameter to be ( Digit radix )
|
|
|
|
|
|
2023-02-18 04:15:47 +01:00
|
|
|
|
match dst_type {
|
|
|
|
|
TypeTerm::Type {
|
|
|
|
|
id: _, args
|
|
|
|
|
} => {
|
|
|
|
|
if args.len() > 0 {
|
2023-03-02 03:43:38 +01:00
|
|
|
|
match (args[0].0)[0] {
|
2023-02-20 03:40:37 +01:00
|
|
|
|
TypeTerm::Num(_radix) => {
|
2023-03-25 08:56:38 +01:00
|
|
|
|
PTYListController::for_node(
|
|
|
|
|
&mut node,
|
2023-02-18 04:15:47 +01:00
|
|
|
|
Some(','),
|
2023-03-25 08:56:38 +01:00
|
|
|
|
None,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
PTYListStyle::for_node(
|
|
|
|
|
&mut node,
|
|
|
|
|
("0d", "", "")
|
2023-02-18 04:15:47 +01:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
Some(node)
|
|
|
|
|
},
|
|
|
|
|
_ => None
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_ => None
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
2023-02-17 00:59:07 +01:00
|
|
|
|
ctx.write().unwrap().add_node_ctor(
|
2022-11-19 01:45:57 +01:00
|
|
|
|
"PosInt", Arc::new(
|
2023-02-18 04:15:47 +01:00
|
|
|
|
|ctx: Arc<RwLock<Context>>, dst_typ: TypeTerm, depth: usize| {
|
|
|
|
|
match dst_typ.clone() {
|
2022-11-19 01:45:57 +01:00
|
|
|
|
TypeTerm::Type {
|
2022-12-18 01:39:01 +01:00
|
|
|
|
id: _, args
|
2022-11-19 01:45:57 +01:00
|
|
|
|
} => {
|
|
|
|
|
if args.len() > 0 {
|
2023-03-02 03:43:38 +01:00
|
|
|
|
match (args[0].0)[0] {
|
2022-11-19 01:45:57 +01:00
|
|
|
|
TypeTerm::Num(radix) => {
|
2023-02-18 04:15:47 +01:00
|
|
|
|
|
|
|
|
|
let mut node = Context::make_node(
|
|
|
|
|
&ctx,
|
|
|
|
|
TypeTerm::Type {
|
2023-03-25 08:56:38 +01:00
|
|
|
|
id: ctx.read().unwrap().get_fun_typeid("List").unwrap(),
|
2023-02-18 04:15:47 +01:00
|
|
|
|
args: vec![
|
|
|
|
|
TypeTerm::new(ctx.read().unwrap().get_typeid("Digit").unwrap())
|
|
|
|
|
.num_arg(radix)
|
|
|
|
|
.clone()
|
2023-03-02 03:43:38 +01:00
|
|
|
|
.into()
|
2023-02-18 04:15:47 +01:00
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
depth+1
|
|
|
|
|
).unwrap();
|
|
|
|
|
|
|
|
|
|
node = node.morph(dst_typ);
|
|
|
|
|
|
|
|
|
|
Some(node)
|
|
|
|
|
}
|
2022-11-19 01:45:57 +01:00
|
|
|
|
_ => None
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_ => None
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
)
|
2023-02-18 04:15:47 +01:00
|
|
|
|
);
|
2022-11-18 00:21:29 +01:00
|
|
|
|
|
2023-02-13 18:39:45 +01:00
|
|
|
|
ctx.write().unwrap().add_list_typename("RGB".into());
|
2023-02-17 00:59:07 +01:00
|
|
|
|
ctx.write().unwrap().add_node_ctor(
|
2023-02-13 18:39:45 +01:00
|
|
|
|
"RGB", Arc::new(
|
2023-02-17 00:59:07 +01:00
|
|
|
|
|ctx: Arc<RwLock<Context>>, _ty: TypeTerm, depth: usize| {
|
2023-02-13 18:39:45 +01:00
|
|
|
|
let editor = ProductEditor::new(depth, ctx.clone())
|
|
|
|
|
.with_t(Point2::new(0, 0), "r: ")
|
|
|
|
|
.with_n(Point2::new(1, 0),
|
|
|
|
|
vec![
|
|
|
|
|
ctx.read().unwrap().type_term_from_str("( PosInt 16 BigEndian )").unwrap()
|
2023-02-26 19:41:10 +01:00
|
|
|
|
].into())
|
2023-02-13 18:39:45 +01:00
|
|
|
|
.with_t(Point2::new(0, 1), "g: ")
|
|
|
|
|
.with_n(Point2::new(1, 1),
|
|
|
|
|
vec![
|
|
|
|
|
ctx.read().unwrap().type_term_from_str("( PosInt 16 BigEndian )").unwrap()
|
2023-02-26 19:41:10 +01:00
|
|
|
|
].into())
|
2023-02-13 18:39:45 +01:00
|
|
|
|
.with_t(Point2::new(0, 2), "b: ")
|
|
|
|
|
.with_n(Point2::new(1, 2),
|
|
|
|
|
vec![
|
|
|
|
|
ctx.read().unwrap().type_term_from_str("( PosInt 16 BigEndian )").unwrap()
|
2023-02-26 19:41:10 +01:00
|
|
|
|
].into()
|
2023-02-13 18:39:45 +01:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
let view = editor.get_term_view();
|
|
|
|
|
let diag = editor.get_msg_port();
|
|
|
|
|
let editor = Arc::new(RwLock::new(editor));
|
|
|
|
|
|
2023-02-18 04:15:47 +01:00
|
|
|
|
let node = NestedNode::new(depth)
|
2023-02-13 18:39:45 +01:00
|
|
|
|
.set_ctx(ctx)
|
|
|
|
|
.set_cmd(editor.clone())
|
|
|
|
|
.set_nav(editor.clone())
|
|
|
|
|
.set_view(view)
|
|
|
|
|
.set_diag(diag)
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
Some(node)
|
|
|
|
|
}
|
|
|
|
|
));
|
2023-02-26 19:41:10 +01:00
|
|
|
|
|
|
|
|
|
ctx.write().unwrap().add_typename("Date".into());
|
|
|
|
|
ctx.write().unwrap().add_typename("ISO-8601".into());
|
|
|
|
|
ctx.write().unwrap().add_typename("TimeSinceEpoch".into());
|
|
|
|
|
ctx.write().unwrap().add_typename("Duration".into());
|
|
|
|
|
ctx.write().unwrap().add_typename("Seconds".into());
|
|
|
|
|
ctx.write().unwrap().add_typename("ℕ".into());
|
2023-02-13 18:39:45 +01:00
|
|
|
|
|
2022-11-18 00:21:29 +01:00
|
|
|
|
ctx
|
2022-05-08 23:30:49 +02:00
|
|
|
|
}
|
|
|
|
|
|