feat: Template operations #41

Merged
glen merged 10 commits from template_operations into main 2022-08-01 10:09:32 +00:00
Showing only changes of commit 5c3716ff99 - Show all commits

View File

@ -5,6 +5,8 @@ import {subsetOfKeys, typesOfSignature} from './utils.mjs'
const anySpec = {} // fixed dummy specification of 'any' type const anySpec = {} // fixed dummy specification of 'any' type
const theTemplateParam = 'T' // First pass: only allow this one exact parameter
export default class PocomathInstance { export default class PocomathInstance {
/* Disallowed names for ops; beware, this is slightly non-DRY /* Disallowed names for ops; beware, this is slightly non-DRY
* in that if a new top-level PocomathInstance method is added, its name * in that if a new top-level PocomathInstance method is added, its name
@ -339,7 +341,7 @@ export default class PocomathInstance {
* We will start this out very simply: the special string `T` is always * We will start this out very simply: the special string `T` is always
* a template parameter, and that's the only one * a template parameter, and that's the only one
*/ */
_templateParam(t) { return t === 'T' } _templateParam(t) { return t === theTemplateParam }
_addAffect(dependency, dependent) { _addAffect(dependency, dependent) {
if (dependency in this._affects) { if (dependency in this._affects) {
@ -401,8 +403,8 @@ export default class PocomathInstance {
Object.defineProperty(this, name, {configurable: true, value: 'limbo'}) Object.defineProperty(this, name, {configurable: true, value: 'limbo'})
const tf_imps = {} const tf_imps = {}
for (const [rawSignature, {uses, does}] of usableEntries) { for (const [rawSignature, {uses, does}] of usableEntries) {
/* For now, replace 'T' with 'any' */ /* For now, replace theTemplateParam with 'any' */
const signature = rawSignature.replaceAll('T', 'any') const signature = rawSignature.replaceAll(theTemplateParam, 'any')
if (uses.length === 0) { if (uses.length === 0) {
tf_imps[signature] = does() tf_imps[signature] = does()
} else { } else {
@ -413,7 +415,7 @@ export default class PocomathInstance {
let [func, needsig] = dep.split(/[()]/) let [func, needsig] = dep.split(/[()]/)
const needTypes = needsig ? typesOfSignature(needsig) : new Set() const needTypes = needsig ? typesOfSignature(needsig) : new Set()
/* For now, punt on template parameters */ /* For now, punt on template parameters */
if (needTypes.has('T')) needsig = '' if (needTypes.has(theTemplateParam)) needsig = ''
if (func === 'self') { if (func === 'self') {
if (needsig) { if (needsig) {
if (full_self_referential) { if (full_self_referential) {