Skip to content
This repository was archived by the owner on Oct 18, 2023. It is now read-only.

Commit 84757e9

Browse files
committed
Merge branch 'v0.1-beta' into 'main'
Interim merge See merge request mech-lang/syntax!21
2 parents d5ccfb1 + dc5848b commit 84757e9

File tree

8 files changed

+489
-100
lines changed

8 files changed

+489
-100
lines changed

.gitlab-ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ image: "rust:latest"
22

33
test:cargo:
44
script:
5-
- rustup default nightly-2022-03-27
5+
- rustup default nightly-2022-08-25
66
- rustup show
77
- rustc --version && cargo --version
88
- rustup component add rust-src

Cargo.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ keywords = ["mech", "language", "programming", "parser", "compiler"]
1010
categories = ["no-std", "science::robotics", "science", "parser-implementations"]
1111
license = "Apache-2.0"
1212
readme = "README.md"
13-
edition = "2018"
13+
edition = "2021"
1414

1515
[badges]
1616
gitlab = { repository = "mech-lang/syntax", branch = "main" }
@@ -23,11 +23,11 @@ no-std = ["mech-core/no-std", "rlibc"]
2323
[dependencies]
2424
mech-core = {git = "https://gitlab.com/mech-lang/core", branch = "v0.1-beta"}
2525

26-
hashbrown = "0.12.1"
26+
hashbrown = "0.12.3"
2727
lazy_static = "1.4.0"
2828
nom = "7.1.1"
2929
nom-unicode = "0.3.0"
3030
unicode-segmentation = "1.9.0"
3131
rlibc = { version = "=1.0", optional = true }
32-
serde = "1.0.133"
33-
serde_derive = "1.0.133"
32+
serde = "1.0.144"
33+
serde_derive = "1.0.144"

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
<img width="500px" src="http://mech-lang.org/img/logo.png">
33
</p>
44

5-
Mech is a language for developing **data-driven**, **reactive** systems like animations, games, and robots. It makes **composing**, **transforming**, and **distributing** data easy, allowing you to focus on the essential complexity of your project.
5+
Mech is a language for developing **data-driven**, **reactive** systems like animations, games, and robots. It makes **composing**, **transforming**, and **distributing** data easy, allowing you to focus on the essential complexity of your project.
66

