aboutsummaryrefslogtreecommitdiff
path: root/src/index.ts
blob: 4775823edf19a0106fcfaab321cabace6f9a017c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { program } from 'commander'
import { createContext } from './context'
import { cleanup } from './eval'
import { evalList } from './util'

const main = () => {
  program
    .name('ts-types-lang')
    .description(
      `A runtime for typescript's type system that turns it into a general purpose, purely functional programming language!`
    )

  program
    .command('run')
    .description('Run a typescript .ts file')
    .argument('<file>', 'Typescript file to run')
    .action(async (filePath) => {
      try {
        const ctx = createContext({ filePath })
        const resultType = ctx.entryPoint.getType()
        const effects = resultType.isTuple()
          ? resultType.getTupleElements()
          : [resultType]
        await evalList(ctx, effects)
      } catch (e) {
        console.error(e)
        process.exit(1)
      }
    })

  return program.parseAsync()
}

main().finally(() => cleanup())