aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2023-01-05 19:28:43 +0530
committerAkshay Nair <phenax5@gmail.com>2023-01-05 19:28:43 +0530
commit395b01feaadb896c1747696cd874bd70de727110 (patch)
tree120d73963432fdbbe63164da6b9253fe68a80809 /src
parenta32741ec698473e9575679c145806fb96dc7ccf5 (diff)
downloadts-types-lang-395b01feaadb896c1747696cd874bd70de727110.tar.gz
ts-types-lang-395b01feaadb896c1747696cd874bd70de727110.zip
feat: adds getargs function
Diffstat (limited to 'src')
-rw-r--r--src/index.ts14
-rw-r--r--src/runtime.ts14
2 files changed, 22 insertions, 6 deletions
diff --git a/src/index.ts b/src/index.ts
index 6097752..b8a69ac 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1,7 +1,7 @@
export interface EffectAtom<T = unknown> { output: T }
export type Effect = EffectAtom[]
-export interface PrintString<_ extends string> extends EffectAtom { }
+export interface PutString<_ extends string> extends EffectAtom { }
export interface Print<_ extends any> extends EffectAtom { }
export interface Debug<_ extends string, T> extends EffectAtom<T> { }
@@ -9,6 +9,7 @@ export interface WriteFile<_Path extends string, _Content extends string> extend
export interface ReadFile<_Path extends string> extends EffectAtom<string> { }
export interface GetEnv<_Name extends string> extends EffectAtom<string> { }
+export interface GetArgs extends EffectAtom<string[]> { }
export interface ReadLine extends EffectAtom<string> { }
@@ -37,13 +38,14 @@ interface PrintK<Label extends string = ""> extends Kind1<unknown> {
// return: ChainIO<ReadLine, PrintK<this['input']>>
// }
-// ChainIO<ReadLine, WithInputK>,
-// ChainIO<ReadFile<"./default.nix">, PrintK>,
-// Print<"Your name?:">,
-// ChainIO<ReadLine, PrintK<"Hello,">>,
-
export type main = Program<[
+ ChainIO<GetArgs, PrintK>,
[1, 2, 3] extends infer Res ? Print<Res> : never,
ChainIO<GetEnv<"NODE_ENV">, PrintK>,
ChainIO<JsExpr<"{ boobaa: [5 * 3, 5 * 2] }">, PrintK>,
+ // ChainIO<ReadLine, WithInputK>,
+ ChainIO<ReadFile<"./default.nix">, PrintK>,
+ PutString<"Your name? ">,
+ ChainIO<ReadLine, PrintK<"Hello,">>,
]>
+
diff --git a/src/runtime.ts b/src/runtime.ts
index 8620add..b3c49c3 100644
--- a/src/runtime.ts
+++ b/src/runtime.ts
@@ -2,6 +2,7 @@ import { Project, ScriptTarget, Type, Node, StringLiteral, TypeFormatFlags, Synt
import path from 'path'
import { promises as fs } from 'fs'
import readline from 'readline';
+import { stdout } from 'process';
const rl = readline.createInterface({
input: process.stdin,
@@ -86,6 +87,12 @@ const accumulateResults = async (effTyp: Type, node: Node): Promise<string[]> =>
return [hash]
},
+ GetArgs: async () => {
+ const hash = createHash()
+ addResult(hash, `${JSON.stringify(process.argv.slice(2))}`)
+ return [hash]
+ },
+
ReadLine: async () => {
const line = await readLineFromStdin()
const hash = createHash()
@@ -118,6 +125,13 @@ const evalAccumulator = async (effNode: Node, node: Node) => {
console.log(...effTyp.getTypeArguments().map(typeToString));
},
+ PutString: async () => {
+ const [strinTyp] = effTyp.getTypeArguments()
+ const typString = typeToString(strinTyp)
+ const string = JSON.parse(!typString.startsWith('"') ? `"${typString}"` : typString)
+ stdout.write(string);
+ },
+
Debug: async () => {
const [labelTyp, valueTyp] = effTyp.getTypeArguments()
const label = JSON.parse(typeToString(labelTyp))