Skip to content

Latest commit

 

History

History
37 lines (20 loc) · 2.06 KB

README.md

File metadata and controls

37 lines (20 loc) · 2.06 KB

tyvm

An experimental bytecode interpreter for type-level Typescript.

About

tyvm is another Typescript type-checker project, but this time with a focus on nailing type-level Typescript first.

The idea is that type-level Typescript is a very simple, purely functional programming language.

Tackling type-level Typescript alone is a lot less complex of a task then trying to reach feature parity with tsc in implementing the entirety of Typescript.

This would, theoretically, allow tyvm to be useful much more quickly. It could start being used as a converter for Typescript types -> X, where X is GraphQL, Prisma, JSON Schema, etc.

I'm also just fascinated by this kind of stuff, so it's also a fun side project for me.

Architectural Overview

This project is comprised of 2 main parts:

  1. Compiler: Written in Rust, takes Typescript type-level source code -> tyvm bytecode
  2. VM: Written in Zig, takes tyvm bytecode and executes it.

Compiler

The compiler uses the oxc project's parser to parse Typescript source code into an AST, which is then converted to a specialized intermediate representation (IR).

The IR makes compilation into bytecode much easier. It also doesn't constrain us to any one particular AST, conceptually, any AST from any of the JS/TS compiler projects (e.g. SWC, Babel, etc.) could be converted to the IR, allowing us to support many different compiler frontends.

VM

The VM is a stack based machine that runs the generated bytecode from the compiler.

Because of the simplicity and immutable nature of type-level Typescript, there many cool performance optimizations we can borrow from FP: