diff --git a/schala-lang/language/src/reduced_ir/mod.rs b/schala-lang/language/src/reduced_ir/mod.rs index e5cf494..7035052 100644 --- a/schala-lang/language/src/reduced_ir/mod.rs +++ b/schala-lang/language/src/reduced_ir/mod.rs @@ -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()) }, diff --git a/schala-lang/language/src/reduced_ir/types.rs b/schala-lang/language/src/reduced_ir/types.rs index 0fb33b5..147e117 100644 --- a/schala-lang/language/src/reduced_ir/types.rs +++ b/schala-lang/language/src/reduced_ir/types.rs @@ -50,10 +50,7 @@ pub enum Statement { pub enum Expression { Literal(Literal), Tuple(Vec), - 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, @@ -89,9 +86,9 @@ pub enum Function { #[derive(Debug, Clone)] pub enum Lookup { - LocalVar, - GlobalVar, - Function, + LocalVar(DefId), + GlobalVar(DefId), + Function(DefId), Param(u8), } diff --git a/schala-lang/language/src/tree_walk_eval/mod.rs b/schala-lang/language/src/tree_walk_eval/mod.rs index e6c3bc6..200af03 100644 --- a/schala-lang/language/src/tree_walk_eval/mod.rs +++ b/schala-lang/language/src/tree_walk_eval/mod.rs @@ -217,32 +217,30 @@ 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::>>()?), - Expression::Lookup { ref id, kind } => { - match kind { - Lookup::Function => { - let mem = id.into(); - match self.environments.lookup(&mem) { - // This just checks that the function exists in "memory" by ID, we don't - // actually retrieve it until `apply_function()` - Some(RuntimeValue::Function(_)) => Primitive::Callable(Function::UserDefined(id.clone())), - x => return Err(format!("Function not found for id: {} : {:?}", id, x).into()), - } - }, - Lookup::Param(n) => { - let mem = n.into(); - match self.environments.lookup(&mem) { - Some(RuntimeValue::Primitive(prim)) => prim.clone(), - e => return Err(format!("Param lookup error, got {:?}", e).into()), - } - }, - kind @ Lookup::LocalVar | kind @ Lookup::GlobalVar => { - 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()), - } - }, - } + 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 + // actually retrieve it until `apply_function()` + Some(RuntimeValue::Function(_)) => Primitive::Callable(Function::UserDefined(id.clone())), + x => return Err(format!("Function not found for id: {} : {:?}", id, x).into()), + } + }, + Lookup::Param(n) => { + let mem = n.into(); + match self.environments.lookup(&mem) { + Some(RuntimeValue::Primitive(prim)) => prim.clone(), + e => return Err(format!("Param lookup error, got {:?}", e).into()), + } + }, + 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 local/gloval variable lookup {}", id).into()), + } + }, }, Expression::Assign { ref lval, box rval } => { let mem = lval.into();