aboutsummaryrefslogtreecommitdiff
path: root/src/runtime.ts
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2023-01-05 18:49:34 +0530
committerAkshay Nair <phenax5@gmail.com>2023-01-05 18:49:34 +0530
commit9842f84ecd47011149c928287e63fb5de399e161 (patch)
treecd243838ac7cba673d053855b3818b9ec0b4b3a6 /src/runtime.ts
parent1e2b8780906744ad51248ee7021bd5d1d1e86ebb (diff)
downloadts-types-lang-9842f84ecd47011149c928287e63fb5de399e161.tar.gz
ts-types-lang-9842f84ecd47011149c928287e63fb5de399e161.zip
feat: js expr in types now. aaaa. kill me pliz
Diffstat (limited to '')
-rw-r--r--src/runtime.ts37
1 files changed, 35 insertions, 2 deletions
diff --git a/src/runtime.ts b/src/runtime.ts
index 231dcd3..11a7e61 100644
--- a/src/runtime.ts
+++ b/src/runtime.ts
@@ -1,6 +1,17 @@
import { Project, ScriptTarget, Type, Node, StringLiteral, TypeFormatFlags, SyntaxKind } from 'ts-morph'
import path from 'path'
import { promises as fs } from 'fs'
+import readline from 'readline';
+
+const rl = readline.createInterface({
+ input: process.stdin,
+ output: process.stdout,
+ terminal: false
+});
+
+const readLineFromStdin = (): Promise<string> => new Promise((res) => {
+ rl.on('line', res)
+})
const project = new Project({
compilerOptions: {
@@ -75,6 +86,22 @@ const accumulateResults = async (effTyp: Type, node: Node): Promise<string[]> =>
return [hash]
},
+ ReadLine: async () => {
+ const line = await readLineFromStdin()
+ const hash = createHash()
+ addResult(hash, `${JSON.stringify(line)}`)
+ return [hash]
+ },
+
+ JsExpr: async () => {
+ const [exprTyp] = effTyp.getTypeArguments()
+ const exprStr = JSON.parse(typeToString(exprTyp))
+ const result = eval(exprStr)
+ const hash = createHash()
+ addResult(hash, `${JSON.stringify(result)}`)
+ return [hash]
+ },
+
_: async () => {
console.log(`${name} result effect is unhandled`)
return []
@@ -91,6 +118,13 @@ const evalAccumulator = async (effNode: Node, node: Node) => {
console.log(...effTyp.getTypeArguments().map(typeToString));
},
+ Debug: async () => {
+ const [labelTyp, valueTyp] = effTyp.getTypeArguments()
+ const label = JSON.parse(typeToString(labelTyp))
+ const value = JSON.parse(typeToString(valueTyp))
+ console.log(label, value)
+ },
+
ReadFile: async () => {
const [hash] = await accumulateResults(effTyp, node)
effNode.replaceWithText(`${RESULT_TYPE_NAME}[${JSON.stringify(hash)}]`)
@@ -104,9 +138,8 @@ const evalAccumulator = async (effNode: Node, node: Node) => {
},
ChainIO: async () => {
- const inputTyp = effTyp.getProperty('input')?.getTypeAtLocation(node)
const chainToKind = effTyp.getProperty('chainTo')?.getTypeAtLocation(node)
- const [hashRes] = inputTyp ? await accumulateResults(inputTyp, node) : []
+ const [hashRes] = await accumulateResults(effTyp, node)
const chainRes = `(${typeToString(chainToKind)} & { input: ${RESULT_TYPE_NAME}[${JSON.stringify(hashRes)}]['output'] })['return']`
const updateEffNode = effNode.replaceWithText(chainRes)
await evalAccumulator(updateEffNode, node)