diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2019-01-09 12:59:46 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-09 12:59:46 -0500 |
commit | 0ceb554343ff3d311a19f027b7aa8f0806bbb162 (patch) | |
tree | 24603f165b7da831c2b68ad9472e26fabf72134c /src/main.rs | |
parent | 3afdae165d3bc9acb5e5a4749334d2673f2566af (diff) |
Native ES modules (#1460)
* Native ES modules
This is a major refactor of internal compiler.
Before: JS and TS both were sent through the typescript compiler where
their imports were parsed and handled. Both compiled to AMD JS and
finally sent to V8
Now: JS is sent directly into V8. TS is sent through the typescript
compiler, but tsc generates ES modules now instead of AMD. This
generated JS is then dumped into V8.
This should much faster for pure JS code. It may improve TS compilation
speed.
In the future this allows us to separate TS out of the runtime heap and
into its own dedicated snapshot. This will result in a smaller runtime
heap, and thus should be faster.
Some tests were unfortunately disabled to ease landing this patch:
1. compiler_tests.ts which I intend to bring back in later commits.
2. Some text_encoding_test.ts tests which made the file invalid utf8.
See PR for a discussion.
Also worth noting that this is necessary to support WASM
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs index 75cc61b58..629605e0e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,7 +10,6 @@ extern crate rand; extern crate remove_dir_all; extern crate ring; extern crate rustyline; -extern crate serde_json; extern crate source_map_mappings; extern crate tempfile; extern crate tokio; @@ -27,7 +26,10 @@ extern crate lazy_static; extern crate log; #[macro_use] extern crate futures; +#[macro_use] +extern crate serde_json; +pub mod compiler; pub mod deno_dir; pub mod errors; pub mod flags; @@ -47,7 +49,7 @@ pub mod snapshot; mod tokio_util; mod tokio_write; pub mod version; -mod workers; +pub mod workers; #[cfg(unix)] mod eager_unix; @@ -100,10 +102,21 @@ fn main() { let state = Arc::new(isolate::IsolateState::new(flags, rest_argv, None)); let snapshot = snapshot::deno_snapshot(); let isolate = isolate::Isolate::new(snapshot, state, ops::dispatch); + tokio_util::init(|| { + // Setup runtime. isolate .execute("denoMain();") .unwrap_or_else(print_err_and_exit); + + // Execute input file. + if isolate.state.argv.len() > 1 { + let input_filename = &isolate.state.argv[1]; + isolate + .execute_mod(input_filename) + .unwrap_or_else(print_err_and_exit); + } + isolate.event_loop().unwrap_or_else(print_err_and_exit); }); } |