aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2023-01-12 17:33:57 +0530
committerAkshay Nair <phenax5@gmail.com>2023-01-12 17:33:57 +0530
commit7a9520b3879bccb872aaca6245c92071a957deff (patch)
treea66f10b31a4ec9290897178cc1bc9627dbe65dc3 /src
parent83b6bcaa81a645e1b3936d856fbb84ea219ee04e (diff)
downloadts-types-lang-7a9520b3879bccb872aaca6245c92071a957deff.tar.gz
ts-types-lang-7a9520b3879bccb872aaca6245c92071a957deff.zip
feat: adds try/catch effects
Diffstat (limited to 'src')
-rw-r--r--src/eval.ts22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/eval.ts b/src/eval.ts
index c34e911..12997b1 100644
--- a/src/eval.ts
+++ b/src/eval.ts
@@ -4,6 +4,7 @@ import readline from 'readline'
import { match } from './util'
import { Ctx } from './types'
+import { assert } from 'console'
const rl = readline.createInterface({
input: process.stdin,
@@ -117,8 +118,25 @@ export const evaluateType = async (
},
Exit: async () => {
- const exitCode = args[0] && ctx.getTypeValue(args[0])
- process.exit(exitCode)
+ process.exit(args[0] && ctx.getTypeValue(args[0]))
+ },
+
+ Try: async () => {
+ const [effTyp, catchK] = args
+
+ try {
+ if (!effTyp) throw new Error('wow')
+ return await evaluateType(ctx, effTyp)
+ } catch(e) {
+ const error = JSON.stringify((e as any)?.message ?? e)
+ const catchResExpr = `(${ctx.typeToString(catchK)} & { input: ${error} })['return']`
+ const [resultKey, _] = ctx.createResult(catchResExpr)
+ return [resultKey]
+ }
+ },
+
+ Throw: async () => {
+ throw args[0] && ctx.getTypeValue(args[0])
},
ReadLine: async () => {