From 87eef2bf84164c840c0e536ea3a64ad86b6a86a6 Mon Sep 17 00:00:00 2001 From: cedric05 Date: Tue, 9 Oct 2018 08:06:04 +0530 Subject: [PATCH 01/10] repl loop inside deno, initial phase --- BUILD.gn | 1 + build_extra/rust/BUILD.gn | 52 ++++++++++++++++++++++++++++++++++++++- js/main.ts | 8 +++--- src/main.rs | 46 ++++++++++++++++++++++++++++++++++ 4 files changed, 103 insertions(+), 4 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 4f2bf2a5b37671..8bcbdc4c65ff8c 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -51,6 +51,7 @@ main_extern = [ "$rust_build:libc", "$rust_build:log", "$rust_build:ring", + "$rust_build:rustyline", "$rust_build:tempfile", "$rust_build:rand", "$rust_build:tokio", diff --git a/build_extra/rust/BUILD.gn b/build_extra/rust/BUILD.gn index fffe76e86b9ebd..763655cfd50294 100644 --- a/build_extra/rust/BUILD.gn +++ b/build_extra/rust/BUILD.gn @@ -11,6 +11,56 @@ import("rust.gni") crates = "//third_party/rust_crates" registry_github = "$crates/registry/src/github.com-1ecc6299db9ec823/" +rust_crate("nix") { + source_root = "$registry_github/nix-0.11.0/src/lib.rs" + extern=[ + ":cfg_if", + ":libc", + ":void", + ":bitflags" + ] +} + +rust_crate("rustyline") { + source_root = "$registry_github/rustyline-2.1.0/src/lib.rs" + extern=[ + ":dirs", + ":libc", + ":log", + ":memchr", + ":nix", + ":unicode_segmentation", + ":unicode_width", + ":utf8parse" + ] +} + +rust_crate("bitflags") { + source_root = "$registry_github/bitflags-1.0.4/src/lib.rs" +} + + + + + +rust_crate("unicode_segmentation") { + source_root = "$registry_github/unicode-segmentation-1.2.1/src/lib.rs" +} +rust_crate("memchr") { + source_root = "$registry_github/memchr-2.1.0/src/lib.rs" + extern=[ + ":cfg_if", + ":libc" + ] +} +rust_crate("utf8parse") { + source_root = "$registry_github/utf8parse-0.1.1/src/lib.rs" +} +rust_crate("unicode_width") { + source_root = "$registry_github/unicode-width-0.1.5/src/lib.rs" +} + + rust_crate("libc") { source_root = "$registry_github/libc-0.2.43/src/lib.rs" features = [ "use_std" ] @@ -676,7 +726,7 @@ rust_crate("hyper_rustls") { } rust_crate("dirs") { - source_root = "$registry_github/dirs-1.0.3/src/lib.rs" + source_root = "$registry_github/dirs-1.0.4/src/lib.rs" extern = [ ":libc", ":winapi", diff --git a/js/main.ts b/js/main.ts index 2650371119347c..c28f8481c0bbf3 100644 --- a/js/main.ts +++ b/js/main.ts @@ -53,13 +53,14 @@ export default function denoMain() { } log("args", args); Object.freeze(args); - + console.log('hahahaha') const inputFn = args[0]; if (!inputFn) { + console.log("not exiting") console.log("No input script specified."); - os.exit(1); + // os.exit(1); } - + else { const printDeps = startResMsg.depsFlag(); if (printDeps) { for (const dep of compiler.getModuleDependencies(inputFn, `${cwd}/`)) { @@ -71,3 +72,4 @@ export default function denoMain() { compiler.recompile = startResMsg.recompileFlag(); compiler.run(inputFn, `${cwd}/`); } +} diff --git a/src/main.rs b/src/main.rs index f6c85ef831e22d..98a2d87dc4de1a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,9 +2,11 @@ extern crate flatbuffers; #[macro_use] extern crate futures; +// extern crate rustyline; extern crate hyper; extern crate libc; extern crate msg_rs as msg; +extern crate rustyline; extern crate rand; extern crate tempfile; extern crate tokio; @@ -22,6 +24,10 @@ extern crate hyper_rustls; extern crate remove_dir_all; extern crate ring; + +use rustyline::error::ReadlineError; +use rustyline::Editor; + mod deno_dir; mod errors; mod flags; @@ -68,6 +74,7 @@ fn main() { log::set_logger(&LOGGER).unwrap(); let args = env::args().collect(); + let args2: Vec = env::args().collect(); let mut isolate = isolate::Isolate::new(args, ops::dispatch); flags::process(&isolate.state.flags); tokio_util::init(|| { @@ -78,5 +85,44 @@ fn main() { std::process::exit(1); }); isolate.event_loop(); + if args2.len() == 1{ + repl_loop(isolate) + } }); } + +#[allow(dead_code)] +fn repl_loop(isolate:Box) { + // `()` can be used when no completer is required + let mut rl = Editor::<()>::new(); + if rl.load_history("history.txt").is_err() { + println!("No previous history."); + } + loop { + let readline = rl.readline(">> "); + match readline { + Ok(line) => { + rl.add_history_entry(line.as_ref()); + isolate.execute("deno_main.js", &line) + .unwrap_or_else(|_err| { + // error!("{}", err); + println!("{}","error happened" ) + }); + // println!("Line: {}", line); + }, + Err(ReadlineError::Interrupted) => { + println!("CTRL-C"); + break + }, + Err(ReadlineError::Eof) => { + println!("CTRL-D"); + break + }, + Err(err) => { + println!("Error: {:?}", err); + break + } + } + } + rl.save_history("history.txt").unwrap(); +} \ No newline at end of file From b78bd390203e65e7b6f017a0a592bb5ca50464fc Mon Sep 17 00:00:00 2001 From: cedric05 Date: Tue, 9 Oct 2018 08:06:04 +0530 Subject: [PATCH 02/10] repl loop inside deno, initial phase --- BUILD.gn | 1 + build_extra/rust/BUILD.gn | 52 ++++++++++++++++++++++++++++++++++++++- js/main.ts | 8 +++--- src/main.rs | 46 ++++++++++++++++++++++++++++++++++ 4 files changed, 103 insertions(+), 4 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 4f2bf2a5b37671..8bcbdc4c65ff8c 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -51,6 +51,7 @@ main_extern = [ "$rust_build:libc", "$rust_build:log", "$rust_build:ring", + "$rust_build:rustyline", "$rust_build:tempfile", "$rust_build:rand", "$rust_build:tokio", diff --git a/build_extra/rust/BUILD.gn b/build_extra/rust/BUILD.gn index fffe76e86b9ebd..763655cfd50294 100644 --- a/build_extra/rust/BUILD.gn +++ b/build_extra/rust/BUILD.gn @@ -11,6 +11,56 @@ import("rust.gni") crates = "//third_party/rust_crates" registry_github = "$crates/registry/src/github.com-1ecc6299db9ec823/" +rust_crate("nix") { + source_root = "$registry_github/nix-0.11.0/src/lib.rs" + extern=[ + ":cfg_if", + ":libc", + ":void", + ":bitflags" + ] +} + +rust_crate("rustyline") { + source_root = "$registry_github/rustyline-2.1.0/src/lib.rs" + extern=[ + ":dirs", + ":libc", + ":log", + ":memchr", + ":nix", + ":unicode_segmentation", + ":unicode_width", + ":utf8parse" + ] +} + +rust_crate("bitflags") { + source_root = "$registry_github/bitflags-1.0.4/src/lib.rs" +} + + + + + +rust_crate("unicode_segmentation") { + source_root = "$registry_github/unicode-segmentation-1.2.1/src/lib.rs" +} +rust_crate("memchr") { + source_root = "$registry_github/memchr-2.1.0/src/lib.rs" + extern=[ + ":cfg_if", + ":libc" + ] +} +rust_crate("utf8parse") { + source_root = "$registry_github/utf8parse-0.1.1/src/lib.rs" +} +rust_crate("unicode_width") { + source_root = "$registry_github/unicode-width-0.1.5/src/lib.rs" +} + + rust_crate("libc") { source_root = "$registry_github/libc-0.2.43/src/lib.rs" features = [ "use_std" ] @@ -676,7 +726,7 @@ rust_crate("hyper_rustls") { } rust_crate("dirs") { - source_root = "$registry_github/dirs-1.0.3/src/lib.rs" + source_root = "$registry_github/dirs-1.0.4/src/lib.rs" extern = [ ":libc", ":winapi", diff --git a/js/main.ts b/js/main.ts index 826d3e811bb685..1941327975c0ee 100644 --- a/js/main.ts +++ b/js/main.ts @@ -57,13 +57,14 @@ export default function denoMain() { } log("args", args); Object.freeze(args); - + console.log('hahahaha') const inputFn = args[0]; if (!inputFn) { + console.log("not exiting") console.log("No input script specified."); - os.exit(1); + // os.exit(1); } - + else { const printDeps = startResMsg.depsFlag(); if (printDeps) { for (const dep of compiler.getModuleDependencies(inputFn, `${cwd}/`)) { @@ -75,3 +76,4 @@ export default function denoMain() { compiler.recompile = startResMsg.recompileFlag(); compiler.run(inputFn, `${cwd}/`); } +} diff --git a/src/main.rs b/src/main.rs index f6c85ef831e22d..98a2d87dc4de1a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,9 +2,11 @@ extern crate flatbuffers; #[macro_use] extern crate futures; +// extern crate rustyline; extern crate hyper; extern crate libc; extern crate msg_rs as msg; +extern crate rustyline; extern crate rand; extern crate tempfile; extern crate tokio; @@ -22,6 +24,10 @@ extern crate hyper_rustls; extern crate remove_dir_all; extern crate ring; + +use rustyline::error::ReadlineError; +use rustyline::Editor; + mod deno_dir; mod errors; mod flags; @@ -68,6 +74,7 @@ fn main() { log::set_logger(&LOGGER).unwrap(); let args = env::args().collect(); + let args2: Vec = env::args().collect(); let mut isolate = isolate::Isolate::new(args, ops::dispatch); flags::process(&isolate.state.flags); tokio_util::init(|| { @@ -78,5 +85,44 @@ fn main() { std::process::exit(1); }); isolate.event_loop(); + if args2.len() == 1{ + repl_loop(isolate) + } }); } + +#[allow(dead_code)] +fn repl_loop(isolate:Box) { + // `()` can be used when no completer is required + let mut rl = Editor::<()>::new(); + if rl.load_history("history.txt").is_err() { + println!("No previous history."); + } + loop { + let readline = rl.readline(">> "); + match readline { + Ok(line) => { + rl.add_history_entry(line.as_ref()); + isolate.execute("deno_main.js", &line) + .unwrap_or_else(|_err| { + // error!("{}", err); + println!("{}","error happened" ) + }); + // println!("Line: {}", line); + }, + Err(ReadlineError::Interrupted) => { + println!("CTRL-C"); + break + }, + Err(ReadlineError::Eof) => { + println!("CTRL-D"); + break + }, + Err(err) => { + println!("Error: {:?}", err); + break + } + } + } + rl.save_history("history.txt").unwrap(); +} \ No newline at end of file From e5cb43c9089b4e550b17f8b02b40fac22b30fe33 Mon Sep 17 00:00:00 2001 From: Andy Hayden Date: Wed, 10 Oct 2018 21:26:10 -0700 Subject: [PATCH 03/10] Move repl Run event_loop after each input line --- js/main.ts | 12 ++++++++---- src/main.rs | 47 ++++------------------------------------------- src/repl.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ third_party | 2 +- 4 files changed, 56 insertions(+), 48 deletions(-) create mode 100644 src/repl.rs diff --git a/js/main.ts b/js/main.ts index 1941327975c0ee..ac952bd82f28d9 100644 --- a/js/main.ts +++ b/js/main.ts @@ -32,7 +32,12 @@ function onGlobalError( } else { console.log(`Thrown: ${String(error)}`); } - os.exit(1); + // FIXME this is a hack, and anyway doesn't work for `throw "error"` + // which (for some reason) has source == undefined + if (source !== 'deno repl') { + console.log(`Source: ${source}`); + os.exit(1); + } } /* tslint:disable-next-line:no-default-export */ @@ -57,11 +62,10 @@ export default function denoMain() { } log("args", args); Object.freeze(args); - console.log('hahahaha') const inputFn = args[0]; if (!inputFn) { - console.log("not exiting") - console.log("No input script specified."); + // console.log("not exiting") + // console.log("No input script specified."); // os.exit(1); } else { diff --git a/src/main.rs b/src/main.rs index 98a2d87dc4de1a..642926815e8896 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,10 +24,6 @@ extern crate hyper_rustls; extern crate remove_dir_all; extern crate ring; - -use rustyline::error::ReadlineError; -use rustyline::Editor; - mod deno_dir; mod errors; mod flags; @@ -36,6 +32,7 @@ mod http; mod isolate; mod libdeno; pub mod ops; +mod repl; mod resources; mod tokio_util; mod version; @@ -74,7 +71,6 @@ fn main() { log::set_logger(&LOGGER).unwrap(); let args = env::args().collect(); - let args2: Vec = env::args().collect(); let mut isolate = isolate::Isolate::new(args, ops::dispatch); flags::process(&isolate.state.flags); tokio_util::init(|| { @@ -85,44 +81,9 @@ fn main() { std::process::exit(1); }); isolate.event_loop(); - if args2.len() == 1{ - repl_loop(isolate) + // if no args then enter repl + if isolate.state.argv.len() == 1 { + repl::repl_loop(&mut isolate) } }); } - -#[allow(dead_code)] -fn repl_loop(isolate:Box) { - // `()` can be used when no completer is required - let mut rl = Editor::<()>::new(); - if rl.load_history("history.txt").is_err() { - println!("No previous history."); - } - loop { - let readline = rl.readline(">> "); - match readline { - Ok(line) => { - rl.add_history_entry(line.as_ref()); - isolate.execute("deno_main.js", &line) - .unwrap_or_else(|_err| { - // error!("{}", err); - println!("{}","error happened" ) - }); - // println!("Line: {}", line); - }, - Err(ReadlineError::Interrupted) => { - println!("CTRL-C"); - break - }, - Err(ReadlineError::Eof) => { - println!("CTRL-D"); - break - }, - Err(err) => { - println!("Error: {:?}", err); - break - } - } - } - rl.save_history("history.txt").unwrap(); -} \ No newline at end of file diff --git a/src/repl.rs b/src/repl.rs new file mode 100644 index 00000000000000..f5db86a3b740d5 --- /dev/null +++ b/src/repl.rs @@ -0,0 +1,43 @@ +use rustyline::error::ReadlineError; +use rustyline::Editor; + +use isolate; + + +#[allow(dead_code)] +pub fn repl_loop(isolate: &mut isolate::Isolate) { + // `()` can be used when no completer is required + let mut rl = Editor::<()>::new(); + if rl.load_history("history.txt").is_err() { + println!("No previous history."); + } + loop { + let readline = rl.readline(">> "); + match readline { + Ok(line) => { + rl.add_history_entry(line.as_ref()); + isolate + .execute("deno repl", &line) + .unwrap_or_else(|err| { + println!("{}", err); + }); + // FIXME we should move this to a thread (and run it only once)... + isolate.event_loop(); + // println!("Line: {}", line); + }, + Err(ReadlineError::Interrupted) => { + println!("CTRL-C"); + break + }, + Err(ReadlineError::Eof) => { + println!("CTRL-D"); + break + }, + Err(err) => { + println!("Error: {:?}", err); + break + } + } + } + rl.save_history("history.txt").unwrap(); +} \ No newline at end of file diff --git a/third_party b/third_party index 30c059313d7b54..f58bf920c0c570 160000 --- a/third_party +++ b/third_party @@ -1 +1 @@ -Subproject commit 30c059313d7b5440ca91dc06619f30958369088d +Subproject commit f58bf920c0c570f2c2d4dc21d36b713dd0755ab9 From 88d3d7d3c15558f7c586a6e70a2d8a1e197f873e Mon Sep 17 00:00:00 2001 From: Shiva Prasanth Date: Fri, 12 Oct 2018 21:11:27 +0530 Subject: [PATCH 04/10] changes intermediate changes --- build_extra/rust/BUILD.gn | 17 ++++----- js/io.ts | 2 +- js/main.ts | 25 ++++++-------- src/isolate.rs | 9 +++-- src/main.rs | 72 +++++++++++++++++++-------------------- 5 files changed, 57 insertions(+), 68 deletions(-) diff --git a/build_extra/rust/BUILD.gn b/build_extra/rust/BUILD.gn index 3d286ba8aa88df..19e5bcb9bdd5f7 100644 --- a/build_extra/rust/BUILD.gn +++ b/build_extra/rust/BUILD.gn @@ -13,17 +13,17 @@ registry_github = "$crates/registry/src/github.com-1ecc6299db9ec823/" rust_crate("nix") { source_root = "$registry_github/nix-0.11.0/src/lib.rs" - extern=[ + extern = [ ":cfg_if", ":libc", ":void", - ":bitflags" + ":bitflags", ] } rust_crate("rustyline") { source_root = "$registry_github/rustyline-2.1.0/src/lib.rs" - extern=[ + extern = [ ":dirs", ":libc", ":log", @@ -31,7 +31,7 @@ rust_crate("rustyline") { ":nix", ":unicode_segmentation", ":unicode_width", - ":utf8parse" + ":utf8parse", ] } @@ -39,18 +39,14 @@ rust_crate("bitflags") { source_root = "$registry_github/bitflags-1.0.4/src/lib.rs" } - - - - rust_crate("unicode_segmentation") { source_root = "$registry_github/unicode-segmentation-1.2.1/src/lib.rs" } rust_crate("memchr") { source_root = "$registry_github/memchr-2.1.0/src/lib.rs" - extern=[ + extern = [ ":cfg_if", - ":libc" + ":libc", ] } rust_crate("utf8parse") { @@ -60,7 +56,6 @@ rust_crate("unicode_width") { source_root = "$registry_github/unicode-width-0.1.5/src/lib.rs" } - rust_crate("libc") { source_root = "$registry_github/libc-0.2.43/src/lib.rs" features = [ "use_std" ] diff --git a/js/io.ts b/js/io.ts index 77ef790732cdcf..afe8b40048d5fd 100644 --- a/js/io.ts +++ b/js/io.ts @@ -101,7 +101,7 @@ export interface ReadWriteSeeker extends Reader, Writer, Seeker {} // https://golang.org/pkg/io/#Copy export async function copy(dst: Writer, src: Reader): Promise { let n = 0; - const b = new Uint8Array(32*1024); + const b = new Uint8Array(32 * 1024); let gotEOF = false; while (gotEOF === false) { const result = await src.read(b); diff --git a/js/main.ts b/js/main.ts index 5cb530b8caa073..73519b33955a25 100644 --- a/js/main.ts +++ b/js/main.ts @@ -65,22 +65,17 @@ export default function denoMain() { } log("args", args); Object.freeze(args); - console.log('hahahaha') const inputFn = args[0]; - if (!inputFn) { - console.log("not exiting") - console.log("No input script specified."); - // os.exit(1); - } - - // handle `--deps` - if (startResMsg.depsFlag()) { - for (const dep of compiler.getModuleDependencies(inputFn, `${cwd}/`)) { - console.log(dep); + if (inputFn) { + // handle `--deps` + if (startResMsg.depsFlag()) { + for (const dep of compiler.getModuleDependencies(inputFn, `${cwd}/`)) { + console.log(dep); + } + os.exit(0); } - os.exit(0); - } - compiler.recompile = startResMsg.recompileFlag(); - compiler.run(inputFn, `${cwd}/`); + compiler.recompile = startResMsg.recompileFlag(); + compiler.run(inputFn, `${cwd}/`); + } } diff --git a/src/isolate.rs b/src/isolate.rs index 40dff5ed254b3a..1de23bca804316 100644 --- a/src/isolate.rs +++ b/src/isolate.rs @@ -294,11 +294,10 @@ extern "C" fn pre_dispatch( // manually. isolate.ntasks_increment(); - let task = op - .and_then(move |buf| { - state.send_to_js(req_id, buf); - Ok(()) - }).map_err(|_| ()); + let task = op.and_then(move |buf| { + state.send_to_js(req_id, buf); + Ok(()) + }).map_err(|_| ()); tokio::spawn(task); } } diff --git a/src/main.rs b/src/main.rs index d8318b3a3606c6..6a94bca1018d40 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,8 +6,8 @@ extern crate futures; extern crate hyper; extern crate libc; extern crate msg_rs as msg; -extern crate rustyline; extern crate rand; +extern crate rustyline; extern crate tempfile; extern crate tokio; extern crate tokio_executor; @@ -24,7 +24,6 @@ extern crate hyper_rustls; extern crate remove_dir_all; extern crate ring; - use rustyline::error::ReadlineError; use rustyline::Editor; @@ -85,44 +84,45 @@ fn main() { std::process::exit(1); }); isolate.event_loop(); - if args2.len() == 1{ + if args2.len() == 1 { repl_loop(isolate) } }); } #[allow(dead_code)] -fn repl_loop(mut isolate:isolate::Isolate) { - // `()` can be used when no completer is required - let mut rl = Editor::<()>::new(); - if rl.load_history("history.txt").is_err() { - println!("No previous history."); - } - loop { - let readline = rl.readline(">> "); - match readline { - Ok(line) => { - rl.add_history_entry(line.as_ref()); - isolate.execute("deno_main.js", &line) - .unwrap_or_else(|_err| { - // error!("{}", err); - println!("{}","error happened" ) - }); - // println!("Line: {}", line); - }, - Err(ReadlineError::Interrupted) => { - println!("CTRL-C"); - break - }, - Err(ReadlineError::Eof) => { - println!("CTRL-D"); - break - }, - Err(err) => { - println!("Error: {:?}", err); - break - } - } +fn repl_loop(mut isolate: isolate::Isolate) { + // `()` can be used when no completer is required + let mut rl = Editor::<()>::new(); + if rl.load_history("history.txt").is_err() { + println!("No previous history."); + } + loop { + let readline = rl.readline(">> "); + match readline { + Ok(line) => { + rl.add_history_entry(line.as_ref()); + isolate + .execute("deno_main.js", &line) + .unwrap_or_else(|_err| { + // error!("{}", err); + println!("{}", "error happened") + }); + // println!("Line: {}", line); + } + Err(ReadlineError::Interrupted) => { + println!("CTRL-C"); + break; + } + Err(ReadlineError::Eof) => { + println!("CTRL-D"); + break; + } + Err(err) => { + println!("Error: {:?}", err); + break; + } } - rl.save_history("history.txt").unwrap(); -} \ No newline at end of file + } + rl.save_history("history.txt").unwrap(); +} From 484288eec65dc38e218dde513538d72a10202f62 Mon Sep 17 00:00:00 2001 From: cedric05 Date: Tue, 9 Oct 2018 08:06:04 +0530 Subject: [PATCH 05/10] repl loop inside deno, initial phase --- BUILD.gn | 1 + build_extra/rust/BUILD.gn | 52 ++++++++++++++++++++++++++++++++++++++- js/main.ts | 6 +++-- src/main.rs | 46 ++++++++++++++++++++++++++++++++++ 4 files changed, 102 insertions(+), 3 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 259c5bdc44c7a4..948884a802231c 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -51,6 +51,7 @@ main_extern = [ "$rust_build:libc", "$rust_build:log", "$rust_build:ring", + "$rust_build:rustyline", "$rust_build:tempfile", "$rust_build:rand", "$rust_build:tokio", diff --git a/build_extra/rust/BUILD.gn b/build_extra/rust/BUILD.gn index 93c370c41803a8..3d286ba8aa88df 100644 --- a/build_extra/rust/BUILD.gn +++ b/build_extra/rust/BUILD.gn @@ -11,6 +11,56 @@ import("rust.gni") crates = "//third_party/rust_crates" registry_github = "$crates/registry/src/github.com-1ecc6299db9ec823/" +rust_crate("nix") { + source_root = "$registry_github/nix-0.11.0/src/lib.rs" + extern=[ + ":cfg_if", + ":libc", + ":void", + ":bitflags" + ] +} + +rust_crate("rustyline") { + source_root = "$registry_github/rustyline-2.1.0/src/lib.rs" + extern=[ + ":dirs", + ":libc", + ":log", + ":memchr", + ":nix", + ":unicode_segmentation", + ":unicode_width", + ":utf8parse" + ] +} + +rust_crate("bitflags") { + source_root = "$registry_github/bitflags-1.0.4/src/lib.rs" +} + + + + + +rust_crate("unicode_segmentation") { + source_root = "$registry_github/unicode-segmentation-1.2.1/src/lib.rs" +} +rust_crate("memchr") { + source_root = "$registry_github/memchr-2.1.0/src/lib.rs" + extern=[ + ":cfg_if", + ":libc" + ] +} +rust_crate("utf8parse") { + source_root = "$registry_github/utf8parse-0.1.1/src/lib.rs" +} +rust_crate("unicode_width") { + source_root = "$registry_github/unicode-width-0.1.5/src/lib.rs" +} + + rust_crate("libc") { source_root = "$registry_github/libc-0.2.43/src/lib.rs" features = [ "use_std" ] @@ -659,7 +709,7 @@ rust_crate("hyper_rustls") { } rust_crate("dirs") { - source_root = "$registry_github/dirs-1.0.3/src/lib.rs" + source_root = "$registry_github/dirs-1.0.4/src/lib.rs" extern = [ ":libc", ":winapi", diff --git a/js/main.ts b/js/main.ts index 0d33cf063ecc39..97d9d55da5c6eb 100644 --- a/js/main.ts +++ b/js/main.ts @@ -68,11 +68,12 @@ export default function denoMain() { } log("args", args); Object.freeze(args); - + console.log('hahahaha') const inputFn = args[0]; if (!inputFn) { + console.log("not exiting") console.log("No input script specified."); - os.exit(1); + // os.exit(1); } // handle `--deps` @@ -86,3 +87,4 @@ export default function denoMain() { compiler.recompile = startResMsg.recompileFlag(); compiler.run(inputFn, `${cwd}/`); } +} diff --git a/src/main.rs b/src/main.rs index b84ee78d960676..ae1612378c20a9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,9 +2,11 @@ extern crate flatbuffers; #[macro_use] extern crate futures; +// extern crate rustyline; extern crate hyper; extern crate libc; extern crate msg_rs as msg; +extern crate rustyline; extern crate rand; extern crate tempfile; extern crate tokio; @@ -22,6 +24,10 @@ extern crate hyper_rustls; extern crate remove_dir_all; extern crate ring; + +use rustyline::error::ReadlineError; +use rustyline::Editor; + mod deno_dir; mod errors; mod flags; @@ -68,6 +74,7 @@ fn main() { log::set_logger(&LOGGER).unwrap(); let args = env::args().collect(); + let args2: Vec = env::args().collect(); let mut isolate = isolate::Isolate::new(args, ops::dispatch); flags::process(&isolate.state.flags); tokio_util::init(|| { @@ -78,5 +85,44 @@ fn main() { std::process::exit(1); }); isolate.event_loop(); + if args2.len() == 1{ + repl_loop(isolate) + } }); } + +#[allow(dead_code)] +fn repl_loop(isolate:Box) { + // `()` can be used when no completer is required + let mut rl = Editor::<()>::new(); + if rl.load_history("history.txt").is_err() { + println!("No previous history."); + } + loop { + let readline = rl.readline(">> "); + match readline { + Ok(line) => { + rl.add_history_entry(line.as_ref()); + isolate.execute("deno_main.js", &line) + .unwrap_or_else(|_err| { + // error!("{}", err); + println!("{}","error happened" ) + }); + // println!("Line: {}", line); + }, + Err(ReadlineError::Interrupted) => { + println!("CTRL-C"); + break + }, + Err(ReadlineError::Eof) => { + println!("CTRL-D"); + break + }, + Err(err) => { + println!("Error: {:?}", err); + break + } + } + } + rl.save_history("history.txt").unwrap(); +} \ No newline at end of file From 0735cd319c91b01f77d4ad8ee6e5924a95cc32fd Mon Sep 17 00:00:00 2001 From: Andy Hayden Date: Wed, 10 Oct 2018 21:26:10 -0700 Subject: [PATCH 06/10] Move repl Run event_loop after each input line --- js/main.ts | 12 ++++++++---- src/main.rs | 47 ++++------------------------------------------- src/repl.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ third_party | 2 +- 4 files changed, 56 insertions(+), 48 deletions(-) create mode 100644 src/repl.rs diff --git a/js/main.ts b/js/main.ts index 97d9d55da5c6eb..3c3f61f3b0f3c8 100644 --- a/js/main.ts +++ b/js/main.ts @@ -33,7 +33,12 @@ function onGlobalError( } else { console.log(`Thrown: ${String(error)}`); } - os.exit(1); + // FIXME this is a hack, and anyway doesn't work for `throw "error"` + // which (for some reason) has source == undefined + if (source !== 'deno repl') { + console.log(`Source: ${source}`); + os.exit(1); + } } /* tslint:disable-next-line:no-default-export */ @@ -68,11 +73,10 @@ export default function denoMain() { } log("args", args); Object.freeze(args); - console.log('hahahaha') const inputFn = args[0]; if (!inputFn) { - console.log("not exiting") - console.log("No input script specified."); + // console.log("not exiting") + // console.log("No input script specified."); // os.exit(1); } diff --git a/src/main.rs b/src/main.rs index ae1612378c20a9..8a9f88f516b378 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,10 +24,6 @@ extern crate hyper_rustls; extern crate remove_dir_all; extern crate ring; - -use rustyline::error::ReadlineError; -use rustyline::Editor; - mod deno_dir; mod errors; mod flags; @@ -36,6 +32,7 @@ mod http_util; mod isolate; mod libdeno; pub mod ops; +mod repl; mod resources; mod tokio_util; mod version; @@ -74,7 +71,6 @@ fn main() { log::set_logger(&LOGGER).unwrap(); let args = env::args().collect(); - let args2: Vec = env::args().collect(); let mut isolate = isolate::Isolate::new(args, ops::dispatch); flags::process(&isolate.state.flags); tokio_util::init(|| { @@ -85,44 +81,9 @@ fn main() { std::process::exit(1); }); isolate.event_loop(); - if args2.len() == 1{ - repl_loop(isolate) + // if no args then enter repl + if isolate.state.argv.len() == 1 { + repl::repl_loop(&mut isolate) } }); } - -#[allow(dead_code)] -fn repl_loop(isolate:Box) { - // `()` can be used when no completer is required - let mut rl = Editor::<()>::new(); - if rl.load_history("history.txt").is_err() { - println!("No previous history."); - } - loop { - let readline = rl.readline(">> "); - match readline { - Ok(line) => { - rl.add_history_entry(line.as_ref()); - isolate.execute("deno_main.js", &line) - .unwrap_or_else(|_err| { - // error!("{}", err); - println!("{}","error happened" ) - }); - // println!("Line: {}", line); - }, - Err(ReadlineError::Interrupted) => { - println!("CTRL-C"); - break - }, - Err(ReadlineError::Eof) => { - println!("CTRL-D"); - break - }, - Err(err) => { - println!("Error: {:?}", err); - break - } - } - } - rl.save_history("history.txt").unwrap(); -} \ No newline at end of file diff --git a/src/repl.rs b/src/repl.rs new file mode 100644 index 00000000000000..f5db86a3b740d5 --- /dev/null +++ b/src/repl.rs @@ -0,0 +1,43 @@ +use rustyline::error::ReadlineError; +use rustyline::Editor; + +use isolate; + + +#[allow(dead_code)] +pub fn repl_loop(isolate: &mut isolate::Isolate) { + // `()` can be used when no completer is required + let mut rl = Editor::<()>::new(); + if rl.load_history("history.txt").is_err() { + println!("No previous history."); + } + loop { + let readline = rl.readline(">> "); + match readline { + Ok(line) => { + rl.add_history_entry(line.as_ref()); + isolate + .execute("deno repl", &line) + .unwrap_or_else(|err| { + println!("{}", err); + }); + // FIXME we should move this to a thread (and run it only once)... + isolate.event_loop(); + // println!("Line: {}", line); + }, + Err(ReadlineError::Interrupted) => { + println!("CTRL-C"); + break + }, + Err(ReadlineError::Eof) => { + println!("CTRL-D"); + break + }, + Err(err) => { + println!("Error: {:?}", err); + break + } + } + } + rl.save_history("history.txt").unwrap(); +} \ No newline at end of file diff --git a/third_party b/third_party index a133fa714b960d..a129f078fa27df 160000 --- a/third_party +++ b/third_party @@ -1 +1 @@ -Subproject commit a133fa714b960d8f88c55188ccc1a41882961e6e +Subproject commit a129f078fa27df51c1a2aa2307d31bec50fe90e9 From e1a9b0334a369f57dd07ed637c5e7653084bda69 Mon Sep 17 00:00:00 2001 From: Andy Hayden Date: Sun, 14 Oct 2018 23:59:41 -0700 Subject: [PATCH 07/10] Running repl from js side --- js/main.ts | 14 +++++++---- js/repl.ts | 51 +++++++++++++++++++++++++++++++++++++ src/isolate.rs | 3 +++ src/main.rs | 6 ++--- src/msg.fbs | 10 ++++++++ src/ops.rs | 38 ++++++++++++++++++++++++++++ src/repl.rs | 68 +++++++++++++++++++++++--------------------------- 7 files changed, 145 insertions(+), 45 deletions(-) create mode 100644 js/repl.ts diff --git a/js/main.ts b/js/main.ts index 3c3f61f3b0f3c8..8f1e8796fb05c2 100644 --- a/js/main.ts +++ b/js/main.ts @@ -8,6 +8,8 @@ import { libdeno } from "./libdeno"; import { args } from "./deno"; import { sendSync, handleAsyncMsgFromRust } from "./dispatch"; import { promiseErrorExaminer, promiseRejectHandler } from "./promise_util"; +import { repl_loop } from "./repl"; + function sendStart(): msg.StartRes { const builder = new flatbuffers.Builder(); @@ -75,20 +77,22 @@ export default function denoMain() { Object.freeze(args); const inputFn = args[0]; if (!inputFn) { - // console.log("not exiting") + // repl!! // console.log("No input script specified."); // os.exit(1); } // handle `--deps` - if (startResMsg.depsFlag()) { + if (inputFn && startResMsg.depsFlag()) { for (const dep of compiler.getModuleDependencies(inputFn, `${cwd}/`)) { console.log(dep); } os.exit(0); } - compiler.recompile = startResMsg.recompileFlag(); - compiler.run(inputFn, `${cwd}/`); -} + if (inputFn) { + compiler.run(inputFn, `${cwd}/`); + } else { + repl_loop(); + } } diff --git a/js/repl.ts b/js/repl.ts new file mode 100644 index 00000000000000..171af830981819 --- /dev/null +++ b/js/repl.ts @@ -0,0 +1,51 @@ +// Copyright 2018 the Deno authors. All rights reserved. MIT license. +import * as msg from "gen/msg_generated"; +import { flatbuffers } from "flatbuffers"; +import { assert } from "./util"; +import * as dispatch from "./dispatch"; +import { window } from "./globals"; + +/** Read the next line for the repl. + * + * import { readFile } from "deno"; + * const decoder = new TextDecoder("utf-8"); + * const data = await readFile("hello.txt"); + * console.log(decoder.decode(data)); + */ +async function readline(prompt: string): Promise { + return res(await dispatch.sendAsync(...req(prompt))); +} + +function req( + prompt: string +): [flatbuffers.Builder, msg.Any, flatbuffers.Offset] { + const builder = new flatbuffers.Builder(); + const prompt_ = builder.createString(prompt); + msg.Repl.startRepl(builder); + msg.Repl.addPrompt(builder, prompt_); + const inner = msg.Repl.endRepl(builder); + return [builder, msg.Any.Repl, inner]; +} + +function res(baseRes: null | msg.Base): string { + assert(baseRes != null); + assert(msg.Any.ReplRes === baseRes!.innerType()); + const inner = new msg.ReplRes(); + assert(baseRes!.inner(inner) != null); + const line = inner.line(); + assert(line !== null); + return line ? line : "FIXME" // FIXME null handling +} + +export async function repl_loop() { + while(true){ + let line = await readline('>> ') + try { + let result = eval.call(window, line); + if (result) { console.log(result) }; + } catch (err) { + console.log(err); + } + } +} + \ No newline at end of file diff --git a/src/isolate.rs b/src/isolate.rs index 5a09b8855c8e88..e882582d1fd0eb 100644 --- a/src/isolate.rs +++ b/src/isolate.rs @@ -11,6 +11,7 @@ use libdeno; use futures::Future; use libc::c_void; +use rustyline::Editor; use std; use std::ffi::CStr; use std::ffi::CString; @@ -56,6 +57,7 @@ pub struct IsolateState { pub flags: flags::DenoFlags, tx: Mutex>>, pub metrics: Mutex, + pub repl: Mutex>>, } impl IsolateState { @@ -120,6 +122,7 @@ impl Isolate { flags, tx: Mutex::new(Some(tx)), metrics: Mutex::new(Metrics::default()), + repl: Mutex::new(None), }), } } diff --git a/src/main.rs b/src/main.rs index 8a9f88f516b378..409252488e6310 100644 --- a/src/main.rs +++ b/src/main.rs @@ -82,8 +82,8 @@ fn main() { }); isolate.event_loop(); // if no args then enter repl - if isolate.state.argv.len() == 1 { - repl::repl_loop(&mut isolate) - } + // if isolate.state.argv.len() == 1 { + // repl::repl_loop(&mut isolate) + // } }); } diff --git a/src/msg.fbs b/src/msg.fbs index 5b60213ade2dce..ab5b47531d392c 100644 --- a/src/msg.fbs +++ b/src/msg.fbs @@ -23,6 +23,8 @@ union Any { Rename, Readlink, ReadlinkRes, + Repl, + ReplRes, Symlink, Stat, StatRes, @@ -248,6 +250,14 @@ table ReadlinkRes { path: string; } +table Repl { + prompt: string; +} + +table ReplRes { + line: string; +} + table Symlink { oldname: string; newname: string; diff --git a/src/ops.rs b/src/ops.rs index 261ed67f5d4445..50b169e62686e4 100644 --- a/src/ops.rs +++ b/src/ops.rs @@ -9,6 +9,7 @@ use isolate::Isolate; use isolate::IsolateState; use isolate::Op; use msg; +use repl; use resources; use resources::Resource; use tokio_util; @@ -91,6 +92,7 @@ pub fn dispatch( msg::Any::ReadDir => op_read_dir, msg::Any::Rename => op_rename, msg::Any::Readlink => op_read_link, + msg::Any::Repl => op_repl, msg::Any::Symlink => op_symlink, msg::Any::SetEnv => op_set_env, msg::Any::Stat => op_stat, @@ -1063,6 +1065,42 @@ fn op_read_link( }) } +fn op_repl( + state: Arc, // FIXME (this will be needed!) + base: &msg::Base, + data: &'static mut [u8], +) -> Box { + assert_eq!(data.len(), 0); + let inner = base.inner_as_repl().unwrap(); + let cmd_id = base.cmd_id(); + let prompt = inner.prompt().unwrap().to_owned(); + // let f = || repl::readline(state, prompt); + + blocking!(base.sync(), || -> OpResult { + // debug!("op_repl {}", prompt); + let line = repl::readline(&state, &prompt)?; // FIXME + // let line = f()?; + let builder = &mut FlatBufferBuilder::new(); + let line_off = builder.create_string(&line); + let inner = msg::ReplRes::create( + builder, + &msg::ReplResArgs { + line: Some(line_off), + ..Default::default() + }, + ); + Ok(serialize_response( + cmd_id, + builder, + msg::BaseArgs { + inner: Some(inner.as_union_value()), + inner_type: msg::Any::ReplRes, + ..Default::default() + }, + )) + }) +} + fn op_truncate( state: Arc, base: &msg::Base, diff --git a/src/repl.rs b/src/repl.rs index f5db86a3b740d5..cdeb14747812b5 100644 --- a/src/repl.rs +++ b/src/repl.rs @@ -1,43 +1,37 @@ -use rustyline::error::ReadlineError; +// Copyright 2018 the Deno authors. All rights reserved. MIT license. +extern crate rustyline; use rustyline::Editor; +use std::sync::Arc; +use std::error::Error; +//use futures::Future; +use msg::ErrorKind; + + use isolate; +use errors::DenoResult; +use errors::new as deno_error; +pub fn readline(_state: &Arc, prompt: &String) -> DenoResult { + // FIXME + // let mut maybe_editor = state.repl.lock().unwrap(); + // if maybe_editor.is_none() { + // println!("{}", "Creating new Editor<()>"); + // *maybe_editor = Some(start_repl()); // will this assign within IsolateState? + // } + let maybe_editor = Some(start_repl()); + maybe_editor + .unwrap() + .readline(prompt) + .map_err(|err| deno_error(ErrorKind::Other, err.description().to_string())) +} -#[allow(dead_code)] -pub fn repl_loop(isolate: &mut isolate::Isolate) { - // `()` can be used when no completer is required - let mut rl = Editor::<()>::new(); - if rl.load_history("history.txt").is_err() { - println!("No previous history."); - } - loop { - let readline = rl.readline(">> "); - match readline { - Ok(line) => { - rl.add_history_entry(line.as_ref()); - isolate - .execute("deno repl", &line) - .unwrap_or_else(|err| { - println!("{}", err); - }); - // FIXME we should move this to a thread (and run it only once)... - isolate.event_loop(); - // println!("Line: {}", line); - }, - Err(ReadlineError::Interrupted) => { - println!("CTRL-C"); - break - }, - Err(ReadlineError::Eof) => { - println!("CTRL-D"); - break - }, - Err(err) => { - println!("Error: {:?}", err); - break - } - } +// FIXME can we call save_history when this is dropped / upon exit? +// rl.save_history("history.txt").unwrap(); +fn start_repl() -> Editor<()> { + let mut editor = Editor::<()>::new(); + if editor.load_history("history.txt").is_err() { + eprintln!("No previous history."); } - rl.save_history("history.txt").unwrap(); -} \ No newline at end of file + editor +} From 375048c3765f21b51c3c3adc5a49948c9a1f54b0 Mon Sep 17 00:00:00 2001 From: Shiva Prasanth Date: Mon, 15 Oct 2018 19:26:03 +0530 Subject: [PATCH 08/10] thirdParty --- third_party | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party b/third_party index a133fa714b960d..0f61667878d446 160000 --- a/third_party +++ b/third_party @@ -1 +1 @@ -Subproject commit a133fa714b960d8f88c55188ccc1a41882961e6e +Subproject commit 0f61667878d44606346590b2f531b82444d7c3d8 From d890eff8e3bfb50c0da1b29d938646c7721cdd93 Mon Sep 17 00:00:00 2001 From: Shiva Prasanth Date: Mon, 15 Oct 2018 19:42:52 +0530 Subject: [PATCH 09/10] adding deno namespace to repl --- js/repl.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/js/repl.ts b/js/repl.ts index 171af830981819..0e2791c943aab6 100644 --- a/js/repl.ts +++ b/js/repl.ts @@ -4,7 +4,10 @@ import { flatbuffers } from "flatbuffers"; import { assert } from "./util"; import * as dispatch from "./dispatch"; import { window } from "./globals"; +import * as deno from './deno'; +// FIXME assignis like this is bad +window.deno = deno /** Read the next line for the repl. * * import { readFile } from "deno"; From 0f6bce216c3127cebef3a5421622fe1d1f0b2720 Mon Sep 17 00:00:00 2001 From: Shiva Prasanth Date: Mon, 15 Oct 2018 20:28:19 +0530 Subject: [PATCH 10/10] formating --- js/main.ts | 3 +-- js/repl.ts | 17 +++++++++-------- src/main.rs | 2 +- src/ops.rs | 6 +++--- src/repl.rs | 22 ++++++++++++---------- 5 files changed, 26 insertions(+), 24 deletions(-) diff --git a/js/main.ts b/js/main.ts index 8f1e8796fb05c2..f249baf3eecb95 100644 --- a/js/main.ts +++ b/js/main.ts @@ -10,7 +10,6 @@ import { sendSync, handleAsyncMsgFromRust } from "./dispatch"; import { promiseErrorExaminer, promiseRejectHandler } from "./promise_util"; import { repl_loop } from "./repl"; - function sendStart(): msg.StartRes { const builder = new flatbuffers.Builder(); msg.Start.startStart(builder); @@ -37,7 +36,7 @@ function onGlobalError( } // FIXME this is a hack, and anyway doesn't work for `throw "error"` // which (for some reason) has source == undefined - if (source !== 'deno repl') { + if (source !== "deno repl") { console.log(`Source: ${source}`); os.exit(1); } diff --git a/js/repl.ts b/js/repl.ts index 0e2791c943aab6..487e4893bb524a 100644 --- a/js/repl.ts +++ b/js/repl.ts @@ -4,10 +4,10 @@ import { flatbuffers } from "flatbuffers"; import { assert } from "./util"; import * as dispatch from "./dispatch"; import { window } from "./globals"; -import * as deno from './deno'; +import * as deno from "./deno"; // FIXME assignis like this is bad -window.deno = deno +window.deno = deno; /** Read the next line for the repl. * * import { readFile } from "deno"; @@ -37,18 +37,19 @@ function res(baseRes: null | msg.Base): string { assert(baseRes!.inner(inner) != null); const line = inner.line(); assert(line !== null); - return line ? line : "FIXME" // FIXME null handling + return line ? line : "FIXME"; // FIXME null handling } export async function repl_loop() { - while(true){ - let line = await readline('>> ') + while (true) { + const line = await readline(">> "); try { - let result = eval.call(window, line); - if (result) { console.log(result) }; + const result = eval.call(window, line); + if (result) { + console.log(result); + } } catch (err) { console.log(err); } } } - \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 409252488e6310..d79ac65a644562 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,8 +6,8 @@ extern crate futures; extern crate hyper; extern crate libc; extern crate msg_rs as msg; -extern crate rustyline; extern crate rand; +extern crate rustyline; extern crate tempfile; extern crate tokio; extern crate tokio_executor; diff --git a/src/ops.rs b/src/ops.rs index 50b169e62686e4..928fc5123aa3ed 100644 --- a/src/ops.rs +++ b/src/ops.rs @@ -1066,7 +1066,7 @@ fn op_read_link( } fn op_repl( - state: Arc, // FIXME (this will be needed!) + state: Arc, // FIXME (this will be needed!) base: &msg::Base, data: &'static mut [u8], ) -> Box { @@ -1078,8 +1078,8 @@ fn op_repl( blocking!(base.sync(), || -> OpResult { // debug!("op_repl {}", prompt); - let line = repl::readline(&state, &prompt)?; // FIXME - // let line = f()?; + let line = repl::readline(&state, &prompt)?; // FIXME + // let line = f()?; let builder = &mut FlatBufferBuilder::new(); let line_off = builder.create_string(&line); let inner = msg::ReplRes::create( diff --git a/src/repl.rs b/src/repl.rs index cdeb14747812b5..8056f894617fdc 100644 --- a/src/repl.rs +++ b/src/repl.rs @@ -2,17 +2,19 @@ extern crate rustyline; use rustyline::Editor; -use std::sync::Arc; use std::error::Error; +use std::sync::Arc; //use futures::Future; use msg::ErrorKind; - -use isolate; -use errors::DenoResult; use errors::new as deno_error; +use errors::DenoResult; +use isolate; -pub fn readline(_state: &Arc, prompt: &String) -> DenoResult { +pub fn readline( + _state: &Arc, + prompt: &String, +) -> DenoResult { // FIXME // let mut maybe_editor = state.repl.lock().unwrap(); // if maybe_editor.is_none() { @@ -29,9 +31,9 @@ pub fn readline(_state: &Arc, prompt: &String) -> DenoRes // FIXME can we call save_history when this is dropped / upon exit? // rl.save_history("history.txt").unwrap(); fn start_repl() -> Editor<()> { - let mut editor = Editor::<()>::new(); - if editor.load_history("history.txt").is_err() { - eprintln!("No previous history."); - } - editor + let mut editor = Editor::<()>::new(); + if editor.load_history("history.txt").is_err() { + eprintln!("No previous history."); + } + editor }