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 Sep 23, 2024
2 parents 73404e8 + acc7be0 commit aede6bd
Show file tree
Hide file tree
Showing 9 changed files with 166 additions and 37 deletions.
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mech"
version = "0.2.11"
version = "0.2.12"
authors = ["Corey Montella <corey@mech-lang.org>"]
description = "Mech is a reactive programming language for building robots, games, and animations."
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.11"
mech-syntax = "0.2.11"
mech-core = "0.2.12"
mech-syntax = "0.2.12"
#mech-program = "0.2.2"
#mech-utilities = "0.2.2"

Expand Down Expand Up @@ -69,7 +69,7 @@ mech-utilities = { path = 'src/utilities'}
mech-wasm = { path = 'src/wasm'}

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

[patch.'https://gitlab.com/mech-lang/syntax']
mech-syntax = { path = 'src/syntax', version = '0.2.11' }
mech-syntax = { path = 'src/syntax', version = '0.2.12' }
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Comprehensive documentation is available at [mech-lang.org](https://mech-lang.or

### 💾 From Binary

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

### 🔨 From Source

Expand Down
2 changes: 1 addition & 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.11";
let version = "0.2.12";
let text_logo = r#"
┌─────────┐ ┌──────┐ ┌─┐ ┌──┐ ┌─┐ ┌─┐
└───┐ ┌───┘ └──────┘ │ │ └┐ │ │ │ │ │
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.11"
version = "0.2.12"
authors = ["Corey Montella <corey@mech-lang.org>"]
description = "The Mech language runtime."
documentation = "http://docs.mech-lang.org"
Expand Down
19 changes: 9 additions & 10 deletions src/core/src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ fn section(section: &Section, plan: Plan, symbols: SymbolTableRef, functions: Fu
fn section_element(element: &SectionElement, plan: Plan, symbols: SymbolTableRef, functions: FunctionsRef) -> MResult<Value> {
let out = match element {
SectionElement::MechCode(code) => {mech_code(&code, plan.clone(), symbols.clone(), functions.clone())?},
SectionElement::Section(sctn) => todo!(),
SectionElement::Section(sctn) => Value::Empty,
SectionElement::Comment(cmmnt) => Value::Empty,
SectionElement::Paragraph(p) => Value::Empty,
SectionElement::UnorderedList(ul) => todo!(),
SectionElement::CodeBlock => todo!(),
SectionElement::OrderedList => todo!(),
SectionElement::BlockQuote => todo!(),
SectionElement::ThematicBreak => todo!(),
SectionElement::Image => todo!(),
SectionElement::UnorderedList(ul) => Value::Empty,
SectionElement::CodeBlock => Value::Empty,
SectionElement::OrderedList => Value::Empty,
SectionElement::BlockQuote => Value::Empty,
SectionElement::ThematicBreak => Value::Empty,
SectionElement::Image => Value::Empty,
};
Ok(out)
}
Expand Down Expand Up @@ -160,9 +160,8 @@ fn statement(stmt: &Statement, plan: Plan, symbols: SymbolTableRef, functions: F

fn enum_define(enm_def: &EnumDefine, plan: Plan, symbols: SymbolTableRef, functions: FunctionsRef) -> MResult<Value> {
let id = enm_def.name.hash();


Ok(Value::Empty)
let variants = enm_def.variants.iter().map(|v| (v.name.hash(),None)).collect::<Vec<(u64, Option<Value>)>>();
Ok(Value::Enum(Box::new(MechEnum{id, variants})))
}

fn kind_define(knd_def: &KindDefine, plan: Plan, symbols: SymbolTableRef, functions: FunctionsRef) -> MResult<Value> {
Expand Down
20 changes: 10 additions & 10 deletions src/core/src/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ pub struct Set {
pub elements: Vec<Expression>,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
pub struct Atom {
pub name: Identifier,
}
Expand Down Expand Up @@ -553,7 +553,7 @@ pub struct VariableAssign {
pub expression: Expression,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub struct Identifier {
pub name: Token,
}
Expand Down Expand Up @@ -648,7 +648,7 @@ pub struct Binding {
pub value: Expression,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
pub struct KindAnnotation {
pub kind: Kind
}
Expand All @@ -667,7 +667,7 @@ impl KindAnnotation {
}
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize,Eq, PartialEq)]
pub enum Kind {
Tuple(Vec<Kind>),
Bracket((Vec<Kind>,Vec<Literal>)),
Expand Down Expand Up @@ -696,7 +696,7 @@ impl Kind {
}
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
pub enum Literal {
Empty(Token),
Boolean(Token),
Expand All @@ -717,7 +717,7 @@ impl Literal {
}
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub struct MechString {
pub text: Token,
}
Expand Down Expand Up @@ -749,7 +749,7 @@ pub type Imaginary = Box<Number>;
pub type Base = (Whole, Part);
pub type Exponent = (Sign, Whole, Part);

#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
pub enum Number {
Real(RealNumber),
Imaginary(ComplexNumber),
Expand All @@ -764,7 +764,7 @@ impl Number {
}
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
pub enum RealNumber {
Negated(Box<RealNumber>),
Integer(Token),
Expand All @@ -786,12 +786,12 @@ impl RealNumber {
}
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
pub struct ImaginaryNumber {
pub number: RealNumber,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
pub struct ComplexNumber {
pub real: Option<RealNumber>,
pub imaginary: ImaginaryNumber
Expand Down
36 changes: 34 additions & 2 deletions src/core/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ macro_rules! impl_as_type {
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum ValueKind {
U8, U16, U32, U64, U128, I8, I16, I32, I64, I128, F32, F64,
String, Bool, Matrix(Box<ValueKind>,Vec<usize>), Set, Map, Record, Table, Tuple, Id, Index, Reference, Atom(u64), Empty, Any
String, Bool, Matrix(Box<ValueKind>,Vec<usize>), Enum(u64), Set, Map, Record, Table, Tuple, Id, Index, Reference, Atom(u64), Empty, Any
}

#[derive(Clone, Debug, PartialEq, Eq)]
Expand Down Expand Up @@ -84,6 +84,7 @@ pub enum Value {
Record(MechMap),
Table(MechTable),
Tuple(MechTuple),
Enum(Box<MechEnum>),
Id(u64),
Index(Ref<usize>),
MutableReference(MutableReference),
Expand Down Expand Up @@ -117,6 +118,7 @@ impl Hash for Value {
Value::Table(x) => x.hash(state),
Value::Tuple(x) => x.hash(state),
Value::Record(x) => x.hash(state),
Value::Enum(x) => x.hash(state),
Value::String(x) => x.hash(state),
Value::MatrixBool(x) => x.hash(state),
Value::MatrixIndex(x) => x.hash(state),
Expand Down Expand Up @@ -166,6 +168,7 @@ impl Value {
Value::Table(x) => {return x.pretty_print();},
Value::Tuple(x) => {return x.pretty_print();},
Value::Record(x) => {return x.pretty_print();},
Value::Enum(x) => {return x.pretty_print();},
Value::MatrixIndex(x) => {return x.pretty_print();}
Value::MatrixBool(x) => {return x.pretty_print();}
Value::MatrixU8(x) => {return x.pretty_print();},
Expand All @@ -186,7 +189,6 @@ impl Value {
Value::IndexAll => builder.push_record(vec![":"]),
Value::Id(x) => builder.push_record(vec![format!("{:?}",humanize(x))]),
Value::Kind(x) => builder.push_record(vec![format!("{:?}",x)]),

};
let mut table = builder.build();
table.with(Style::modern());
Expand Down Expand Up @@ -226,6 +228,7 @@ impl Value {
Value::MatrixF32(x) => x.shape(),
Value::MatrixF64(x) => x.shape(),
Value::MatrixValue(x) => x.shape(),
Value::Enum(x) => vec![1,1],
Value::Table(x) => x.shape(),
Value::Set(x) => vec![1,x.set.len()],
Value::Map(x) => vec![1,x.map.len()],
Expand Down Expand Up @@ -276,6 +279,7 @@ impl Value {
Value::Map(x) => ValueKind::Map,
Value::Record(x) => ValueKind::Record,
Value::Tuple(x) => ValueKind::Tuple,
Value::Enum(x) => ValueKind::Enum(x.id),
Value::MutableReference(x) => ValueKind::Reference,
Value::Empty => ValueKind::Empty,
Value::IndexAll => ValueKind::Empty,
Expand Down Expand Up @@ -628,4 +632,32 @@ impl Hash for MechTuple {
x.hash(state)
}
}
}

// Enum -----------------------------------------------------------------------

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct MechEnum {
pub id: u64,
pub variants: Vec<(u64, Option<Value>)>,
}

impl MechEnum {

pub fn pretty_print(&self) -> String {
let mut builder = Builder::default();
let string_elements: Vec<String> = vec![format!("{}{:?}",self.id,self.variants)];
builder.push_record(string_elements);
let mut table = builder.build();
table.with(Style::modern());
format!("{table}")
}

}

impl Hash for MechEnum {
fn hash<H: Hasher>(&self, state: &mut H) {
self.id.hash(state);
self.variants.hash(state);
}
}
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.11"
version = "0.2.12"
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.11"
mech-core = "0.2.12"

hashbrown = "0.14.5"
lazy_static = "1.5.0"
Expand Down
Loading

0 comments on commit aede6bd

Please sign in to comment.