From e847a76c6d746ba88421cbdc8978ea4ba3bb951a Mon Sep 17 00:00:00 2001 From: Erin Date: Tue, 27 Jul 2021 11:51:05 +0200 Subject: [PATCH 01/22] Added cart support into AST --- src/ast.rs | 5 +++++ src/interpret.rs | 1 + 2 files changed, 6 insertions(+) diff --git a/src/ast.rs b/src/ast.rs index f84c47a..3fede85 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -102,6 +102,11 @@ pub enum ExprKind { }, Not(Box), Literal(Value), + Cart(Vec<(Expr, Expr)>), + Index { + cart: Box, + index: Box, + }, Variable(String), } diff --git a/src/interpret.rs b/src/interpret.rs index 7318056..888b314 100644 --- a/src/interpret.rs +++ b/src/interpret.rs @@ -195,6 +195,7 @@ impl ExecEnv { } Not(expr) => Bool(!self.eval_expr(&expr)?.into_bool()), Literal(value) => value.clone(), + Cart(_) | Index { .. } => todo!("cart support"), // TODO: not too happy with constructing an artificial // Iden here. From ab1515cdb03af3c710b1021fb904acdd2e66f4f7 Mon Sep 17 00:00:00 2001 From: Erin Date: Tue, 27 Jul 2021 11:52:43 +0200 Subject: [PATCH 02/22] Added arrow token --- src/lexer.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/lexer.rs b/src/lexer.rs index 7632386..b84c86b 100644 --- a/src/lexer.rs +++ b/src/lexer.rs @@ -48,6 +48,9 @@ pub enum Token { #[token("=")] Equal, + #[token("<=")] + Arrow, + // Logical operators #[token("<")] LessThan, From e7bd81e12a0e482a4271b5aa15b0711bc7883efe Mon Sep 17 00:00:00 2001 From: Erin Date: Tue, 27 Jul 2021 12:09:36 +0200 Subject: [PATCH 03/22] Implemented cart indexing parsing --- src/parser.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/parser.rs b/src/parser.rs index d276154..7a3ca6f 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -98,6 +98,7 @@ impl<'source> Parser<'source> { | Token::Integer(_) | Token::Abool(_) | Token::Bool(_) + | Token::LeftBracket | Token::LeftParen => Ok(Stmt::new( self.value_flow(token)?, start..self.lexer.span().end, @@ -188,6 +189,17 @@ impl<'source> Parser<'source> { start..self.lexer.span().end, )), + Token::LeftBracket => match buf.take() { + Some(buf) => Ok(Expr::new( + ExprKind::Index { + cart: Box::new(buf), + index: Box::new(self.expr_flow(Token::RightBracket)?), + }, + start..self.lexer.span().end, + )), + None => todo!("cart construction"), + }, + // Operations Token::Plus | Token::Minus @@ -213,6 +225,7 @@ impl<'source> Parser<'source> { }, start..self.lexer.span().end, )), + Token::LeftParen => self.expr_flow(Token::RightParen), t => Err(Error::new(ErrorKind::UnexpectedToken(t), self.lexer.span())), } From bf2e73a5d15c670e19b615ef66d134f7992130e6 Mon Sep 17 00:00:00 2001 From: Erin Date: Tue, 27 Jul 2021 12:14:11 +0200 Subject: [PATCH 04/22] Extracted construction of carts to separate function --- src/parser.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/parser.rs b/src/parser.rs index 7a3ca6f..fa6d118 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -197,7 +197,7 @@ impl<'source> Parser<'source> { }, start..self.lexer.span().end, )), - None => todo!("cart construction"), + None => Ok(Expr::new(self.cart_flow()?, start..self.lexer.span().end)), }, // Operations @@ -231,6 +231,11 @@ impl<'source> Parser<'source> { } } + /// Flow for creating carts + fn cart_flow(&mut self) -> Result { + todo!("cart construction") + } + /// Flow for operators /// /// Generates operation from LHS buffer and next expression as RHS From b53cc1e768614f3bf4982cb453d68a72231375b5 Mon Sep 17 00:00:00 2001 From: Erin Date: Thu, 29 Jul 2021 18:17:08 +0200 Subject: [PATCH 05/22] Not fails on cart contruction parsing, does nothing. --- src/parser.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/parser.rs b/src/parser.rs index fa6d118..45d4dfd 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -233,7 +233,9 @@ impl<'source> Parser<'source> { /// Flow for creating carts fn cart_flow(&mut self) -> Result { - todo!("cart construction") + let mut cart = vec![]; + + Ok(ExprKind::Cart(cart)) } /// Flow for operators From 0d497bccdd4f32cfa8b56031152a736dde7bbb85 Mon Sep 17 00:00:00 2001 From: Erin Date: Thu, 29 Jul 2021 18:58:11 +0200 Subject: [PATCH 06/22] Added cart parsing --- src/parser.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/parser.rs b/src/parser.rs index 45d4dfd..978ca6a 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -234,6 +234,43 @@ impl<'source> Parser<'source> { /// Flow for creating carts fn cart_flow(&mut self) -> Result { let mut cart = vec![]; + let mut buf = None; + + match self.checked_next()? { + Token::RightBracket => return Ok(ExprKind::Cart(cart)), + t => buf = Some(self.parse_expr(t, &mut buf)?), + } + + 'cart: loop { + let value = loop { + match self.checked_next()? { + Token::Arrow => break buf.take(), + t => buf = Some(self.parse_expr(t, &mut buf)?), + } + } + .ok_or_else(|| { + Error::new(ErrorKind::UnexpectedToken(Token::Arrow), self.lexer.span()) + })?; + + let key = loop { + match self.checked_next()? { + Token::RightBracket => { + cart.push(( + value, + buf.take() + .ok_or_else(|| Error::unexpected_eof(self.lexer.span().start))?, + )); + + break 'cart; + } + Token::Comma => break buf.take(), + t => buf = Some(self.parse_expr(t, &mut buf)?), + } + } + .ok_or_else(|| Error::unexpected_eof(self.lexer.span().start))?; + + cart.push((value, key)); + } Ok(ExprKind::Cart(cart)) } From 603a244b781c7c5c9afd48c520f77ace4f1c9acd Mon Sep 17 00:00:00 2001 From: Erin Date: Thu, 29 Jul 2021 19:17:10 +0200 Subject: [PATCH 07/22] Nest the loop inside a match arm --- src/parser.rs | 62 ++++++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/src/parser.rs b/src/parser.rs index 978ca6a..e271488 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -237,39 +237,41 @@ impl<'source> Parser<'source> { let mut buf = None; match self.checked_next()? { - Token::RightBracket => return Ok(ExprKind::Cart(cart)), - t => buf = Some(self.parse_expr(t, &mut buf)?), - } - - 'cart: loop { - let value = loop { - match self.checked_next()? { - Token::Arrow => break buf.take(), - t => buf = Some(self.parse_expr(t, &mut buf)?), - } - } - .ok_or_else(|| { - Error::new(ErrorKind::UnexpectedToken(Token::Arrow), self.lexer.span()) - })?; - - let key = loop { - match self.checked_next()? { - Token::RightBracket => { - cart.push(( - value, - buf.take() - .ok_or_else(|| Error::unexpected_eof(self.lexer.span().start))?, - )); - - break 'cart; + Token::RightBracket => (), + t => { + buf = Some(self.parse_expr(t, &mut buf)?); + 'cart: loop { + let value = loop { + match self.checked_next()? { + Token::Arrow => break buf.take(), + t => buf = Some(self.parse_expr(t, &mut buf)?), + } } - Token::Comma => break buf.take(), - t => buf = Some(self.parse_expr(t, &mut buf)?), + .ok_or_else(|| { + Error::new(ErrorKind::UnexpectedToken(Token::Arrow), self.lexer.span()) + })?; + + let key = loop { + match self.checked_next()? { + Token::RightBracket => { + cart.push(( + value, + buf.take().ok_or_else(|| { + Error::unexpected_eof(self.lexer.span().start) + })?, + )); + + break 'cart; + } + Token::Comma => break buf.take(), + t => buf = Some(self.parse_expr(t, &mut buf)?), + } + } + .ok_or_else(|| Error::unexpected_eof(self.lexer.span().start))?; + + cart.push((value, key)); } } - .ok_or_else(|| Error::unexpected_eof(self.lexer.span().start))?; - - cart.push((value, key)); } Ok(ExprKind::Cart(cart)) From a6f86b7e2653f0cccca28576de4e25fc79e846f7 Mon Sep 17 00:00:00 2001 From: Erin Date: Thu, 29 Jul 2021 19:18:06 +0200 Subject: [PATCH 08/22] Bumped version to 0.2.0 --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3594179..78ceab8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,7 +4,7 @@ version = 3 [[package]] name = "able-script" -version = "0.1.0" +version = "0.2.0" dependencies = [ "clap", "logos", diff --git a/Cargo.toml b/Cargo.toml index 9981fd7..7738841 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "able-script" -version = "0.1.0" +version = "0.2.0" authors = ["able "] edition = "2018" From 0bca9ff79ce2084074bdc4e277c625c881212df5 Mon Sep 17 00:00:00 2001 From: Alex Bethel Date: Thu, 29 Jul 2021 13:29:23 -0500 Subject: [PATCH 09/22] Get carts sort of working still a bunch of `todo`s and needs a lot of work, but I'm hungry and going on lunch break :) --- src/interpret.rs | 19 +++++++++- src/variables.rs | 90 ++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 97 insertions(+), 12 deletions(-) diff --git a/src/interpret.rs b/src/interpret.rs index 888b314..b0b5049 100644 --- a/src/interpret.rs +++ b/src/interpret.rs @@ -195,7 +195,24 @@ impl ExecEnv { } Not(expr) => Bool(!self.eval_expr(&expr)?.into_bool()), Literal(value) => value.clone(), - Cart(_) | Index { .. } => todo!("cart support"), + ExprKind::Cart(members) => Value::Cart( + members + .iter() + .map(|(value, key)| { + self.eval_expr(value).and_then(|value| { + self.eval_expr(key) + .map(|key| (key, Rc::new(RefCell::new(value)))) + }) + }) + .collect::, _>>()?, + ), + Index { cart, index } => { + let cart = self.eval_expr(cart)?; + let index = self.eval_expr(index)?; + + // TODO: this probably shouldn't be cloned + cart.index(&index).borrow().clone() + } // TODO: not too happy with constructing an artificial // Iden here. diff --git a/src/variables.rs b/src/variables.rs index 7f3184c..6a213c5 100644 --- a/src/variables.rs +++ b/src/variables.rs @@ -1,10 +1,10 @@ -use std::{cell::RefCell, fmt::Display, io::Write, rc::Rc}; +use std::{cell::RefCell, collections::HashMap, fmt::Display, hash::Hash, io::Write, rc::Rc}; use rand::Rng; use crate::{ast::Stmt, consts}; -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, Copy, PartialEq)] pub enum Abool { Never = -1, Sometimes = 0, @@ -43,7 +43,7 @@ pub enum Functio { }, } -#[derive(Debug, PartialEq, Clone)] +#[derive(Debug, Clone)] pub enum Value { Nul, Str(String), @@ -51,8 +51,43 @@ pub enum Value { Bool(bool), Abool(Abool), Functio(Functio), + Cart(HashMap>>), } +impl Hash for Value { + fn hash(&self, state: &mut H) { + match self { + Value::Nul => (), + Value::Str(v) => v.hash(state), + Value::Int(v) => v.hash(state), + Value::Bool(v) => v.hash(state), + Value::Abool(v) => v.to_string().hash(state), + Value::Functio(_) => todo!(), + Value::Cart(_) => self.to_string().hash(state), + } + } +} + +impl PartialEq for Value { + fn eq(&self, other: &Self) -> bool { + match (self, other) { + (Value::Nul, Value::Nul) => true, + (Value::Str(left), Value::Str(right)) => left == right, + (Value::Int(left), Value::Int(right)) => left == right, + (Value::Bool(left), Value::Bool(right)) => left == right, + (Value::Abool(left), Value::Abool(right)) => left == right, + (Value::Functio(left), Value::Functio(right)) => left == right, + (Value::Cart(_left), Value::Cart(_right)) => { + todo!() + } + (_, _) => false, + // TODO: do more coercions! + } + } +} + +impl Eq for Value {} + impl Value { /// Write an AbleScript value to a Brainfuck input stream by /// coercing the value to an integer, then truncating that integer @@ -66,10 +101,10 @@ impl Value { } /// Coerce a value to an integer. - pub fn into_i32(self) -> i32 { + pub fn into_i32(&self) -> i32 { match self { - Value::Abool(a) => a as _, - Value::Bool(b) => b as _, + Value::Abool(a) => *a as _, + Value::Bool(b) => *b as _, Value::Functio(func) => match func { Functio::BfFunctio { instructions, @@ -77,23 +112,47 @@ impl Value { } => (instructions.len() + tape_len) as _, Functio::AbleFunctio { params, body } => (params.len() + body.len()) as _, }, - Value::Int(i) => i, + Value::Int(i) => *i, Value::Nul => consts::ANSWER, Value::Str(text) => text.parse().unwrap_or(consts::ANSWER), + Value::Cart(c) => c.len() as _, } } /// Coerce a Value to a boolean. The conversion cannot fail. - pub fn into_bool(self) -> bool { + pub fn into_bool(&self) -> bool { match self { - Value::Abool(b) => b.into(), - Value::Bool(b) => b, + Value::Abool(b) => b.clone().into(), + Value::Bool(b) => *b, Value::Functio(_) => true, - Value::Int(x) => x != 0, + Value::Int(x) => *x != 0, Value::Nul => true, Value::Str(s) => !s.is_empty(), + Value::Cart(c) => !c.is_empty(), } } + + /// Index a value with another value, as in the "a[b]" syntax. + pub fn index(&self, index: &Value) -> Rc> { + Rc::new(RefCell::new(match self { + Value::Nul => Value::Nul, + Value::Str(s) => Value::Int(s.as_bytes()[index.into_i32() as usize] as i32), + Value::Int(i) => Value::Int( + (format!("{}", i).as_bytes()[index.into_i32() as usize] - ('0' as u8)) as i32, + ), + Value::Bool(b) => Value::Int( + format!("{}", b) + .chars() + .nth(index.into_i32() as usize) + .unwrap_or_else(|| '?') as i32, + ), + Value::Abool(b) => Value::Int(*b as i32), + Value::Functio(_) => Value::Int(42), + Value::Cart(c) => { + return (c.get(index).cloned()).unwrap_or_else(|| Rc::new(RefCell::new(Value::Nul))) + } + })) + } } impl Display for Value { @@ -128,6 +187,15 @@ impl Display for Value { ) } }, + Value::Cart(c) => { + write!(f, "[")?; + + for (key, value) in c { + write!(f, "{} <= {},", value.borrow(), key)?; + } + + write!(f, "]") + } } } } From eb91aa96fa6050bb08aa911746e36c707348ee46 Mon Sep 17 00:00:00 2001 From: Erin Date: Thu, 29 Jul 2021 22:39:28 +0200 Subject: [PATCH 10/22] Added carts tests --- src/parser.rs | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/src/parser.rs b/src/parser.rs index e271488..c29f475 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -676,4 +676,83 @@ mod tests { let ast = Parser::new(code).init().unwrap(); assert_eq!(ast, expected); } + + #[test] + fn cart_construction() { + let code = r#"["able" <= 1, "script" <= 3 - 1] print;"#; + let expected = &[Stmt { + kind: StmtKind::Print(Expr { + kind: ExprKind::Cart(vec![ + ( + Expr { + kind: ExprKind::Literal(Value::Str("able".to_string())), + span: 1..7, + }, + Expr { + kind: ExprKind::Literal(Value::Int(1)), + span: 11..12, + }, + ), + ( + Expr { + kind: ExprKind::Literal(Value::Str("script".to_string())), + span: 14..22, + }, + Expr { + kind: ExprKind::BinOp { + kind: BinOpKind::Subtract, + lhs: Box::new(Expr { + kind: ExprKind::Literal(Value::Int(3)), + span: 26..27, + }), + rhs: Box::new(Expr { + kind: ExprKind::Literal(Value::Int(1)), + span: 30..31, + }), + }, + span: 26..31, + }, + ), + ]), + span: 0..32, + }), + span: 0..39, + }]; + + let ast = Parser::new(code).init().unwrap(); + assert_eq!(ast, expected); + } + + #[test] + fn cart_index() { + let code = r#"["able" <= "ablecorp"]["ablecorp"] print;"#; + let expected = &[Stmt { + kind: StmtKind::Print(Expr { + kind: ExprKind::Index { + cart: Box::new(Expr { + kind: ExprKind::Cart(vec![( + Expr { + kind: ExprKind::Literal(Value::Str("able".to_string())), + span: 1..7, + }, + Expr { + kind: ExprKind::Literal(Value::Str("ablecorp".to_string())), + span: 11..21, + }, + )]), + span: 0..22, + }), + index: Box::new(Expr { + kind: ExprKind::Literal(Value::Str("ablecorp".to_owned())), + span: 23..33, + }), + }, + span: 0..34, + }), + span: 0..41, + }]; + + let ast = Parser::new(code).init().unwrap(); + assert_eq!(ast, expected); + } } From 241f2261d150bf2fd2e2faf2e82ee39ca8a4f1c4 Mon Sep 17 00:00:00 2001 From: Erin Date: Thu, 29 Jul 2021 22:48:36 +0200 Subject: [PATCH 11/22] Added history (session based) --- src/repl.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/repl.rs b/src/repl.rs index 29486c3..a8afae0 100644 --- a/src/repl.rs +++ b/src/repl.rs @@ -13,12 +13,14 @@ pub fn repl(ast_print: bool) { // end of the string if stdin is connected to a file // or unsupported terminal; this can interfere with // error printing. + rl.add_history_entry(&line); let line = line.trim_end(); if line == "exit" { println!("bye"); break; } + let mut parser = Parser::new(&line); let value = parser.init().and_then(|ast| { if ast_print { From e3cfaaf32c2133399786c1a3f74fc6c7f21f4668 Mon Sep 17 00:00:00 2001 From: Erin Date: Thu, 29 Jul 2021 23:04:04 +0200 Subject: [PATCH 12/22] removed unused enum variant --- src/error.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/error.rs b/src/error.rs index 35a62a3..24cd96d 100644 --- a/src/error.rs +++ b/src/error.rs @@ -13,7 +13,6 @@ pub enum ErrorKind { SyntaxError(String), UnexpectedEof, UnexpectedToken(Token), - InvalidIdentifier, UnknownVariable(String), MeloVariable(String), TopLevelBreak, @@ -52,7 +51,6 @@ impl Display for ErrorKind { ErrorKind::SyntaxError(desc) => write!(f, "syntax error: {}", desc), ErrorKind::UnexpectedEof => write!(f, "unexpected end of file"), ErrorKind::UnexpectedToken(token) => write!(f, "unexpected token {:?}", token), - ErrorKind::InvalidIdentifier => write!(f, "invalid identifier"), ErrorKind::UnknownVariable(name) => write!(f, "unknown identifier \"{}\"", name), ErrorKind::MeloVariable(name) => write!(f, "banned variable \"{}\"", name), ErrorKind::TopLevelBreak => write!(f, "can only `break` out of a loop"), From b451503a2748721aab066930dcb8740e02738b6d Mon Sep 17 00:00:00 2001 From: Erin Date: Thu, 29 Jul 2021 23:22:38 +0200 Subject: [PATCH 13/22] Obeyed clippy --- src/error.rs | 2 -- src/interpret.rs | 16 ++++++++-------- src/repl.rs | 2 +- src/variables.rs | 6 +++--- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/error.rs b/src/error.rs index 24cd96d..bc0ea39 100644 --- a/src/error.rs +++ b/src/error.rs @@ -10,7 +10,6 @@ pub struct Error { #[derive(Debug)] pub enum ErrorKind { - SyntaxError(String), UnexpectedEof, UnexpectedToken(Token), UnknownVariable(String), @@ -48,7 +47,6 @@ impl std::error::Error for Error {} impl Display for ErrorKind { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - ErrorKind::SyntaxError(desc) => write!(f, "syntax error: {}", desc), ErrorKind::UnexpectedEof => write!(f, "unexpected end of file"), ErrorKind::UnexpectedToken(token) => write!(f, "unexpected token {:?}", token), ErrorKind::UnknownVariable(name) => write!(f, "unknown identifier \"{}\"", name), diff --git a/src/interpret.rs b/src/interpret.rs index b0b5049..f4052ab 100644 --- a/src/interpret.rs +++ b/src/interpret.rs @@ -138,8 +138,8 @@ impl ExecEnv { Ok(match &expr.kind { BinOp { lhs, rhs, kind } => { - let lhs = self.eval_expr(&lhs)?; - let rhs = self.eval_expr(&rhs)?; + let lhs = self.eval_expr(lhs)?; + let rhs = self.eval_expr(rhs)?; match kind { // Arithmetic operators. Add | Subtract | Multiply | Divide => { @@ -193,7 +193,7 @@ impl ExecEnv { } } } - Not(expr) => Bool(!self.eval_expr(&expr)?.into_bool()), + Not(expr) => Bool(!self.eval_expr(expr)?.into_bool()), Literal(value) => value.clone(), ExprKind::Cart(members) => Value::Cart( members @@ -268,10 +268,10 @@ impl ExecEnv { } } StmtKind::Call { iden, args } => { - let func = self.get_var(&iden)?; + let func = self.get_var(iden)?; if let Value::Functio(func) = func { - self.fn_call(func, &args, &stmt.span)?; + self.fn_call(func, args, &stmt.span)?; } else { // Fail silently for now. } @@ -286,7 +286,7 @@ impl ExecEnv { }, StmtKind::Assign { iden, value } => { let value = self.eval_expr(value)?; - self.get_var_mut(&iden)?.value.replace(value); + self.get_var_mut(iden)?.value.replace(value); } StmtKind::Break => { return Ok(HaltStatus::Break(stmt.span.clone())); @@ -295,7 +295,7 @@ impl ExecEnv { return Ok(HaltStatus::Hopback(stmt.span.clone())); } StmtKind::Melo(iden) => { - self.get_var_mut(&iden)?.melo = true; + self.get_var_mut(iden)?.melo = true; } StmtKind::Rlyeh => { // Maybe print a creepy error message or something @@ -314,7 +314,7 @@ impl ExecEnv { value += self.get_bit()? as i32; } - self.get_var_mut(&iden)?.value.replace(Value::Int(value)); + self.get_var_mut(iden)?.value.replace(Value::Int(value)); } } diff --git a/src/repl.rs b/src/repl.rs index a8afae0..af084b5 100644 --- a/src/repl.rs +++ b/src/repl.rs @@ -21,7 +21,7 @@ pub fn repl(ast_print: bool) { break; } - let mut parser = Parser::new(&line); + let mut parser = Parser::new(line); let value = parser.init().and_then(|ast| { if ast_print { println!("{:#?}", &ast); diff --git a/src/variables.rs b/src/variables.rs index 6a213c5..3fda15d 100644 --- a/src/variables.rs +++ b/src/variables.rs @@ -122,7 +122,7 @@ impl Value { /// Coerce a Value to a boolean. The conversion cannot fail. pub fn into_bool(&self) -> bool { match self { - Value::Abool(b) => b.clone().into(), + Value::Abool(b) => (*b).into(), Value::Bool(b) => *b, Value::Functio(_) => true, Value::Int(x) => *x != 0, @@ -138,13 +138,13 @@ impl Value { Value::Nul => Value::Nul, Value::Str(s) => Value::Int(s.as_bytes()[index.into_i32() as usize] as i32), Value::Int(i) => Value::Int( - (format!("{}", i).as_bytes()[index.into_i32() as usize] - ('0' as u8)) as i32, + (format!("{}", i).as_bytes()[index.into_i32() as usize] - b'0') as i32, ), Value::Bool(b) => Value::Int( format!("{}", b) .chars() .nth(index.into_i32() as usize) - .unwrap_or_else(|| '?') as i32, + .unwrap_or('?') as i32, ), Value::Abool(b) => Value::Int(*b as i32), Value::Functio(_) => Value::Int(42), From 25a3c141456f014fc38ec6a9554a1a7149db73ff Mon Sep 17 00:00:00 2001 From: Erin Date: Thu, 29 Jul 2021 23:26:43 +0200 Subject: [PATCH 14/22] Changed to correct naming conventions --- src/interpret.rs | 18 +++++++++--------- src/variables.rs | 12 ++++++------ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/interpret.rs b/src/interpret.rs index f4052ab..bf3e49e 100644 --- a/src/interpret.rs +++ b/src/interpret.rs @@ -143,8 +143,8 @@ impl ExecEnv { match kind { // Arithmetic operators. Add | Subtract | Multiply | Divide => { - let lhs = lhs.into_i32(); - let rhs = rhs.into_i32(); + let lhs = lhs.to_i32(); + let rhs = rhs.to_i32(); let res = match kind { Add => lhs.checked_add(rhs), @@ -159,8 +159,8 @@ impl ExecEnv { // Numeric comparisons. Less | Greater => { - let lhs = lhs.into_i32(); - let rhs = rhs.into_i32(); + let lhs = lhs.to_i32(); + let rhs = rhs.to_i32(); let res = match kind { Less => lhs < rhs, @@ -182,8 +182,8 @@ impl ExecEnv { // Logical connectives. And | Or => { - let lhs = lhs.into_bool(); - let rhs = rhs.into_bool(); + let lhs = lhs.to_bool(); + let rhs = rhs.to_bool(); let res = match kind { And => lhs && rhs, Or => lhs || rhs, @@ -193,7 +193,7 @@ impl ExecEnv { } } } - Not(expr) => Bool(!self.eval_expr(expr)?.into_bool()), + Not(expr) => Bool(!self.eval_expr(expr)?.to_bool()), Literal(value) => value.clone(), ExprKind::Cart(members) => Value::Cart( members @@ -257,13 +257,13 @@ impl ExecEnv { instructions: code.to_owned(), tape_len: tape_len .as_ref() - .map(|tape_len| self.eval_expr(tape_len).map(|v| v.into_i32() as usize)) + .map(|tape_len| self.eval_expr(tape_len).map(|v| v.to_i32() as usize)) .unwrap_or(Ok(crate::brian::DEFAULT_TAPE_SIZE_LIMIT))?, }), ); } StmtKind::If { cond, body } => { - if self.eval_expr(cond)?.into_bool() { + if self.eval_expr(cond)?.to_bool() { return self.eval_stmts_hs(&body.block, true); } } diff --git a/src/variables.rs b/src/variables.rs index 3fda15d..499c634 100644 --- a/src/variables.rs +++ b/src/variables.rs @@ -96,12 +96,12 @@ impl Value { /// any IO errors will cause a panic. pub fn bf_write(&self, stream: &mut impl Write) { stream - .write_all(&[self.clone().into_i32() as u8]) + .write_all(&[self.clone().to_i32() as u8]) .expect("Failed to write to Brainfuck input"); } /// Coerce a value to an integer. - pub fn into_i32(&self) -> i32 { + pub fn to_i32(&self) -> i32 { match self { Value::Abool(a) => *a as _, Value::Bool(b) => *b as _, @@ -120,7 +120,7 @@ impl Value { } /// Coerce a Value to a boolean. The conversion cannot fail. - pub fn into_bool(&self) -> bool { + pub fn to_bool(&self) -> bool { match self { Value::Abool(b) => (*b).into(), Value::Bool(b) => *b, @@ -136,14 +136,14 @@ impl Value { pub fn index(&self, index: &Value) -> Rc> { Rc::new(RefCell::new(match self { Value::Nul => Value::Nul, - Value::Str(s) => Value::Int(s.as_bytes()[index.into_i32() as usize] as i32), + Value::Str(s) => Value::Int(s.as_bytes()[index.to_i32() as usize] as i32), Value::Int(i) => Value::Int( - (format!("{}", i).as_bytes()[index.into_i32() as usize] - b'0') as i32, + (format!("{}", i).as_bytes()[index.to_i32() as usize] - b'0') as i32, ), Value::Bool(b) => Value::Int( format!("{}", b) .chars() - .nth(index.into_i32() as usize) + .nth(index.to_i32() as usize) .unwrap_or('?') as i32, ), Value::Abool(b) => Value::Int(*b as i32), From 0c000337d24e38c131ad8aa4733da47184edc7ee Mon Sep 17 00:00:00 2001 From: Erin Date: Sun, 1 Aug 2021 18:28:59 +0200 Subject: [PATCH 15/22] fmt --- src/repl.rs | 2 +- src/variables.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/repl.rs b/src/repl.rs index af084b5..fdebf5d 100644 --- a/src/repl.rs +++ b/src/repl.rs @@ -20,7 +20,7 @@ pub fn repl(ast_print: bool) { println!("bye"); break; } - + let mut parser = Parser::new(line); let value = parser.init().and_then(|ast| { if ast_print { diff --git a/src/variables.rs b/src/variables.rs index 499c634..962f4b6 100644 --- a/src/variables.rs +++ b/src/variables.rs @@ -137,9 +137,9 @@ impl Value { Rc::new(RefCell::new(match self { Value::Nul => Value::Nul, Value::Str(s) => Value::Int(s.as_bytes()[index.to_i32() as usize] as i32), - Value::Int(i) => Value::Int( - (format!("{}", i).as_bytes()[index.to_i32() as usize] - b'0') as i32, - ), + Value::Int(i) => { + Value::Int((format!("{}", i).as_bytes()[index.to_i32() as usize] - b'0') as i32) + } Value::Bool(b) => Value::Int( format!("{}", b) .chars() From 3df3cbbf6d927e96fda73c4acd30bdb70f1fe6db Mon Sep 17 00:00:00 2001 From: Erin Date: Sun, 1 Aug 2021 18:30:07 +0200 Subject: [PATCH 16/22] Implemented callable expressions in AST and Interpret --- src/ast.rs | 2 +- src/interpret.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ast.rs b/src/ast.rs index 3fede85..04a884d 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -69,7 +69,7 @@ pub enum StmtKind { code: Vec, }, Call { - iden: Iden, + expr: Expr, args: Vec, }, Print(Expr), diff --git a/src/interpret.rs b/src/interpret.rs index bf3e49e..1f0f0f6 100644 --- a/src/interpret.rs +++ b/src/interpret.rs @@ -267,8 +267,8 @@ impl ExecEnv { return self.eval_stmts_hs(&body.block, true); } } - StmtKind::Call { iden, args } => { - let func = self.get_var(iden)?; + StmtKind::Call { expr, args } => { + let func = self.eval_expr(expr)?; if let Value::Functio(func) = func { self.fn_call(func, args, &stmt.span)?; From 83a4f671214041b651966eeda2d110722d550c63 Mon Sep 17 00:00:00 2001 From: Erin Date: Sun, 1 Aug 2021 18:36:09 +0200 Subject: [PATCH 17/22] Implemented callable expressions in parser --- src/parser.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/parser.rs b/src/parser.rs index c29f475..f42873e 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -345,13 +345,12 @@ impl<'source> Parser<'source> { // Functio call Token::LeftParen => { - if let Some(Expr { - kind: ExprKind::Variable(iden), - span, - }) = buf - { - break self.functio_call_flow(Iden::new(iden, span))?; - } + break self.functio_call_flow(buf.take().ok_or_else(|| { + Error::new( + ErrorKind::UnexpectedToken(Token::LeftParen), + self.lexer.span(), + ) + })?)?; } // Variable Assignment @@ -480,7 +479,7 @@ impl<'source> Parser<'source> { } /// Parse functio call flow - fn functio_call_flow(&mut self, iden: Iden) -> Result { + fn functio_call_flow(&mut self, expr: Expr) -> Result { let mut args = vec![]; let mut buf = None; loop { @@ -509,7 +508,7 @@ impl<'source> Parser<'source> { } self.require(Token::Semicolon)?; - Ok(StmtKind::Call { iden, args }) + Ok(StmtKind::Call { expr, args }) } /// Parse variable declaration From 3686b3b60899fa8e93839edbec6a19562ab67ec1 Mon Sep 17 00:00:00 2001 From: Erin Date: Sun, 1 Aug 2021 18:47:13 +0200 Subject: [PATCH 18/22] Added carts example --- able-script-test/carts.able | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 able-script-test/carts.able diff --git a/able-script-test/carts.able b/able-script-test/carts.able new file mode 100644 index 0000000..21b5a0d --- /dev/null +++ b/able-script-test/carts.able @@ -0,0 +1,8 @@ +functio helloable() { + "Hello, Able!" print; +} + +var cart = ["able" <= 42, helloable <= "hello"]; + +cart[42] print; +cart["hello"](); \ No newline at end of file From fd9054d3d3073986d1e1bb9ccb87d787d64a6a9d Mon Sep 17 00:00:00 2001 From: Alex Bethel Date: Sat, 7 Aug 2021 16:33:28 -0600 Subject: [PATCH 19/22] Functio & cart comparisons and hashing --- src/ast.rs | 52 +++++++++++++++++++++++++++++++++++++++++------- src/variables.rs | 14 +++++++------ 2 files changed, 53 insertions(+), 13 deletions(-) diff --git a/src/ast.rs b/src/ast.rs index 04a884d..9043283 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -8,11 +8,13 @@ //! just plain subroutines and they do not return any value, //! so their calls are statements. +use std::hash::Hash; + use crate::variables::Value; type Span = std::ops::Range; -#[derive(Debug, PartialEq, Clone)] +#[derive(Debug, Clone)] pub struct Iden { pub iden: String, pub span: Span, @@ -24,19 +26,43 @@ impl Iden { } } -#[derive(Debug, PartialEq, Clone)] +impl PartialEq for Iden { + fn eq(&self, other: &Self) -> bool { + self.iden == other.iden + } +} + +impl Hash for Iden { + fn hash(&self, state: &mut H) { + self.iden.hash(state) + } +} + +#[derive(Debug, PartialEq, Clone, Hash)] pub struct Block { pub block: Vec, } /// A syntactic unit expressing an effect. -#[derive(Debug, PartialEq, Clone)] +#[derive(Debug, Clone)] pub struct Stmt { pub kind: StmtKind, pub span: Span, } -#[derive(Debug, PartialEq, Clone)] +impl PartialEq for Stmt { + fn eq(&self, other: &Self) -> bool { + self.kind == other.kind + } +} + +impl Hash for Stmt { + fn hash(&self, state: &mut H) { + self.kind.hash(state) + } +} + +#[derive(Debug, PartialEq, Clone, Hash)] pub enum StmtKind { // Control flow If { @@ -87,13 +113,25 @@ impl Stmt { /// Expression is parse unit which do not cause any effect, /// like math and logical operations or values. -#[derive(Debug, PartialEq, Clone)] +#[derive(Debug, Clone)] pub struct Expr { pub kind: ExprKind, pub span: Span, } -#[derive(Debug, PartialEq, Clone)] +impl PartialEq for Expr { + fn eq(&self, other: &Self) -> bool { + self.kind == other.kind + } +} + +impl Hash for Expr { + fn hash(&self, state: &mut H) { + self.kind.hash(state) + } +} + +#[derive(Debug, PartialEq, Clone, Hash)] pub enum ExprKind { BinOp { lhs: Box, @@ -116,7 +154,7 @@ impl Expr { } } -#[derive(Debug, PartialEq, Clone)] +#[derive(Debug, PartialEq, Clone, Hash)] pub enum BinOpKind { Add, Subtract, diff --git a/src/variables.rs b/src/variables.rs index 962f4b6..eeaab8d 100644 --- a/src/variables.rs +++ b/src/variables.rs @@ -1,4 +1,7 @@ -use std::{cell::RefCell, collections::HashMap, fmt::Display, hash::Hash, io::Write, rc::Rc}; +use std::{ + cell::RefCell, collections::HashMap, fmt::Display, hash::Hash, io::Write, mem::discriminant, + rc::Rc, +}; use rand::Rng; @@ -31,7 +34,7 @@ impl From for bool { } } -#[derive(Debug, PartialEq, Clone)] +#[derive(Debug, PartialEq, Clone, Hash)] pub enum Functio { BfFunctio { instructions: Vec, @@ -56,13 +59,14 @@ pub enum Value { impl Hash for Value { fn hash(&self, state: &mut H) { + discriminant(self).hash(state); match self { Value::Nul => (), Value::Str(v) => v.hash(state), Value::Int(v) => v.hash(state), Value::Bool(v) => v.hash(state), Value::Abool(v) => v.to_string().hash(state), - Value::Functio(_) => todo!(), + Value::Functio(statements) => statements.hash(state), Value::Cart(_) => self.to_string().hash(state), } } @@ -77,9 +81,7 @@ impl PartialEq for Value { (Value::Bool(left), Value::Bool(right)) => left == right, (Value::Abool(left), Value::Abool(right)) => left == right, (Value::Functio(left), Value::Functio(right)) => left == right, - (Value::Cart(_left), Value::Cart(_right)) => { - todo!() - } + (Value::Cart(_), Value::Cart(_)) => self.to_string() == other.to_string(), (_, _) => false, // TODO: do more coercions! } From aa854a067b1339b148f4529b8a20011e84861ab0 Mon Sep 17 00:00:00 2001 From: Erin Date: Tue, 10 Aug 2021 21:32:12 +0200 Subject: [PATCH 20/22] Restructured project (#37) * Separation to two crates - `ablescript`: library, language - `ablescript_cli` - cli: repl and executor for files * Added lints (back) to library - unsafe_code and unwrap_used are forbidden --- Cargo.lock | 123 +++++++++++++++++---------- Cargo.toml | 20 +---- ablescript/Cargo.toml | 16 ++++ {src => ablescript/src}/ast.rs | 0 {src => ablescript/src}/base_55.rs | 0 {src => ablescript/src}/brian.rs | 0 {src => ablescript/src}/consts.rs | 0 {src => ablescript/src}/error.rs | 0 {src => ablescript/src}/interpret.rs | 0 {src => ablescript/src}/lexer.rs | 0 ablescript/src/lib.rs | 12 +++ {src => ablescript/src}/parser.rs | 0 {src => ablescript/src}/rickroll | 0 {src => ablescript/src}/variables.rs | 0 ablescript_cli/Cargo.toml | 18 ++++ {src => ablescript_cli/src}/main.rs | 17 +--- {src => ablescript_cli/src}/repl.rs | 3 +- 17 files changed, 132 insertions(+), 77 deletions(-) create mode 100644 ablescript/Cargo.toml rename {src => ablescript/src}/ast.rs (100%) rename {src => ablescript/src}/base_55.rs (100%) rename {src => ablescript/src}/brian.rs (100%) rename {src => ablescript/src}/consts.rs (100%) rename {src => ablescript/src}/error.rs (100%) rename {src => ablescript/src}/interpret.rs (100%) rename {src => ablescript/src}/lexer.rs (100%) create mode 100644 ablescript/src/lib.rs rename {src => ablescript/src}/parser.rs (100%) rename {src => ablescript/src}/rickroll (100%) rename {src => ablescript/src}/variables.rs (100%) create mode 100644 ablescript_cli/Cargo.toml rename {src => ablescript_cli/src}/main.rs (89%) rename {src => ablescript_cli/src}/repl.rs (96%) diff --git a/Cargo.lock b/Cargo.lock index 78ceab8..0329313 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3,12 +3,19 @@ version = 3 [[package]] -name = "able-script" +name = "ablescript" version = "0.2.0" dependencies = [ - "clap", "logos", "rand", +] + +[[package]] +name = "ablescript_cli" +version = "0.2.0" +dependencies = [ + "ablescript", + "clap", "rustyline", ] @@ -34,9 +41,9 @@ dependencies = [ [[package]] name = "beef" -version = "0.5.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6736e2428df2ca2848d846c43e88745121a6654696e349ce0054a420815a7409" +checksum = "bed554bd50246729a1ec158d08aa3235d1b69d94ad120ebe187e28894787e736" [[package]] name = "bitflags" @@ -46,9 +53,9 @@ checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" [[package]] name = "cc" -version = "1.0.67" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3c69b077ad434294d3ce9f1f6143a2a4b89a8a2d54ef813d85003a4fd1137fd" +checksum = "e70cc2f62c6ce1868963827bd677764c62d07c3d9a3e1fb1177ee1a9ab199eb2" [[package]] name = "cfg-if" @@ -71,6 +78,17 @@ dependencies = [ "vec_map", ] +[[package]] +name = "clipboard-win" +version = "4.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4ea1881992efc993e4dc50a324cdbd03216e41bdc8385720ff47efc9bd2ca8" +dependencies = [ + "error-code", + "str-buf", + "winapi", +] + [[package]] name = "dirs-next" version = "2.0.0" @@ -99,26 +117,36 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" [[package]] -name = "fnv" -version = "1.0.7" +name = "error-code" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +checksum = "b5115567ac25674e0043e472be13d14e537f37ea8aa4bdc4aef0c89add1db1ff" +dependencies = [ + "libc", + "str-buf", +] [[package]] -name = "fs2" -version = "0.4.3" +name = "fd-lock" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9564fc758e15025b46aa6643b1b77d047d1a56a1aea6e01002ac0c7026876213" +checksum = "0010f02effd88c702318c5dde0463206be67495d0b4d906ba7c0a8f166cc7f06" dependencies = [ "libc", "winapi", ] [[package]] -name = "getrandom" -version = "0.2.2" +name = "fnv" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "getrandom" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" dependencies = [ "cfg-if", "libc", @@ -127,18 +155,18 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.1.18" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" dependencies = [ "libc", ] [[package]] name = "libc" -version = "0.2.93" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9385f66bf6105b241aa65a61cb923ef20efc665cb9f9bb50ac2f0c4b7f378d41" +checksum = "a7f823d141fe0a24df1e23b4af4e3c7ba9e5966ec514ea068c93024aa7deb765" [[package]] name = "log" @@ -175,9 +203,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.3.4" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" +checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc" [[package]] name = "nibble_vec" @@ -208,9 +236,9 @@ checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" [[package]] name = "proc-macro2" -version = "1.0.26" +version = "1.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a152013215dca273577e18d2bf00fa862b89b24169fb78c4c95aeb07992c9cec" +checksum = "5c7ed8b8c7b886ea3ed7dde405212185f423ab44682667c8c6dd14aa1d9f6612" dependencies = [ "unicode-xid", ] @@ -236,9 +264,9 @@ dependencies = [ [[package]] name = "rand" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e" +checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8" dependencies = [ "libc", "rand_chacha", @@ -248,9 +276,9 @@ dependencies = [ [[package]] name = "rand_chacha" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", "rand_core", @@ -258,27 +286,27 @@ dependencies = [ [[package]] name = "rand_core" -version = "0.6.2" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7" +checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" dependencies = [ "getrandom", ] [[package]] name = "rand_hc" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73" +checksum = "d51e9f596de227fda2ea6c84607f5558e196eeaf43c986b724ba4fb8fdf497e7" dependencies = [ "rand_core", ] [[package]] name = "redox_syscall" -version = "0.2.7" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85dd92e586f7355c633911e11f77f3d12f04b1b1bd76a198bd34ae3af8341ef2" +checksum = "8383f39639269cde97d255a32bdb68c047337295414940c68bdd30c2e13203ff" dependencies = [ "bitflags", ] @@ -295,20 +323,21 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.23" +version = "0.6.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24d5f089152e60f62d28b835fbff2cd2e8dc0baf1ac13343bef92ab7eed84548" +checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" [[package]] name = "rustyline" -version = "8.0.0" +version = "8.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9e1b597fcd1eeb1d6b25b493538e5aa19629eb08932184b85fef931ba87e893" +checksum = "fbd4eaf7a7738f76c98e4f0395253ae853be3eb018f7b0bb57fe1b6c17e31874" dependencies = [ "bitflags", "cfg-if", + "clipboard-win", "dirs-next", - "fs2", + "fd-lock", "libc", "log", "memchr", @@ -334,6 +363,12 @@ version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" +[[package]] +name = "str-buf" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d44a3643b4ff9caf57abcee9c2c621d6c03d9135e0d8b589bd9afb5992cb176a" + [[package]] name = "strsim" version = "0.8.0" @@ -342,9 +377,9 @@ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" [[package]] name = "syn" -version = "1.0.69" +version = "1.0.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48fe99c6bd8b1cc636890bcc071842de909d902c81ac7dab53ba33c421ab8ffb" +checksum = "1873d832550d4588c3dbc20f01361ab00bfe741048f71e3fecf145a7cc18b29c" dependencies = [ "proc-macro2", "quote", @@ -362,9 +397,9 @@ dependencies = [ [[package]] name = "unicode-segmentation" -version = "1.7.1" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796" +checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b" [[package]] name = "unicode-width" @@ -374,9 +409,9 @@ checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" [[package]] name = "unicode-xid" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" +checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" [[package]] name = "utf8-ranges" diff --git a/Cargo.toml b/Cargo.toml index 7738841..d893b91 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,18 +1,2 @@ -[package] -name = "able-script" -version = "0.2.0" -authors = ["able "] -edition = "2018" - -description = "The best programming language" -license-file = "LICENSE" -documentation = "https://ablecorp.us/able-script-the-book/" -repository = "https://github.com/AbleCorp/able-script" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -clap = "2.33" -logos = "0.12" -rand = "0.8" -rustyline = "8.0.0" +[workspace] +members = ["ablescript", "ablescript_cli"] \ No newline at end of file diff --git a/ablescript/Cargo.toml b/ablescript/Cargo.toml new file mode 100644 index 0000000..66a6381 --- /dev/null +++ b/ablescript/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "ablescript" +version = "0.2.0" +authors = ["able "] +edition = "2018" + +description = "The best programming language" +license-file = "LICENSE" +documentation = "https://ablecorp.us/able-script-the-book/" +repository = "https://github.com/AbleCorp/able-script" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +logos = "0.12" +rand = "0.8" \ No newline at end of file diff --git a/src/ast.rs b/ablescript/src/ast.rs similarity index 100% rename from src/ast.rs rename to ablescript/src/ast.rs diff --git a/src/base_55.rs b/ablescript/src/base_55.rs similarity index 100% rename from src/base_55.rs rename to ablescript/src/base_55.rs diff --git a/src/brian.rs b/ablescript/src/brian.rs similarity index 100% rename from src/brian.rs rename to ablescript/src/brian.rs diff --git a/src/consts.rs b/ablescript/src/consts.rs similarity index 100% rename from src/consts.rs rename to ablescript/src/consts.rs diff --git a/src/error.rs b/ablescript/src/error.rs similarity index 100% rename from src/error.rs rename to ablescript/src/error.rs diff --git a/src/interpret.rs b/ablescript/src/interpret.rs similarity index 100% rename from src/interpret.rs rename to ablescript/src/interpret.rs diff --git a/src/lexer.rs b/ablescript/src/lexer.rs similarity index 100% rename from src/lexer.rs rename to ablescript/src/lexer.rs diff --git a/ablescript/src/lib.rs b/ablescript/src/lib.rs new file mode 100644 index 0000000..7a4e40b --- /dev/null +++ b/ablescript/src/lib.rs @@ -0,0 +1,12 @@ +#![forbid(unsafe_code, clippy::unwrap_used)] + +pub mod ast; +pub mod interpret; +pub mod parser; + +mod base_55; +mod brian; +mod consts; +mod error; +mod lexer; +mod variables; diff --git a/src/parser.rs b/ablescript/src/parser.rs similarity index 100% rename from src/parser.rs rename to ablescript/src/parser.rs diff --git a/src/rickroll b/ablescript/src/rickroll similarity index 100% rename from src/rickroll rename to ablescript/src/rickroll diff --git a/src/variables.rs b/ablescript/src/variables.rs similarity index 100% rename from src/variables.rs rename to ablescript/src/variables.rs diff --git a/ablescript_cli/Cargo.toml b/ablescript_cli/Cargo.toml new file mode 100644 index 0000000..1561e2c --- /dev/null +++ b/ablescript_cli/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "ablescript_cli" +version = "0.2.0" +authors = ["able "] +edition = "2018" + +description = "The best programming language" +license-file = "LICENSE" +documentation = "https://ablecorp.us/able-script-the-book/" +repository = "https://github.com/AbleCorp/able-script" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +ablescript = { path = "../ablescript" } + +clap = "2.33" +rustyline = "8.0.0" diff --git a/src/main.rs b/ablescript_cli/src/main.rs similarity index 89% rename from src/main.rs rename to ablescript_cli/src/main.rs index 6863062..079dc5c 100644 --- a/src/main.rs +++ b/ablescript_cli/src/main.rs @@ -1,22 +1,11 @@ #![forbid(unsafe_code, clippy::unwrap_used)] - -mod ast; -mod base_55; -mod brian; -mod consts; -mod error; -mod interpret; -mod lexer; -mod parser; mod repl; -mod variables; use std::process::exit; +use ablescript::interpret::ExecEnv; +use ablescript::parser::Parser; use clap::{App, Arg}; -use interpret::ExecEnv; -use logos::Source; -use parser::Parser; fn main() { // variables::test(); // NOTE(Able): Add this as a test case @@ -64,7 +53,7 @@ fn main() { "Error `{:?}` occurred at span: {:?} = `{:?}`", e.kind, e.span.clone(), - source.slice(e.span) + &source[e.span] ); } } diff --git a/src/repl.rs b/ablescript_cli/src/repl.rs similarity index 96% rename from src/repl.rs rename to ablescript_cli/src/repl.rs index fdebf5d..c98a31e 100644 --- a/src/repl.rs +++ b/ablescript_cli/src/repl.rs @@ -1,6 +1,7 @@ use rustyline::Editor; -use crate::{interpret::ExecEnv, parser::Parser}; +use ablescript::interpret::ExecEnv; +use ablescript::parser::Parser; pub fn repl(ast_print: bool) { let mut rl = Editor::<()>::new(); From c70e77f717632d9bd09682642d7b950c074029a6 Mon Sep 17 00:00:00 2001 From: Erin Date: Wed, 11 Aug 2021 20:32:12 +0200 Subject: [PATCH 21/22] Relicensed to MIT --- LICENSE | 24 ++++++++++++++++++------ ablescript/Cargo.toml | 2 +- ablescript_cli/Cargo.toml | 2 +- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/LICENSE b/LICENSE index a460031..b0345ed 100644 --- a/LICENSE +++ b/LICENSE @@ -1,7 +1,19 @@ -You can do whatever you want with this software assuming you meet the following conditions: -1) Answer me why? -2) Never attribute me +Copyright (c) 2021 AbleCorp -You can do whatever you want with this license assuming you meet the following conditions: -1) attribute me -2) I (AbleTheAbove#3819 on discord) own you +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE +OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/ablescript/Cargo.toml b/ablescript/Cargo.toml index 66a6381..5ed7fd1 100644 --- a/ablescript/Cargo.toml +++ b/ablescript/Cargo.toml @@ -5,7 +5,7 @@ authors = ["able "] edition = "2018" description = "The best programming language" -license-file = "LICENSE" +license = "MIT" documentation = "https://ablecorp.us/able-script-the-book/" repository = "https://github.com/AbleCorp/able-script" diff --git a/ablescript_cli/Cargo.toml b/ablescript_cli/Cargo.toml index 1561e2c..55479a4 100644 --- a/ablescript_cli/Cargo.toml +++ b/ablescript_cli/Cargo.toml @@ -5,7 +5,7 @@ authors = ["able "] edition = "2018" description = "The best programming language" -license-file = "LICENSE" +license = "MIT" documentation = "https://ablecorp.us/able-script-the-book/" repository = "https://github.com/AbleCorp/able-script" From 3297605bf22818e08b92dae486d0f35c00ec6642 Mon Sep 17 00:00:00 2001 From: Erin Date: Sun, 15 Aug 2021 00:59:44 +0200 Subject: [PATCH 22/22] Changed license file to MIT from Github template --- LICENSE | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/LICENSE b/LICENSE index b0345ed..010c404 100644 --- a/LICENSE +++ b/LICENSE @@ -1,3 +1,5 @@ +MIT License + Copyright (c) 2021 AbleCorp Permission is hereby granted, free of charge, to any person obtaining a copy @@ -10,10 +12,10 @@ furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE -OR OTHER DEALINGS IN THE SOFTWARE. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE.