Skip to content

Commit

Permalink
Merge branch 'main' of https://gitlab.com/mech-lang/mech
Browse files Browse the repository at this point in the history
  • Loading branch information
cmontella committed Aug 5, 2024
2 parents 604f370 + 998cd1c commit f9098ab
Show file tree
Hide file tree
Showing 9 changed files with 436 additions and 58 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mech"
version = "0.2.4"
version = "0.2.5"
authors = ["Corey Montella <corey@mech-lang.org>"]
description = "Toolchain for the Mech programming language."
documentation = "https://mech-lang.org/docs"
Expand All @@ -18,8 +18,8 @@ gitlab = { repository = "mech-lang/mech", branch = "main" }
maintenance = { status = "actively-developed" }

[dependencies]
mech-core = "0.2.4"
mech-syntax = "0.2.4"
mech-core = "0.2.5"
mech-syntax = "0.2.5"
#mech-program = "0.2.2"
#mech-utilities = "0.2.2"

Expand Down
8 changes: 7 additions & 1 deletion src/bin/mech.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use serde_json;


fn main() -> Result<(), MechError> {
let version = "0.2.4";
let version = "0.2.5";
let text_logo = r#"
┌─────────┐ ┌──────┐ ┌─┐ ┌──┐ ┌─┐ ┌─┐
└───┐ ┌───┘ └──────┘ │ │ └┐ │ │ │ │ │
Expand Down Expand Up @@ -139,11 +139,17 @@ fn main() -> Result<(), MechError> {
io::stdin().read_line(&mut input).unwrap();
match parser::parse(&input) {
Ok(tree) => {
let now = Instant::now();
let result = intrp.interpret(&tree);
let elapsed_time = now.elapsed();
let cycle_duration = elapsed_time.as_nanos() as f64;

match result {
Ok(r) => println!("{}", r.pretty_print()),
Err(err) => println!("{:?}", err),
}
println!("{:0.2?} ns", cycle_duration / 1000000.0);

}
Err(err) => {
if let MechErrorKind::ParserError(report, _) = err.kind {
Expand Down
2 changes: 1 addition & 1 deletion src/core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mech-core"
version = "0.2.4"
version = "0.2.5"
authors = ["Corey Montella <corey@mech-lang.org>"]
description = "The Mech language runtime."
documentation = "http://docs.mech-lang.org"
Expand Down
4 changes: 2 additions & 2 deletions src/syntax/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mech-syntax"
version = "0.2.4"
version = "0.2.5"
authors = ["Corey Montella <corey@mech-lang.org>"]
description = "A toolchain for compiling textual syntax into Mech blocks."
documentation = "http://docs.mech-lang.org"
Expand All @@ -21,7 +21,7 @@ default = []
no-std = ["mech-core/no-std", "rlibc"]

[dependencies]
mech-core = "0.2.4"
mech-core = "0.2.5"

hashbrown = "0.14.5"
lazy_static = "1.4.0"
Expand Down
28 changes: 26 additions & 2 deletions src/syntax/src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,12 +359,36 @@ fn subscript(sbscrpt: &Subscript, val: &Value, plan: Plan, symbols: SymbolTableR
result.as_index()
},
Subscript::Bracket(subs) => {
let mut fxn_input = vec![val.clone()];
/*match &subs[..] {
[Subscript::Formula(ix)] => {
let result = factor(&ix, plan.clone(), symbols.clone(), functions.clone())?;
fxn_input.push(result.as_index()?);
let new_fxn = MatrixAccessFormula{}.compile(&fxn_input)?;
new_fxn.solve();
let res = new_fxn.out();
let mut plan_brrw = plan.borrow_mut();
plan_brrw.push(new_fxn);
return Ok(res);
},
[Subscript::Range(ix)] => (),
[Subscript::All] => (),
[Subscript::All,Subscript::All] => (),
[Subscript::Formula(ix1),Subscript::Formula(ix2)] => (),
[Subscript::Range(ix1),Subscript::Range(ix2)] => (),
[Subscript::All,Subscript::Formula(ix2)] => (),
[Subscript::Formula(ix1),Subscript::All] => (),
[Subscript::Range(ix1),Subscript::Formula(ix2)] => (),
[Subscript::Formula(ix1),Subscript::Range(ix2)] => (),
[Subscript::All,Subscript::Range(ix2)] => (),
[Subscript::Range(ix1),Subscript::All] => (),
_ => unreachable!()
}*/
let mut resolved_subs = vec![];
for s in subs {
let result = subscript(&s, val, plan.clone(), symbols.clone(), functions.clone())?;
resolved_subs.push(result);
}
let mut fxn_input = vec![val.clone()];
fxn_input.append(&mut resolved_subs);
let new_fxn = MatrixAccess{}.compile(&fxn_input)?;
new_fxn.solve();
Expand All @@ -374,7 +398,7 @@ fn subscript(sbscrpt: &Subscript, val: &Value, plan: Plan, symbols: SymbolTableR
Ok(res)
},
Subscript::Brace(x) => todo!(),
Subscript::All => todo!(),
Subscript::All => Ok(Value::IndexAll),
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/syntax/src/matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ macro_rules! impl_to_matrix {
match (rows,cols) {
(1,1) => Matrix::Matrix1(new_ref(Matrix1::from_element(elements[0].clone()))),
(2,2) => Matrix::Matrix2(new_ref(Matrix2::from_vec(elements))),
(3,4) => Matrix::Matrix3(new_ref(Matrix3::from_vec(elements))),
(3,3) => Matrix::Matrix3(new_ref(Matrix3::from_vec(elements))),
(4,2) => Matrix::Matrix4(new_ref(Matrix4::from_vec(elements))),
(2,3) => Matrix::Matrix2x3(new_ref(Matrix2x3::from_vec(elements))),
(3,2) => Matrix::Matrix3x2(new_ref(Matrix3x2::from_vec(elements))),
Expand All @@ -36,7 +36,8 @@ macro_rules! impl_to_matrix {
(m,1) => Matrix::DVector(new_ref(DVector::from_vec(elements))),
(m,n) => Matrix::DMatrix(new_ref(DMatrix::from_vec(m,n,elements))),
}}}};}


impl_to_matrix!(usize);
impl_to_matrix!(bool);
impl_to_matrix!(u8);
impl_to_matrix!(u16);
Expand Down
Loading

0 comments on commit f9098ab

Please sign in to comment.