Skip to content

Commit

Permalink
hello world
Browse files Browse the repository at this point in the history
  • Loading branch information
marcj committed Oct 17, 2022
1 parent 1af7ceb commit 65eb256
Show file tree
Hide file tree
Showing 60 changed files with 708 additions and 368 deletions.
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# TypeRunner

High-performance TypeScript compiler.

## Goal

- Parser
- Type checking (as CLI and as library)
- Language Server
- Interactive type debugging
- Type information in other languages
- (optional) transpiling to JavaScript
- (optional) RTTI in JavaScript

The goal is to make TypeScript type checking as fast as possible and provide alongside with it a native TS library for other languages, so they can use TypeScript type information
without the need for a JavaScript engine for all sorts of use cases like JSON-Schema replacement, ORM DSL, encoding information (like Protocol Buffers schema) and more.

The goal is not to be a drop-in replacement for the entire official TypeScript compiler (tsc). TypeScript just supports so much that is not always necessary.
We focus on the more strict TS part which means TypeRunner won't support JSDoc and a lot of compiler options.

## Status

The source code in the initial version is really only a proof of concept. It consists of roughly 30k LoC and shows very promising results.
The approach is a TS-to-bytecode compiler and then run the bytecode in a custom virtual machine.
The data show that this approach can lead to a hundred- to several-thousand-fold improvement in speed.

-- todo show data as graphs, maybe even make auto-generated --

![TypeRunner Debugger](./docs/typerunner-debugger.png)

Once the project gets funding through the community, the development will continue.

## Development

TypeRunner is written in modern C++ with cmake, doctest, imgui, tracy, fmt. To work on this project first clone the repository:

```sh
$ git clone [email protected]:marcj/TypeRunner.git
$ cd TypeRunner
```

then make sure cmake and a C++ compiler is installed. We use LLVM toolchain per default. To build the project run the usual cmake command:

```sh
$ mkdir build
$ cd build
$ cmake ..
```

Now you find in the build folder some binaries you can execute.
Binary file added docs/typerunner-debugger.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void compileAndRun(const string &code, const string &file, const string &fileNam

int main(int argc, char *argv[]) {
ZoneScoped;
std::string file = "/Users/marc/bude/typescript-cpp/tests/basic1.ts";
std::string file = "/Users/marc/bude/TypeRunner/tests/basic1.ts";
auto cwd = std::filesystem::current_path();

if (argc > 1) {
Expand Down
16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
{
"name": "typescript-cpp",
"version": "1.0.0",
"name": "typerunner",
"version": "0.0.1",
"description": "",
"main": "index.js",
"files": [
"README.md"
],
"directories": {
"test": "tests"
},
Expand All @@ -11,15 +14,14 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/marcj/typescript-cpp.git"
"url": "git+https://github.com/marcj/TypeRunner.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/marcj/typescript-cpp/issues"
"url": "https://github.com/marcj/TypeRunner/issues"
},
"homepage": "https://github.com/marcj/typescript-cpp#readme",
"dependencies": {
"homepage": "https://github.com/marcj/TypeRunner#readme",
"devDependencies": {
"ts-node": "^10.9.1",
"typescript": "^4.7.4"
}
Expand Down
33 changes: 32 additions & 1 deletion src/checker/check2.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "./types2.h"

namespace ts::vm2 {
namespace tr::vm2 {

namespace check {
struct Check {
Expand All @@ -29,6 +29,37 @@ namespace ts::vm2 {

return true;
}
case TypeKind::Function: {
switch (left->kind) {
case TypeKind::Function: {
auto leftFirst = (TypeRef *) left->type;
auto leftSecond = (TypeRef *) leftFirst->next;
auto leftReturnType = leftSecond->type;

auto rightFirst = (TypeRef *) right->type;
auto rightSecond = (TypeRef *) rightFirst->next;
auto rightReturnType = rightSecond->type;

auto leftCurrent = leftSecond->next;
auto rightCurrent = rightSecond->next;
while (leftCurrent) {
if (!rightCurrent) return false;

auto leftParameter = leftCurrent->type;
auto rightParameter = rightCurrent->type;

if (!extends(leftParameter, rightParameter)) return false;

leftCurrent = leftCurrent->next;
rightCurrent = rightCurrent->next;
}

return extends(leftReturnType, rightReturnType);
}
}
return false;
break;
}
case TypeKind::Tuple: {
switch (left->kind) {
case TypeKind::Tuple: {
Expand Down
2 changes: 1 addition & 1 deletion src/checker/checks.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "./types.h"
#include "../core.h"

namespace ts::vm {
namespace tr::vm {
static auto emptyString = HashString("");

HashString &getName(const shared<Type> &member) {
Expand Down
Loading

0 comments on commit 65eb256

Please sign in to comment.