-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hash table for union/object literal/class, new array memory pool, typ…
…e inference
- Loading branch information
Showing
22 changed files
with
1,620 additions
and
609 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Oops, something went wrong.