Unimplemented sigil

This commit is contained in:
greg 2018-05-11 00:45:32 -07:00
parent 633b4fe7a4
commit 9de66a9af3
2 changed files with 20 additions and 21 deletions

View File

@ -23,6 +23,7 @@ pub enum Expr {
f: Func, f: Func,
args: Vec<Expr>, args: Vec<Expr>,
}, },
UnimplementedSigilValue
} }
#[derive(Debug)] #[derive(Debug)]
@ -44,51 +45,50 @@ pub enum Func {
} }
impl AST { impl AST {
pub fn reduce(&self) -> Result<ReducedAST, String> { pub fn reduce(&self) -> ReducedAST {
use parsing::Statement::*; use parsing::Statement::*;
let mut output = vec![]; let mut output = vec![];
for statement in self.0.iter() { for statement in self.0.iter() {
match statement { match statement {
&ExpressionStatement(ref expr) => output.push(Stmt::Expr(expr.reduce()?)), &ExpressionStatement(ref expr) => output.push(Stmt::Expr(expr.reduce())),
&Declaration(ref decl) => output.push(decl.reduce()?), &Declaration(ref decl) => output.push(decl.reduce()),
} }
} }
Ok(ReducedAST(output)) ReducedAST(output)
} }
} }
impl Expression { impl Expression {
fn reduce(&self) -> Result<Expr, String> { fn reduce(&self) -> Expr {
use parsing::ExpressionType::*; use parsing::ExpressionType::*;
let ref input = self.0; let ref input = self.0;
let output_expr = match input { match input {
&IntLiteral(ref n) => Expr::Lit(Lit::Nat(*n)), //TODO I should rename IntLiteral if I want the Nat/Int distinction, which I do &IntLiteral(ref n) => Expr::Lit(Lit::Nat(*n)), //TODO I should rename IntLiteral if I want the Nat/Int distinction, which I do
&FloatLiteral(ref f) => Expr::Lit(Lit::Float(*f)), &FloatLiteral(ref f) => Expr::Lit(Lit::Float(*f)),
&StringLiteral(ref s) => Expr::Lit(Lit::StringLit(s.clone())), &StringLiteral(ref s) => Expr::Lit(Lit::StringLit(s.clone())),
&BoolLiteral(ref b) => Expr::Lit(Lit::Bool(*b)), &BoolLiteral(ref b) => Expr::Lit(Lit::Bool(*b)),
&BinExp(ref binop, ref lhs, ref rhs) => binop.reduce(lhs, rhs)?, &BinExp(ref binop, ref lhs, ref rhs) => binop.reduce(lhs, rhs),
&PrefixExp(ref op, ref arg) => op.reduce(arg)?, &PrefixExp(ref op, ref arg) => op.reduce(arg),
e => return Err(format!("{:?} not implemented in reduction", e)) e => Expr::UnimplementedSigilValue,
}; }
Ok(output_expr)
} }
} }
impl Declaration { impl Declaration {
fn reduce(&self) -> Result<Stmt, String> { fn reduce(&self) -> Stmt {
Ok(Stmt::Expr(Expr::Lit(Lit::Int(0)))) Stmt::Expr(Expr::UnimplementedSigilValue)
} }
} }
impl BinOp { impl BinOp {
fn reduce(&self, lhs: &Box<Expression>, rhs: &Box<Expression>) -> Result<Expr, String> { fn reduce(&self, lhs: &Box<Expression>, rhs: &Box<Expression>) -> Expr {
let f = Func::BuiltIn(self.sigil().clone()); let f = Func::BuiltIn(self.sigil().clone());
Ok(Expr::Call { f, args: vec![lhs.reduce()?, rhs.reduce()?]}) Expr::Call { f, args: vec![lhs.reduce(), rhs.reduce()]}
} }
} }
impl PrefixOp { impl PrefixOp {
fn reduce(&self, arg: &Box<Expression>) -> Result<Expr, String> { fn reduce(&self, arg: &Box<Expression>) -> Expr {
Err(format!("NOTDONE")) Expr::UnimplementedSigilValue
} }
} }

View File

@ -95,8 +95,7 @@ fn typechecking(handle: &mut Schala, input: parsing::AST, comp: Option<&mut Unfi
type TempASTReduction = (ast_reducing::ReducedAST, parsing::AST); type TempASTReduction = (ast_reducing::ReducedAST, parsing::AST);
fn ast_reducing(handle: &mut Schala, input: parsing::AST, comp: Option<&mut UnfinishedComputation>) -> Result<TempASTReduction, String> { fn ast_reducing(handle: &mut Schala, input: parsing::AST, comp: Option<&mut UnfinishedComputation>) -> Result<TempASTReduction, String> {
let output = input.reduce()?; let output = input.reduce();
println!("REDUCED: {:?}", output);
Ok((output, input)) Ok((output, input))
} }
@ -106,8 +105,8 @@ fn eval(handle: &mut Schala, input: TempASTReduction, _comp: Option<&mut Unfinis
let new_eval_output = handle.state.evaluate_new(new_input, true); let new_eval_output = handle.state.evaluate_new(new_input, true);
match new_eval_output[0] { match new_eval_output[0] {
Ok(ref s) => println!("NEW OUTPUT> {}", s), Ok(ref s) => println!("NEW OUTPUT> {}", s),
Err(ref e) => println!("NEW ERR> {}", e), Err(ref s) => println!("NEW Err> {}", s),
} };
/* old-style eval */ /* old-style eval */
let input = input.1; let input = input.1;