Skip to content

Commit 0c0d6b3

Browse files
committed
Add await for operations and support function imports
1 parent 2542306 commit 0c0d6b3

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

interpreter.ts

+11-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const exp = api => exp => {
2222
}
2323

2424
// evaluate a list (AST)
25-
export const evalAst = api => ast => {
25+
export const evalAst = api => async ast => {
2626
// () = null
2727
if (ast.length === 0) {
2828
return ['atom', null]
@@ -42,12 +42,18 @@ export const evalAst = api => ast => {
4242
}
4343
}
4444
let fn = api.getValue(op)
45-
if (fn !== undefined && fn[0] === 'fn') {
46-
return evaluateFn(api, op, fn[1], args)
45+
if (fn !== undefined) {
46+
if (fn[0] === 'fn') {
47+
return evaluateFn(api, op, fn[1], args)
48+
} else if (typeof fn === 'function') {
49+
return await fn(api, args)
50+
} else {
51+
return api.evalAst(['throw', `'The operation is not valid: ${op}'`])
52+
}
4753
} else if (api.env[op]) {
48-
return api.env[op](api, args)
54+
return await api.env[op](api, args)
4955
} else if (atoms[op]) {
50-
return atoms[op](api, args)
56+
return await atoms[op](api, args)
5157
} else {
5258
return api.evalAst(['throw', `'The operation is not defined: ${op}'`])
5359
}

0 commit comments

Comments
 (0)