-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP repl inside deno, initial phase #947
Conversation
Perhaps rustyline looks pretty great 👍 . One thing worth noting is there's not (yet) tokio support kkawakam/rustyline#126 I'm not sure if that's a problem.. |
i still node able to import deno package/functions into repl loop(after adding to global.ts its working, i think that is not correct way). i will work on repl with ts instead of js and will update here. @hayd yes, i will create a new file. |
src/main.rs
Outdated
@@ -68,6 +74,7 @@ fn main() { | |||
|
|||
log::set_logger(&LOGGER).unwrap(); | |||
let args = env::args().collect(); | |||
let args2: Vec<String> = env::args().collect(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
an alternative here is to do:
let start_repl = args.len() == 1
(You'll need to set args: Vec<String>
above.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I take this back, in future you're going to have to parse args. e.g. -D
.
console is getting exited, whenever there is some exception, will work on that as well. |
Also Edit: It seems to exit inside the libdeno::execute unsafe, but I haven't uncovered why. |
setTimeout is not working but deno.mkdir is working for me. i will try test suite and see what else if failing. |
@cedric05 in |
My intuition is that we might want to run repl_loop on another thread (such that we can spawn an event loop to its side that does not block by repl). Also, I feel we can use the trick of setting a huge timeout that ensures |
Also, current global error handler for libdeno would cause the program to exit whenever an exception happens. Lines 23 to 36 in 8ada287
I could help look into REPL this weekend if possible |
yes @kevinkassimo that global error handler really helped, i will keep posting my current status. please take over what all you can pick. |
i'm looking at compilation of ts to js on the fly for repl now. |
It seems like with the global error change it works fine with errors! (Interestingly throw behaves a little differently / source is undefined in onGlobalError.) The event_loop call is blocking until all setTimeouts are finished, so it's not running at all inside the loop. If you add event_loop to after the execute (inside the loop) then it works... waiting for all setTimeouts to complete - which is probably not desired but shows it works! One thing that doesn't work yet is multi-line input. kkawakam/rustyline#79 |
Some more of the way there hayd@e5cb43c Edit: Modulo timeouts: each line waits until all the timeouts are finished... which personally I prefer anyway - ha! Or compiling... |
What's a good way to approach the ts compilation? From a ts (rust) String to a js String. |
my thought process is to expose some api main.ts and do some thing like |
@cedric05 I only really got this far: hayd@e5cb43c (one commit after a rebase of your work). |
Perhaps the alternative is to create a flatbuffers table/result and do the compile and eval in js... ? |
AFAICT we need to be able to call |
trying to understand https://github.com/denoland/deno/blob/master/js/compiler_test.ts#L292, we will have to do the same for repl IMO |
@kitsonk for compiler questions |
Talking with @ry yesterday, the objective for the first REPL would be direct JavaScript support, not supporting TypeScript. I think the REPL for TypeScript will require a bit of change to the compiler or morel likely additional APIs and a specific runtime context that can be built up over time for evaluating types, which trust me, is something that we should build on once the initial REPL is there, versus trying to deliver it in one go. |
Executing javascript is pretty much there. Though as mentioned above doesn't print the returned value (since that's not returned by libdeno::execute)... At the moment this is relying on libdeno::execute BUT in order to do the compile IIUC this is going to have to happen in ts? So I wonder if we're structuring this wrong: Currently: Maybe it needs to be: It seems like this is necessary in order to do ts at some point it needs evaluate in ts? |
@kitsonk I guess I am asking if initially the (javascript) eval should happen in the ts-side (rather than rust) if we're going to have to move that way in future... Node exports https://nodejs.org/api/repl.html and https://nodejs.org/api/vm.html which ts-node relies on. https://github.com/TypeStrong/ts-node/blob/master/src/bin.ts#L163-L190 So I think it makes sense to do the same in deno (even if we're initially only eval-ing and not compiling)... |
So, here's a version that evals javascript: hayd@e1a9b03 The loop is: export async function repl_loop() {
while(true){
let line = await readline('>> ') // this calls rust for the entered text
try {
let result = eval.call(window, line);;
if (result) { console.log(result) };
} catch (err) {
console.log(err);
}
} set timeouts work! and it's non-blocking. |
Just thinking out loud, should we have a different global scope for the REPL, one in particular that doesn't require the import of the |
@hayd pushed your changes, and added deno to global namespace. |
windows build keeps failing, i need to setup my windows machine. |
is this expected??
|
You might be better to checkout my commit/branch and force push that here. I wonder if there was an issue in your merge conflict resolution. I didn't try running the tests yet. Let me look at adding a repl test. Now it's in the ts side we can accept multi-line (though only edit the last line) and later compile. is there anything else we're missing? |
current issues