https://github.com/zackradisic/tyvm
An experimental bytecode interpreter / type-checker for type-level Typescript
https://github.com/zackradisic/tyvm
Last synced: about 1 year ago
JSON representation
An experimental bytecode interpreter / type-checker for type-level Typescript
- Host: GitHub
- URL: https://github.com/zackradisic/tyvm
- Owner: zackradisic
- Created: 2023-08-15T18:06:33.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2024-11-25T04:46:18.000Z (over 1 year ago)
- Last Synced: 2025-04-01T07:45:57.921Z (about 1 year ago)
- Language: Zig
- Homepage: https://tyvm.vercel.app
- Size: 31.8 MB
- Stars: 528
- Watchers: 11
- Forks: 21
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-typescript-compilers - tyvm - Level` | Experimental bytecode interpreter / type-checker for type-level TypeScript, written in Zig. | (Experimental/Research Projects)
README
# 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](https://github.com/web-infra-dev/oxc/) 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:
- Structurally shared data structures: [hash array mapped tries](https://en.wikipedia.org/wiki/Hash_array_mapped_trie), [RRB trees](https://citeseerx.ist.psu.edu/viewdoc/download;jsessionid=F16EC1235F2CFF0ED612C3C1ADC87EAF?doi=10.1.1.592.5377&rep=rep1&type=pdf)
- Static reference count optimizations ([Perceus](https://www.microsoft.com/en-us/research/publication/perceus-garbage-free-reference-counting-with-reuse/))