77
You can try Mech online at [try.mech-lang.org](http://try.mech-lang.org).
88

99
Usage and installation instructions can be found in the [documentation](http://mech-lang.org/page/learn/) or the [main Mech repository](https://github.com/mech-lang/mech).
1010

11-
Read about progress on our [blog](http://mech-lang.org/blog/), follow us on Twitter [@MechLang](https://twitter.com/MechLang), get live help on our [Gitter channel](https://gitter.im/mech-lang/community), or join the [mailing list](https://groups.google.com/forum/#!forum/mechtalk).
11+
Read about progress on our [blog](http://mech-lang.org/blog/), and follow us on Twitter [@MechLang](https://twitter.com/MechLang).
1212

1313
# Mech Syntax
1414

src/ast.rs

+54-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ pub enum Node {
4949
Binding{ children: Vec<Node> },
5050
FunctionBinding{ children: Vec<Node> },
5151
Function{ name: Vec<char>, children: Vec<Node> },
52+
UserFunction{ children: Vec<Node> },
53+
FunctionBody{ children: Vec<Node> },
54+
FunctionArgs{ children: Vec<Node> },
55+
FunctionInput{ children: Vec<Node> },
56+
FunctionOutput{ children: Vec<Node> },
5257
Define { name: Vec<char>, id: u64},
5358
DotIndex { children: Vec<Node>},
5459
Swizzle { children: Vec<Node>},
@@ -76,6 +81,7 @@ pub enum Node {
7681
Add,
7782
Subtract,
7883
Multiply,
84+
MatrixMultiply,
7985
Divide,
8086
Exponent,
8187
LessThan,
@@ -112,6 +118,8 @@ pub enum Node {
112118
InlineMechCode{ children: Vec<Node> },
113119
MechCodeBlock{ children: Vec<Node> },
114120
Null,
121+
Transpose,
122+
TransposeSelect{children: Vec<Node>},
115123
}
116124

117125
impl fmt::Debug for Node {
@@ -163,6 +171,12 @@ pub fn print_recurse(node: &Node, level: usize, f: &mut fmt::Formatter) {
163171
Node::Range => {write!(f,"Range\n").ok(); None},
164172
Node::Expression{children} => {write!(f,"Expression\n").ok(); Some(children)},
165173
Node::Function{name, children} => {write!(f,"Function({:?})\n", name).ok(); Some(children)},
174+
Node::UserFunction{children} => {write!(f,"UserFunction\n").ok(); Some(children)},
175+
Node::FunctionBody{children} => {write!(f,"FunctionBody\n").ok(); Some(children)},
176+
Node::FunctionArgs{children} => {write!(f,"FunctionArgs\n").ok(); Some(children)},
177+
Node::UserFunction{children} => {write!(f,"Expression\n").ok(); Some(children)},
178+
Node::FunctionInput{children} => {write!(f,"FunctionInput\n").ok(); Some(children)},
179+
Node::FunctionOutput{children} => {write!(f,"FunctionOutput\n").ok(); Some(children)},
166180
Node::MathExpression{children} => {write!(f,"MathExpression\n").ok(); Some(children)},
167181
Node::Comment{children} => {write!(f,"Comment\n").ok(); Some(children)},
168182
Node::SelectExpression{children} => {write!(f,"SelectExpression\n").ok(); Some(children)},
@@ -190,13 +204,16 @@ pub fn print_recurse(node: &Node, level: usize, f: &mut fmt::Formatter) {
190204
Node::Add => {write!(f,"Add\n").ok(); None},
191205
Node::Subtract => {write!(f,"Subtract\n").ok(); None},
192206
Node::Multiply => {write!(f,"Multiply\n").ok(); None},
207+
Node::MatrixMultiply => {write!(f,"MatrixMultiply\n").ok(); None},
193208
Node::Divide => {write!(f,"Divide\n").ok(); None},
194209
Node::Exponent => {write!(f,"Exponent\n").ok(); None},
195210
Node::AddUpdate => {write!(f,"AddUpdate\n").ok(); None},
196211
Node::SubtractUpdate => {write!(f,"SubtractUpdate\n").ok(); None},
197212
Node::MultiplyUpdate => {write!(f,"MultiplyUpdate\n").ok(); None},
198213
Node::DivideUpdate => {write!(f,"DivideUpdate\n").ok(); None},
199214
Node::ExponentUpdate => {write!(f,"ExponentUpdate\n").ok(); None},
215+
Node::Transpose => {write!(f,"Transpose\n").ok(); None},
216+
Node::TransposeSelect{children} => {write!(f,"TransposeSelect\n").ok(); Some(children)},
200217
// Markdown Nodes
201218
Node::Title{text} => {write!(f,"Title({:?})\n", text).ok(); None},
202219
Node::ParagraphText{text} => {write!(f,"ParagraphText({:?})\n", text).ok(); None},
@@ -305,6 +322,8 @@ impl Ast {
305322
reversed.reverse();
306323
let mut select_data_children: Vec<Node> = vec![];
307324

325+
let mut transpose = false;
326+
308327
for node in reversed {
309328
match node {
310329
Node::Table{name, id} => {
@@ -318,7 +337,13 @@ impl Ast {
318337
if select_data_children.is_empty() {
319338
select_data_children = vec![Node::Null; 1];
320339
}
321-
compiled.push(Node::SelectData{name, id: TableId::Local(id), children: select_data_children.clone()});
340+
select_data_children.reverse();
341+
let select = Node::SelectData{name, id: TableId::Local(id), children: select_data_children.clone()};
342+
if transpose {
343+
compiled.push(Node::TransposeSelect{children: vec![select]});
344+
} else {
345+
compiled.push(select);
346+
}
322347
},
323348
Node::DotIndex{children} => {
324349
let mut reversed = children.clone();
@@ -337,6 +362,9 @@ impl Ast {
337362
Node::ReshapeColumn => {
338363
select_data_children.push(Node::ReshapeColumn);
339364
}
365+
Node::Transpose => {
366+
transpose = true;
367+
}
340368
_ => (),
341369
}
342370
}
@@ -796,6 +824,7 @@ impl Ast {
796824
Node::Add => "math/add".chars().collect(),
797825
Node::Subtract => "math/subtract".chars().collect(),
798826
Node::Multiply => "math/multiply".chars().collect(),
827+
Node::MatrixMultiply => "matrix/multiply".chars().collect(),
799828
Node::Divide => "math/divide".chars().collect(),
800829
Node::Exponent => "math/exponent".chars().collect(),
801830
Node::GreaterThan => "compare/greater-than".chars().collect(),
@@ -821,6 +850,26 @@ impl Ast {
821850
let result = self.compile_nodes(children);
822851
compiled.push(Node::Function{name: "math/negate".chars().collect(), children: result});
823852
},
853+
parser::Node::UserFunction{children} => {
854+
let result = self.compile_nodes(children);
855+
compiled.push(Node::UserFunction{children: result.clone()});
856+
}
857+
parser::Node::FunctionArgs{children} => {
858+
let result = self.compile_nodes(children);
859+
compiled.push(Node::FunctionArgs{children: result.clone()});
860+
}
861+
parser::Node::FunctionInput{children} => {
862+
let result = self.compile_nodes(children);
863+
compiled.push(Node::FunctionInput{children: result.clone()});
864+
}
865+
parser::Node::FunctionOutput{children} => {
866+
let result = self.compile_nodes(children);
867+
compiled.push(Node::FunctionOutput{children: result.clone()});
868+
}
869+
parser::Node::FunctionBody{children} => {
870+
let result = self.compile_nodes(children);
871+
compiled.push(Node::FunctionBody{children: result.clone()});
872+
}
824873
parser::Node::Function{children} => {
825874
let result = self.compile_nodes(children);
826875
let mut children: Vec<Node> = Vec::new();
@@ -873,6 +922,9 @@ impl Ast {
873922
parser::Node::True => {
874923
compiled.push(Node::True);
875924
},
925+
parser::Node::Transpose => {
926+
compiled.push(Node::Transpose);
927+
},
876928
parser::Node::False => {
877929
compiled.push(Node::False);
878930
},
@@ -934,6 +986,7 @@ impl Ast {
934986
parser::Node::Add => compiled.push(Node::Add),
935987
parser::Node::Subtract => compiled.push(Node::Subtract),
936988
parser::Node::Multiply => compiled.push(Node::Multiply),
989+
parser::Node::MatrixMultiply => compiled.push(Node::MatrixMultiply),
937990
parser::Node::Divide => compiled.push(Node::Divide),
938991
parser::Node::Exponent => compiled.push(Node::Exponent),
939992
parser::Node::And => compiled.push(Node::And),

src/bin/main.rs

+14-15
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ use std::rc::Rc;
99
fn main() -> Result<(),MechError> {
1010

1111
let input = r#"
12-
block
13-
#y = [[1;2];[3]]
14-
block
15-
x -< #y
16-
#test = stats/sum(column: x)"#;
12+
x = [1 2 3]
13+
y = [4 5; 6 7; 8 9]
14+
z = x ** y
15+
#test = stats/sum(row: z)"#;
1716
let input = String::from(input);
1817

1918
let mut ast = Ast::new();
@@ -26,9 +25,9 @@ block
2625

2726
println!("{:?}", ast.syntax_tree);
2827

29-
let blocks = compiler.compile_blocks(&vec![ast.syntax_tree.clone()]).unwrap();
28+
let sections = compiler.compile_sections(&vec![ast.syntax_tree.clone()]).unwrap();
3029

31-
core.load_blocks(blocks);
30+
core.load_sections(sections);
3231
println!("{:#?}", core.blocks);
3332
println!("{:?}", core);
3433

@@ -78,14 +77,14 @@ block
7877
];
7978
core.process_transaction(&txn)?;
8079
println!("{:#?}", core.get_table("balls").unwrap().borrow());
81-
}
82-
let txn: Vec<Change> = vec![
83-
Change::Set((hash_str("time/timer"), vec![(TableIndex::Index(1), TableIndex::Alias(hash_str("ticks")), Value::U64(U64::new(1)))])),
84-
Change::Set((hash_str("time/timer"), vec![(TableIndex::Index(1), TableIndex::Alias(hash_str("ticks")), Value::U64(U64::new(2)))])),
85-
];
86-
println!("Processing Txn...");
87-
core.process_transaction(&txn);
88-
println!("Done Txn.");*/
80+
}*/
81+
//let txn: Vec<Change> = vec![
82+
//Change::Set((hash_str("time/timer"), vec![(TableIndex::Index(1), TableIndex::Alias(hash_str("ticks")), Value::U64(U64::new(1)))])),
83+
//Change::Set((hash_str("time/timer"), vec![(TableIndex::Index(1), TableIndex::Alias(hash_str("ticks")), Value::U64(U64::new(2)))])),
84+
//];
85+
//println!("Processing Txn...");
86+
//core.process_transaction(&txn);
87+
//println!("Done Txn.");
8988
//println!("{:#?}", core.blocks);
9089

9190
//println!("Core:");

0 commit comments

Comments
 (0)