feat: Template operations #41
@ -434,9 +434,35 @@ export default class PocomathInstance {
|
|||||||
substituteInSig(rawSignature, theTemplateParam, instType)
|
substituteInSig(rawSignature, theTemplateParam, instType)
|
||||||
this._addTFimplementation(tf_imps, signature, behavior, 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')
|
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)
|
const tf = this._typed(name, tf_imps)
|
||||||
Object.defineProperty(this, name, {configurable: true, value: tf})
|
Object.defineProperty(this, name, {configurable: true, value: tf})
|
||||||
|
Loading…
Reference in New Issue
Block a user