theprogrammablemind 9.7.1-beta.4 → 9.7.1-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/config.js +1 -0
- package/src/debug.js +17 -2
- package/src/fragments.js +29 -2
- package/src/generators.js +20 -15
- package/src/semantics.js +29 -24
package/package.json
CHANGED
package/src/config.js
CHANGED
package/src/debug.js
CHANGED
|
@@ -27,6 +27,18 @@ const unhit = (name) => {
|
|
|
27
27
|
hits[name] = false
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
const hitScoped = async (name, call) => {
|
|
31
|
+
hit(name)
|
|
32
|
+
try {
|
|
33
|
+
const result = await call()
|
|
34
|
+
unhit(name)
|
|
35
|
+
return result
|
|
36
|
+
} catch( e ) {
|
|
37
|
+
unhit(name)
|
|
38
|
+
throw e
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
30
42
|
const wasHit = (name) => {
|
|
31
43
|
return hits[name]
|
|
32
44
|
}
|
|
@@ -64,16 +76,19 @@ const _break = (name) => {
|
|
|
64
76
|
}
|
|
65
77
|
}
|
|
66
78
|
|
|
79
|
+
const breakAt = _break;
|
|
80
|
+
|
|
67
81
|
module.exports = {
|
|
68
82
|
counter,
|
|
69
83
|
get,
|
|
70
84
|
_break, // break is a keyword
|
|
71
|
-
|
|
85
|
+
breakAt,
|
|
72
86
|
// used for tests
|
|
73
87
|
reset,
|
|
74
88
|
hit,
|
|
75
89
|
unhit,
|
|
76
90
|
wasHit,
|
|
77
91
|
getDb,
|
|
78
|
-
setDb
|
|
92
|
+
setDb,
|
|
93
|
+
hitScoped,
|
|
79
94
|
}
|
package/src/fragments.js
CHANGED
|
@@ -1,6 +1,29 @@
|
|
|
1
1
|
const _ = require('lodash')
|
|
2
2
|
const helpers = require('./helpers')
|
|
3
3
|
|
|
4
|
+
function createChangeTracker(obj) {
|
|
5
|
+
const changes = new Set();
|
|
6
|
+
|
|
7
|
+
const handler = {
|
|
8
|
+
set(target, prop, value) {
|
|
9
|
+
changes.add(prop);
|
|
10
|
+
target[prop] = value;
|
|
11
|
+
return true;
|
|
12
|
+
},
|
|
13
|
+
deleteProperty(target, prop) {
|
|
14
|
+
changes.add(prop);
|
|
15
|
+
delete target[prop];
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
proxy: new Proxy(obj, handler),
|
|
22
|
+
getChanges: () => Array.from(changes)
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
4
27
|
function fragmentInstantiator (args, contexts) {
|
|
5
28
|
return new Object({
|
|
6
29
|
contexts: () => {
|
|
@@ -13,13 +36,15 @@ function fragmentInstantiator (args, contexts) {
|
|
|
13
36
|
args.pathEquals = helpers.pathEquals
|
|
14
37
|
while (todo.length > 0) {
|
|
15
38
|
const { context, path } = todo.pop()
|
|
16
|
-
|
|
39
|
+
const { proxy, getChanges } = createChangeTracker(context);
|
|
40
|
+
args.context = proxy
|
|
17
41
|
args.path = path
|
|
18
42
|
for (const mapping of mappings) {
|
|
19
43
|
if (await mapping.match(args)) {
|
|
20
44
|
await mapping.apply(args)
|
|
21
45
|
}
|
|
22
46
|
}
|
|
47
|
+
const ignore = getChanges()
|
|
23
48
|
for (const key of Object.keys(context)) {
|
|
24
49
|
// if (['number', 'string', 'boolean'].includes(typeof (context[key]))) {
|
|
25
50
|
if (!helpers.isCompound(context[key])) {
|
|
@@ -28,7 +53,9 @@ function fragmentInstantiator (args, contexts) {
|
|
|
28
53
|
if (context[key].instantiated) {
|
|
29
54
|
continue
|
|
30
55
|
}
|
|
31
|
-
|
|
56
|
+
if (!ignore.includes(key)) {
|
|
57
|
+
todo.push({ context: context[key], path: [...path, key] })
|
|
58
|
+
}
|
|
32
59
|
}
|
|
33
60
|
}
|
|
34
61
|
if (contexts.length == 1 && instantiated.length == 1) {
|
package/src/generators.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const { args: contextArgs, normalizeGenerator } = require('./helpers')
|
|
2
2
|
const Lines = require('../lines')
|
|
3
3
|
const helpers = require('./helpers')
|
|
4
|
+
const debug = require('./debug')
|
|
4
5
|
|
|
5
6
|
class Generator {
|
|
6
7
|
// constructor ({ match, apply, uuid, index, km, priority, notes }) {
|
|
@@ -65,14 +66,16 @@ class Generator {
|
|
|
65
66
|
}
|
|
66
67
|
const args = Object.assign({}, baseArgs, moreArgs, (baseArgs.getUUIDScoped || (() => { return {} }))(this.uuid))
|
|
67
68
|
// return this.match(args)
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
69
|
+
return await debug.hitScoped(args.callId, async () => {
|
|
70
|
+
const matches = await this.match(args)
|
|
71
|
+
if ((matches && (options.debug || {}).match) ||
|
|
72
|
+
callId === this.callId) {
|
|
73
|
+
// next line is the matcher
|
|
74
|
+
debugger // eslint-disable-line no-debugger
|
|
75
|
+
await this.match(args)
|
|
76
|
+
}
|
|
77
|
+
return matches
|
|
78
|
+
})
|
|
76
79
|
}
|
|
77
80
|
|
|
78
81
|
// apply (baseArgs, objects, g, gs, context, hierarchy, config, response, log, options = {}) {
|
|
@@ -121,11 +124,13 @@ class Generator {
|
|
|
121
124
|
if (this.property === 'generatorp') {
|
|
122
125
|
args.g = args.gp
|
|
123
126
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
127
|
+
return await debug.hitScoped(args.callId, async () => {
|
|
128
|
+
if ((options.debug || {}).apply ||
|
|
129
|
+
callId === this.callId) {
|
|
130
|
+
debugger // eslint-disable-line no-debugger
|
|
131
|
+
}
|
|
132
|
+
return await this._apply(args)
|
|
133
|
+
})
|
|
129
134
|
}
|
|
130
135
|
}
|
|
131
136
|
|
|
@@ -220,7 +225,7 @@ class Generators {
|
|
|
220
225
|
lines.setElement(0, 2, stack)
|
|
221
226
|
lines.newRow()
|
|
222
227
|
lines.setElement(0, 1, 'DEBUG')
|
|
223
|
-
lines.setElement(0, 2, `To debug this use
|
|
228
|
+
lines.setElement(0, 2, `To debug this use debug.breakAt('${args.calls.current()}')`)
|
|
224
229
|
lines.newRow()
|
|
225
230
|
lines.setElement(0, 1, 'ERROR')
|
|
226
231
|
lines.setElement(0, 2, errorMessage)
|
|
@@ -252,7 +257,7 @@ class Generators {
|
|
|
252
257
|
lines.setElement(0, 2, stack)
|
|
253
258
|
lines.newRow()
|
|
254
259
|
lines.setElement(0, 1, 'DEBUG')
|
|
255
|
-
lines.setElement(0, 2, `To debug this use
|
|
260
|
+
lines.setElement(0, 2, `To debug this use debug.breakAt('${args.calls.current()}')`)
|
|
256
261
|
lines.newRow()
|
|
257
262
|
lines.setElement(0, 1, 'TO')
|
|
258
263
|
lines.setElement(0, 2, `context_id: ${context.context_id}`)
|
package/src/semantics.js
CHANGED
|
@@ -75,13 +75,15 @@ class Semantic {
|
|
|
75
75
|
async matches (args, context, options = {}) {
|
|
76
76
|
args = {...args}
|
|
77
77
|
this.fixUpArgs(args, context)
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
78
|
+
return await debug.hitScoped(args.callId, async () => {
|
|
79
|
+
const matches = await this.matcher(args)
|
|
80
|
+
if (matches && (options.debug || {}).match || args.callId === this.callId) {
|
|
81
|
+
// next line is the matcher
|
|
82
|
+
debugger // eslint-disable-line no-debugger
|
|
83
|
+
await this.matcher(args)
|
|
84
|
+
}
|
|
85
|
+
return matches
|
|
86
|
+
})
|
|
85
87
|
}
|
|
86
88
|
|
|
87
89
|
async apply (args, context, s, options = {}) {
|
|
@@ -97,21 +99,24 @@ class Semantic {
|
|
|
97
99
|
const contextPrime = Object.assign({}, context)
|
|
98
100
|
this.fixUpArgs(args, contextPrime)
|
|
99
101
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
102
|
+
return await debug.hitScoped(args.callId, async () => {
|
|
103
|
+
if ((options.debug || {}).apply || args.callId === this.callId) {
|
|
104
|
+
debugger // eslint-disable-line no-debugger
|
|
105
|
+
}
|
|
106
|
+
if (args.breakOnSemantics) {
|
|
107
|
+
debugger // eslint-disable-line no-debugger
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
try {
|
|
111
|
+
args.handlerStack.push(this)
|
|
112
|
+
await this._apply(args)
|
|
113
|
+
args.handlerStack.pop()
|
|
114
|
+
} catch( e ) {
|
|
115
|
+
args.handlerStack.pop()
|
|
116
|
+
throw e
|
|
117
|
+
}
|
|
118
|
+
return contextPrime
|
|
119
|
+
})
|
|
115
120
|
}
|
|
116
121
|
}
|
|
117
122
|
|
|
@@ -253,7 +258,7 @@ class Semantics {
|
|
|
253
258
|
lines.setElement(0, 2, semantic.toString())
|
|
254
259
|
lines.newRow()
|
|
255
260
|
lines.setElement(0, 1, 'DEBUG')
|
|
256
|
-
lines.setElement(0, 2, `To debug this use
|
|
261
|
+
lines.setElement(0, 2, `To debug this use debug.breakAt('${args.calls.current()}')`)
|
|
257
262
|
lines.newRow()
|
|
258
263
|
lines.setElement(0, 1, 'TO')
|
|
259
264
|
lines.setElement(0, 2, `context_id: ${context.context_id}`)
|
|
@@ -288,7 +293,7 @@ class Semantics {
|
|
|
288
293
|
lines.setElement(0, 2, semantic.toString())
|
|
289
294
|
lines.newRow()
|
|
290
295
|
lines.setElement(0, 1, 'DEBUG')
|
|
291
|
-
lines.setElement(0, 2, `To debug this use
|
|
296
|
+
lines.setElement(0, 2, `To debug this use debug.breakAt('${args.calls.current()}')`)
|
|
292
297
|
lines.newRow()
|
|
293
298
|
lines.setElement(0, 1, 'TO')
|
|
294
299
|
lines.setElement(0, 2, `context_id: ${context.context_id}`)
|