Skip to content
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

Merged
merged 1 commit into from
Nov 5, 2018
Merged

Add repl #998

merged 1 commit into from
Nov 5, 2018

Conversation

hayd
Copy link
Contributor

@hayd hayd commented Oct 16, 2018

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

Copy link
Contributor

@kitsonk kitsonk left a 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};
Copy link
Contributor

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.

Copy link
Contributor Author

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!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try again.

Copy link
Contributor Author

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 Show resolved Hide resolved
js/repl.ts Outdated Show resolved Hide resolved
js/repl.ts Outdated Show resolved Hide resolved
js/repl.ts Outdated
assert(baseRes != null);
assert(msg.Any.ReplRes === baseRes!.innerType());
const inner = new msg.ReplRes();
assert(baseRes!.inner(inner) != null);
Copy link
Contributor

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.

Copy link
Contributor Author

@hayd hayd Oct 16, 2018

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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);
Copy link
Contributor

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.

js/repl.ts Outdated Show resolved Hide resolved
js/repl.ts Outdated Show resolved Hide resolved
tools/repl_test.py Outdated Show resolved Hide resolved
@hayd
Copy link
Contributor Author

hayd commented Oct 17, 2018

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.

@ry
Copy link
Member

ry commented Oct 17, 2018

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.

src/repl.rs Outdated Show resolved Hide resolved
src/repl.rs Outdated Show resolved Hide resolved
@bartlomieju
Copy link
Member

bartlomieju commented Oct 21, 2018

EDIT: @hayd I managed to get REPLs stored on IsolateState, and refactored it to struct. History loading is done from name of the repl so we can handle multiple of them as you suggested. Feel free to cherry-pick those commits.

You can check it out here: https://github.com/bartlomieju/deno/commits/repl

@hayd
Copy link
Contributor Author

hayd commented Oct 22, 2018

@bartlomieju 👍 I've merged it to this branch and rebased, but github is still playing catch up/down.

@hayd hayd mentioned this pull request Oct 22, 2018
3 tasks
@bartlomieju
Copy link
Member

@hayd awesome 👍 I think we can start figuring out how to compile TS to JS. @kitsonk can you give us a hand here and point into right direction?

@hayd
Copy link
Contributor Author

hayd commented Oct 24, 2018

@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:

🦕>

@ry
Copy link
Member

ry commented Oct 24, 2018

@hayd I want to get #1081 in before looking into this one.
And no emoji in the prompt. "> " is sufficient.

@hayd
Copy link
Contributor Author

hayd commented Oct 28, 2018

rebased. Build fail due to new third_party commit not in denoland repo.

Strangely #1087 doesn't appear to be an issue any more in the repl (or perhaps I've forgotten how to trigger it).

Squashed from cbef6b6.

@hayd hayd force-pushed the repl branch 6 times, most recently from be8922c to c560981 Compare November 3, 2018 07:13
@piscisaureus
Copy link
Member

piscisaureus commented Nov 3, 2018

@hayd - you can work around the issue with this patch: piscisaureus@repl_send

cc @ry

@hayd
Copy link
Contributor Author

hayd commented Nov 3, 2018

The build/tests are now green on appveyor + travis.

Copy link
Member

@ry ry left a 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 Show resolved Hide resolved
src/repl.rs Outdated Show resolved Hide resolved
src/repl.rs Outdated Show resolved Hide resolved
src/deno_dir.rs Outdated Show resolved Hide resolved
src/isolate.rs Outdated Show resolved Hide resolved
src/repl.rs Outdated
}
}

pub struct DenoRepl {
Copy link
Member

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 (?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linereader.readline 🤢 . hmmm

Copy link
Contributor Author

@hayd hayd Nov 4, 2018

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.

Copy link
Member

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice!

src/isolate.rs Outdated Show resolved Hide resolved
src/msg.fbs Show resolved Hide resolved
src/msg.fbs Outdated Show resolved Hide resolved
@bartlomieju
Copy link
Member

@hayd do you need help with requested changes?

@hayd
Copy link
Contributor Author

hayd commented Nov 4, 2018

@bartlomieju yes please, if you could add to resources table, change name to history_file etc. would be very helpful, thanks 👍

@ry
Copy link
Member

ry commented Nov 5, 2018

@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.

@hayd
Copy link
Contributor Author

hayd commented Nov 5, 2018

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.

@hayd
Copy link
Contributor Author

hayd commented Nov 5, 2018

@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:

$ ./out/debug/deno -D
DEBUG RS - starting background reactor
DEBUG RS - msg_from_js Start sync true
DEBUG JS - cwd /Users/hayd/OSS/deno
DEBUG JS - args []
DEBUG RS - op_repl_start deno_history.txt
DEBUG RS - Loading REPL history: "/Users/hayd/.deno/deno_history.txt"
DEBUG RS - msg_from_js ReplStart sync true
DEBUG RS - op_repl_readline 3 >
> DEBUG RS - key: Char('a')
DEBUG RS - Emacs command: SelfInsert(1, 'a')
DEBUG RS - Changeset::insert(0, 'a')
> aDEBUG RS - key: Char('b')
DEBUG RS - Emacs command: SelfInsert(1, 'b')
DEBUG RS - Changeset::insert(1, 'b')
> abDEBUG RS - key: Char('c')
DEBUG RS - Emacs command: SelfInsert(1, 'c')
DEBUG RS - Changeset::insert(2, 'c')
> abc

Every key stroke logged, yet the repl remains functional... which is nice.

@ry
Copy link
Member

ry commented Nov 5, 2018

I suspect we'll need to do async (at some point).

Yah, I think so too...

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

- Running repl from js side.
- Add tests for repl behavior.
- Handle ctrl-C and ctrl-D.
@ry ry merged commit 27ecfc1 into denoland:master Nov 5, 2018
@hayd hayd deleted the repl branch November 5, 2018 18:08
ry added a commit to ry/deno that referenced this pull request Nov 5, 2018
- 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)
@ry ry mentioned this pull request Nov 5, 2018
ry added a commit that referenced this pull request Nov 5, 2018
- 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants