Skip to content

Commit

Permalink
add better memory allocator parser (increasing perf 2x)
Browse files Browse the repository at this point in the history
started with support for inferring type arguments from parameters.

added dockerfile for linux build

add MIT license
  • Loading branch information
marcj committed Nov 2, 2022
1 parent e269638 commit 5e573db
Show file tree
Hide file tree
Showing 52 changed files with 5,508 additions and 4,857 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.idea
cmake-*
build*
Dockerfile
12 changes: 6 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
cmake_minimum_required(VERSION 3.22)
cmake_minimum_required(VERSION 3.16)
project(typescript)

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD 20)

set(CMAKE_CXX_FLAGS "-Wno-unused-variable -Wno-switch")
set(CMAKE_CXX_FLAGS "-Wno-unused-variable -Wno-switch -Wno-trigraphs")

if(CMAKE_BUILD_TYPE STREQUAL "Release")
set(CMAKE_CXX_FLAGS "-Wno-unused-variable -O3 -ffast-math")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -ffast-math")
endif()

include_directories(libs/tracy/)
Expand All @@ -19,13 +19,13 @@ add_subdirectory(libs/tracy)
add_subdirectory(libs/fmt)

set(ASMJIT_STATIC TRUE)
add_subdirectory(libs/asmjit)
#add_subdirectory(libs/asmjit)

# enable for profiling
#add_definitions(-DTRACY_ENABLE)
#link_libraries(Tracy::TracyClient)

include_directories(libs/asmjit/src)
#include_directories(libs/asmjit/src)
include_directories(libs/magic_enum)

add_subdirectory(src)
Expand Down
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM debian:bullseye

RUN apt-get update && apt-get -y install gnupg wget
RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|apt-key add -
RUN echo "deb http://apt.llvm.org/bullseye/ llvm-toolchain-bullseye-14 main" > /etc/apt/sources.list.d/clang.list

# Install dependencies
RUN apt-get -qq update && \
apt-get install -qqy --no-install-recommends \
clang-14 lldb-14 lld-14 ca-certificates \
autoconf automake cmake dpkg-dev file git make patch \
libc-dev libc++-dev libgcc-10-dev libstdc++-10-dev \
dirmngr gnupg2 lbzip2 wget xz-utils libtinfo5 && \
rm -rf /var/lib/apt/lists/*

ADD . /typerunner
WORKDIR /typerunner
RUN mkdir build
RUN cd build && cmake -DCMAKE_CXX_COMPILER=clang++-14 -DCMAKE_C_COMPILER=clang-14 -DCMAKE_BUILD_TYPE=Release ..
RUN cd build && make bench typescript_main -j 8
RUN ./build/bench tests/objectLiterals1.ts
RUN ./build/typescript_main tests/objectLiterals1.ts
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2021 Marc J. Schmidt <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,14 @@ $ 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
$ git clone https://github.com/marcj/TypeRunner.git
$ cd TypeRunner
$ git submodule update --init --recursive
$ mkdir build
$ cd build
$ cmake ..
$ cmake -DCMAKE_CXX_COMPILER=clang++-14 -DCMAKE_C_COMPILER=clang-14 -DCMAKE_BUILD_TYPE=Release ..
$ make bench -j 8
$ ./bench ../tests/objectLiterals1.ts
```

Now you find in the build folder some binaries you can execute.
37 changes: 37 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Todo

| Type | Parser | Compiler | VM |
|------------------|--------|----------|-----|
| String | [X] | [X] | [X] |
| Number | [X] | [X] | [X] |
| Boolean | [X] | [X] | [X] |
| BigInt | [X] | [X] | [X] |
| String Literal | [X] | [X] | [X] |
| Number Literal | [X] | [X] | [X] |
| BigInt Literal | [X] | [X] | [X] |
| Bool Literal | [X] | [X] | [X] |
| Interfaces | [X] | [X] | 50% |
| Object Literal | [X] | [X] | [X] |
| Classes | [X] | 20% | 5% |
| Union | [X] | [X] | [X] |
| Intersection | [X] | [] | [] |
| Functions | [X] | 50% | 30% |
| Template Literal | [X] | 50% | 20% |

- [] Optimiser Parser
- [] Memory pool
- [] Inference
- [] Binary Expressions
- [] Binary Expressions
- [] Type narrowing
- [] If-Else
- [] While
- [] Early Return
- [] Type Guards
- [] Type Assertions
- [] Interface merging
- [] Primitives (lazy)
- [] Globals
- [] Modules
- [] Namespaces

3 changes: 1 addition & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
cmake_minimum_required(VERSION 3.22)
project(typescript)

#add_definitions(-DTRACY_ENABLE)
Expand All @@ -17,4 +16,4 @@ add_library(typescript utf.h utf.cpp core.h core.cpp utilities.h utilities.cpp n
target_link_libraries(typescript fmt)
#target_link_libraries(typescript asmjit::asmjit)

add_subdirectory(gui)
#add_subdirectory(gui)
20 changes: 10 additions & 10 deletions src/checker/checks.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace tr::vm {
static auto emptyString = HashString("");

HashString &getName(const shared<Type> &member) {
HashString &getName(const node<Type> &member) {
switch (member->kind) {
case TypeKind::MethodSignature: return to<TypeMethodSignature>(member)->name;
case TypeKind::Method: return to<TypeMethod>(member)->name;
Expand All @@ -16,7 +16,7 @@ namespace tr::vm {
return emptyString;
}

sharedOpt<Type> findMember(const vector<shared<Type>> &members, HashString &name) {
optionalNode<Type> findMember(const vector<node<Type>> &members, HashString &name) {
for (auto &&member: members) {
switch (member->kind) {
case TypeKind::MethodSignature: if (to<TypeMethodSignature>(member)->name == name) return member;
Expand All @@ -33,14 +33,14 @@ namespace tr::vm {
return nullptr;
}

bool isMember(const shared<Type> &type) {
bool isMember(const node<Type> &type) {
return type->kind == TypeKind::PropertySignature || type->kind == TypeKind::Property
|| type->kind == TypeKind::MethodSignature || type->kind == TypeKind::Method;
}

struct StackEntry {
const shared<Type> left;
const shared<Type> right;
const node<Type> left;
const node<Type> right;
};

struct ExtendableStack {
Expand Down Expand Up @@ -77,7 +77,7 @@ namespace tr::vm {
return DiagnosticMessage(message, left->ip);
}

void push(const shared<Type> &left, const shared<Type> &right) {
void push(const node<Type> &left, const node<Type> &right) {
stack.push_back({left, right});
}

Expand Down Expand Up @@ -108,7 +108,7 @@ namespace tr::vm {
return true;
}

bool has(const shared<Type> &left, const shared<Type> &right) {
bool has(const node<Type> &left, const node<Type> &right) {
for (auto &&entry: stack) {
if (entry.left == left && entry.right == right) return true;
}
Expand All @@ -123,7 +123,7 @@ namespace tr::vm {
*
* `left extends right ? true : false`
*/
bool isExtendable(shared<Type> &left, shared<Type> &right, ExtendableStack &stack) {
bool isExtendable(node<Type> &left, node<Type> &right, ExtendableStack &stack) {
if (right->kind == TypeKind::Parameter) {
if (left->kind == TypeKind::Undefined && isOptional(right)) return true;
right = to<TypeParameter>(right)->type;
Expand Down Expand Up @@ -290,7 +290,7 @@ namespace tr::vm {
return false;
}

bool isExtendable2(shared<Type> &left, shared<Type> &right, ExtendableStack &stack) {
bool isExtendable2(node<Type> &left, node<Type> &right, ExtendableStack &stack) {
// if (stack.has(left, right)) return true;
// stack.push(left, right);
if (stack.stack.empty()) stack.push(left, right);
Expand Down Expand Up @@ -504,7 +504,7 @@ namespace tr::vm {
// return false;
}

bool isExtendable(shared<Type> &left, shared<Type> &right) {
bool isExtendable(node<Type> &left, node<Type> &right) {
ExtendableStack stack;
return isExtendable(left, right, stack);
}
Expand Down
Loading

0 comments on commit 5e573db

Please sign in to comment.