Thanks to some pointers from @dartbits, it seems that there may be some hope of using a real editor, namely Emacs, with Dart.
To do so, I need to download the Dart SDK, which can be found amongst the Dart builds. The SDK are the ones without "DartBuild" in the filename. For my Ubuntu system, that means that I need "dart-linux.zip":
➜ Downloads wget http://gsdview.appspot.com/dart-editor-archive-continuous/latest/dart-linux.zip ... 2011-12-30 16:08:40 (130 KB/s) - `dart-linux.zip' saved [6683485/6683485]Using the mnemonic suggested in yesterday's comments (
unzip -d
-- I might actually remember that), I extract the SDK into a temporary directory until I can decide what to do with it:➜ Downloads unzip -d ~/tmp/dart dart-linux.zipTaking a look at the contents, I find:
➜ dart cd ~/Downloads ➜ Downloads cd ~/tmp/dart ➜ dart ls dart-sdk ➜ dart ls dart-sdk/* dart-sdk/revision dart-sdk/bin: dart frogc frogc.dart dart-sdk/lib: builtin core coreimpl dom frog html htmlimpl json dart-sdk/util: dartdocFor what it is worth to future readers, the
revision
that I am using here is 2886:➜ dart cat dart-sdk/revision 2886Since the dart SDK follows an almost UNIX like directory structure (with
bin
and lib
sub-directories), I am almost tempted to move those sub-directories directly into my $HOME/local
. I worry about confusion with the likes of $HOME/local/lib/builtin
, so, at least for now, I move the dart SDK directory into $HOME/local
and sym-link the executables:➜ dart mv dart-sdk ~/local ➜ dart cd ~/local/bin/ ➜ bin ln -s ../dart-sdk/bin/dart ➜ bin ln -s ../dart-sdk/bin/frogc ➜ bin ln -s ../dart-sdk/bin/frogc.dartFirst, I think that I will try to replicate yesterday's Dart to Javascript compilation with these tools. If I am successful, I can eschew the Eclipse-based Dart Editor in favor of my beloved Emacs.
Back in the directory containing my simple iterating code, I "frogc" (hunh?) the dart code:
➜ iterator frogc iterator.dart error: File not found: /home/cstrom/local/lib/core/core_frog.dart error: File not found: /home/cstrom/local/lib/html/html.dart iterator.dart:6:5: warning: can not resolve "document" on "iterator" document.query('#status').innerHTML = ''; ^^^^^^^^ iterator.dart:6:5: warning: document is not defined anywhere in the world. document.query('#status').innerHTML = ''; ^^^^^^^^ iterator.dart:6:5: warning: can not resolve "noSuchMethod" on "iterator" document.query('#status').innerHTML = ''; ^^^^^^^^ iterator.dart:6:5: warning: noSuchMethod is not defined anywhere in the world. document.query('#status').innerHTML = ''; ^^^^^^^^ compilation failed with 2 errors Unhandled exception: Compilation failed 0. Function: '::main' url: '/home/cstrom/local/dart-sdk/lib/frog/minfrogc.dart' line:32 col:5 1. Function: '::main' url: '/home/cstrom/local/dart-sdk/bin/frogc.dart' line:11 col:16Yikes! Well, not too bad I suppose. The reason for the failure is that the compiler cannot find the core libraries. Looks as though I need to sym-link them into my
$HOME/local/lib
directory after all:➜ iterator cd ~/local/lib ➜ lib ln -s ../dart-sdk/lib/* . ➜ lib ls -l total 14068 lrwxrwxrwx 1 cstrom cstrom 23 2011-12-30 21:51 builtin -> ../dart-sdk/lib/builtin lrwxrwxrwx 1 cstrom cstrom 20 2011-12-30 21:51 core -> ../dart-sdk/lib/core lrwxrwxrwx 1 cstrom cstrom 24 2011-12-30 21:51 coreimpl -> ../dart-sdk/lib/coreimpl lrwxrwxrwx 1 cstrom cstrom 19 2011-12-30 21:51 dom -> ../dart-sdk/lib/dom drwxr-xr-x 2 cstrom cstrom 4096 2011-05-14 21:39 engines lrwxrwxrwx 1 cstrom cstrom 20 2011-12-30 21:51 frog -> ../dart-sdk/lib/frog lrwxrwxrwx 1 cstrom cstrom 20 2011-12-30 21:51 html -> ../dart-sdk/lib/html lrwxrwxrwx 1 cstrom cstrom 24 2011-12-30 21:51 htmlimpl -> ../dart-sdk/lib/htmlimpl drwxr-xr-x 3 cstrom cstrom 4096 2011-03-06 12:00 io lrwxrwxrwx 1 cstrom cstrom 20 2011-12-30 21:51 json -> ../dart-sdk/lib/json ...At least that is a little better than moving those Dart sub-directories directly into
$HOME/local/lib
—the sym-links describe the source of what might otherwise be mysterious entries 6 months hence.Back in my simple iterator directory, I try again:
➜ iterator frogc iterator.dart /home/cstrom/local/lib/htmlimpl/htmlimpl.dart:23094:21: warning: a map literal takes one type argument specifying the value type _listenerMap = <String, EventListenerList>{}; ^^^^^^Er... What?
That is not an error from my code. That is from Dart itself. Ugh. Checking line 23,094 of htmlimpl.dart, I see:
EventsImplementation._wrap(this._ptr) { // TODO(sigmund): the key type (String) yields a warning in frog and the vm, // but it is currently necessary to compile with dartc. _listenerMap =Ah, so it is an expected warning. But why then did the expected Javascript version of the app not compile?{}; }
➜ iterator ls -l total 2272 -rw-rw-r-- 1 cstrom cstrom 416 2011-12-30 21:58 iterator.dart -rw-rw-r-- 1 cstrom cstrom 2125072 2011-12-30 00:05 iterator.dart.app.js.bak -rw-rw-r-- 1 cstrom cstrom 182516 2011-12-30 21:58 iterator.dart.js -rw-rw-r-- 1 cstrom cstrom 220 2011-12-29 23:07 iterator.html drwxrwxr-x 4 cstrom cstrom 4096 2011-12-30 00:04 workspaceIt turns out that it did compile. I had expected it to be named
iterator.dart.app.js
like it was when the Dart Editor generated it. Instead it is just iterator.dart.js
. And wow, it is an order of magnitude smaller than the Editor generated version.Of course, it does not mean squat unless the smaller version actually works. So I point the HTML to the new Javascript file and load the page in the browser to find:
Awesome. That is a huge win for me. Not only was the Dart Editor not Emacs, it was also a bit slow with the code auto-completion (which I detest anyway) and took up much memory.
In addition to compiled Dart into Javascript, I expect to want to execute pure Dart from the command line as well. That should be what the
dart
command is for:➜ iterator dart iterator.dart '/home/cstrom/dart/iterator/iterator.dart': Error: line 1 pos 1: library handler failed: Do not know how to load 'dart:html' #import('dart:html'); ^Hrm... One the one hand, why would I want to load
dart:html
when I am working on the command line? On the other hand, if I want to load it, why can't I?I can kinda-sorta get it working by changing the
#import
statement to:#import('./lib/html/html.dart'); // #import('dart:html');And sym-linking the html library:
$ ln -s ~/local/dart-sdk/lib .does the trick. Sort of:
➜ iterator dart iterator.dart '/home/cstrom/dart/iterator/iterator.dart': Error: line 1 pos 1: library handler failed: '/home/cstrom/local/dart-sdk/lib/html/html.dart': Error: line 3 pos 1: library handler failed: Do not know how to load 'dart:dom' #import('dart:dom', prefix:'dom'); ^ #import('./lib/html/html.dart'); ^Of course
dart:html
references dart:dom
so now that does no resolve. I am not going to worry about that too much. Not yet at least. For now, it is good to be able to call and compile Dart code.I call it a night here. Tomorrow, I plan to get a little more familiar with this
dart
executable. As well as Dart itself.Day #250
Great posts! Looking forward for the book!
ReplyDeleteAt least on macosx I could compile with frogc without any problem and without having to symlink the libs just by unziping to a folder and putting the bin dir on my path.