Skip to content

Commit

Permalink
hash table for union/object literal/class, new array memory pool, typ…
Browse files Browse the repository at this point in the history
…e inference
  • Loading branch information
marcj committed Aug 4, 2022
1 parent df8d115 commit 82001c5
Show file tree
Hide file tree
Showing 22 changed files with 1,620 additions and 609 deletions.
7 changes: 3 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@ project(typescript)

set(CMAKE_CXX_STANDARD 23)

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

if(CMAKE_BUILD_TYPE STREQUAL "Release")
set(CMAKE_CXX_FLAGS "-Wall -Wextra -O3 -ffast-math")
set(CMAKE_CXX_FLAGS "-Wno-unused-variable -O3 -ffast-math")
endif()

include_directories(libs/tracy/)
include_directories(libs/fmt/include/)

list(APPEND CMAKE_MODULE_PATH libs)

#add_definitions(-DTRACY_ENABLE)
#include_directories(libs/tracy/)

add_subdirectory(libs/doctest)
add_subdirectory(libs/tracy)
add_subdirectory(libs/fmt)
Expand Down
35 changes: 20 additions & 15 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,57 +1,62 @@
#include <iostream>
#include <memory>
#include <unistd.h>

#include "./src/core.h"
#include "./src/fs.h"
#include "./src/parser2.h"
#include "./src/checker/vm.h"
#include "./src/checker/vm2.h"
#include "./src/checker/module2.h"
#include "./src/checker/debug.h"
#include "./src/checker/compiler.h"

using namespace ts;


void run(const string &bytecode, const string &code, const string &fileName) {
vm::VM vm;
auto module = make_shared<vm::Module>(bytecode, fileName, code);
ZoneScoped;
auto module = std::make_shared<vm2::Module>(bytecode, fileName, code);
bench(1, [&]{
vm.run(module);
vm.printErrors();
vm2::run(module);
module->printErrors();
});
}

void compileAndRun(const string &code, const string &file, const string &fileName) {
ZoneScoped;
auto bytecodePath = file + ".tsb";
auto buffer = readFile(file);
auto buffer = fileRead(file);
checker::Compiler compiler;
Parser parser;
auto result = parser.parseSourceFile(file, buffer, ts::types::ScriptTarget::Latest, false, ScriptKind::TS, {});
auto program = compiler.compileSourceFile(result);
auto bin = program.build();
writeFile(bytecodePath, bin);
fileWrite(bytecodePath, bin);
std::filesystem::last_write_time(bytecodePath, std::filesystem::last_write_time(file));
vm::VM vm;
checker::printBin(bin);
auto module = make_shared<vm::Module>(bin, fileName, code);
vm.run(module);
vm.printErrors();
auto module = make_shared<vm2::Module>(bin, fileName, code);
vm2::run(module);
module->printErrors();
}

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

if (argc > 1) {
file = cwd.string() + "/" + argv[1];
}

auto code = readFile(file);
auto code = fileRead(file);
auto bytecode = file + ".tsb";
auto relative = std::filesystem::relative(file, cwd);

if (exists(bytecode) && std::filesystem::last_write_time(bytecode) == std::filesystem::last_write_time(file)) {
run(readFile(bytecode), code, relative.string());
if (fileExists(bytecode) && std::filesystem::last_write_time(bytecode) == std::filesystem::last_write_time(file)) {
run(fileRead(bytecode), code, relative.string());
} else {
compileAndRun(code, file, relative.string());
}
usleep(100000);
return 0;
}
Loading

0 comments on commit 82001c5

Please sign in to comment.