diff options
| author | Akshay Nair <phenax5@gmail.com> | 2023-01-14 17:38:24 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2023-01-14 17:39:24 +0530 |
| commit | f31caa5baad20553cac0330ae9ff279b8f88f340 (patch) | |
| tree | 52c7e6e0b2acdece8f013b64e3dbb2b70f5b14f5 /src | |
| parent | aee5d90a2397e68a753ab05e20566d0a23604931 (diff) | |
| download | ts-types-lang-f31caa5baad20553cac0330ae9ff279b8f88f340.tar.gz ts-types-lang-f31caa5baad20553cac0330ae9ff279b8f88f340.zip | |
feat: adds test cases for do and seq + fixes behavior with empty results
Diffstat (limited to 'src')
| -rw-r--r-- | src/context.ts | 4 | ||||
| -rw-r--r-- | src/eval-env/builtins.ts | 14 | ||||
| -rw-r--r-- | src/util.ts | 7 |
3 files changed, 14 insertions, 11 deletions
diff --git a/src/context.ts b/src/context.ts index fab6653..f70a17d 100644 --- a/src/context.ts +++ b/src/context.ts @@ -39,7 +39,9 @@ export const createContext = (options: CtxOptions): Ctx => { ) const getResultExpr = (resultKey?: string) => - `(${RESULT_TYPE_NAME}[${JSON.stringify(resultKey)})` + resultKey + ? `((${RESULT_TYPE_NAME}[${JSON.stringify(resultKey)})['output'])` + : 'undefined' const addResult = (name: string, ty: string): Node | undefined => resultTypeNode diff --git a/src/eval-env/builtins.ts b/src/eval-env/builtins.ts index c5b0c82..d90bc2e 100644 --- a/src/eval-env/builtins.ts +++ b/src/eval-env/builtins.ts @@ -49,6 +49,8 @@ export default (ctx: Ctx, args: Type[]) => ({ return [resultKey] }, + Noop: async () => [], + Print: async () => { console.log(...args.map(ctx.typeToString)) return [] @@ -77,7 +79,7 @@ export default (ctx: Ctx, args: Type[]) => ({ const resultType = applyFunc( ctx, chainToKind, - resultKey ? `(${ctx.getResultExpr(resultKey)})['output']` : 'never' + resultKey ? `${ctx.getResultExpr(resultKey)}` : 'never' ) return ctx.evaluateType(ctx, resultType) }), @@ -102,7 +104,7 @@ export default (ctx: Ctx, args: Type[]) => ({ return [value] }, - Try: async () => { + Try: ctx.withScope(async () => { const [effTyp, catchK] = args try { @@ -113,7 +115,7 @@ export default (ctx: Ctx, args: Type[]) => ({ const resultType = applyFunc(ctx, catchK, error) return ctx.evaluateType(ctx, resultType) } - }, + }), Throw: async () => { throw args[0] && ctx.getTypeValue(args[0]) @@ -134,8 +136,8 @@ export default (ctx: Ctx, args: Type[]) => ({ effectTyps?.getTupleElements() ?? [] ) const [resultKey, _] = ctx.createResult(`[ - ${effectResults.map(ctx.getResultExpr).join(', ')} - ]`) + ${effectResults.map(ctx.getResultExpr).join(', ')} + ]`) return [resultKey] }), @@ -148,7 +150,7 @@ export default (ctx: Ctx, args: Type[]) => ({ // TODO: Use last type's result instead of last result key const lastResKey = effectResults[effectResults.length - 1] const [resultKey, _] = ctx.createResult( - `(${ctx.getResultExpr(lastResKey)})['output']` + `${ctx.getResultExpr(lastResKey)}` ) return [resultKey] }), diff --git a/src/util.ts b/src/util.ts index a486294..b7d4efe 100644 --- a/src/util.ts +++ b/src/util.ts @@ -7,9 +7,10 @@ export const match = <K extends string, R>( ) => (k && pattern[k] ? pattern[k]() : pattern._()) export const evalList = async (ctx: Ctx, effectTyps: Type[]) => { - const effectResults: string[] = [] + const effectResults: (string | undefined)[] = [] for (const item of effectTyps ?? []) { - effectResults.push(...(await ctx.evaluateType(ctx, item))) + const [resultKey] = await ctx.evaluateType(ctx, item) + effectResults.push(resultKey ? resultKey : undefined) } return effectResults } @@ -69,8 +70,6 @@ export const applyFunc = ( return undefined })() - // TODO: Cleanup unwanted result node values - if (!resultType) { throw new Error('Couldnt get result for function application') } |
