evaluate and evaluateInFrame calls

16 views
Skip to first unread message

Austin Cummings

unread,
Sep 10, 2015, 11:44:07 AM9/10/15
to observato...@dartlang.org
Hello everyone,

I've been playing around with writing a REPL for Dart using the vm service and I was hoping I could get a few questions answered.

First of all, is it even viable to write a Dart REPL using the vm service and the evaluate and evaluateInFrame calls? I have gotten function calls and math expressions to work correctly using evaluate, but have not found a way to dynamically add new code like variables and functions.

If the vm service is too limited for use in a REPL, are there any other services or API's that would be useful?

What capabilites and limitations do the evaluate and evaluateInFrame calls have with regard to execution and declaration of code?

How would I go about declaring variables, functions, and classes via the vm service? Are these types of things even possible?

Thanks,
Austin

Ryan Macnak

unread,
Sep 14, 2015, 2:01:00 PM9/14/15
to observato...@dartlang.org
On Mon, Sep 7, 2015 at 7:35 PM, Austin Cummings <aus...@austincummings.com> wrote:
Hello everyone,

I've been playing around with writing a REPL for Dart using the vm service and I was hoping I could get a few questions answered.

First of all, is it even viable to write a Dart REPL using the vm service and the evaluate and evaluateInFrame calls? I have gotten function calls and math expressions to work correctly using evaluate, but have not found a way to dynamically add new code like variables and functions.

If the vm service is too limited for use in a REPL, are there any other services or API's that would be useful?

What capabilites and limitations do the evaluate and evaluateInFrame calls have with regard to execution and declaration of code?

Evaluate takes expressions, not declarations. In particular it only accepts the kinds of expressions that can be the right-hand-side of an arrow function, i.e. eval() => <expression>;

Evaluate-in-frame has the additional limitation that assignments to local variables don't affect the values in the frame.

example() {
  var n = 5;
  debugger();
  print(n);
}

evaluateInFrame(0, 'n = 10'); ===> 10
evaluateInFrame(0, 'n'); ===> 5
resume()
stdout: 5

How would I go about declaring variables, functions, and classes via the vm service? Are these types of things even possible?

Sadly, that is not currently possible with the service protocol. Using the C embedding API (dart-sdk/include/dart_api.h) it is possible to define new libraries, but even there you cannot add/remove/edit methods from existing classes or add/remove/edit classes from existing libraries. We have briefly looked into implementing this. The VM is mostly prepared to deal with such changes since it must already be prepared to handle lazy loading and deoptimization when it encounters new types, but this feature is not currently a priority.
Reply all
Reply to author
Forward
0 new messages