CurryPseudo/bingyan-summer-camp-2018 3
2018游戏组夏令营
CurryPseudo/Slither.io-SinglePlayer 2
a single player copy version of slither.io
A soft 2d light implement in unity
A pixel running game
push eventDanielmelody/Ruschm
commit sha d36508dc35d97b69becf50bfeabc688486b77ade
refactor: export macro match_expect_type
commit sha 921e39ffaf35148189ba5e92c1328718a688624f
feat: value expect more
push 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
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
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
push time in a month
PR merged Danielmelody/Ruschm
- 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
pr closed time in a month
PR opened Danielmelody/Ruschm
- 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
pr created time in a month
push eventDanielmelody/Ruschm
commit sha f844507741bf7c2d63ddedb4e944272393f72a68
feat: pairs and lists
commit sha cf307b7a79c9e2dc05e506481c800b660bd6d793
fix: :bug: fix vector-ref error message
commit sha f621527db3253b63e57aa521cbf7b443b6ae2765
feat: :sparkles: wrap vector in object, add vector-set!, fix vector's parameter
commit sha c2c9c2e44e05de2ef019439de13e5830d5a5dc71
refactor: :art: clean buildin function error about argument length
commit sha 2552ac6bbdc713c46493dc6b66f2ef1b8fb0bf46
feat: :sparkles: value expect type
commit sha 90d38a4f919929aed246e9cb7424f306481b163f
refactor: :art: rename Object to ValueReference, Immutable use Rc
commit sha 410165154791fca6ef6a92a06a414d923ed370de
feat: :sparkles: make-vector buildin procedure
commit sha ddc562126a7936b606c222d592a48de1c89d2aaa
feat: :sparkles: vector-length buildin procedure
commit sha 66cb88e3f8b1fb63b692969e5b1d9e52299d710f
feat: :sparkles: expect_list_or_pair
push time in a month
push eventDanielmelody/Ruschm
commit sha fe929f744e41f01ab60815eca1e92038f3b3e666
feat: :sparkles: make-vector buildin procedure
commit sha 28765e8666634bd5131a87d4fca38c25787427e4
feat: :sparkles: vector-length buildin procedure
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
comment created time in a month
PR closed Danielmelody/Ruschm
- 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
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
comment created time in a month
PR opened Danielmelody/Ruschm
- 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
pr created time in a month
push eventDanielmelody/Ruschm
commit sha 37b6a979ff933d809aeed35a281ae97336ceba17
feat: :sparkles: value expect type
commit sha 4d2ec1c268357fd886932a01138ca3db52012de0
refactor: :art: rename Object to ValueReference, Immutable use Rc
push time in a month
push eventDanielmelody/Ruschm
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 <[email protected]>
push time in a month
PR merged Danielmelody/Ruschm
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
pr closed time in a month
push eventDanielmelody/Ruschm
commit sha eecf87b657a0924200e8c5ddb63979c7c41ba63c
fix: :bug: return (&String, &Value) iterator, improve get_mut's test
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.
comment created time in 2 months
PR opened Danielmelody/Ruschm
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
pr created time in 2 months
push eventDanielmelody/Ruschm
commit sha 6dc8bb74ebabb087ff66a4f9ae4bcac78732a2e9
feat: :sparkles: enviroment can get_mut
push time in 2 months
push eventDanielmelody/Ruschm
commit sha c6d4a162336436c9bc84d28fa76f25a4ada85578
initial commit
commit sha 79fc8f8f6dc7296aa56edf82d6dd82981650ce06
Add GPL License
commit sha 72ac42b621d9e0482f60a56df3fb02e8d1a2d3b0
Add Gitter badge
commit sha d3ca2a2d514767c6a367044045ad4934efaabbdd
chore(build): typo
commit sha 404e09e0d0b98adea2e57a13a683c2aec15dce77
chore: add .editorconfig Use EditorConfig to define and maintain consistent coding styles
commit sha 9b70ee76b81369d81ac2af43e2566ef1e809f648
chore(git): update .gitignore Ignore tag files.
commit sha 55aac33b42a474399ca7d5727fb87ad5e797283b
:construction_worker: ignore Cargo.lock
commit sha 5e14876369dd79a12ca180951f0bad9c75e4d2f3
:construction_worker: rename repo
commit sha 6b0a0555851265de5cc3faf74e96dded6d349ddb
fix cargo edition
commit sha 262dc06478dc4cde58d45e5ef31f90f9286f7468
test
commit sha a9cc9a36c0a18c021d5973797ce8d8a21e6091c0
re-track Cargo.lock
commit sha d795990b5ca3ae4239b20259e5ce95bbebc5b61d
Create default.yml
commit sha 20f455148ee2e1e29fb636ee02273fbe07eb207b
Update default.yml
commit sha 9cf647615df5e87e27bb3111b38b41e86bcc4d19
add build status badge to README
commit sha 356fd702a632090cc20968c0cff4591901e11baf
Create workflow.yml
commit sha 0163dce3899089b6b95b48cd3d184e7407625af7
feat(lexer): simple tokens
commit sha ff30832fdf581e58ac1cabc900cf01352e2d5501
feat(lexer): identifier
commit sha 2f1f7ef7174db6658bd19fd76f768cfa0d82595e
feat(lexer): character
commit sha 9a21a23e77b5c916947fe2762ec271dead165cdc
feat(lexer): string
commit sha e50c16354f6424c627c7feccbde9f96887e20fba
refactor(lexer): retarget to r7r5
push time in 2 months
started38/plotters
started time in 2 months
pull request commentDanielmelody/Ruschm
new buildin procedures:
- vector-ref
- floor
- ceiling
- floor-quotient
- floor-remainder
- exact
comment created time in 2 months
push eventDanielmelody/Ruschm
commit sha fed4c76d7e85831d0017fa46e21645856dd4acdc
feat: :sparkles: new buildin function ceiling
push time in 2 months
pull request commentDanielmelody/Ruschm
feat: buildin procedure for implement ordered dither
Maybe need another buildin function ceiling
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
comment created time in 2 months
push eventDanielmelody/Ruschm
commit sha 8e720e2a7561b6e2589aa1c62da521a9716c7c19
fix: :bug: remove a test that use a rational number with negative denominator
push time in 2 months
push eventDanielmelody/Ruschm
commit sha 97965ac88c4a4a2c74abee6fc5ca35056672311f
fix: :bug: fix the logic_error message in div function
commit sha 8f00fd4987fa096b595934cdf781de910015001e
feat: report error location when interpreting files
commit sha d83974cdd7f00bf64e8dbbf155725377a457b415
fix(interpreter): remove unused assignment before apply_procedure
commit sha d598fc159356b58402e059d72e1dcd4f3cb293ee
fix(lexer): prevent rational number denominator being zero (#39) Co-authored-by: CurryPseudo <[email protected]>
commit sha 4414337ce4282ec028155c841ce15fdd1fc72152
feat: :sparkles: user defined variadic function
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
push time in 2 months
startedlextm/windowsterminal-shell
started time in 2 months
startedkerol2r20/Windows-terminal-context-menu
started time in 2 months
push eventDanielmelody/Ruschm
commit sha d598fc159356b58402e059d72e1dcd4f3cb293ee
fix(lexer): prevent rational number denominator being zero (#39) Co-authored-by: CurryPseudo <[email protected]>
push time in 2 months
push eventDanielmelody/Ruschm
commit sha fea93dec2670aab99e191589d04477c55c9dbbe6
Merge branch 'master' into fix-rational
push time in 2 months
push eventDanielmelody/Ruschm
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
commit sha 97965ac88c4a4a2c74abee6fc5ca35056672311f
fix: :bug: fix the logic_error message in div function
commit sha 8f00fd4987fa096b595934cdf781de910015001e
feat: report error location when interpreting files
commit sha d83974cdd7f00bf64e8dbbf155725377a457b415
fix(interpreter): remove unused assignment before apply_procedure
commit sha 7cf3e56c88daee2e8a344f11127ebd498404322a
Merge branch 'master' into fix-rational
push 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 {
Ok, I get it. But, for builder pattern, I think with_location or located is more appropriate.
comment created time in 2 months
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
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
comment created time in 2 months
pull request commentDanielmelody/Ruschm
feat: :sparkles: floor buildin function
Closed, merge into #36
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
comment created time in 2 months
PR opened Danielmelody/Ruschm
Less argument error message in buildin div function is wrong.
pr created time in 2 months
push eventDanielmelody/Ruschm
commit sha 61aa9d9bf43845ab9f5559cf57ddbec5908b3cc1
refactor: :art: move closure out of impure, use apply_procedure pass env, revert IEnvironment::new
push time in 2 months
push eventDanielmelody/Ruschm
commit sha af4ed739a90f9e3196b76e62c1111f47b4dcf7ec
refactor: :art: rename closure to env in BuildinProcedurePointer
push time in 2 months
PR opened Danielmelody/Ruschm
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.
pr created time in 2 months
create barnchDanielmelody/Ruschm
branch : feat-impure-buildin-function-pointer
created branch time in 2 months
push eventDanielmelody/Ruschm
commit sha e12245165287f63afd892121a4d65d72685cb571
refactor: :art: remove redundent variable
push time in 2 months
PR opened Danielmelody/Ruschm
Previous PR #31 accidently broke public api Interpreter::apply_procedure, now fix it
pr created time in 2 months
PR opened Danielmelody/Ruschm
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.
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
commit sha 78800a0c073f6f7a76613a8cace0ec01a21bebdd
fix: :bug: always create local_env for procedure, even tail call (Rc pointer will destroy unused env), remove unecessary api
commit sha 047f7d62b31eb2f639132517f26d135cf4d22b27
test: :white_check_mark: add unit test for eval_tail_expression
commit sha 1250823c5eebd5a1bab546876996280d3798b5b7
test: :white_check_mark: edit fib-tail and sum-tail example to do perfermance test
commit sha 9849f48e3be2fcca0ed4e1960df6ccf5f3b7b9ce
Revert "refactor: :art: wrap (Box<Expression>, Vec<Expression>) into struct ProcedureCall in Expression::ProcedureCall variant" This reverts commit 84da2194d3fdcfbf0b6bfe36fa5b4533024c2eb2.
push time in 2 months
Pull request review commentDanielmelody/Ruschm
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
comment created time in 2 months
Pull request review commentDanielmelody/Ruschm
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.
comment created time in 2 months
PR opened Danielmelody/Ruschm
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
pr created time in 2 months
push eventDanielmelody/Ruschm
commit sha 84da2194d3fdcfbf0b6bfe36fa5b4533024c2eb2
refactor: :art: wrap (Box<Expression>, Vec<Expression>) into struct ProcedureCall in Expression::ProcedureCall variant
commit sha 09872811012f62e07b631ac7b51625894048a1b8
feat: :sparkles: proper tail recursion
commit sha d869a091d9fae7196d8f3e71efd3147fe4ba1c77
test: :white_check_mark: add fib-tail and sum-tail scheme code example
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)
comment created 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;
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
comment created time in 2 months
push eventDanielmelody/Ruschm
commit sha 74ba504ed5239db60a65c820fc632499ce101b20
perf: :zap: only clear definition other than create new enviroment when apply tail procedure, to avoid import base library
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
CurryPseudopush eventCurryPseudo/Ruschm
commit sha 374e020c8f2da5f1b2db9c24aa7c5a13550be36c
refactor: rename IEnviroment::child to IEnvironment::new_child
push time 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
commit sha 3fae32a227149eb2d0ad4ee4b2178090d3b04120
Update readme.md
push time in 3 months