summaryrefslogtreecommitdiff
path: root/src/lang/ks-lang/index.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/lang/ks-lang/index.ts')
-rw-r--r--src/lang/ks-lang/index.ts13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/lang/ks-lang/index.ts b/src/lang/ks-lang/index.ts
index 772c9c9..633d9b9 100644
--- a/src/lang/ks-lang/index.ts
+++ b/src/lang/ks-lang/index.ts
@@ -8,6 +8,7 @@ import {
CallFn,
EmptyStackFrame,
ASTNode,
+ StackFrame,
} from "../ts-lang";
export type TransformArgs<Args extends readonly ASTNode[]> = {
@@ -40,13 +41,17 @@ export const createFn =
: EvalError<`Program's args do not extend args constraint`>
: EvalError<"Cannot create a function from a program that does not eval to a function">
: never => {
- const [programFn] = evaluate(parse(lex(program))) as Array<FnPrim>;
- if (!programFn.fn) {
+ const [e] = evaluate(parse(lex(program))) as [
+ FnPrim | [FnPrim, StackFrame, ASTNode["name"]]
+ ];
+
+ const fn: FnPrim = Array.isArray(e) ? e[0] : e;
+
+ if (!fn.fn) {
throw new Error(
"Cannot create a function from a program that does not eval to a function"
);
}
- return ((...args: any[]) =>
- callFn(programFn, args, emptyStackFrame)) as any;
+ return ((...args: any[]) => callFn(e, args, emptyStackFrame)) as any;
};