• Stars
    star
    430
  • Rank 101,083 (Top 2 %)
  • Language
    Zig
  • Created over 1 year ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An experimental bytecode interpreter / type-checker for type-level Typescript

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:

More Repositories

1

aussieplusplus

Programming language from down under
Rust
612
star
2

go-playground-wasm

A version of play.golang.org that runs completely in the browser
TypeScript
183
star
3

glyph

My own personal code editor built with Rust + OpenGL
Rust
157
star
4

rust-vs-zig

Comparing unsafe Rust vs Zig by writing a bytecode interpreter with GC in both langs
Rust
154
star
5

node-soundcloud-downloader

A SoundCloud API v2 wrapper for Node.js
TypeScript
134
star
6

tyfsm

(wip) simple and typesafe finite automata based state management library. Inspired by zustand and xstate
TypeScript
123
star
7

tether

WIP high-performance code editor inspired by Doom Emacs and neovim. Comes with explosions.
Zig
65
star
8

lofi-cli

Listen to ChilledCow's lofi hip-hop stream from the command line
JavaScript
27
star
9

soundcloud-api

A SoundCloud API v2 wrapper for Go
Go
26
star
10

write-your-own-zod

Write your own Zod from scratch
TypeScript
14
star
11

force-directed-graph

experiment
Rust
11
star
12

bun-macros-flappy-bird

C
5
star
13

prisma2gql

prisma schema 2 graphql schema generator
Haskell
4
star
14

iszacksleeping

A way to actually contact me and hold me accountable to a sleep schedule
TypeScript
3
star
15

toilet-paper-twitter

a stupid graphics experiment
HTML
3
star
16

cheatsheets

TypeScript
2
star
17

rasta

Building a software rasterizer for fun
Rust
2
star
18

downloadsound.cloud-api-go

Go
1
star
19

c-template

Simple C project starter template
C
1
star
20

rust-emscripten-bug

Rust
1
star
21

youtube-rooms-frontend

TypeScript
1
star
22

learning-crdts-rust

Learning and implementing CRDTs in Rust
Rust
1
star
23

downloadsound.cloud-api

TypeScript
1
star
24

youtube-rooms

Go
1
star
25

downloadsound.cloud

TypeScript
1
star
26

sticky

Fixing my broken right arrow key
Objective-C
1
star