Remove most unused variables
This commit is contained in:
parent
009095f771
commit
96595d8fb6
@ -44,7 +44,7 @@ impl<'a> Reducer<'a> {
|
|||||||
ast::StatementKind::Expression(expr) => {
|
ast::StatementKind::Expression(expr) => {
|
||||||
entrypoint.push(Statement::Expression(self.expression(&expr)));
|
entrypoint.push(Statement::Expression(self.expression(&expr)));
|
||||||
},
|
},
|
||||||
ast::StatementKind::Declaration(ast::Declaration::Binding { name, constant, expr, ..}) => {
|
ast::StatementKind::Declaration(ast::Declaration::Binding { name: _, constant, expr, ..}) => {
|
||||||
let symbol = self.symbol_table.lookup_symbol(item_id).unwrap();
|
let symbol = self.symbol_table.lookup_symbol(item_id).unwrap();
|
||||||
entrypoint.push(Statement::Binding { id: symbol.def_id.clone(), constant: *constant, expr: self.expression(&expr) });
|
entrypoint.push(Statement::Binding { id: symbol.def_id.clone(), constant: *constant, expr: self.expression(&expr) });
|
||||||
},
|
},
|
||||||
@ -73,7 +73,7 @@ impl<'a> Reducer<'a> {
|
|||||||
_ => ()
|
_ => ()
|
||||||
},
|
},
|
||||||
ast::StatementKind::Import(..) => (),
|
ast::StatementKind::Import(..) => (),
|
||||||
ast::StatementKind::Module(modspec) => {
|
ast::StatementKind::Module(_modspec) => {
|
||||||
//TODO handle modules
|
//TODO handle modules
|
||||||
()
|
()
|
||||||
}
|
}
|
||||||
@ -132,7 +132,7 @@ impl<'a> Reducer<'a> {
|
|||||||
body: self.function(body),
|
body: self.function(body),
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
NamedStruct { name, fields } => Expression::ReductionError("NamedStruct not implemented".to_string()), //self.reduce_named_struct(name, fields),
|
NamedStruct { .. } => Expression::ReductionError("NamedStruct not implemented".to_string()), //self.reduce_named_struct(name, fields),
|
||||||
Index { .. } => Expression::ReductionError("Index expr not implemented".to_string()),
|
Index { .. } => Expression::ReductionError("Index expr not implemented".to_string()),
|
||||||
WhileExpression { .. } => Expression::ReductionError("While expr not implemented".to_string()),
|
WhileExpression { .. } => Expression::ReductionError("While expr not implemented".to_string()),
|
||||||
ForExpression { .. } => Expression::ReductionError("For expr not implemented".to_string()),
|
ForExpression { .. } => Expression::ReductionError("For expr not implemented".to_string()),
|
||||||
@ -140,7 +140,7 @@ impl<'a> Reducer<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reduce_if_expression(&mut self, discriminator: Option<&ast::Expression>, body: &ast::IfExpressionBody) -> Expression {
|
fn reduce_if_expression(&mut self, _discriminator: Option<&ast::Expression>, _body: &ast::IfExpressionBody) -> Expression {
|
||||||
Expression::ReductionError("if expr".to_string())
|
Expression::ReductionError("if expr".to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,7 +210,8 @@ impl<'a> Reducer<'a> {
|
|||||||
fn value(&mut self, qualified_name: &ast::QualifiedName) -> Expression {
|
fn value(&mut self, qualified_name: &ast::QualifiedName) -> Expression {
|
||||||
use SymbolSpec::*;
|
use SymbolSpec::*;
|
||||||
|
|
||||||
let ast::QualifiedName { id, components, .. } = qualified_name;
|
let ast::QualifiedName { id: _, components, .. } = qualified_name;
|
||||||
|
let _ = components;
|
||||||
|
|
||||||
let symbol = match self.symbol_table.lookup_symbol(&qualified_name.id) {
|
let symbol = match self.symbol_table.lookup_symbol(&qualified_name.id) {
|
||||||
Some(s) => s,
|
Some(s) => s,
|
||||||
@ -222,7 +223,7 @@ impl<'a> Reducer<'a> {
|
|||||||
GlobalBinding => Expression::Lookup { id: def_id.clone(), kind: Lookup::GlobalVar },
|
GlobalBinding => Expression::Lookup { id: def_id.clone(), kind: Lookup::GlobalVar },
|
||||||
LocalVariable => Expression::Lookup { id: def_id.clone(), kind: Lookup::LocalVar },
|
LocalVariable => Expression::Lookup { id: def_id.clone(), kind: Lookup::LocalVar },
|
||||||
FunctionParam(n) => Expression::Lookup { id: def_id.clone(), kind: Lookup::Param(*n) },
|
FunctionParam(n) => Expression::Lookup { id: def_id.clone(), kind: Lookup::Param(*n) },
|
||||||
DataConstructor { index, arity, .. } => {
|
DataConstructor { .. } => {
|
||||||
Expression::ReductionError("DataConstructor not supported".to_string())
|
Expression::ReductionError("DataConstructor not supported".to_string())
|
||||||
},
|
},
|
||||||
RecordConstructor { .. } => {
|
RecordConstructor { .. } => {
|
||||||
|
@ -17,6 +17,7 @@ pub struct ReducedIR {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ReducedIR {
|
impl ReducedIR {
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn debug(&self, symbol_table: &SymbolTable) {
|
pub fn debug(&self, symbol_table: &SymbolTable) {
|
||||||
println!("Reduced IR:");
|
println!("Reduced IR:");
|
||||||
println!("Functions:");
|
println!("Functions:");
|
||||||
|
@ -4,8 +4,6 @@ use crate::ast::*;
|
|||||||
use crate::symbol_table::{Fqsn, Scope, SymbolTable, SymbolSpec};
|
use crate::symbol_table::{Fqsn, Scope, SymbolTable, SymbolSpec};
|
||||||
use crate::util::ScopeStack;
|
use crate::util::ScopeStack;
|
||||||
|
|
||||||
type FqsnPrefix = Vec<Scope>;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum NameType {
|
enum NameType {
|
||||||
//TODO eventually this needs to support closures
|
//TODO eventually this needs to support closures
|
||||||
@ -17,6 +15,7 @@ enum NameType {
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum ScopeType {
|
enum ScopeType {
|
||||||
Function {
|
Function {
|
||||||
|
#[allow(dead_code)]
|
||||||
name: Rc<String>
|
name: Rc<String>
|
||||||
},
|
},
|
||||||
Lambda,
|
Lambda,
|
||||||
|
@ -58,6 +58,7 @@ impl From<&str> for RuntimeError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl RuntimeError {
|
impl RuntimeError {
|
||||||
|
#[allow(dead_code)]
|
||||||
fn get_msg(&self) -> String {
|
fn get_msg(&self) -> String {
|
||||||
format!("Runtime error: {}", self.msg)
|
format!("Runtime error: {}", self.msg)
|
||||||
}
|
}
|
||||||
@ -98,8 +99,8 @@ fn expr_to_repl(expr: &Expression) -> String {
|
|||||||
Literal::StringLit(s) => format!("\"{}\"", s),
|
Literal::StringLit(s) => format!("\"{}\"", s),
|
||||||
}
|
}
|
||||||
Expression::Tuple(terms) => paren_wrapped(terms.iter().map(|x| expr_to_repl(x))),
|
Expression::Tuple(terms) => paren_wrapped(terms.iter().map(|x| expr_to_repl(x))),
|
||||||
Expression::Assign { lval, rval } => {
|
Expression::Assign { .. } => {
|
||||||
"".to_string()
|
"".to_string() //TODO maybe the repl should say *something* here?
|
||||||
},
|
},
|
||||||
e => format!("Expression {:?} shouldn't be here", e),
|
e => format!("Expression {:?} shouldn't be here", e),
|
||||||
}
|
}
|
||||||
@ -109,7 +110,7 @@ impl RuntimeValue {
|
|||||||
fn to_repl(&self) -> String {
|
fn to_repl(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
RuntimeValue::Primitive(ref prim) => expr_to_repl(&prim.to_expr()),
|
RuntimeValue::Primitive(ref prim) => expr_to_repl(&prim.to_expr()),
|
||||||
RuntimeValue::Function(ref expr) => "<function>".to_string(),
|
RuntimeValue::Function(..) => "<function>".to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -193,7 +194,7 @@ impl<'a> State<'a> {
|
|||||||
|
|
||||||
fn statement(&mut self, stmt: Statement) -> EvalResult<Option<RuntimeValue>> {
|
fn statement(&mut self, stmt: Statement) -> EvalResult<Option<RuntimeValue>> {
|
||||||
match stmt {
|
match stmt {
|
||||||
Statement::Binding { ref id, expr, constant } => {
|
Statement::Binding { ref id, expr, constant: _ } => {
|
||||||
println!("eval() binding id: {}", id);
|
println!("eval() binding id: {}", id);
|
||||||
let evaluated = self.expression(expr)?;
|
let evaluated = self.expression(expr)?;
|
||||||
self.environments.insert(id.into(), evaluated.into());
|
self.environments.insert(id.into(), evaluated.into());
|
||||||
@ -239,7 +240,8 @@ impl<'a> State<'a> {
|
|||||||
},
|
},
|
||||||
Expression::Assign { ref lval, box rval } => {
|
Expression::Assign { ref lval, box rval } => {
|
||||||
let mem = lval.into();
|
let mem = lval.into();
|
||||||
let mut env = self.environments.lookup(&mem);
|
let _ = rval;
|
||||||
|
let _env = self.environments.lookup(&mem);
|
||||||
return Err("Assign not implemented".into());
|
return Err("Assign not implemented".into());
|
||||||
},
|
},
|
||||||
Expression::Call { box f, args } => self.call_expression(f, args)?,
|
Expression::Call { box f, args } => self.call_expression(f, args)?,
|
||||||
@ -288,6 +290,21 @@ impl<'a> State<'a> {
|
|||||||
(FieldAccess, /*&[Node::PrimObject { .. }]*/ _) => {
|
(FieldAccess, /*&[Node::PrimObject { .. }]*/ _) => {
|
||||||
return Err("Field access unimplemented".into());
|
return Err("Field access unimplemented".into());
|
||||||
}
|
}
|
||||||
|
/* builtin functions */
|
||||||
|
(IOPrint, &[ref anything]) => {
|
||||||
|
print!("{}", expr_to_repl(anything));
|
||||||
|
Primitive::Tuple(vec![])
|
||||||
|
},
|
||||||
|
(IOPrintLn, &[ref anything]) => {
|
||||||
|
println!("{}", expr_to_repl(anything));
|
||||||
|
Primitive::Tuple(vec![])
|
||||||
|
},
|
||||||
|
(IOGetLine, &[]) => {
|
||||||
|
let mut buf = String::new();
|
||||||
|
std::io::stdin().read_line(&mut buf).expect("Error readling line in 'getline'");
|
||||||
|
StringLit(Rc::new(buf.trim().to_string())).into()
|
||||||
|
},
|
||||||
|
/* Binops */
|
||||||
(binop, &[ref lhs, ref rhs]) => match (binop, lhs, rhs) {
|
(binop, &[ref lhs, ref rhs]) => match (binop, lhs, rhs) {
|
||||||
(Add, Lit(Nat(l)), Lit(Nat(r))) => Nat(l + r).into(),
|
(Add, Lit(Nat(l)), Lit(Nat(r))) => Nat(l + r).into(),
|
||||||
(Concatenate, Lit(StringLit(ref s1)), Lit(StringLit(ref s2))) => StringLit(Rc::new(format!("{}{}", s1, s2))).into(),
|
(Concatenate, Lit(StringLit(ref s1)), Lit(StringLit(ref s2))) => StringLit(Rc::new(format!("{}{}", s1, s2))).into(),
|
||||||
@ -338,20 +355,6 @@ impl<'a> State<'a> {
|
|||||||
(Increment, Lit(Nat(n))) => Nat(*n),
|
(Increment, Lit(Nat(n))) => Nat(*n),
|
||||||
_ => return Err("No valid prefix op".into())
|
_ => return Err("No valid prefix op".into())
|
||||||
}.into(),
|
}.into(),
|
||||||
/* builtin functions */
|
|
||||||
(IOPrint, &[ref anything]) => {
|
|
||||||
print!("{}", expr_to_repl(anything));
|
|
||||||
Primitive::Tuple(vec![])
|
|
||||||
},
|
|
||||||
(IOPrintLn, &[ref anything]) => {
|
|
||||||
println!("{}", expr_to_repl(anything));
|
|
||||||
Primitive::Tuple(vec![])
|
|
||||||
},
|
|
||||||
(IOGetLine, &[]) => {
|
|
||||||
let mut buf = String::new();
|
|
||||||
std::io::stdin().read_line(&mut buf).expect("Error readling line in 'getline'");
|
|
||||||
StringLit(Rc::new(buf.trim().to_string())).into()
|
|
||||||
},
|
|
||||||
(x, args) => return Err(format!("bad or unimplemented builtin {:?} | {:?}", x, args).into()),
|
(x, args) => return Err(format!("bad or unimplemented builtin {:?} | {:?}", x, args).into()),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user