Coder Social home page Coder Social logo

dart_repl's Introduction

dart_repl

About

A proof of concept REPL environment for Dart.

Example 1

asciicast

Example 2

asciicast

Further work

See the Dart REPL Directions brain-dump for possible ideas and directions.

Usage

pub global run

You can install and setup dart_repl using:

pub global activate dart_repl

To run it, simply execute:

pub global run dart_repl

If you run it from a directory that contains a Dart package (it needs a .packages file), it will load all dependencies automatically and allow you to import libraries adhoc from the command-line:

pub global run dart_repl --adhoc-import package:built_collection/built_collection.dart

(if your package depends on built_collection).

Alternatively, you can use the import() builtin command instead of the commmand-line flag --adhoc-import:

$ pub global run dart_repl

>>> import('package:built_collection/built_collection.dart');

This is the preferred way of running dart_repl as it requires no additional setup.

From another package

You can add a dev_dependency: to your pubspec.yaml:

dev_dependencies:
  dart_repl:
  [...]

You can then run the REPL with:

pub run dart_repl

It will automatically resolve all additional adhoc imports against the dependencies of your package:

pub run dart_repl --adhoc-import package:built_collection/built_collection.dart

From a checkout

From the command-line

dart bin/dart_repl.dart

To import additional libraries, you need to specify a package directory (--package-dir) to allow it to resolve dependencies:

dart bin/dart_repl.dart --package-dir ~/git/built_collection.dart/ --adhoc-import lib/built_collection.dart

Features requests and bugs

Please file feature requests and bugs at the issue tracker.

Appendix

TODOs

[X] provide a back channel for the sandbox to change its own package config. [] find a way to unexport a library (can we enumerate all the symbols from a library and hide them?)

Changes and open questions

Variable shadowing

Variables need to be declared with var or final now. Each top level declaration spawns a new compilation unit. All compilation units are chained together. This means that you can freely redeclare variables. They will shadow each other. This can lead to unintended consequences though:

>>> var a = 1
>>> void ip() { print(a++); }
>>> ip()
1
>>> ip()
2
>>> var a = 1;
>>> ip()
3
>>> a
1

Old Scope behavior

The old behavior (non-shadowed, undeclared variables) is available using the scratch Scope.

>>> scratch.a = 1
1
>>> void ip() { print(++scratch.a); }
>>> ip()
2
>>> ip()
3
>>> scratch.a = 1
1
>>> ip()
2

Why can't I keep this default?

The Scope behavior is ideal, however, I don't know how to lift it into the global namespace. Before I was evaluating every expression and statement within the Scope, so you could access all its fields without qualification. However, with top-level declaration, this is not possible anymore. This would mean having different semantics:

>>> a = 1
1

but

>>> class X { void ip() { print(++scratch.a); } }

A solution would be to generate a global scope file that is constantly reloaded. This seems infeasible for more complex inputs and for redefinitions.

Export not import!

Because each top-level decl is its own compilation unit, imports only work within the same cell/input.

>>> import 'dart:io'; get pwd => Directory.current;
>>> pwd
Directory: '/Users/blackhc/IdeaProjects/dart_repl'
>>> Directory.current
Unhandled exception:
NoSuchMethodError: No top-level getter 'Directory' declared.

To make a library available to following cells, you have to use export.

>>>  export 'dart:io'
>>> Directory.current
Directory: '/Users/blackhc/IdeaProjects/dart_repl'

dart_repl's People

Contributors

blackhc avatar refi64 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dart_repl's Issues

Dart 2.1

I tried to install dart_repl and I got:

Resolving dependencies...
The current Dart SDK version is 2.1.0.

Because pub global activate depends on dart_repl any which requires SDK version >=1.0.0 <2.0.0, version solving
  failed.

Is there any chance of support Dart 2.1 ?

Transformer error on unknown sandbox.

on Pub Upgrade

A transformer imported unknown package "dart_repl_sandbox" (in "package:dart_repl_sandbox/isolate_messages.dart").

on Execution

dart --enable-vm-service bin/dart_repl
Observatory listening on http://127.0.0.1:8181/
Unhandled exception:
Could not load "file:///Users/rayk/Projects/uncertapp/bin/dart_repl": FileSystemException: Cannot open file, path = '/Users/rayk/Projects/uncertapp/bin/dart_repl' (OS Error: No such file or directory, errno = 2)
null
  • Have check dart_repl did install to the dir OK.

Set in dev_dependencies
dart_repl: '0.9.0'

The Vm
Dart VM version: 1.21.1 (Fri Jan 13 01:40:43 2017) on "macos_x64"

What is the package file

