From 8b610f2bcfc223333254ce9679730c42dce6d26e Mon Sep 17 00:00:00 2001 From: Kai Stevenson Date: Mon, 3 Nov 2025 23:41:31 -0800 Subject: add createFn --- src/js-lang/builtin/builtin.ts | 39 --------------------------------------- 1 file changed, 39 deletions(-) delete mode 100644 src/js-lang/builtin/builtin.ts (limited to 'src/js-lang/builtin/builtin.ts') 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 = { - arr: V_BUILTIN_Arr, - tostring: V_BUILTIN_ToString, - add: V_BUILTIN_Add, - mul: V_BUILTIN_Mul, -}; -- cgit v1.2.3-70-g09d2