From 1a84f62818cbcf025166141a5913698b1e7ca507 Mon Sep 17 00:00:00 2001 From: greg Date: Sat, 12 May 2018 01:02:44 -0700 Subject: [PATCH] Kill some old code, make very_simple example print --- schala-lang/src/eval.rs | 77 +------------------------- source_files/schala/very_simple.schala | 2 +- 2 files changed, 2 insertions(+), 77 deletions(-) diff --git a/schala-lang/src/eval.rs b/schala-lang/src/eval.rs index 8b39584..b529a81 100644 --- a/schala-lang/src/eval.rs +++ b/schala-lang/src/eval.rs @@ -25,34 +25,11 @@ enum ValueEntry { Binding { constant: bool, val: /*FullyEvaluatedExpr*/ Expr, - }, - /* - Function { - param_names: Vec>, - body: Vec, } - */ } type EvalResult = Result; -/* - -impl<'a> State<'a> { - - fn insert(&mut self, name: Rc, value: ValueEntry) { - self.values.insert(name, value); - } - fn lookup(&self, name: &Rc) -> Option<&ValueEntry> { - match (self.values.get(name), self.parent_frame) { - (None, None) => None, - (None, Some(parent)) => parent.lookup(name), - (Some(value), _) => Some(value), - } - } -} -*/ - /* #[derive(Debug, PartialEq, Clone)] @@ -288,46 +265,6 @@ impl<'a> State<'a> { } } - fn eval_binexp(&mut self, op: BinOp, lhs: Box, rhs: Box) -> EvalResult { - use self::FullyEvaluatedExpr::*; - let evaled_lhs = self.eval_expr(*lhs)?; - let evaled_rhs = self.eval_expr(*rhs)?; - let sigil = op.sigil(); - //let sigil: &str = op.sigil().as_ref().as_str(); - Ok(match (sigil.as_str(), evaled_lhs, evaled_rhs) { - ("+", UnsignedInt(l), UnsignedInt(r)) => UnsignedInt(l + r), - ("++", Str(s1), Str(s2)) => Str(format!("{}{}", s1, s2)), - ("-", UnsignedInt(l), UnsignedInt(r)) => UnsignedInt(l - r), - ("*", UnsignedInt(l), UnsignedInt(r)) => UnsignedInt(l * r), - ("/", UnsignedInt(l), UnsignedInt(r)) => Float((l as f64)/ (r as f64)), - ("//", UnsignedInt(l), UnsignedInt(r)) => if r == 0 { - return Err(format!("Runtime error: divide by zero")); - } else { - UnsignedInt(l / r) - }, - ("%", UnsignedInt(l), UnsignedInt(r)) => UnsignedInt(l % r), - ("^", UnsignedInt(l), UnsignedInt(r)) => UnsignedInt(l ^ r), - ("&", UnsignedInt(l), UnsignedInt(r)) => UnsignedInt(l & r), - ("|", UnsignedInt(l), UnsignedInt(r)) => UnsignedInt(l | r), - _ => return Err(format!("Runtime error: not yet implemented")), - }) - } - - fn eval_prefix_exp(&mut self, op: PrefixOp, expr: Box) -> EvalResult { - use self::FullyEvaluatedExpr::*; - let evaled_expr = self.eval_expr(*expr)?; - let sigil = op.sigil(); - - Ok(match (sigil.as_str(), evaled_expr) { - ("!", Bool(true)) => Bool(false), - ("!", Bool(false)) => Bool(true), - ("-", UnsignedInt(n)) => SignedInt(-1*(n as i64)), - ("-", SignedInt(n)) => SignedInt(-1*(n as i64)), - ("+", SignedInt(n)) => SignedInt(n), - ("+", UnsignedInt(n)) => UnsignedInt(n), - _ => return Err(format!("Runtime error: not yet implemented")), - }) - } } */ @@ -454,7 +391,7 @@ impl<'a> State<'a> { ("+", &[Lit(Int(n))]) => Lit(Int(n)), ("+", &[Lit(Nat(n))]) => Lit(Nat(n)), - _ => return Err(format!("Runtime error: not yet implemented")), + _ => return Err(format!("Runtime error: bad or unimplemented builtin")), }) } @@ -473,16 +410,4 @@ impl<'a> State<'a> { } } } - /* - fn eval_value(&mut self, name: Rc) -> EvalResult { - use self::ValueEntry::*; - match self.lookup(&name) { - None => return Err(format!("Value {} not found", *name)), - Some(lookup) => match lookup { - &Binding { ref val } => Ok(val.clone()), - &Function { .. } => Ok(FullyEvaluatedExpr::FuncLit(name.clone())) - } - } - } - */ } diff --git a/source_files/schala/very_simple.schala b/source_files/schala/very_simple.schala index f146ae3..63e5ca8 100644 --- a/source_files/schala/very_simple.schala +++ b/source_files/schala/very_simple.schala @@ -1,4 +1,4 @@ const a = 10 -a + 8 +print(a + 8)