diff options
| author | Kai Stevenson <kai@kaistevenson.com> | 2025-11-03 23:41:31 -0800 |
|---|---|---|
| committer | Kai Stevenson <kai@kaistevenson.com> | 2025-11-03 23:41:31 -0800 |
| commit | 8b610f2bcfc223333254ce9679730c42dce6d26e (patch) | |
| tree | ac1eab726395523f8725bda3d040e22214cba409 /src/js-lang/builtin/builtin.ts | |
| parent | 56040f3ff85e77311f0c864a89afd63fcf1bdb50 (diff) | |
add createFn
Diffstat (limited to 'src/js-lang/builtin/builtin.ts')
| -rw-r--r-- | src/js-lang/builtin/builtin.ts | 39 |
1 files changed, 0 insertions, 39 deletions
diff --git a/src/js-lang/builtin/builtin.ts b/src/js-lang/builtin/builtin.ts deleted file mode 100644 index dde91b6..0000000 --- a/src/js-lang/builtin/builtin.ts +++ /dev/null @@ -1,39 +0,0 @@ -type BUILTIN = (args: any[]) => any; - -export const V_BUILTIN_Arr: BUILTIN = (args) => args; - -// FIXME actually implement this properly -export const V_BUILTIN_ToString: BUILTIN = (args) => - args.length === 1 ? JSON.stringify(args[0]) : JSON.stringify(args); - -export const V_BUILTIN_Add: BUILTIN = (args) => { - if (args.every((arg) => ["string", "number"].includes(typeof arg))) { - return args.reduce( - (acc, cur) => acc + cur, - typeof args[0] === "string" ? "" : 0 - ); - } - - throw new Error(`Cannot add operands ${JSON.stringify(args, undefined, 2)}`); -}; - -export const V_BUILTIN_Mul: BUILTIN = (args) => { - if (args.every((arg) => typeof arg === "number") && args.length === 2) { - return args.reduce((acc, cur) => acc * cur, 1); - } - - throw new Error( - `Can only multiply [number, number], but got ${JSON.stringify( - args, - undefined, - 2 - )}` - ); -}; - -export const nameToBUILTIN: Record<string, BUILTIN> = { - arr: V_BUILTIN_Arr, - tostring: V_BUILTIN_ToString, - add: V_BUILTIN_Add, - mul: V_BUILTIN_Mul, -}; |
