aboutsummaryrefslogtreecommitdiff
path: root/src/eval.ts
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2023-01-12 18:41:49 +0530
committerAkshay Nair <phenax5@gmail.com>2023-01-12 18:41:49 +0530
commita107048f87828b87b3bd55db1b6217710c40ee84 (patch)
tree2aa04a13f0d2987cc3eb7efe979d77834e2b57ce /src/eval.ts
parent3020be98876613b19dcc79f6cc8cade12460ba48 (diff)
downloadts-types-lang-a107048f87828b87b3bd55db1b6217710c40ee84.tar.gz
ts-types-lang-a107048f87828b87b3bd55db1b6217710c40ee84.zip
feat: adds mutable reference effects
Diffstat (limited to '')
-rw-r--r--src/eval.ts27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/eval.ts b/src/eval.ts
index 12997b1..8b53982 100644
--- a/src/eval.ts
+++ b/src/eval.ts
@@ -4,7 +4,6 @@ import readline from 'readline'
import { match } from './util'
import { Ctx } from './types'
-import { assert } from 'console'
const rl = readline.createInterface({
input: process.stdin,
@@ -39,6 +38,32 @@ export const evaluateType = async (
return []
},
+ CreateRef: async () => {
+ const val = ctx.typeToString(args[0])
+ const refKey = ctx.createRef(val)
+ const [resultKey, _] = ctx.createResult(JSON.stringify(refKey))
+ return [resultKey]
+ },
+
+ GetRef: async () => {
+ const refKey = ctx.getTypeValue(args[0])
+ const val = ctx.getRef(refKey)
+ if (!val) throw new Error('Ref has been deleted')
+ const [resultKey, _] = ctx.createResult(val)
+ return [resultKey]
+ },
+
+ SetRef: async () => {
+ const [ keyTy, valTyp ] = args
+ ctx.setRef(ctx.getTypeValue(keyTy), ctx.typeToString(valTyp))
+ return []
+ },
+
+ DeleteRef: async () => {
+ ctx.deleteRef(ctx.getTypeValue(args[0]))
+ return []
+ },
+
Pure: async () => {
const [valTyp] = args
const [resultKey, _] = ctx.createResult(ctx.typeToString(valTyp))