Modify how lookup type works
This commit is contained in:
parent
97117827c6
commit
b5141e27d6
@ -228,10 +228,10 @@ impl<'a> Reducer<'a> {
|
|||||||
let def_id = symbol.def_id();
|
let def_id = symbol.def_id();
|
||||||
|
|
||||||
match symbol.spec() {
|
match symbol.spec() {
|
||||||
Func(_) => Expression::Lookup { id: def_id.unwrap(), kind: Lookup::Function },
|
Func(_) => Expression::Lookup(Lookup::Function(def_id.unwrap())),
|
||||||
GlobalBinding => Expression::Lookup { id: def_id.unwrap(), kind: Lookup::GlobalVar },
|
GlobalBinding => Expression::Lookup(Lookup::GlobalVar(def_id.unwrap())),
|
||||||
LocalVariable => Expression::Lookup { id: def_id.unwrap(), kind: Lookup::LocalVar },
|
LocalVariable => Expression::Lookup(Lookup::LocalVar(def_id.unwrap())),
|
||||||
FunctionParam(n) => Expression::Lookup { id: def_id.unwrap(), kind: Lookup::Param(n) },
|
FunctionParam(n) => Expression::Lookup(Lookup::Param(n)),
|
||||||
DataConstructor { .. } => {
|
DataConstructor { .. } => {
|
||||||
Expression::ReductionError("DataConstructor not supported".to_string())
|
Expression::ReductionError("DataConstructor not supported".to_string())
|
||||||
},
|
},
|
||||||
|
@ -50,10 +50,7 @@ pub enum Statement {
|
|||||||
pub enum Expression {
|
pub enum Expression {
|
||||||
Literal(Literal),
|
Literal(Literal),
|
||||||
Tuple(Vec<Expression>),
|
Tuple(Vec<Expression>),
|
||||||
Lookup {
|
Lookup(Lookup),
|
||||||
id: DefId, //TODO eventually not everything that can be looked up will have a DefId
|
|
||||||
kind: Lookup,
|
|
||||||
},
|
|
||||||
Assign {
|
Assign {
|
||||||
lval: DefId,
|
lval: DefId,
|
||||||
rval: Box<Expression>,
|
rval: Box<Expression>,
|
||||||
@ -89,9 +86,9 @@ pub enum Function {
|
|||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum Lookup {
|
pub enum Lookup {
|
||||||
LocalVar,
|
LocalVar(DefId),
|
||||||
GlobalVar,
|
GlobalVar(DefId),
|
||||||
Function,
|
Function(DefId),
|
||||||
Param(u8),
|
Param(u8),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,32 +217,30 @@ impl<'a> State<'a> {
|
|||||||
Ok(match expression {
|
Ok(match expression {
|
||||||
Expression::Literal(lit) => Primitive::Literal(lit),
|
Expression::Literal(lit) => Primitive::Literal(lit),
|
||||||
Expression::Tuple(items) => Primitive::Tuple(items.into_iter().map(|expr| self.expression(expr)).collect::<EvalResult<Vec<Primitive>>>()?),
|
Expression::Tuple(items) => Primitive::Tuple(items.into_iter().map(|expr| self.expression(expr)).collect::<EvalResult<Vec<Primitive>>>()?),
|
||||||
Expression::Lookup { ref id, kind } => {
|
Expression::Lookup(kind) => match kind {
|
||||||
match kind {
|
Lookup::Function(ref id) => {
|
||||||
Lookup::Function => {
|
let mem = id.into();
|
||||||
let mem = id.into();
|
match self.environments.lookup(&mem) {
|
||||||
match self.environments.lookup(&mem) {
|
// This just checks that the function exists in "memory" by ID, we don't
|
||||||
// This just checks that the function exists in "memory" by ID, we don't
|
// actually retrieve it until `apply_function()`
|
||||||
// actually retrieve it until `apply_function()`
|
Some(RuntimeValue::Function(_)) => Primitive::Callable(Function::UserDefined(id.clone())),
|
||||||
Some(RuntimeValue::Function(_)) => Primitive::Callable(Function::UserDefined(id.clone())),
|
x => return Err(format!("Function not found for id: {} : {:?}", id, x).into()),
|
||||||
x => return Err(format!("Function not found for id: {} : {:?}", id, x).into()),
|
}
|
||||||
}
|
},
|
||||||
},
|
Lookup::Param(n) => {
|
||||||
Lookup::Param(n) => {
|
let mem = n.into();
|
||||||
let mem = n.into();
|
match self.environments.lookup(&mem) {
|
||||||
match self.environments.lookup(&mem) {
|
Some(RuntimeValue::Primitive(prim)) => prim.clone(),
|
||||||
Some(RuntimeValue::Primitive(prim)) => prim.clone(),
|
e => return Err(format!("Param lookup error, got {:?}", e).into()),
|
||||||
e => return Err(format!("Param lookup error, got {:?}", e).into()),
|
}
|
||||||
}
|
},
|
||||||
},
|
Lookup::LocalVar(ref id) | Lookup::GlobalVar(ref id) => {
|
||||||
kind @ Lookup::LocalVar | kind @ Lookup::GlobalVar => {
|
let mem = id.into();
|
||||||
let mem = id.into();
|
match self.environments.lookup(&mem) {
|
||||||
match self.environments.lookup(&mem) {
|
Some(RuntimeValue::Primitive(expr)) => expr.clone(),
|
||||||
Some(RuntimeValue::Primitive(expr)) => expr.clone(),
|
_ => return Err(format!("Nothing found for local/gloval variable lookup {}", id).into()),
|
||||||
_ => return Err(format!("Nothing found for variable lookup {} of kind {:?}", id, kind).into()),
|
}
|
||||||
}
|
},
|
||||||
},
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
Expression::Assign { ref lval, box rval } => {
|
Expression::Assign { ref lval, box rval } => {
|
||||||
let mem = lval.into();
|
let mem = lval.into();
|
||||||
|
Loading…
Reference in New Issue
Block a user