analyzer:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/analyzer-0.29.3/lib/
args:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/args-0.13.7/lib/
async:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/async-1.11.3/lib/
barback:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/barback-0.15.2+9/lib/
boolean_selector:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/boolean_selector-1.0.2/lib/
browser:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/browser-0.10.0+2/lib/
build:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/build-0.6.3/lib/
build_barback:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/build_barback-0.0.3/lib/
build_runner:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/build_runner-0.1.1/lib/
built_collection:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/built_collection-1.3.0/lib/
built_value:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/built_value-0.5.0/lib/
built_value_generator:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/built_value_generator-0.5.0/lib/
charcode:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/charcode-1.1.1/lib/
cli_util:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/cli_util-0.0.1+2/lib/
code_transformers:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/code_transformers-0.5.0+2/lib/
collection:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/collection-1.13.0/lib/
convert:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/convert-2.0.1/lib/
crypto:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/crypto-2.0.1/lib/
csslib:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/csslib-0.13.2+2/lib/
dart_repl:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/dart_repl-0.9.0/lib/
dart_style:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/dart_style-0.2.14/lib/
dart_to_js_script_rewriter:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/dart_to_js_script_rewriter-1.0.2/lib/
glob:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/glob-1.1.3/lib/
html:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/html-0.13.1/lib/
http:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/http-0.11.3+9/lib/
http_multi_server:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/http_multi_server-2.0.3/lib/
http_parser:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/http_parser-3.1.1/lib/
isolate:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/isolate-0.2.3/lib/
json_rpc_2:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/json_rpc_2-2.0.3/lib/
logging:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/logging-0.11.3+1/lib/
matcher:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/matcher-0.12.0+2/lib/
meta:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/meta-1.0.4/lib/
mime:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/mime-0.9.3/lib/
package_config:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/package_config-1.0.0/lib/
package_resolver:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/package_resolver-1.0.2/lib/
path:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/path-1.4.1/lib/
plugin:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/plugin-0.2.0/lib/
pool:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/pool-1.2.4/lib/
pub_semver:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/pub_semver-1.3.2/lib/
quiver:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/quiver-0.23.0/lib/
quiver_hashcode:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/quiver_hashcode-1.0.0/lib/
sass:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/sass-1.0.0-alpha.7/lib/
shelf:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/shelf-0.6.7+2/lib/
shelf_packages_handler:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/shelf_packages_handler-1.0.0/lib/
shelf_static:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/shelf_static-0.2.4/lib/
shelf_web_socket:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/shelf_web_socket-0.2.1/lib/
simple_sass_transformer:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/simple_sass_transformer-0.0.1+1/lib/
source_gen:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/source_gen-0.5.3+2/lib/
source_map_stack_trace:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/source_map_stack_trace-1.1.4/lib/
source_maps:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/source_maps-0.10.2/lib/
source_span:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/source_span-1.3.1/lib/
stack_trace:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/stack_trace-1.7.0/lib/
stream_channel:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/stream_channel-1.5.0/lib/
string_scanner:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/string_scanner-1.0.1/lib/
test:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/test-0.12.18+1/lib/
tuple:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/tuple-1.0.1/lib/
typed_data:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/typed_data-1.1.3/lib/
utf:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/utf-0.9.0+3/lib/
vm_service_client:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/vm_service_client-0.2.3/lib/
watcher:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/watcher-0.9.7+3/lib/
web_socket_channel:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/web_socket_channel-1.0.4/lib/
when:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/when-0.2.0/lib/
which:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/which-0.1.3/lib/
yaml:file:///Users/rayk/.pub-cache/hosted/pub.dartlang.org/yaml-2.1.12/lib/
uncertaintyApp:lib/

What is in the Yaml

--cut

dependencies:
quiver: any
meta: ^1.0.4
built_collection: ^1.0.0
built_value: ^0.5.0

dev_dependencies:
browser: '>=0.10.0 <0.11.0'
build: '0.6.3'
build_barback: any
build_runner: any
built_value_generator: any
dart_repl: '0.9.0'
dart_to_js_script_rewriter: '1.0.2'
simple_sass_transformer: '0.0.1+1'
source_gen: '>=0.5.0+03 <0.6.0'
test: '>=0.12.0 <0.13.0'

dependency_overrides:

transformers:

  • dart_to_js_script_rewriter
  • simple_sass_transformer

NoSuchMethodError on exit when an invalid import is run and Ctrl-D is used

ryan@DevPC-LX ~ $ pub global run dart_repl
Observatory listening on http://127.0.0.1:53556/
1.23.0 (Fri Apr 21 10:05:24 2017) on "linux_x64"
Type `exit()` to quit.
>>> import 'bad:import';
Unhandled exception:
Could not import "bad:import" from "file:///tmp/dart_repl48zwAL/cell2.dart": Unknown scheme (bad) for bad:import
null
>>> Unhandled exception:
NoSuchMethodError: The getter 'isEmpty' was called on null.
Receiver: null
Tried calling: isEmpty
#0      Object._noSuchMethod (dart:core-patch/object_patch.dart:43)
#1      Object.noSuchMethod (dart:core-patch/object_patch.dart:47)
#2      runRepl (package:dart_repl/src/kernel.dart:54)
<asynchronous suspension>
#3      dartRepl (package:dart_repl/dart_repl.dart:17)
<asynchronous suspension>
#4      main (file:///home/ryan/.pub-cache/hosted/pub.dartlang.org/dart_repl-0.11.1/bin/dart_repl.dart:27)
<asynchronous suspension>
#5      _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:263)
#6      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:151)
ryan@DevPC-LX ~ $ 

(You can't see it here, but I'm using Ctrl-D to exit.)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.