git.delta.rocks / jrsonnet / refs/commits / abdb122c59b2

difftreelog

refactor(evaluator) replace Binding with LazyBinding

Лач2020-06-11parent: #96f2d11.patch.diff
in: master

4 files changed

modifiedcrates/jsonnet-evaluator/src/evaluate.rsdiffbeforeafterboth
1use crate::{1use crate::{
2 binding, context_creator, create_error, future_wrapper, lazy_val, push, with_state, Context,2 context_creator, create_error, future_wrapper, lazy_val, push, with_state, Context,
3 ContextCreator, FuncDesc, LazyBinding, ObjMember, ObjValue, Result, Val,3 ContextCreator, FuncDesc, LazyBinding, LazyVal, ObjMember, ObjValue, Result, Val,
4};4};
5use closure::closure;5use closure::closure;
6use jsonnet_parser::{6use jsonnet_parser::{
252 ObjMember {252 ObjMember {
253 add: plus,253 add: plus,
254 visibility: visibility.clone(),254 visibility: visibility.clone(),
255 invoke: binding!(255 invoke: LazyBinding::Bindable(Rc::new(
256 closure!(clone name, clone value, clone context_creator, |this, super_obj| {256 closure!(clone name, clone value, clone context_creator, |this, super_obj| {
257 push(value.clone(), "object ".to_owned()+&name+" field", ||{257 Ok(LazyVal::new_resolved(push(value.clone(), "object ".to_owned()+&name+" field", ||{
258 let context = context_creator.0(this, super_obj)?;258 let context = context_creator.0(this, super_obj)?;
259 evaluate(259 evaluate(
260 context,260 context,
261 &value,261 &value,
262 )?.unwrap_if_lazy()262 )?.unwrap_if_lazy()
263 })263 })?))
264 })264 }),
265 ),265 )),
266 },266 },
267 );267 );
268 }268 }
282 ObjMember {282 ObjMember {
283 add: false,283 add: false,
284 visibility: Visibility::Hidden,284 visibility: Visibility::Hidden,
285 invoke: binding!(285 invoke: LazyBinding::Bindable(Rc::new(
286 closure!(clone value, clone context_creator, |this, super_obj| {286 closure!(clone value, clone context_creator, |this, super_obj| {
287 // TODO: Assert287 // TODO: Assert
288 Ok(evaluate_method(288 Ok(LazyVal::new_resolved(evaluate_method(
289 context_creator.0(this, super_obj)?,289 context_creator.0(this, super_obj)?,
290 params.clone(),290 params.clone(),
291 value.clone(),291 value.clone(),
292 ))292 )))
293 })293 }),
294 ),294 )),
295 },295 },
296 );296 );
297 }297 }
modifiedcrates/jsonnet-evaluator/src/lib.rsdiffbeforeafterboth
--- a/crates/jsonnet-evaluator/src/lib.rs
+++ b/crates/jsonnet-evaluator/src/lib.rs
@@ -22,12 +22,6 @@
 use std::{cell::RefCell, collections::HashMap, fmt::Debug, path::PathBuf, rc::Rc};
 pub use val::*;
 
-rc_fn_helper!(
-	Binding,
-	binding,
-	dyn Fn(Option<ObjValue>, Option<ObjValue>) -> Result<Val>
-);
-
 type BindableFn = dyn Fn(Option<ObjValue>, Option<ObjValue>) -> Result<LazyVal>;
 #[derive(Clone)]
 pub enum LazyBinding {
modifiedcrates/jsonnet-evaluator/src/map.rsdiffbeforeafterboth
--- a/crates/jsonnet-evaluator/src/map.rs
+++ b/crates/jsonnet-evaluator/src/map.rs
@@ -18,6 +18,7 @@
 		}))
 	}
 
+	#[inline(always)]
 	pub fn get<Q: ?Sized>(&self, key: &Q) -> Option<&V>
 	where
 		K: Borrow<Q>,
modifiedcrates/jsonnet-evaluator/src/obj.rsdiffbeforeafterboth
--- a/crates/jsonnet-evaluator/src/obj.rs
+++ b/crates/jsonnet-evaluator/src/obj.rs
@@ -1,4 +1,4 @@
-use crate::{evaluate_add_op, Binding, Result, Val};
+use crate::{evaluate_add_op, LazyBinding, Result, Val};
 use indexmap::IndexMap;
 use jsonnet_parser::Visibility;
 use std::{
@@ -12,7 +12,7 @@
 pub struct ObjMember {
 	pub add: bool,
 	pub visibility: Visibility,
-	pub invoke: Binding,
+	pub invoke: LazyBinding,
 }
 
 #[derive(Debug)]
@@ -102,12 +102,16 @@
 	}
 	pub(crate) fn get_raw(&self, key: &str, real_this: &ObjValue) -> Result<Option<Val>> {
 		match (self.0.this_entries.get(key), &self.0.super_obj) {
-			(Some(k), None) => Ok(Some(k.invoke.0(
-				Some(real_this.clone()),
-				self.0.super_obj.clone(),
-			)?)),
+			(Some(k), None) => Ok(Some(
+				k.invoke
+					.evaluate(Some(real_this.clone()), self.0.super_obj.clone())?
+					.evaluate()?,
+			)),
 			(Some(k), Some(s)) => {
-				let our = k.invoke.0(Some(real_this.clone()), self.0.super_obj.clone())?;
+				let our = k
+					.invoke
+					.evaluate(Some(real_this.clone()), self.0.super_obj.clone())?
+					.evaluate()?;
 				if k.add {
 					s.get_raw(key, real_this)?
 						.map_or(Ok(Some(our.clone())), |v| {