calcium-lang
Version:
Calcium language interpreter
24 lines • 892 B
JavaScript
import { default as Sym } from "../symbol";
import { AttributeNotFound } from "../error";
import builtinFunctionOrMethod from "./builtinFunctionOrMethod";
export default function createBuiltinMethod({ 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=builtinMethod.js.map