profile
viewpoint
CurryPseudo CurryPseudo Tencent 笨蛋一枚 叫我咖喱就好ww

create barnchDanielmelody/Ruschm

branch : feat-deep-clone

created branch time in 6 days

push eventDanielmelody/Ruschm

Daniel

commit sha d36508dc35d97b69becf50bfeabc688486b77ade

refactor: export macro match_expect_type

view details

curryyzheng

commit sha 921e39ffaf35148189ba5e92c1328718a688624f

feat: value expect more

view details

push time in 17 days

PR opened Danielmelody/Ruschm

Reviewers
feat: value expect more
+30 -0

0 comment

1 changed file

pr created time in 17 days

create barnchDanielmelody/Ruschm

branch : feat-expect-more

created branch time in 17 days

startedInternationalDefy/comedy-writer-rs

started time in 25 days

issue commentDanielmelody/Ruschm

vector literal should include procedure call

And also, identifier should evaluate to value while creating literal vector, not as symbol

Ruschm Version 0.1.3
> (define a 1)
> (define b #(a 2))
> (vector-ref b 0)
a
CurryPseudo

comment created time in a month

issue openedDanielmelody/Ruschm

vector literal should include procedure call

src/interpreter/mod.rs minimal:

#(1 2 (vector 1))
thread 'main' panicked at 'internal error: entered unreachable code: expression should not be ProcedureCall(Located { data: Identifier("vector"), location: Some([1, 14]) }, [Located { data: Integer(1), location: Some([1, 16]) }])', src\interpreter\mod.rs:788:18
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: process didn't exit successfully: `target\release\ruschm.exe` (exit code: 101)

created time in a month

push eventDanielmelody/Ruschm

CurryPseudo

commit sha 94f693c2004a206c7321677a0125724880ab4c13

refactor some buildin procedures, wrap Vector in Rc, new buildin procedures (#47) * Use Value::expect_xxx to get the expect type of value, simplify the buildin library code * Add unit test for add, sub, mul, div, greater and min * Refactor Value::Vector to avoid clone, intro mutability * New buildin procedure vector-set!, vector-length and make-vector

view details

push time in a month

PR merged Danielmelody/Ruschm

Reviewers
Refactor some buildin procedures, wrap Vector in Rc, new buildin procedures
  • Use Value::expect_xxx to get the expect type of value, simplify the buildin library code
  • Add unit test for add, sub, mul, div, greater and min
  • Refactor Value::Vector to avoid clone, intro mutability
  • New buildin procedure vector-set!, vector-length and make-vector
+511 -202

0 comment

2 changed files

CurryPseudo

pr closed time in a month

PR opened Danielmelody/Ruschm

Refactor some buildin procedures, wrap Vector in Rc, new buildin procedures
  • Use Value::expect_xxx to get the expect type of value, simplify the buildin library code
  • Add unit test for add, sub, mul, div, greater and min
  • Refactor Value::Vector to avoid clone, intro mutability
  • New buildin procedure vector-set!, vector-length and make-vector
+511 -202

0 comment

2 changed files

pr created time in a month

push eventDanielmelody/Ruschm

Daniel

commit sha f844507741bf7c2d63ddedb4e944272393f72a68

feat: pairs and lists

view details

curryyzheng

commit sha cf307b7a79c9e2dc05e506481c800b660bd6d793

fix: :bug: fix vector-ref error message

view details

curryyzheng

commit sha f621527db3253b63e57aa521cbf7b443b6ae2765

feat: :sparkles: wrap vector in object, add vector-set!, fix vector's parameter

view details

curryyzheng

commit sha c2c9c2e44e05de2ef019439de13e5830d5a5dc71

refactor: :art: clean buildin function error about argument length

view details

curryyzheng

commit sha 2552ac6bbdc713c46493dc6b66f2ef1b8fb0bf46

feat: :sparkles: value expect type

view details

curryyzheng

commit sha 90d38a4f919929aed246e9cb7424f306481b163f

refactor: :art: rename Object to ValueReference, Immutable use Rc

view details

curryyzheng

commit sha 410165154791fca6ef6a92a06a414d923ed370de

feat: :sparkles: make-vector buildin procedure

view details

curryyzheng

commit sha ddc562126a7936b606c222d592a48de1c89d2aaa

feat: :sparkles: vector-length buildin procedure

view details

curryyzheng

commit sha 66cb88e3f8b1fb63b692969e5b1d9e52299d710f

feat: :sparkles: expect_list_or_pair

view details

push time in a month

push eventDanielmelody/Ruschm

curryyzheng

commit sha fe929f744e41f01ab60815eca1e92038f3b3e666

feat: :sparkles: make-vector buildin procedure

view details

curryyzheng

commit sha 28765e8666634bd5131a87d4fca38c25787427e4

feat: :sparkles: vector-length buildin procedure

view details

push time in a month

Pull request review commentDanielmelody/Ruschm

New buildin procedure vector-set!, refactor all buildin procedures.

 pub fn base_library<'a, R: RealNumberInternalTrait, E: IEnvironment<R>>(         ),         function_mapping!("display", vec!["value".to_string()], None, display),         function_mapping!("newline", vec![], None, newline),-        function_mapping!("vector", vec![], None, vector),+        function_mapping!("vector", vec![], Some("x".to_string()), vector),         function_mapping!(             "vector-ref",             vec!["vector".to_string(), "k".to_string()],             None,             vector_ref         ),+        function_mapping!(+            "vector-set!",+            vec!["vector".to_string(), "k".to_string(), "obj".to_string()],

图片 From r7rs

CurryPseudo

comment created time in a month

PullRequestReviewEvent

PR closed Danielmelody/Ruschm

Reviewers
New buildin procedure vector-set!, refactor all buildin procedures.
  • Use Value::expect_xxx to get the expect type of value, simplify the buildin library code
  • Add unit test for add, sub, mul, div, greater and min
  • Refactor Value::Vector to avoid clone, intro mutability
+419 -206

1 comment

2 changed files

CurryPseudo

pr closed time in a month

pull request commentDanielmelody/Ruschm

New buildin procedure vector-set!, refactor all buildin procedures.

Need add more buildin procedure, reopen once finished

CurryPseudo

comment created time in a month

PR opened Danielmelody/Ruschm

Reviewers
New buildin procedure vector-set!, refactor all buildin procedures.
  • Use Value::expect_xxx to get the expect type of value, simplify the buildin library code
  • Add unit test for add, sub, mul, div, greater and min
  • Refactor Value::Vector to avoid clone, intro mutability
+419 -206

0 comment

2 changed files

pr created time in a month

push eventDanielmelody/Ruschm

curryyzheng

commit sha 37b6a979ff933d809aeed35a281ae97336ceba17

feat: :sparkles: value expect type

view details

curryyzheng

commit sha 4d2ec1c268357fd886932a01138ca3db52012de0

refactor: :art: rename Object to ValueReference, Immutable use Rc

view details

push time in a month

create barnchDanielmelody/Ruschm

branch : feat-vector-set

created branch time in a month

push eventDanielmelody/Ruschm

CurryPseudo

commit sha 7fa26936cf1d10b7b90d754125e792f572a8a2a8

Refactor: RefCell on definition other than on environment (#43) * refactor: :art: RefCell on definition other than on environment * feat: :sparkles: enviroment can get_mut * fix: :bug: return (&String, &Value) iterator, improve get_mut's test Co-authored-by: curryyzheng <curryyzheng@tencent.com>

view details

push time in a month

PR merged Danielmelody/Ruschm

Refactor: RefCell on definition other than on environment

Intro cell crate's RefVal for the iter_local_definitions's return value. Now environment get value's reference other than clone, and also has get_mut function

+97 -59

0 comment

3 changed files

CurryPseudo

pr closed time in a month

push eventDanielmelody/Ruschm

curryyzheng

commit sha eecf87b657a0924200e8c5ddb63979c7c41ba63c

fix: :bug: return (&String, &Value) iterator, improve get_mut's test

view details

push time in a month

Pull request review commentDanielmelody/Ruschm

Refactor: RefCell on definition other than on environment

 use crate::interpreter::scheme; use crate::interpreter::Interpreter; use crate::interpreter::RealNumberInternalTrait; use crate::interpreter::Value;-use std::cell::RefCell;+use cell::{Ref, RefCell, RefMut, RefVal}; use std::collections::HashMap; use std::rc::Rc; +pub type DefinitionIter<'a, R, E> = Box<dyn 'a + Iterator<Item = (&'a str, &'a Value<R, E>)>>;+ pub trait IEnvironment<R: RealNumberInternalTrait>: std::fmt::Debug + Clone + PartialEq {     fn new() -> Self     where         Self: Sized;-    fn define(&mut self, name: String, value: Value<R, Self>)+    fn define(&self, name: String, value: Value<R, Self>)+    where+        Self: Sized;+    fn get(&self, name: &str) -> Option<Ref<Value<R, Self>>>     where         Self: Sized;-    fn get(&self, name: &str) -> Option<Value<R, Self>>+    fn get_mut(&self, name: &str) -> Option<RefMut<Value<R, Self>>>     where         Self: Sized;-    fn set(&mut self, name: &str, value: Value<R, Self>) -> Result<(), SchemeError>+    fn set(&self, name: &str, value: Value<R, Self>) -> Result<(), SchemeError>     where         Self: Sized;-    fn new_child(parent: Rc<RefCell<Self>>) -> Self+    fn new_child(parent: Rc<Self>) -> Self     where         Self: Sized; -    fn iter_local_definitions<'a>(-        &'a self,-    ) -> Box<dyn 'a + Iterator<Item = (&'a String, &'a Value<R, Self>)>>;+    fn iter_local_definitions<'a, 'b: 'a>(&'b self) -> RefVal<'a, DefinitionIter<'b, R, Self>>; }  #[derive(Clone, Debug, PartialEq)] pub struct StandardEnv<R: RealNumberInternalTrait> {-    parent: Option<Rc<RefCell<StandardEnv<R>>>>,-    definitions: HashMap<String, Value<R, StandardEnv<R>>>,+    parent: Option<Rc<StandardEnv<R>>>,+    definitions: RefCell<HashMap<String, Value<R, StandardEnv<R>>>>, }  impl<R: RealNumberInternalTrait> IEnvironment<R> for StandardEnv<R> {-    // type DefinitionCollection = std::collections::hash_map::Iter<'a, String, Value<R, StandardEnv<R>>>;-     fn new() -> Self {         Self {             parent: None,-            definitions: scheme::base::base_library::<R, StandardEnv<R>>(),+            definitions: RefCell::new(scheme::base::base_library::<R, StandardEnv<R>>()),         }     }-    fn new_child(parent: Rc<RefCell<StandardEnv<R>>>) -> Self {+    fn new_child(parent: Rc<StandardEnv<R>>) -> Self {         Self {             parent: Some(parent),-            definitions: HashMap::new(),+            definitions: RefCell::new(HashMap::new()),         }     } -    fn define(&mut self, name: String, value: Value<R, Self>) {-        self.definitions.insert(name, value);+    fn define(&self, name: String, value: Value<R, Self>) {+        self.definitions.borrow_mut().insert(name, value);     } -    fn get(&self, name: &str) -> Option<Value<R, Self>> {-        match self.definitions.get(name) {-            None => match &self.parent {-                None => return None,-                Some(parent) => parent.borrow().get(name),-            },-            Some(value) => Some(value.clone()),+    fn get(&self, name: &str) -> Option<Ref<Value<R, Self>>> {+        if self.definitions.borrow().contains_key(name) {+            Some(Ref::map(self.definitions.borrow(), |definitions| {+                definitions.get(name).unwrap()+            }))+        } else {+            match &self.parent {+                Some(parent) => parent.get(name),+                None => None,+            }+        }+    }+    fn get_mut(&self, name: &str) -> Option<RefMut<Value<R, Self>>> {+        if self.definitions.borrow().contains_key(name) {+            Some(RefMut::map(self.definitions.borrow_mut(), |definitions| {+                definitions.get_mut(name).unwrap()+            }))+        } else {+            match &self.parent {+                Some(parent) => parent.get_mut(name),+                None => None,+            }         }     } -    fn set(&mut self, name: &str, value: Value<R, Self>) -> Result<(), SchemeError> {-        match self.definitions.get_mut(name) {+    fn set(&self, name: &str, value: Value<R, Self>) -> Result<(), SchemeError> {+        match self.definitions.borrow_mut().get_mut(name) {             None => match &self.parent {                 None => logic_error!("unbound variable {}", name),-                Some(parent) => parent.borrow_mut().set(name, value)?,+                Some(parent) => parent.set(name, value)?,             },             Some(variable) => *variable = value,         };         Ok(())     } -    fn iter_local_definitions<'a>(-        &'a self,-    ) -> Box<dyn 'a + Iterator<Item = (&'a String, &'a Value<R, Self>)>> {-        Box::new(self.definitions.iter())+    fn iter_local_definitions<'a, 'b: 'a>(&'b self) -> RefVal<'a, DefinitionIter<'b, R, Self>> {+        Ref::map_val(self.definitions.borrow(), |definitions| {+            let iter: DefinitionIter<'b, R, Self> =+                Box::new(definitions.iter().map(|(s, v)| (s.as_str(), v)));

Because the return iterator is for item type (&str, &Value), not for (&String, &Value), so as_str is required. I think &str is more general than &String, so I change the item type.

CurryPseudo

comment created time in 2 months

PullRequestReviewEvent

PR opened Danielmelody/Ruschm

Refactor: RefCell on definition other than on environment

Intro cell crate's RefVal for the iter_local_definitions's return value. Now environment get value's reference other than clone, and also has get_mut function

+88 -59

0 comment

3 changed files

pr created time in 2 months

push eventDanielmelody/Ruschm

curryyzheng

commit sha 6dc8bb74ebabb087ff66a4f9ae4bcac78732a2e9

feat: :sparkles: enviroment can get_mut

view details

push time in 2 months

push eventDanielmelody/Ruschm

yiminghu

commit sha c6d4a162336436c9bc84d28fa76f25a4ada85578

initial commit

view details

yiminghu

commit sha 79fc8f8f6dc7296aa56edf82d6dd82981650ce06

Add GPL License

view details

The Gitter Badger

commit sha 72ac42b621d9e0482f60a56df3fb02e8d1a2d3b0

Add Gitter badge

view details

xu0o0

commit sha d3ca2a2d514767c6a367044045ad4934efaabbdd

chore(build): typo

view details

xu0o0

commit sha 404e09e0d0b98adea2e57a13a683c2aec15dce77

chore: add .editorconfig Use EditorConfig to define and maintain consistent coding styles

view details

xu0o0

commit sha 9b70ee76b81369d81ac2af43e2566ef1e809f648

chore(git): update .gitignore Ignore tag files.

view details

yiminghu

commit sha 55aac33b42a474399ca7d5727fb87ad5e797283b

:construction_worker: ignore Cargo.lock

view details

yiminghu

commit sha 5e14876369dd79a12ca180951f0bad9c75e4d2f3

:construction_worker: rename repo

view details

yiminghu

commit sha 6b0a0555851265de5cc3faf74e96dded6d349ddb

fix cargo edition

view details

yiminghu

commit sha 262dc06478dc4cde58d45e5ef31f90f9286f7468

test

view details

yiminghu

commit sha a9cc9a36c0a18c021d5973797ce8d8a21e6091c0

re-track Cargo.lock

view details

yiminghu

commit sha d795990b5ca3ae4239b20259e5ce95bbebc5b61d

Create default.yml

view details

yiminghu

commit sha 20f455148ee2e1e29fb636ee02273fbe07eb207b

Update default.yml

view details

yiminghu

commit sha 9cf647615df5e87e27bb3111b38b41e86bcc4d19

add build status badge to README

view details

yiminghu

commit sha 356fd702a632090cc20968c0cff4591901e11baf

Create workflow.yml

view details

yiminghu

commit sha 0163dce3899089b6b95b48cd3d184e7407625af7

feat(lexer): simple tokens

view details

yiminghu

commit sha ff30832fdf581e58ac1cabc900cf01352e2d5501

feat(lexer): identifier

view details

yiminghu

commit sha 2f1f7ef7174db6658bd19fd76f768cfa0d82595e

feat(lexer): character

view details

yiminghu

commit sha 9a21a23e77b5c916947fe2762ec271dead165cdc

feat(lexer): string

view details

yiminghu

commit sha e50c16354f6424c627c7feccbde9f96887e20fba

refactor(lexer): retarget to r7r5

view details

push time in 2 months

started38/plotters

started time in 2 months

PullRequestReviewEvent

pull request commentDanielmelody/Ruschm

feat: buildin procedures

new buildin procedures:

  • vector-ref
  • floor
  • ceiling
  • floor-quotient
  • floor-remainder
  • exact
CurryPseudo

comment created time in 2 months

PullRequestEvent

push eventDanielmelody/Ruschm

curryyzheng

commit sha fed4c76d7e85831d0017fa46e21645856dd4acdc

feat: :sparkles: new buildin function ceiling

view details

push time in 2 months

pull request commentDanielmelody/Ruschm

feat: buildin procedure for implement ordered dither

Maybe need another buildin function ceiling

CurryPseudo

comment created time in 2 months

Pull request review commentDanielmelody/Ruschm

feat: buildin procedure for implement ordered dither

 impl<R: RealNumberInternalTrait> std::ops::Div<Number<R>> for Number<R> {     } } +impl<R: RealNumberInternalTrait> Number<R> {+    pub fn sqrt(self) -> Self {+        match self {+            Number::Integer(num) => Number::Real(R::from(num).unwrap().sqrt()),+            Number::Real(num) => Number::Real(num.sqrt()),+            Number::Rational(a, b) => {+                Number::Real(R::from(a).unwrap() / R::from(b).unwrap().sqrt())+            }+        }+    }+    pub fn floor(self) -> Self {+        match self {+            Number::Integer(num) => Number::Integer(num),+            Number::Real(num) => Number::Real(num.floor()),+            Number::Rational(a, b) => Number::Integer({+                let quot = a / b;+                if quot >= 0 || quot * b == a {+                    quot+                } else {+                    quot - 1+                }+            }),+        }+    }++    pub fn floor_quotient(self, rhs: Self) -> Result<Self> {+        Ok((self / rhs)?.floor())+    }++    pub fn floor_remainder(self, rhs: Self) -> Result<Self> {+        Ok(self - self.floor_quotient(rhs)? * rhs)+    }++    // Return an exact number that is numerically closest to the given number+    pub fn exact(self) -> Result<Self> {+        match self {+            Number::Real(num) => match num.round().to_i32() {+                Some(i) => Ok(Number::Integer(i)),+                None => logic_error!("cannot be converted to an exact number"),+            },+            exact => Ok(exact),+        }+    }+}+#[test]+fn number_floor() {+    assert_eq!(Number::<f32>::Integer(5).floor(), Number::Integer(5));+    assert_eq!(Number::<f32>::Rational(28, 3).floor(), Number::Integer(9));+    assert_eq!(Number::<f32>::Rational(-43, 7).floor(), Number::Integer(-7));+    assert_eq!(Number::<f32>::Rational(43, -7).floor(), Number::Integer(-7));

Fixed 8e720e2

CurryPseudo

comment created time in 2 months

PullRequestReviewEvent

push eventDanielmelody/Ruschm

curryyzheng

commit sha 8e720e2a7561b6e2589aa1c62da521a9716c7c19

fix: :bug: remove a test that use a rational number with negative denominator

view details

push time in 2 months

push eventDanielmelody/Ruschm

curryyzheng

commit sha 97965ac88c4a4a2c74abee6fc5ca35056672311f

fix: :bug: fix the logic_error message in div function

view details

Danielhu

commit sha 8f00fd4987fa096b595934cdf781de910015001e

feat: report error location when interpreting files

view details

Danielhu

commit sha d83974cdd7f00bf64e8dbbf155725377a457b415

fix(interpreter): remove unused assignment before apply_procedure

view details

Daniel

commit sha d598fc159356b58402e059d72e1dcd4f3cb293ee

fix(lexer): prevent rational number denominator being zero (#39) Co-authored-by: CurryPseudo <currypseudo@gmail.com>

view details

Danielhu

commit sha 4414337ce4282ec028155c841ce15fdd1fc72152

feat: :sparkles: user defined variadic function

view details

curryyzheng

commit sha 033d34a1e23680b62bede22381a3b7f764959735

feat: new buildin procedure: vector-ref, floor, floor-quotient, floor-remainder, exact * feat: :sparkles: new buildin procedure vector-ref * refactor: :art: move buildin function out of base_library function, change vector-ref implementation from swap_remove to clone value * test: :white_check_mark: delete unecessary example, add vector-ref unit test * refactor: :art: change vector_ref test name * test: :white_check_mark: add missing vector_ref unit test about error * feat: :sparkles: new buildin function floor * refactor: :art: move floor logic to Number struct * fix: :bug: fix number floor * feat: :sparkles: new buildint funtion floor-quotient and floor-remainder * refactor: :art: macro numeric_one * refactor: :art: macro numeric_two * refactor: :art: rename numeric_one and numeric_two, add err_handle variant support * feat: :sparkles: exact buildin function

view details

push time in 2 months

PullRequestReviewEvent

startedlextm/windowsterminal-shell

started time in 2 months

startedkerol2r20/Windows-terminal-context-menu

started time in 2 months

push eventDanielmelody/Ruschm

Daniel

commit sha d598fc159356b58402e059d72e1dcd4f3cb293ee

fix(lexer): prevent rational number denominator being zero (#39) Co-authored-by: CurryPseudo <currypseudo@gmail.com>

view details

push time in 2 months

push eventDanielmelody/Ruschm

CurryPseudo

commit sha fea93dec2670aab99e191589d04477c55c9dbbe6

Merge branch 'master' into fix-rational

view details

push time in 2 months

push eventDanielmelody/Ruschm

CurryPseudo

commit sha d96ac14cd08a8a68798330f510d6b30a502277ac

feat(interpreter): tail recursion optimization * refactor: :art: wrap (Box<Expression>, Vec<Expression>) into struct ProcedureCall in Expression::ProcedureCall variant * feat: :sparkles: proper tail recursion * test: :white_check_mark: add fib-tail and sum-tail scheme code example * fix: :bug: always create local_env for procedure, even tail call (Rc pointer will destroy unused env), remove unecessary api * test: :white_check_mark: add unit test for eval_tail_expression * test: :white_check_mark: edit fib-tail and sum-tail example to do perfermance test * Revert "refactor: :art: wrap (Box<Expression>, Vec<Expression>) into struct ProcedureCall in Expression::ProcedureCall variant" This reverts commit 84da2194d3fdcfbf0b6bfe36fa5b4533024c2eb2. Co-authored-by: curryyzheng <curryyzheng@tencent.com>

view details

CurryPseudo

commit sha 0e2ea6a53a8fdec068d1e4b374531b7f6f4e1719

fix: :bug: broken public function Interpreter::apply_procedure (#33) * fix: :bug: fix broken public function Interpreter::apply_procedure * refactor: :art: remove redundent variable Co-authored-by: curryyzheng <curryyzheng@tencent.com>

view details

CurryPseudo

commit sha 20eca2c6880b2c249ca216dbe5976272bca3e8c0

feat: :sparkles: add impure function pointer variant in BuildinProcedure (#34) * feat: :sparkles: add impure function pointer variant in BuildinProcedure * refactor: :art: rename closure to env in BuildinProcedurePointer * refactor: :art: move closure out of impure, use apply_procedure pass env, revert IEnvironment::new Co-authored-by: curryyzheng <curryyzheng@tencent.com>

view details

curryyzheng

commit sha 97965ac88c4a4a2c74abee6fc5ca35056672311f

fix: :bug: fix the logic_error message in div function

view details

Danielhu

commit sha 8f00fd4987fa096b595934cdf781de910015001e

feat: report error location when interpreting files

view details

Danielhu

commit sha d83974cdd7f00bf64e8dbbf155725377a457b415

fix(interpreter): remove unused assignment before apply_procedure

view details

CurryPseudo

commit sha 7cf3e56c88daee2e8a344f11127ebd498404322a

Merge branch 'master' into fix-rational

view details

push time in 2 months

PullRequestReviewEvent

Pull request review commentDanielmelody/Ruschm

feat: report error location when interpreting files

 use std::error::Error; use std::fmt; +use fmt::Display;+ #[derive(Debug, PartialEq)] pub enum ErrorType {     Lexical,     Syntax,     Logic, }+#[derive(Debug, Clone)]+pub struct Located<T: PartialEq + Display> {+    pub data: T,+    pub location: Option<[u32; 2]>,+}++impl<T: PartialEq + Display> Located<T> {+    pub fn from_data(data: T) -> Self {+        Self {+            data,+            location: None,+        }+    }++    pub fn set_location(mut self, location: Option<[u32; 2]>) -> Self {

Ok, I get it. But, for builder pattern, I think with_location or located is more appropriate.

Danielmelody

comment created time in 2 months

PullRequestReviewEvent

Pull request review commentDanielmelody/Ruschm

feat: report error location when interpreting files

 impl<R: RealNumberInternalTrait, E: IEnvironment<R>> Interpreter<R, E> {                     _ => logic_error!("if condition should be a boolean expression"),                 }             }-            other => TailExpressionResult::Value(Self::eval_expression(&other, &env)?),+            _ => TailExpressionResult::Value(Self::eval_expression(&expression, &env)?),         })     }      pub fn eval_expression(expression: &Expression, env: &Rc<RefCell<E>>) -> Result<Value<R, E>> {-        Ok(match expression {-            Expression::ProcedureCall(procedure_expr, arguments) => {-                let (procedure, args) = Self::eval_procedure_call(procedure_expr, arguments, env)?;-                Self::apply_procedure(&procedure, args, env)?+        Ok(match &expression.data {+            ExpressionBody::ProcedureCall(procedure_expr, arguments) => {+                let first = Self::eval_expression(procedure_expr, env)?;+                let evaluated_args: Result<ArgVec<R, E>> = arguments+                    .into_iter()+                    .map(|arg| Self::eval_expression(arg, env))+                    .collect();+                match first {+                    Value::Procedure(procedure) => {+                        Self::apply_procedure(&procedure, evaluated_args?, env)?+                    }+                    _ => logic_error_with_location!(expression.location, "expect a procedure here"),

Consider using eval_procedure_call function, and change eval_procedure_call's logic_error to logic_error_with_location

Danielmelody

comment created time in 2 months

Pull request review commentDanielmelody/Ruschm

feat: report error location when interpreting files

 use std::error::Error; use std::fmt; +use fmt::Display;+ #[derive(Debug, PartialEq)] pub enum ErrorType {     Lexical,     Syntax,     Logic, }+#[derive(Debug, Clone)]+pub struct Located<T: PartialEq + Display> {+    pub data: T,+    pub location: Option<[u32; 2]>,+}++impl<T: PartialEq + Display> Located<T> {+    pub fn from_data(data: T) -> Self {+        Self {+            data,+            location: None,+        }+    }++    pub fn set_location(mut self, location: Option<[u32; 2]>) -> Self {

Consider using name into_with_location, set_xxx usually for &mut self

Danielmelody

comment created time in 2 months

PullRequestReviewEvent
PullRequestReviewEvent

PR closed Danielmelody/Ruschm

Reviewers
feat: :sparkles: floor buildin function
+21 -0

1 comment

1 changed file

CurryPseudo

pr closed time in 2 months

pull request commentDanielmelody/Ruschm

feat: :sparkles: floor buildin function

Closed, merge into #36

CurryPseudo

comment created time in 2 months

Pull request review commentDanielmelody/Ruschm

feat: :sparkles: floor buildin function

 pub fn base_library<'a, R: RealNumberInternalTrait, E: IEnvironment<R>>(         }     } +    fn floor<R: RealNumberInternalTrait, E: IEnvironment<R>>(+        arguments: impl IntoIterator<Item = Value<R, E>>,+    ) -> Result<Value<R, E>> {+        match arguments.into_iter().next() {+            Some(Value::Number(number)) => Ok(Value::Number(match number {+                Number::Integer(num) => Number::Integer(num),+                Number::Real(num) => Number::Integer(num.floor().to_i32().unwrap()),+                Number::Rational(a, _) => {+                    if a >= 0 {+                        Number::Integer(a)+                    } else {+                        Number::Integer(a - 1)+                    }+                }

Oh, I misunderstand Number::Rational, my wrong, I will fix it

CurryPseudo

comment created time in 2 months

PullRequestReviewEvent

PR opened Danielmelody/Ruschm

feat: :sparkles: floor buildin function
+21 -0

0 comment

1 changed file

pr created time in 2 months

create barnchDanielmelody/Ruschm

branch : feat-floor

created branch time in 2 months

PR opened Danielmelody/Ruschm

Reviewers
feat: vector-ref buildin procedure
+28 -0

0 comment

2 changed files

pr created time in 2 months

create barnchDanielmelody/Ruschm

branch : feat-vector-ref

created branch time in 2 months

PR opened Danielmelody/Ruschm

fix: :bug: fix the logic_error message in div function

Less argument error message in buildin div function is wrong.

+1 -1

0 comment

1 changed file

pr created time in 2 months

create barnchDanielmelody/Ruschm

branch : fix-div-error

created branch time in 2 months

push eventDanielmelody/Ruschm

curryyzheng

commit sha 61aa9d9bf43845ab9f5559cf57ddbec5908b3cc1

refactor: :art: move closure out of impure, use apply_procedure pass env, revert IEnvironment::new

view details

push time in 2 months

push eventDanielmelody/Ruschm

curryyzheng

commit sha af4ed739a90f9e3196b76e62c1111f47b4dcf7ec

refactor: :art: rename closure to env in BuildinProcedurePointer

view details

push time in 2 months

PR opened Danielmelody/Ruschm

Reviewers
feat: :sparkles: add impure function pointer variant in BuildinProcedure

Some buildin procedure do need some side effect for environment(for example, bind a texture slot, in you-know-what), so we need to add env to function pointer.

+52 -21

0 comment

3 changed files

pr created time in 2 months

create barnchDanielmelody/Ruschm

branch : feat-impure-buildin-function-pointer

created branch time in 2 months

push eventDanielmelody/Ruschm

curryyzheng

commit sha e12245165287f63afd892121a4d65d72685cb571

refactor: :art: remove redundent variable

view details

push time in 2 months

PR opened Danielmelody/Ruschm

Reviewers
fix: :bug: fix broken public function Interpreter::apply_procedure

Previous PR #31 accidently broke public api Interpreter::apply_procedure, now fix it

+64 -59

0 comment

1 changed file

pr created time in 2 months

create barnchDanielmelody/Ruschm

branch : fix-apply-procedure

created branch time in 2 months

PR opened Danielmelody/Ruschm

Refactor: IEnvironment::get return Ref<Value> other than Value

IEnvironment::get should return Ref<Value> to do further optimization (like not to clone but reference a procedure). But this involves iter_local_definition's api changing, I think it's not a big problem.

+59 -54

0 comment

2 changed files

pr created time in 2 months

create barnchDanielmelody/Ruschm

branch : refactor-env-get-value-ref

created branch time in 2 months

delete branch Danielmelody/Ruschm

delete branch : feat-proper-tail-recursion

delete time in 2 months

push eventDanielmelody/Ruschm

curryyzheng

commit sha 78800a0c073f6f7a76613a8cace0ec01a21bebdd

fix: :bug: always create local_env for procedure, even tail call (Rc pointer will destroy unused env), remove unecessary api

view details

curryyzheng

commit sha 047f7d62b31eb2f639132517f26d135cf4d22b27

test: :white_check_mark: add unit test for eval_tail_expression

view details

curryyzheng

commit sha 1250823c5eebd5a1bab546876996280d3798b5b7

test: :white_check_mark: edit fib-tail and sum-tail example to do perfermance test

view details

curryyzheng

commit sha 9849f48e3be2fcca0ed4e1960df6ccf5f3b7b9ce

Revert "refactor: :art: wrap (Box<Expression>, Vec<Expression>) into struct ProcedureCall in Expression::ProcedureCall variant" This reverts commit 84da2194d3fdcfbf0b6bfe36fa5b4533024c2eb2.

view details

push time in 2 months

Pull request review commentDanielmelody/Ruschm

Feat proper tail recursion

 fn definition() -> Result<()> {                     "add".to_string(),                     simple_procedure(                         vec!["x".to_string(), "y".to_string()],-                        Expression::ProcedureCall(+                        Expression::ProcedureCall(ProcedureCall::new(                             Box::new(Expression::Identifier("+".to_string())),                             vec![                                 Expression::Identifier("x".to_string()),                                 Expression::Identifier("y".to_string()),                             ]-                        )+                        ))+                    )+                ))+            )+        }+        {+            let tokens = vec![

Ok, I will add some tests for eval_tail_expression

CurryPseudo

comment created time in 2 months

PullRequestReviewEvent

Pull request review commentDanielmelody/Ruschm

Feat proper tail recursion

 impl fmt::Display for Expression {     } } +#[derive(PartialEq, Debug, Clone)]+pub struct ProcedureCall {

I think new struct is necessary for simplify code here and here. Or else I would need to unpack enum variant to tuple, pass tuple around, maybe intro a new type alias, etc.

CurryPseudo

comment created time in 2 months

PullRequestReviewEvent

PR opened Danielmelody/Ruschm

Reviewers
Feat proper tail recursion

With this scheme example:

(define (sum-internal acc i x)
    (define i-plus-one (+ i 1))
    (if (< i x)
        (sum-internal (+ acc i-plus-one) i-plus-one x)
        acc
    )
)
(define (sum x)
    (sum-internal 0 0 x)
)
(display (sum 40))
(newline)
(display (sum 100))
(newline)
(display (sum 200))
(newline)
(display (sum 60000))
(newline)

In master branch(without proper tail recursion):

PS C:\Dev\Ruschm> cargo run .\examples\sum-tail.scm # debug build
    Finished dev [unoptimized + debuginfo] target(s) in 0.04s
     Running `target\debug\ruschm.exe .\examples\sum-tail.scm`
820

thread 'main' has overflowed its stack
error: process didn't exit successfully: `target\debug\ruschm.exe .\examples\sum-tail.scm` (exit code: 0xc00000fd, STATUS_STACK_OVERFLOW)

Debug build's stack will overflowed for evaluate (sum 100).

PS C:\Dev\Ruschm> cargo run --release .\examples\sum-tail.scm # release build
   Compiling ruschm v0.1.3 (C:\Dev\Ruschm)
    Finished release [optimized] target(s) in 5.08s
     Running `target\release\ruschm.exe .\examples\sum-tail.scm`
820
5050

thread 'main' has overflowed its stack
error: process didn't exit successfully: `target\release\ruschm.exe .\examples\sum-tail.scm` (exit code: 0xc00000fd, STATUS_STACK_OVERFLOW)

Release build's stack will overflowed for evaluate (sum 200).

While, in this feat-proper-tail-recursion branch(with proper tail recursion):

PS C:\Dev\Ruschm> cargo run .\examples\sum-tail.scm # debug build
   Compiling ruschm v0.1.3 (C:\Dev\Ruschm)
    Finished dev [unoptimized + debuginfo] target(s) in 2.60s
     Running `target\debug\ruschm.exe .\examples\sum-tail.scm`
820
5050
20100
1800030000

Debug build is enough to evaluate (sum 60000).

This is a benchmark for release build:

PS C:\Dev\Ruschm> hyperfine "cargo run --release .\examples\sum-tail.scm" --prepare "cargo build --release" --warmup 5
Benchmark #1: cargo run --release .\examples\sum-tail.scm                                                              0
  Time (mean ± σ):     712.3 ms ± 485.4 ms    [User: 1.4 ms, System: 6.3 ms]                                           0
  Range (min … max):   498.6 ms … 2087.1 ms    10 runs
+309 -111

0 comment

5 changed files

pr created time in 2 months

push eventDanielmelody/Ruschm

curryyzheng

commit sha 84da2194d3fdcfbf0b6bfe36fa5b4533024c2eb2

refactor: :art: wrap (Box<Expression>, Vec<Expression>) into struct ProcedureCall in Expression::ProcedureCall variant

view details

curryyzheng

commit sha 09872811012f62e07b631ac7b51625894048a1b8

feat: :sparkles: proper tail recursion

view details

curryyzheng

commit sha d869a091d9fae7196d8f3e71efd3147fe4ba1c77

test: :white_check_mark: add fib-tail and sum-tail scheme code example

view details

push time in 2 months

Pull request review commentDanielmelody/Ruschm

feat: :sparkles: proper tail recursion

 impl<R: RealNumberInternalTrait, E: IEnvironment<R>> Interpreter<R, E> {         }     } -    fn apply_scheme_procedure(+    fn init_procedure_env(         formals: &Vec<String>,         internal_definitions: &Vec<Definition>,         expressions: &Vec<Expression>,-        closure: Rc<RefCell<E>>,+        env: &Rc<RefCell<E>>,         args: ArgVec<R, E>,     ) -> Result<Value<R, E>> {-        let local_env = Rc::new(RefCell::new(E::new_child(closure.clone())));         for (param, arg) in formals.iter().zip(args.into_iter()) {-            local_env.borrow_mut().define(param.clone(), arg);+            env.borrow_mut().define(param.clone(), arg);         }         for Definition(name, expr) in internal_definitions {-            let value = Self::eval_expression(&expr, &local_env)?;-            local_env.borrow_mut().define(name.clone(), value)+            let value = Self::eval_expression(&expr, &env)?;+            env.borrow_mut().define(name.clone(), value)         }         match expressions.split_last() {             Some((last, before_last)) => {                 for expr in before_last {-                    Self::eval_expression(expr, &local_env)?;+                    Self::eval_expression(expr, &env)?;                 }-                Self::eval_expression(last, &local_env)+                Self::eval_expression(last, &env)             }             None => logic_error!("no expression in function body"),         }     } +    fn apply_scheme_procedure(+        formals: &Vec<String>,+        internal_definitions: &Vec<Definition>,+        expressions: &Vec<Expression>,+        closure: Rc<RefCell<E>>,+        args: ArgVec<R, E>,+        is_tail: bool,+    ) -> Result<Value<R, E>> {+        let mut _local_env = None;

And also, try add some tests?

Yeah, I do add a long test in parser::definition(parser.rs), and edit some old test to suit the change(parser.rs, parser.rs, parser.rs)

CurryPseudo

comment created time in 2 months

PullRequestReviewEvent

Pull request review commentDanielmelody/Ruschm

feat: :sparkles: proper tail recursion

 impl<R: RealNumberInternalTrait, E: IEnvironment<R>> Interpreter<R, E> {         }     } -    fn apply_scheme_procedure(+    fn init_procedure_env(         formals: &Vec<String>,         internal_definitions: &Vec<Definition>,         expressions: &Vec<Expression>,-        closure: Rc<RefCell<E>>,+        env: &Rc<RefCell<E>>,         args: ArgVec<R, E>,     ) -> Result<Value<R, E>> {-        let local_env = Rc::new(RefCell::new(E::new_child(closure.clone())));         for (param, arg) in formals.iter().zip(args.into_iter()) {-            local_env.borrow_mut().define(param.clone(), arg);+            env.borrow_mut().define(param.clone(), arg);         }         for Definition(name, expr) in internal_definitions {-            let value = Self::eval_expression(&expr, &local_env)?;-            local_env.borrow_mut().define(name.clone(), value)+            let value = Self::eval_expression(&expr, &env)?;+            env.borrow_mut().define(name.clone(), value)         }         match expressions.split_last() {             Some((last, before_last)) => {                 for expr in before_last {-                    Self::eval_expression(expr, &local_env)?;+                    Self::eval_expression(expr, &env)?;                 }-                Self::eval_expression(last, &local_env)+                Self::eval_expression(last, &env)             }             None => logic_error!("no expression in function body"),         }     } +    fn apply_scheme_procedure(+        formals: &Vec<String>,+        internal_definitions: &Vec<Definition>,+        expressions: &Vec<Expression>,+        closure: Rc<RefCell<E>>,+        args: ArgVec<R, E>,+        is_tail: bool,+    ) -> Result<Value<R, E>> {+        let mut _local_env = None;

variable should not begin with an underscore. https://doc.rust-lang.org/1.0.0/style/style/naming/README.html

        let mut local_env = None;
        let closure_ref = if is_tail {
            closure.borrow_mut().clear_definition();
            &closure
        } else {
            local_env = Some(Rc::new(RefCell::new(E::new_child(closure.clone()))));
            &local_env.as_ref().unwrap()
        };

If I write the code like this, rustc will warn: warning: value assigned to local_env is never read --> src\interpreter\mod.rs:320:13 | 320 | let mut local_env = None; | ^^^^^^^^^^^^^ | = note: #[warn(unused_assignments)] on by default = help: maybe it is overwritten before being read?

warning: 1 warning emitted

CurryPseudo

comment created time in 2 months

push eventDanielmelody/Ruschm

curryyzheng

commit sha 74ba504ed5239db60a65c820fc632499ce101b20

perf: :zap: only clear definition other than create new enviroment when apply tail procedure, to avoid import base library

view details

push time in 2 months

create barnchDanielmelody/Ruschm

branch : feat-proper-tail-recursion

created branch time in 2 months

startedsharkdp/hyperfine

started time in 2 months

issue closedDanielhu229/Ruschm

Ambiguous function name "child" in trait IEnvironment

environment.rs "child" often means get a reference of the parent node's child node, recommands to use function name "new_child".

closed time in 2 months

CurryPseudo

push eventCurryPseudo/Ruschm

curryyzheng

commit sha 374e020c8f2da5f1b2db9c24aa7c5a13550be36c

refactor: rename IEnviroment::child to IEnvironment::new_child

view details

push time in 2 months

fork CurryPseudo/Ruschm

Scheme(R7RS) interpretor/compiler rust implementation

fork in 2 months

issue openedDanielhu229/Ruschm

Ambiguous function name "child" in trait IEnvironment

environment.rs "child" often means get a reference of the parent node's child node. Recommands to use function name "new_child".

created time in 2 months

startedDanielhu229/Ruschm

started time in 2 months

startedeqrion/cbindgen

started time in 2 months

startedgoogle/autocxx

started time in 2 months

startedshunf4/proxychains-windows

started time in 2 months

startedocornut/imgui

started time in 2 months

startedtylearymf/SETUNA2

started time in 2 months

push eventCurryPseudo/curry-pbrt

CurryPseudo

commit sha 3fae32a227149eb2d0ad4ee4b2178090d3b04120

Update readme.md

view details

push time in 3 months

PublicEvent
more