Skip to content

Commit c83aa4e

Browse files
committed
Merge branch 'main' of https://gitlab.com/mech-lang/mech
2 parents 3c6f667 + 5de15ba commit c83aa4e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+3966
-4229
lines changed

Cargo.toml

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mech"
3-
version = "0.2.6"
3+
version = "0.2.7"
44
authors = ["Corey Montella <[email protected]>"]
55
description = "Toolchain for the Mech programming language."
66
documentation = "https://mech-lang.org/docs"
@@ -18,20 +18,20 @@ gitlab = { repository = "mech-lang/mech", branch = "main" }
1818
maintenance = { status = "actively-developed" }
1919

2020
[dependencies]
21-
mech-core = "0.2.6"
22-
mech-syntax = "0.2.6"
21+
mech-core = "0.2.7"
22+
mech-syntax = "0.2.7"
2323
#mech-program = "0.2.2"
2424
#mech-utilities = "0.2.2"
2525

26-
clap = {version = "4.5.13", features = ["cargo"]}
26+
clap = {version = "4.5.15", features = ["cargo"]}
2727
colored = "2.1.0"
2828
#nom = "7.1.3"
2929
#hashbrown = "0.14.5"
3030
#reqwest = {version = "0.12.4", features = ["blocking"]}
3131
bincode = "1.3.3"
32-
serde = "1.0.204"
33-
serde_derive = "1.0.204"
34-
serde_json = "1.0.122"
32+
serde = "1.0.207"
33+
serde_derive = "1.0.207"
34+
serde_json = "1.0.124"
3535
crossbeam-channel = "0.5.13"
3636
#seahash = "4.1.0"
3737
crossterm = "0.28.1"
@@ -69,16 +69,7 @@ mech-utilities = { path = 'src/utilities'}
6969
mech-wasm = { path = 'src/wasm'}
7070

7171
[patch.'https://gitlab.com/mech-lang/core']
72-
mech-core = { path = 'src/core', version = '0.2.1' }
72+
mech-core = { path = 'src/core', version = '0.2.7' }
7373

7474
[patch.'https://gitlab.com/mech-lang/syntax']
75-
mech-syntax = { path = 'src/syntax', version = '0.2.1' }
76-
77-
[patch.'https://gitlab.com/mech-lang/program']
78-
mech-program = { path = 'src/program', version = '0.2.1' }
79-
80-
[patch.'https://gitlab.com/mech-lang/utilities']
81-
mech-utilities = { path = 'src/utilities', version = '0.2.1' }
82-
83-
[patch.'https://gitlab.com/mech-lang/wasm']
84-
mech-wasm = { path = 'src/wasm', version = '0.2.1' }
75+
mech-syntax = { path = 'src/syntax', version = '0.2.7' }

src/bin/mech.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use mech::format_parse_tree;
44
use mech_core::*;
55
use mech_syntax::parser;
66
//use mech_syntax::analyzer::*;
7-
use mech_syntax::interpreter::*;
7+
use mech_core::interpreter::*;
88
use std::time::Instant;
99
use std::fs;
1010
use std::env;
@@ -25,7 +25,7 @@ use serde_json;
2525

2626

