refactor: add stub for patch to generic template behavior

This commit is contained in:
Glen Whitney 2022-07-31 21:08:28 -07:00
parent 171b6941f4
commit 7bbdc049ce

View File

@ -434,9 +434,35 @@ export default class PocomathInstance {
substituteInSig(rawSignature, theTemplateParam, instType)
this._addTFimplementation(tf_imps, signature, behavior, instType)
}
/* Now add the catchall signature; for now, punting on the behavior */
/* Now add the catchall signature */
const signature = substituteInSig(rawSignature, theTemplateParam, 'any')
this._addTFimplementation(tf_imps, signature, behavior)
/* The catchall signature has to detect the actual type of the call
* and add the new instantiations
*/
const argTypes = rawSignature.split(',')
let exemplar = -1
for (let i = 0; i < argTypes.length; ++i) {
const argType = argTypes[i].trim()
if (argType === theTemplateParam) {
exemplar = i
break
}
}
if (exemplar < 0) {
throw new SyntaxError(
`Cannot find template parameter in ${rawSignature}`)
}
const self = this
const patch = (refs) => {
const original = behavior.does(refs)
return (...args) => {
const example = args[exemplar]
console.log('Have to match template to', example)
return original(...args)
}
}
this._addTFimplementation(
tf_imps, signature, {uses: behavior.uses, does: patch})
}
const tf = this._typed(name, tf_imps)
Object.defineProperty(this, name, {configurable: true, value: tf})