UNPKG

calcium-lang

Version:
30 lines 1 kB
import { default as Sym } from "../symbol"; import { AttributeNotFound } from "../error"; import builtinFunctionOrMethod from "./builtinFunctionOrMethod"; /** * * @param name * @param body * @returns the internal representation of a built-in function */ export default function createBuiltinFunction({ name, body, }) { const self = new Proxy({}, { get(target, property, receiver) { if (property === Sym.name) return name; else if (property === Sym.call) return (args, env) => { const result = body(args, env); return result; }; else if (property === Sym.evaluate) return (env) => self; else if (property === Sym.class) return builtinFunctionOrMethod; else throw new AttributeNotFound(property.toString()); }, }); return self; } //# sourceMappingURL=builtinFunction.js.map