mirror of
https://github.com/vale981/tridactyl
synced 2025-03-05 09:31:41 -05:00

This commit makes the compiler pass use different classes in order to represent the metadata. This enables adding per-class toString/convert functions. This enables easy type checking and conversion in the `:set` excmd.
28 lines
777 B
TypeScript
28 lines
777 B
TypeScript
import { Type } from "./Type"
|
|
|
|
export class FunctionType implements Type {
|
|
kind = "function"
|
|
|
|
constructor(public args: Type[], public ret: Type) {}
|
|
|
|
toConstructor() {
|
|
return (
|
|
`new FunctionType([` +
|
|
// Convert every argument type to its string constructor representation
|
|
this.args.map(cur => cur.toConstructor()) +
|
|
`], ${this.ret.toConstructor()})`
|
|
)
|
|
}
|
|
|
|
toString() {
|
|
return `(${this.args.map(a => a.toString()).join(", ")}) => ${this.ret.toString()}`
|
|
}
|
|
|
|
convert(argument) {
|
|
// Possible strategies:
|
|
// - eval()
|
|
// - window[argument]
|
|
// - tri.excmds[argument]
|
|
throw new Error(`Conversion to function not implemented: ${argument}`)
|
|
}
|
|
}
|