experementing with ._diff(..)

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2018-10-12 18:31:59 +03:00
parent 664c73ac1c
commit 337d5ba6a3

25
diff.js
View File

@ -1516,6 +1516,14 @@ module.Types = {
options = options || {}
var that = this
// XXX revise...
// XXX can there be a nested pattern that needs a context???
// ...should this be done in walk(..)???
context = context
|| (A instanceof Pattern ? A.context().__context__
: B instanceof Pattern ? B.context().__context__
: {})
// basic compare...
// XXX do we need to differentiate things like: new Number(123) vs. 123???
// XXX we need to maintain the context here...
@ -1530,9 +1538,18 @@ module.Types = {
|| b === that.ANY
// logic patterns...
|| (a instanceof Pattern
&& a.cmp(b))
&& a.cmp(b, cmp, context))
|| (b instanceof Pattern
&& b.cmp(a)) }
&& b.cmp(a, cmp, context)) }
// cached diff...
// XXX this needs cache...
var diff = function(a, b){
var l2 = cache.get(a) || new Map()
var d = l2.get(b) || that.diff(a, b, options, context)
cache.set(a, l2.set(b, d))
return d
}
options.cmp = cmp
@ -1553,6 +1570,10 @@ module.Types = {
var A = node[1]
var B = node[2]
// XXX this both in closure and in 'this' only one should
// be left...
//context = this.context = this.context || context
// cache format:
// Map([
// [<obj_a>, Map([