A few minor cleanups

This commit is contained in:
jonathandturner 2016-03-10 16:19:56 -05:00
parent 924ce2eddc
commit 0e4f194880

View File

@ -31,7 +31,7 @@ impl Error for EvalAltResult {
EvalAltResult::ErrorFunctionArgMismatch => "Function argument types do not match", EvalAltResult::ErrorFunctionArgMismatch => "Function argument types do not match",
EvalAltResult::ErrorFunctionCallNotSupported => "Function call with > 2 argument not supported", EvalAltResult::ErrorFunctionCallNotSupported => "Function call with > 2 argument not supported",
EvalAltResult::ErrorIfGuardMismatch => "If guards expect boolean expression", EvalAltResult::ErrorIfGuardMismatch => "If guards expect boolean expression",
EvalAltResult::ErrorVariableNotFound(ref s) => {println!("Var {} not found", s); "Variable not found"}, EvalAltResult::ErrorVariableNotFound(_) => "Variable not found",
EvalAltResult::ErrorFunctionArityNotSupported => "Functions of more than 3 parameters are not yet supported", EvalAltResult::ErrorFunctionArityNotSupported => "Functions of more than 3 parameters are not yet supported",
EvalAltResult::ErrorAssignmentToUnknownLHS => "Assignment to an unsupported left-hand side", EvalAltResult::ErrorAssignmentToUnknownLHS => "Assignment to an unsupported left-hand side",
EvalAltResult::InternalErrorMalformedDotExpression => "[Internal error] Unexpected expression in dot expression", EvalAltResult::InternalErrorMalformedDotExpression => "[Internal error] Unexpected expression in dot expression",
@ -406,7 +406,6 @@ impl Engine {
break; break;
} }
else { else {
println!("Error when cloning");
return result; return result;
} }
} }
@ -424,7 +423,6 @@ impl Engine {
return result; return result;
} }
println!("Error finding target: {}", id);
return Err(EvalAltResult::ErrorVariableNotFound(id.clone())); return Err(EvalAltResult::ErrorVariableNotFound(id.clone()));
} }
_ => Err(EvalAltResult::InternalErrorMalformedDotExpression) _ => Err(EvalAltResult::InternalErrorMalformedDotExpression)
@ -435,16 +433,11 @@ impl Engine {
match *dot_rhs { match *dot_rhs {
Expr::Identifier(ref id) => { Expr::Identifier(ref id) => {
let set_fn_name = "set$".to_string() + id; let set_fn_name = "set$".to_string() + id;
println!("calling: {}", set_fn_name);
self.call_fn(&set_fn_name, Some(this_ptr), Some(&mut source_val), None, None, None, None) self.call_fn(&set_fn_name, Some(this_ptr), Some(&mut source_val), None, None, None, None)
} }
Expr::Dot(ref inner_lhs, ref inner_rhs) => { Expr::Dot(ref inner_lhs, ref inner_rhs) => {
match **inner_lhs { match **inner_lhs {
Expr::Identifier(ref id) => { Expr::Identifier(ref id) => {
println!("Setting into Dot");
let get_fn_name = "get$".to_string() + id; let get_fn_name = "get$".to_string() + id;
let result = self.call_fn(&get_fn_name, Some(this_ptr), None, None, None, None, None); let result = self.call_fn(&get_fn_name, Some(this_ptr), None, None, None, None, None);
@ -467,7 +460,6 @@ impl Engine {
} }
} }
_ => { _ => {
println!("Setting into unknown AST node");
Err(EvalAltResult::InternalErrorMalformedDotExpression) Err(EvalAltResult::InternalErrorMalformedDotExpression)
} }
} }
@ -944,7 +936,7 @@ fn test_var_scope() {
#[test] #[test]
fn test_method_call() { fn test_method_call() {
#[derive(Debug, Clone)] #[derive(Clone)]
struct TestStruct { struct TestStruct {
x: i32 x: i32
} }
@ -977,7 +969,7 @@ fn test_method_call() {
#[test] #[test]
fn test_get_set() { fn test_get_set() {
#[derive(Debug, Clone)] #[derive(Clone)]
struct TestStruct { struct TestStruct {
x: i32 x: i32
} }
@ -1014,7 +1006,7 @@ fn test_get_set() {
#[test] #[test]
fn test_big_get_set() { fn test_big_get_set() {
#[derive(Debug, Clone)] #[derive(Clone)]
struct TestChild { struct TestChild {
x: i32 x: i32
} }
@ -1033,7 +1025,7 @@ fn test_big_get_set() {
} }
} }
#[derive(Debug, Clone)] #[derive(Clone)]
struct TestParent { struct TestParent {
child: TestChild child: TestChild
} }
@ -1063,6 +1055,7 @@ fn test_big_get_set() {
&(TestParent::get_child as fn(&mut TestParent)->TestChild).register(&mut engine, "get$child"); &(TestParent::get_child as fn(&mut TestParent)->TestChild).register(&mut engine, "get$child");
&(TestParent::set_child as fn(&mut TestParent, TestChild)->()).register(&mut engine, "set$child"); &(TestParent::set_child as fn(&mut TestParent, TestChild)->()).register(&mut engine, "set$child");
&(TestParent::new as fn()->TestParent).register(&mut engine, "new_tp"); &(TestParent::new as fn()->TestParent).register(&mut engine, "new_tp");
if let Ok(result) = engine.eval("var a = new_tp(); a.child.x = 500; a.child.x".to_string()).unwrap().downcast::<i32>() { if let Ok(result) = engine.eval("var a = new_tp(); a.child.x = 500; a.child.x".to_string()).unwrap().downcast::<i32>() {