2727
fn main() -> Result<(), MechError> {
28-
let version = "0.2.6";
28+
let version = "0.2.7";
2929
let text_logo = r#"
3030
┌─────────┐ ┌──────┐ ┌─┐ ┌──┐ ┌─┐ ┌─┐
3131
└───┐ ┌───┘ └──────┘ │ │ └┐ │ │ │ │ │

src/core/Cargo.toml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mech-core"
3-
version = "0.2.6"
3+
version = "0.2.7"
44
authors = ["Corey Montella <[email protected]>"]
55
description = "The Mech language runtime."
66
documentation = "http://docs.mech-lang.org"
@@ -25,8 +25,8 @@ wasm = ["web-sys", "wasm-bindgen"]
2525

2626
[dependencies]
2727
hashbrown = "0.14.5"
28-
serde = {version = "1.0.204", default-features = false, features = ["alloc"] }
29-
serde_derive = "1.0.204"
28+
serde = {version = "1.0.207", default-features = false, features = ["alloc"] }
29+
serde_derive = "1.0.207"
3030
rlibc = { version = "=1.0", optional = true }
3131
lazy_static = "1.5.0"
3232
seahash = "4.1.0"
@@ -38,11 +38,15 @@ getrandom = { version = "0.2.15", features = ["js"]}
3838
rand = {version = "0.8.5"}
3939
tinyrand = "0.5.0"
4040
rand_core = {version = "0.6.4"}
41-
wasm-bindgen = {version = "0.2.92", optional = true}
41+
wasm-bindgen = {version = "0.2.93", optional = true}
4242
nalgebra = "0.33.0"
43+
simba = "0.9.0"
44+
libm = "0.2.8"
45+
tabled = "0.16.0"
46+
paste = "1.0.15"
4347

4448
[dependencies.web-sys]
45-
version = "0.3.69"
49+
version = "0.3.70"
4650
features = [
4751
'Document',
4852
'Element',

src/core/src/enums.rs

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/syntax/src/functions.rs renamed to src/core/src/functions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use crate::types::*;
22
use crate::value::*;
33
use crate::interpreter::*;
4+
use crate::nodes::*;
5+
use crate::*;
46

5-
use mech_core::*;
6-
use mech_core::nodes::*;
77
use hashbrown::{HashMap, HashSet};
88
use indexmap::map::IndexMap;
99
use std::rc::Rc;

src/syntax/src/interpreter.rs renamed to src/core/src/interpreter.rs

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ use crate::stdlib::math::*;
44
use crate::stdlib::logic::*;
55
use crate::stdlib::compare::*;
66
use crate::stdlib::matrix::*;
7-
use crate::stdlib::range::*;
7+
use crate::stdlib::table::*;
8+
use crate::stdlib::range::{RangeInclusive, RangeExclusive};
89
use crate::*;
10+
use crate::{MechError, MechErrorKind, hash_str, nodes::Kind as NodeKind, nodes::*};
11+
use crate::nodes::Matrix as Mat;
912

10-
use mech_core::{MechError, MechErrorKind, hash_str, nodes::Kind as NodeKind, nodes::*};
11-
use mech_core::nodes::Matrix as Mat;
1213
use na::DMatrix;
1314
use indexmap::set::IndexSet;
1415
use indexmap::map::IndexMap;
@@ -58,8 +59,6 @@ impl Interpreter {
5859
}
5960
}
6061

61-
62-
6362
//-----------------------------------------------------------------------------
6463

6564
fn program(program: &Program, plan: Plan, symbols: SymbolTableRef, functions: FunctionsRef) -> MResult<Value> {
@@ -88,7 +87,6 @@ fn section_element(element: &SectionElement, plan: Plan, symbols: SymbolTableRef
8887
SectionElement::Section(sctn) => todo!(),
8988
SectionElement::Comment(cmmnt) => Value::Empty,
9089
SectionElement::Paragraph(p) => Value::Empty,
91-
SectionElement::MechCode(code) => todo!(),
9290
SectionElement::UnorderedList(ul) => todo!(),
9391
SectionElement::CodeBlock => todo!(),
9492
SectionElement::OrderedList => todo!(),
@@ -351,24 +349,12 @@ fn subscript(sbscrpt: &Subscript, val: &Value, plan: Plan, symbols: SymbolTableR
351349
match sbscrpt {
352350
Subscript::Dot(x) => {
353351
let key = x.hash();
354-
match val {
355-
Value::Record(rcrd) => {
356-
match rcrd.map.get(&Value::Id(key)) {
357-
Some(value) => return Ok(value.clone()),
358-
None => { return Err(MechError{tokens: x.tokens(), msg: file!().to_string(), id: line!(), kind: MechErrorKind::UndefinedField(key)});}
359-
}
360-
}
361-
Value::MutableReference(r) => match &*r.borrow() {
362-
Value::Record(rcrd) => {
363-
match rcrd.map.get(&Value::Id(key)) {
364-
Some(value) => return Ok(value.clone()),
365-
None => { return Err(MechError{tokens: x.tokens(), msg: file!().to_string(), id: line!(), kind: MechErrorKind::UndefinedField(key)});}
366-
}
367-
}
368-
_ => todo!(),
369-
}
370-
_ => todo!(),
371-
}
352+
let fxn_input: Vec<Value> = vec![val.clone(), Value::Id(key)];
353+
let new_fxn = AccessColumn{}.compile(&fxn_input)?;
354+
new_fxn.solve();
355+
let res = new_fxn.out();
356+
plan.borrow_mut().push(new_fxn);
357+
return Ok(res);
372358
},
373359
Subscript::DotInt(x) => {
374360
let mut fxn_input = vec![val.clone()];
@@ -584,7 +570,7 @@ fn set(m: &Set, plan: Plan, symbols: SymbolTableRef, functions: FunctionsRef) ->
584570

585571
fn table(t: &Table, plan: Plan, symbols: SymbolTableRef, functions: FunctionsRef) -> MResult<Value> {
586572
let mut rows = vec![];
587-
let header = table_header(&t.header)?;
573+
let (ids,col_kinds) = table_header(&t.header, functions.clone())?;
588574
let mut cols = 0;
589575
// Interpret the rows
590576
for row in &t.rows {
@@ -605,21 +591,35 @@ fn table(t: &Table, plan: Plan, symbols: SymbolTableRef, functions: FunctionsRef
605591
}
606592
// Build the table
607593
let mut data_map = IndexMap::new();
608-
for (field_label,column) in header.iter().zip(data.iter()) {
609-
data_map.insert(field_label.clone(),column.clone());
594+
for (field_label,(column,knd)) in ids.iter().zip(data.iter().zip(col_kinds)) {
595+
let val = Value::to_matrix(column.clone(),column.len(),1);
596+
match knd {
597+
ValueKind::I64 => {data_map.insert(field_label.clone(),(knd,val));},
598+
ValueKind::U8 => {
599+
let vals: Vec<Value> = val.as_vec().iter().map(|x| x.as_u8().unwrap().to_value()).collect::<Vec<Value>>();
600+
data_map.insert(field_label.clone(),(knd,Value::to_matrix(vals.clone(),vals.len(),1)));
601+
},
602+
ValueKind::Bool => {
603+
let vals: Vec<Value> = val.as_vec().iter().map(|x| x.as_bool().unwrap().to_value()).collect::<Vec<Value>>();
604+
data_map.insert(field_label.clone(),(knd,Value::to_matrix(vals.clone(),vals.len(),1)));
605+
},
606+
_ => todo!(),
607+
};
610608
}
611609
let tbl = MechTable{rows: t.rows.len(), cols, data: data_map.clone() };
612610
Ok(Value::Table(tbl))
613611
}
614612

615-
fn table_header(fields: &Vec<Field>) -> MResult<Vec<Value>> {
616-
let mut row: Vec<Value> = Vec::new();
613+
fn table_header(fields: &Vec<Field>, functions: FunctionsRef) -> MResult<(Vec<Value>,Vec<ValueKind>)> {
614+
let mut ids: Vec<Value> = Vec::new();
615+
let mut kinds: Vec<ValueKind> = Vec::new();
617616
for f in fields {
618617
let id = f.name.hash();
619-
let kind = &f.kind;
620-
row.push(Value::Id(id));
618+
let kind = kind_annotation(&f.kind.kind, functions.clone())?;
619+
ids.push(Value::Id(id));
620+
kinds.push(kind.to_value_kind(functions.clone())?);
621621
}
622-
Ok(row)
622+
Ok((ids,kinds))
623623
}
624624

625625
fn table_row(r: &TableRow, plan: Plan, symbols: SymbolTableRef, functions: FunctionsRef) -> MResult<Vec<Value>> {
@@ -693,8 +693,8 @@ fn matrix_row(r: &MatrixRow, plan: Plan, symbols: SymbolTableRef, functions: Fun
693693
Value::I32(_) => {Value::MatrixI32(i32::to_matrix(row.iter().map(|v| v.as_i32().unwrap().borrow().clone()).collect(),1,row.len()))},
694694
Value::I64(_) => {Value::MatrixI64(i64::to_matrix(row.iter().map(|v| v.as_i64().unwrap().borrow().clone()).collect(),1,row.len()))},
695695
Value::I128(_) => {Value::MatrixI128(i128::to_matrix(row.iter().map(|v| v.as_i128().unwrap().borrow().clone()).collect(),1,row.len()))},
696-
Value::F32(_) => {Value::MatrixF32(F32::to_matrix(row.iter().map(|v| F32::new(v.as_f32().unwrap().borrow().clone())).collect(),1,row.len()))},
697-
Value::F64(_) => {Value::MatrixF64(F64::to_matrix(row.iter().map(|v| F64::new(v.as_f64().unwrap().borrow().clone())).collect(),1,row.len()))},
696+
Value::F32(_) => {Value::MatrixF32(F32::to_matrix(row.iter().map(|v| v.as_f32().unwrap().borrow().clone()).collect(),1,row.len()))},
697+
Value::F64(_) => {Value::MatrixF64(F64::to_matrix(row.iter().map(|v| v.as_f64().unwrap().borrow().clone()).collect(),1,row.len()))},
698698
_ => todo!(),
699699
};
700700
Ok(mat)
@@ -779,7 +779,7 @@ fn term(trm: &Term, plan: Plan, symbols: SymbolTableRef, functions: FunctionsRef
779779
FormulaOperator::Comparison(ComparisonOp::GreaterThan) => CompareGreaterThan{}.compile(&vec![lhs,rhs])?,
780780

781781
FormulaOperator::Logic(LogicOp::And) => LogicAnd{}.compile(&vec![lhs,rhs])?,
782-
FormulaOperator::Logic(LogicOp::Or) => LogicOr{}.compile(&vec![lhs,rhs])?,
782+
FormulaOperator::Logic(LogicOp::Or) => LogicOr{}.compile(&vec![lhs,rhs])?,
783783
FormulaOperator::Logic(LogicOp::Not) => LogicNot{}.compile(&vec![lhs,rhs])?,
784784
FormulaOperator::Logic(LogicOp::Xor) => LogicXor{}.compile(&vec![lhs,rhs])?,
785785
};
File renamed without changes.

0 commit comments

Comments
 (0)