Skip to content

Commit aede6bd

Browse files
committed
Merge branch 'main' of https://gitlab.com/mech-lang/mech
2 parents 73404e8 + acc7be0 commit aede6bd

File tree

9 files changed

+166
-37
lines changed

9 files changed

+166
-37
lines changed

Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mech"
3-
version = "0.2.11"
3+
version = "0.2.12"
44
authors = ["Corey Montella <[email protected]>"]
55
description = "Mech is a reactive programming language for building robots, games, and animations."
66
documentation = "https://mech-lang.org/docs"
@@ -18,8 +18,8 @@ gitlab = { repository = "mech-lang/mech", branch = "main" }
1818
maintenance = { status = "actively-developed" }
1919

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

@@ -69,7 +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.11' }
72+
mech-core = { path = 'src/core', version = '0.2.12' }
7373

7474
[patch.'https://gitlab.com/mech-lang/syntax']
75-
mech-syntax = { path = 'src/syntax', version = '0.2.11' }
75+
mech-syntax = { path = 'src/syntax', version = '0.2.12' }

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Comprehensive documentation is available at [mech-lang.org](https://mech-lang.or
1616

1717
### 💾 From Binary
1818

19-
Download the latest release for your platform [here](https://github.com/mech-lang/mech/releases).
19+
Download the latest release for your platform [here](https://github.com/mech-lang/mech/releases/latest).
2020

2121
### 🔨 From Source
2222

src/bin/mech.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use serde_json;
2525

2626

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

src/core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mech-core"
3-
version = "0.2.11"
3+
version = "0.2.12"
44
authors = ["Corey Montella <[email protected]>"]
55
description = "The Mech language runtime."
66
documentation = "http://docs.mech-lang.org"

src/core/src/interpreter.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,15 @@ fn section(section: &Section, plan: Plan, symbols: SymbolTableRef, functions: Fu
8686
fn section_element(element: &SectionElement, plan: Plan, symbols: SymbolTableRef, functions: FunctionsRef) -> MResult<Value> {
8787
let out = match element {
8888
SectionElement::MechCode(code) => {mech_code(&code, plan.clone(), symbols.clone(), functions.clone())?},
89-
SectionElement::Section(sctn) => todo!(),
89+
SectionElement::Section(sctn) => Value::Empty,
9090
SectionElement::Comment(cmmnt) => Value::Empty,
9191
SectionElement::Paragraph(p) => Value::Empty,
92-
SectionElement::UnorderedList(ul) => todo!(),
93-
SectionElement::CodeBlock => todo!(),
94-
SectionElement::OrderedList => todo!(),
95-
SectionElement::BlockQuote => todo!(),
96-
SectionElement::ThematicBreak => todo!(),
97-
SectionElement::Image => todo!(),
92+
SectionElement::UnorderedList(ul) => Value::Empty,
93+
SectionElement::CodeBlock => Value::Empty,
94+
SectionElement::OrderedList => Value::Empty,
95+
SectionElement::BlockQuote => Value::Empty,
96+
SectionElement::ThematicBreak => Value::Empty,
97+
SectionElement::Image => Value::Empty,
9898
};
9999
Ok(out)
100100
}
@@ -160,9 +160,8 @@ fn statement(stmt: &Statement, plan: Plan, symbols: SymbolTableRef, functions: F
160160

161161
fn enum_define(enm_def: &EnumDefine, plan: Plan, symbols: SymbolTableRef, functions: FunctionsRef) -> MResult<Value> {
162162
let id = enm_def.name.hash();
163-
164-
165-
Ok(Value::Empty)
163+
let variants = enm_def.variants.iter().map(|v| (v.name.hash(),None)).collect::<Vec<(u64, Option<Value>)>>();
164+
Ok(Value::Enum(Box::new(MechEnum{id, variants})))
166165
}
167166

168167
fn kind_define(knd_def: &KindDefine, plan: Plan, symbols: SymbolTableRef, functions: FunctionsRef) -> MResult<Value> {

src/core/src/nodes.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ pub struct Set {
445445
pub elements: Vec<Expression>,
446446
}
447447

448-
#[derive(Clone, Debug, Serialize, Deserialize)]
448+
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
449449
pub struct Atom {
450450
pub name: Identifier,
451451
}
@@ -553,7 +553,7 @@ pub struct VariableAssign {
553553
pub expression: Expression,
554554
}
555555

556-
#[derive(Clone, Debug, Serialize, Deserialize)]
556+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
557557
pub struct Identifier {
558558
pub name: Token,
559559
}
@@ -648,7 +648,7 @@ pub struct Binding {
648648
pub value: Expression,
649649
}
650650

651-
#[derive(Clone, Debug, Serialize, Deserialize)]
651+
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
652652
pub struct KindAnnotation {
653653
pub kind: Kind
654654
}
@@ -667,7 +667,7 @@ impl KindAnnotation {
667667
}
668668
}
669669

670-
#[derive(Clone, Debug, Serialize, Deserialize)]
670+
#[derive(Clone, Debug, Serialize, Deserialize,Eq, PartialEq)]
671671
pub enum Kind {
672672
Tuple(Vec<Kind>),
673673
Bracket((Vec<Kind>,Vec<Literal>)),
@@ -696,7 +696,7 @@ impl Kind {
696696
}
697697
}
698698

699-
#[derive(Clone, Debug, Serialize, Deserialize)]
699+
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
700700
pub enum Literal {
701701
Empty(Token),
702702
Boolean(Token),
@@ -717,7 +717,7 @@ impl Literal {
717717
}
718718
}
719719

720-
#[derive(Clone, Debug, Serialize, Deserialize)]
720+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
721721
pub struct MechString {
722722
pub text: Token,
723723
}
@@ -749,7 +749,7 @@ pub type Imaginary = Box<Number>;
749749
pub type Base = (Whole, Part);
750750
pub type Exponent = (Sign, Whole, Part);
751751

752-
#[derive(Clone, Debug, Serialize, Deserialize)]
752+
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
753753
pub enum Number {
754754
Real(RealNumber),
755755
Imaginary(ComplexNumber),
@@ -764,7 +764,7 @@ impl Number {
764764
}
765765
}
766766

767-
#[derive(Clone, Debug, Serialize, Deserialize)]
767+
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
768768
pub enum RealNumber {
769769
Negated(Box<RealNumber>),
770770
Integer(Token),
@@ -786,12 +786,12 @@ impl RealNumber {
786786
}
787787
}
788788

789-
#[derive(Clone, Debug, Serialize, Deserialize)]
789+
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
790790
pub struct ImaginaryNumber {
791791
pub number: RealNumber,
792792
}
793793

794-
#[derive(Clone, Debug, Serialize, Deserialize)]
794+
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
795795
pub struct ComplexNumber {
796796
pub real: Option<RealNumber>,
797797
pub imaginary: ImaginaryNumber

src/core/src/value.rs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ macro_rules! impl_as_type {
4444
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
4545
pub enum ValueKind {
4646
U8, U16, U32, U64, U128, I8, I16, I32, I64, I128, F32, F64,
47-
String, Bool, Matrix(Box<ValueKind>,Vec<usize>), Set, Map, Record, Table, Tuple, Id, Index, Reference, Atom(u64), Empty, Any
47+
String, Bool, Matrix(Box<ValueKind>,Vec<usize>), Enum(u64), Set, Map, Record, Table, Tuple, Id, Index, Reference, Atom(u64), Empty, Any
4848
}
4949

5050
#[derive(Clone, Debug, PartialEq, Eq)]
@@ -84,6 +84,7 @@ pub enum Value {
8484
Record(MechMap),
8585
Table(MechTable),
8686
Tuple(MechTuple),
87+
Enum(Box<MechEnum>),
8788
Id(u64),
8889
Index(Ref<usize>),
8990
MutableReference(MutableReference),
@@ -117,6 +118,7 @@ impl Hash for Value {
117118
Value::Table(x) => x.hash(state),
118119
Value::Tuple(x) => x.hash(state),
119120
Value::Record(x) => x.hash(state),
121+
Value::Enum(x) => x.hash(state),
120122
Value::String(x) => x.hash(state),
121123
Value::MatrixBool(x) => x.hash(state),
122124
Value::MatrixIndex(x) => x.hash(state),
@@ -166,6 +168,7 @@ impl Value {
166168
Value::Table(x) => {return x.pretty_print();},
167169
Value::Tuple(x) => {return x.pretty_print();},
168170
Value::Record(x) => {return x.pretty_print();},
171+
Value::Enum(x) => {return x.pretty_print();},
169172
Value::MatrixIndex(x) => {return x.pretty_print();}
170173
Value::MatrixBool(x) => {return x.pretty_print();}
171174
Value::MatrixU8(x) => {return x.pretty_print();},
@@ -186,7 +189,6 @@ impl Value {
186189
Value::IndexAll => builder.push_record(vec![":"]),
187190
Value::Id(x) => builder.push_record(vec![format!("{:?}",humanize(x))]),
188191
Value::Kind(x) => builder.push_record(vec![format!("{:?}",x)]),
189-
190192
};
191193
let mut table = builder.build();
192194
table.with(Style::modern());
@@ -226,6 +228,7 @@ impl Value {
226228
Value::MatrixF32(x) => x.shape(),
227229
Value::MatrixF64(x) => x.shape(),
228230
Value::MatrixValue(x) => x.shape(),
231+
Value::Enum(x) => vec![1,1],
229232
Value::Table(x) => x.shape(),
230233
Value::Set(x) => vec![1,x.set.len()],
231234
Value::Map(x) => vec![1,x.map.len()],
@@ -276,6 +279,7 @@ impl Value {
276279
Value::Map(x) => ValueKind::Map,
277280
Value::Record(x) => ValueKind::Record,
278281
Value::Tuple(x) => ValueKind::Tuple,
282+
Value::Enum(x) => ValueKind::Enum(x.id),
279283
Value::MutableReference(x) => ValueKind::Reference,
280284
Value::Empty => ValueKind::Empty,
281285
Value::IndexAll => ValueKind::Empty,
@@ -628,4 +632,32 @@ impl Hash for MechTuple {
628632
x.hash(state)
629633
}
630634
}
635+
}
636+
637+
// Enum -----------------------------------------------------------------------
638+
639+
#[derive(Clone, Debug, PartialEq, Eq)]
640+
pub struct MechEnum {
641+
pub id: u64,
642+
pub variants: Vec<(u64, Option<Value>)>,
643+
}
644+
645+
impl MechEnum {
646+
647+
pub fn pretty_print(&self) -> String {
648+
let mut builder = Builder::default();
649+
let string_elements: Vec<String> = vec![format!("{}{:?}",self.id,self.variants)];
650+
builder.push_record(string_elements);
651+
let mut table = builder.build();
652+
table.with(Style::modern());
653+
format!("{table}")
654+
}
655+
656+
}
657+
658+
impl Hash for MechEnum {
659+
fn hash<H: Hasher>(&self, state: &mut H) {
660+
self.id.hash(state);
661+
self.variants.hash(state);
662+
}
631663
}

src/syntax/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mech-syntax"
3-
version = "0.2.11"
3+
version = "0.2.12"
44
authors = ["Corey Montella <[email protected]>"]
55
description = "A toolchain for compiling textual syntax into Mech blocks."
66
documentation = "http://docs.mech-lang.org"
@@ -21,7 +21,7 @@ default = []
2121
no-std = ["mech-core/no-std", "rlibc"]
2222

2323
[dependencies]
24-
mech-core = "0.2.11"
24+
mech-core = "0.2.12"
2525

2626
hashbrown = "0.14.5"
2727
lazy_static = "1.5.0"

0 commit comments

Comments
 (0)