Modify how lookup type works

This commit is contained in:
Greg Shuflin 2021-10-25 14:37:12 -07:00
parent 97117827c6
commit b5141e27d6
3 changed files with 32 additions and 37 deletions

View File

@ -228,10 +228,10 @@ impl<'a> Reducer<'a> {
let def_id = symbol.def_id();
match symbol.spec() {
Func(_) => Expression::Lookup { id: def_id.unwrap(), kind: Lookup::Function },
GlobalBinding => Expression::Lookup { id: def_id.unwrap(), kind: Lookup::GlobalVar },
LocalVariable => Expression::Lookup { id: def_id.unwrap(), kind: Lookup::LocalVar },
FunctionParam(n) => Expression::Lookup { id: def_id.unwrap(), kind: Lookup::Param(n) },
Func(_) => Expression::Lookup(Lookup::Function(def_id.unwrap())),
GlobalBinding => Expression::Lookup(Lookup::GlobalVar(def_id.unwrap())),
LocalVariable => Expression::Lookup(Lookup::LocalVar(def_id.unwrap())),
FunctionParam(n) => Expression::Lookup(Lookup::Param(n)),
DataConstructor { .. } => {
Expression::ReductionError("DataConstructor not supported".to_string())
},

View File

@ -50,10 +50,7 @@ pub enum Statement {
pub enum Expression {
Literal(Literal),
Tuple(Vec<Expression>),
Lookup {
id: DefId, //TODO eventually not everything that can be looked up will have a DefId
kind: Lookup,
},
Lookup(Lookup),
Assign {
lval: DefId,
rval: Box<Expression>,
@ -89,9 +86,9 @@ pub enum Function {
#[derive(Debug, Clone)]
pub enum Lookup {
LocalVar,
GlobalVar,
Function,
LocalVar(DefId),
GlobalVar(DefId),
Function(DefId),
Param(u8),
}

View File

@ -217,9 +217,8 @@ impl<'a> State<'a> {
Ok(match expression {
Expression::Literal(lit) => Primitive::Literal(lit),
Expression::Tuple(items) => Primitive::Tuple(items.into_iter().map(|expr| self.expression(expr)).collect::<EvalResult<Vec<Primitive>>>()?),
Expression::Lookup { ref id, kind } => {
match kind {
Lookup::Function => {
Expression::Lookup(kind) => match kind {
Lookup::Function(ref id) => {
let mem = id.into();
match self.environments.lookup(&mem) {
// This just checks that the function exists in "memory" by ID, we don't
@ -235,14 +234,13 @@ impl<'a> State<'a> {
e => return Err(format!("Param lookup error, got {:?}", e).into()),
}
},
kind @ Lookup::LocalVar | kind @ Lookup::GlobalVar => {
Lookup::LocalVar(ref id) | Lookup::GlobalVar(ref id) => {
let mem = id.into();
match self.environments.lookup(&mem) {
Some(RuntimeValue::Primitive(expr)) => expr.clone(),
_ => return Err(format!("Nothing found for variable lookup {} of kind {:?}", id, kind).into()),
_ => return Err(format!("Nothing found for local/gloval variable lookup {}", id).into()),
}
},
}
},
Expression::Assign { ref lval, box rval } => {
let mem = lval.into();