-
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
Add repl #998
Add repl #998
Conversation
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.
Some feedback.
js/repl.ts
Outdated
// const replScope = Object.create(window); | ||
// Object.defineProperty(replScope, "deno", { value: deno, enumerable: true }); | ||
// const replScope = Object.defineProperty("deno", Object.create(window), { value: deno, enumerable: true }); | ||
// const replScope = {"deno": deno, ...window}; |
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.
This could be:
const replScope = { deno, ...window };
That is the most concise, but it will only deal with enumerable own properties on window
, where as Object.create
would set the prototype of a new object to window
. I would think it is fine for now, but we may want to note, comment, that we are aware of the limitation (enumerable own properties).
sidenote: I just noticed that many of globals have strange enumerability in Node.js and Chrome. For example in Chrome, window.console
is not enumerable but in Node.js it is enumerable.
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.
This (along with eval.call) didn't seem to update variables
var a = 1
a
I suspect there's a permutation that works but I haven't found it!
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'll try again.
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'm still unable to get it.
js/repl.ts
Outdated
assert(baseRes != null); | ||
assert(msg.Any.ReplRes === baseRes!.innerType()); | ||
const inner = new msg.ReplRes(); | ||
assert(baseRes!.inner(inner) != null); |
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.
We should always comment when we use the not null assertion operator.
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.
Hmmm this is copy/pasted. Which is to say, I am not sure what to comment here.
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.
assert(baseRes!.inner(inner) != null); | |
// TypeScript does not track asserts, baseRes asserted above, therefore not null here | |
assert(baseRes!.inner(inner) != null); |
js/repl.ts
Outdated
if (line === ".exit") { break } | ||
try { | ||
let result = eval.call(window, line); | ||
// let result = eval.call(replScope, line); |
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.
We should use this line, but it should be a const
. There is no reassignment within the block. Again, the tslint would error on this.
I've removed my attempt at having a single rustyline Editor instance. It seems fast even when the history file starts with 5k lines. I am not sure where to put history file. I think the scope change could be made later. |
I apologize for the lack of reviews here. I'm glad you guys are working on this. But I want to figure out if we're going to move the event loop into JS (#1003) before landing any REPL code. |
EDIT: @hayd I managed to get REPLs stored on You can check it out here: https://github.com/bartlomieju/deno/commits/repl |
@bartlomieju 👍 I've merged it to this branch and rebased, but github is still playing catch up/down. |
@ry this is mostly ts side now, originally it was calling out isolate's event_loop but now it's not. So it shouldn't be affected by event loop changes. Perhaps it should be:
|
be8922c
to
c560981
Compare
@hayd - you can work around the issue with this patch: piscisaureus@repl_send cc @ry |
The build/tests are now green on appveyor + travis. |
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.
This work is excellent! I'm really excited. I want to try to land this for 0.1.11
.
I have a few superficial comments...
src/repl.rs
Outdated
} | ||
} | ||
|
||
pub struct DenoRepl { |
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.
Rename to Repl
or Linereader
(?)
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.
Linereader.readline 🤢 . hmmm
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.
But you're right, the loop (eval / print) is not in rust. So it's not a repl.
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.
linereader.read sounds fine
|
||
if __name__ == "__main__": | ||
deno_exe = os.path.join(build_path(), "deno" + executable_suffix) | ||
repl_tests(deno_exe) |
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.
Very nice!
@hayd do you need help with requested changes? |
@bartlomieju yes please, if you could add to resources table, change name to history_file etc. would be very helpful, thanks 👍 |
@hayd @bartlomieju I've made the changes to move the REPL into the resources table myself and pushed to this branch... because it's a little tricky. (We're going to refactor the resources table soon - to hopefully be less haphazard.) I've also changed "readline()" to be a synchronous function. Mostly because its simpler to do... but also it might be more correct? Do you really want output printed to the console while you're interacting with the REPL? I suppose it depends on the situation - but for debugging - generally not. |
Awesome! Thanks @ry. The async behavior is from node (and maybe other languages too), but I agree it's kinda strange.... at least, it's strange if you're logging output. |
@ry I've addressed the other feedback I think (aside from it still being called Repl). I suspect we'll need to do async (at some point). A cool thing you can try is running the repl with debug:
Every key stroke logged, yet the repl remains functional... which is nice. |
Yah, I think so too... |
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.
LGTM!
- Performance and stability improvements on all platforms. - Add repl (denoland#998) - Add deno.Buffer (denoland#1121) - Support cargo check (denoland#1128) - Upgrade Rust crates and Flatbuffers. (denoland#1145, denoland#1127) - Add helper to turn deno.Reader into async iterator (denoland#1130) - Add ability to load JSON as modules (denoland#1065) - Add deno.resources() (denoland#1119) - Add application/x-typescript mime type support (denoland#1111)
- Performance and stability improvements on all platforms. - Add repl (#998) - Add deno.Buffer (#1121) - Support cargo check (#1128) - Upgrade Rust crates and Flatbuffers. (#1145, #1127) - Add helper to turn deno.Reader into async iterator (#1130) - Add ability to load JSON as modules (#1065) - Add deno.resources() (#1119) - Add application/x-typescript mime type support (#1111)
Rebase and work upon #947. cc @cedric05
Add tests in form of repl_test.py.
Executes js.
No compiling from ts.
Note: atm the scope of eval is window + window.deno. (I haven't been able to get the tests passing any of the suggested alternatives) @kitsonk