UNPKG

expression-evaluation

Version:
41 lines (40 loc) 1.26 kB
import { typeUnknown } from './Type.js'; export const FUNCTION_ARG_MAX = 16536; export class FunctionSignature { _type; _argTypes; _minArity; _maxArity; _typeInference; _pure; static unknown = new FunctionSignature(typeUnknown, [typeUnknown], 0, FUNCTION_ARG_MAX); constructor(_type, _argTypes, _minArity, _maxArity, _typeInference, _pure = true) { this._type = _type; this._argTypes = _argTypes; this._minArity = _minArity; this._maxArity = _maxArity; this._typeInference = _typeInference; this._pure = _pure; } get pure() { return this._pure; } get minArity() { return this._minArity ?? this._argTypes.length; } get maxArity() { return this._maxArity ?? this._argTypes.length; } get type() { return this._type; } argType(index) { return this._argTypes[index] ?? this._argTypes[this._argTypes.length - 1]; } argTypeInference(type, index) { return this._typeInference && this._typeInference <= index ? this.argType(index).reduce(type) : this.argType(index); } toString() { return `${this._type.toString()}(${this._argTypes.map((i) => i.toString()).join(', ')})`; } }