Showing posts with label runtime. Show all posts
Showing posts with label runtime. Show all posts

Wednesday, January 18, 2012

A List of Errors.

Before I get started on this post on Lists (actually, I already started it yesterday but didn't complete it yet ;), I did want to share the information that Seth Ladd recently shared regarding the Dart issue tracker. Sometimes it can be hard to locate or you just can't recall the location to access the tracker. Well never fear! There is a new redirect URL available to use.
dartbug.com
Redirects to the main issue list.
dartbug.com/new
Redirects to the new issue template.
dartbug.com/1199
Redirects to a specific issue number (in this case 1199, the one I submitted and mentioned in my last blog post).
So I'm continuing with Seth Ladd's series on Dart. Today I'm looking at Lists and Arrays. One particular quote from the post particularly grabbed my attention and interest:
Fun fact: As of 2011-12-22, the word "array" does not appear in the Dart spec.'
This interested me as virtually all languages have arrays and refer to them as such. But sure enough a quick search through the current language spec reveals no results for 'array'. Now, as stated in Seth's blog, Dart arrays are Lists. I found it an interesting point none the less.

Interestingly enough however, the VM does output an error which refers to arrays. But when compiled to Javascript (via frog or dartc) the errors properly reflects 'lists'. First I'll demonstrate the code and error then I'll actually provide some additional comments regarding the code.
main() {
  var list = new List(3); // Create an immutable, or 'non-extendable' list
  list.add(4); // Now try to change it (extend it).
}

This results in the following error:
Unhandled exception:
UnsupportedOperationException: Cannot add to a non-extendable array

But when executed on the dartboard we get the following error:
UnsupportedOperationException: Cannot add to a non-extendable list

It surprises me a little that the VM does specifically reference array whereas the code compiled to Javascript, which does have arrays, correctly references a list. There already exists a couple of bug reports. One which I'll only briefly mention, indicates that the word 'array' should be removed from all internal libraries. The second, which I added a comment to regarding the VM specifically is: Issue 1028. This issue aims to be more encompassing removing references from the Libraries as all references which may become visible.

So you may be wondering why it is that List provides an add method if it just generates an error. Well that's because there are two types of lists. A 'non-extendable' list which is created by passing a size to the constructor, or you can create a list without the optional argument to the constructor which creates an empty list you can extend by adding (or removing) values from. An extendable list can also be created from a list literally such as:
var list = [1, 2, 3];

Note however, that unlike some other languages (such as Ruby), you can not call a method on the List literal. Thus the following is not valid code:
var list = [1, 2, 3].add(4);

You'll receive a warning indicating "expression does not yield a value". But it will compile and run (at least until you try to call a List method on list such as length which will generate a runtime error.

However there is a bug in the add method which I have just discovered. The API for List.add indicates that the return type is 'void' (or no return value). This works as expected in the dartboard (javascript). However in the Dart VM, list.add(value) returns the new size of the list. I have submitted a bug report for it here: Issue 1213.

Tuesday, January 17, 2012

Some easy roads

I received some comments to my last two posts which is great. Always nice to see that it's being reading, even by a small audience. But these particular comments were nice as they were from Seth Ladd, who is a Developer advocate at Google. It's great getting feedback to my issues directly from the team working on the project. First comment was to submit bug reports, the other about some easier roads to take which I was totally unaware of and want to share.

But first regarding the bug reports for those of you who may be curious. I searched through the issue tracker and could not find a similar bug report for the issue I ran into with named arguments being passed to a function. So I created a new issue for that. Issue 1199. I verified the same example code works in dartboard and it does compile with frogc, but will not run in the VM. Take a look at the bug report if you're interested.

Thus far, I have been unable to consistently replicate the issue I'm having with the editor randomly greying out the 'Lunch in Dart Server' button and menu item. I'll continue to work on this to see if I can determine the cause and reproduce the issue. If I do I will also provide information on the bug report for that one.

Seth Ladd also shared with me a link to the root location of Dart Editor downloads. You can find that here: http://gsdview.appspot.com/dart-editor-archive-integration/latest/. Of note here are a couple of other files listed. In particular is: dart-linux-latest.zip which is a pre-compiled version of the SDK (from trunk, not bleeding edge). Also available are the MacOS and Win32 builds however I can't account for how well these may work as I'm running on my linux machine.

After my experiences yesterday pulling down the code, compiling and testing I do highly recommend using the above download unless you are specifically looking for Dartium. This will help save your system a little space and save yourself a little time an patience. I'm glad for the experience I had with pulling down the source but going forward I will most like be sticking the pre-built binaries from the above source to keep consistency with official builds and documentation. Here's to hoping for a pre-built dartium in the (near?) future!

That's all for now. May post more later today as I get some actual coding done ;)

Monday, January 16, 2012

Dart VM Install?.... Yes!

Firstly, allow me to comment that I have been corrected in how Dartboard works. In my post That's a Type of what?, I made mention that I believed that the Dartboard sends code to the server and is executed in the DartVM and the results are displayed back. I have found out that this is incorrect and in actuality the code is sent to the server which is compiled into JavaScript and then sent back to be executed client side. This is what results in the type confusions.

So to circumvent this confusion going forward I am going to work on today on downloading and compiling the dart VM. I will keep information throughout the day on how this process goes and any issues I may run into.
  • Step one: Install the the 32-bit libraries on my 64-bit machine. Following the automated setup instructions (very handy I might add). Running the install-build-deps.sh script is pretty quick and extremely handy. Though the initial question about installing the debugging symbols is a little poorly worded. I wasn't sure if I was being prompted to install the debugging symbols or all the packages. Hitting "N" I receive the message that it will not install the debugging symbols and starts to proceed with the installation of other packages (after asking me for a sudo password).
  • Step one (b): I'm prompted if I want to install the gold linker, which is apparently 5x faster than regular ld.. yeah sure why not. Lots of building and such occurs. No errors encountered that I notice. I wonder will the system detect this is installed automatically or will I have to pass that as an optional parameter myself? We'll see..
  • Step one (c): I'm prompted if I want to install the 32-bit dev libraries to build a 32-bit chrome on a 64-bit system that it will need to download a large number of debs then will extract the files it requires, create new debs and install them (and, one assumes, will remove the larger and more numerous original debs)... wait I thought this is what I was doing already anyways? Re-reading the Preparing Your Machine wiki again says that you may need to install the 32-bit libraries on a 64-bit system. Better hit yes just to be on the safe side
  • Righty, all done that... I notice it left a binutils-2.21.1 directory there... might need to get rid of that later. On to the next part, check out the code. Copy and paste.... and done. And export the path.. Oo no compiling this time yay.
  • Okay, now onto Getting the Source. Now I'm stuck with a choice... do I get 'everything' or do I get the standalone VM? I already have the Dart Editor installed. A little confused as to what additional packages there are to install. Does this install Dartium too? I kinda assume frogc was part of the VM package... well I've got a fair bit of space to install... might as well go ahead and do 'everything', to save me from having to come back and look for them after the fact if I did decide I wanted something else.
  • gclient sync ran into an issue... exited with a non-zero status code. I see a notice that I can't download DumpRenderTree. I'm advised to run a script gsutil config... yeah okay. Enter in the authorization code... blank project-id.. Okay done now...? Well lets try running gclient sync again. Uhm... ends saying Syncing projects: 85% done. I dunno did this work or not? Well only one way to find out. Time to try and build.
  • Building everything: Alright... into the dart directory and run the build... odd that I have to specify my arch as a 32 bit system. A quick groups search shows me that the 64-bit system isn't yet implemented. Hopefully that will change in the future, particularly as server side code starts rolling out. Looks like this may take a while. So I'm going to grab some lunch. -- Back from lunch and it appears that the build failed. Getting an error "Unable to locate tools.jar. Expected to find it in /usr/lib/jvm/java-6-openjdk/lib/tools.jar" A quick google search shows I'm missing the openjdk-6-jdk package. I look where it expected to find the file and it only shows jre directory and such no lib directory. Quick apt-get install openjdk-6-jdk installs this for me. I double check and the file is where it expects. Still... odd though that it wasn't detected with the build deps.
    And bang, another error... This one a little more complex. Lots of information on the screen but it really boils down to this line: "runtime/vm/dart_api_impl_test.cc:1432:15: error: variable ‘result’ set but not used [-Werror=unused-but-set-variable]" Doing some looking around I see a few similar errors though not specifically that file/line. I double check the file and see the declaration and assignment to that variable but not used after that. Not passed or returned apparently. Odd. I double check the source online in both trunk and bleeding_edge. Both are showing the same thing. Looks like I have resort to the work around. I know right away that the work around will fix that error as the work around makes warnings just warnings and stops them from being errors. The work around is comment 8 as seen here.
  • Building has finished apparently, though I can't seem to see the Dartium build in there anywhere. But in anycase lets start with the testing... Oh look an error doesn't like the Chromium testing. Okay we'll just drop that part. Progressing VERY slowly for these tests. A few of them have timed out so far, haven't reached the results yet. Starting to think about if I really need the "All" option. Doesn't appear to have compiled the editor either (which isn't a big deal since I already have that downloaded from the dartlang page anyways.)
  • Eventually my tests finally complete (well over an hour). And I, for reasons I'm still not 100% sure of, decide in my infinite wisdom, decide "No, I only want the standalone VM". So I remove all the sources and start basically from the beginning. First I check out the "standalone.deps" and sync.
  • Now to build again. This time however I also make note to build as a release instead of as debug which is the default. Now to go through the similar steps to build (such as disabling warnings as errors on the compiler). Build is pretty quick. Now tests... wow much faster as well. None time out this time either.
Alright, so now that I have that downloaded and compiled lets give it a try right quick. Yep a simple "hello world" works exactly as expected from the command line. However when I try to run a test in the Dart Editor it just wants to compile it doesn't want to use the VM even after specifying the path.

Upon investigation I do see that there is a new Dart editor release available. I was previously using 3101. Latest build number shows 3331. I try downloading the latest stable release and sure enough it's the 3331 release. One really nice enhancement is that it allows you to decide when making an app if the application type is Web or a script. Choosing script, and having the VM path set automatically runs the examples in the console as well! Success!

In addition. Running the small little script from my previous post gives the following results:
true
true
false
false
false
false

Exactly what we would expect to see. Phew. So now as I progress learning the language I can use the dart VM directly as opposed to running in dartboard all the time. Should help my work flow as well.

Current I only have the dart VM running and did not bother with the compiler, Dartium, etc. I am curious for those of you familiar. Since Frog is written in Dart, does it require the compiler aspect to be compiled or will it work with just the VM as is?
Also for the Dartium build.. the Wiki instructions show to use bleeding_edge repository as opposed to using the trunk. Thoughts on this?

Thursday, January 12, 2012

Ranting Runtime

So to start things off, I decided I would look at a slice of code I had an issue with yesterday. Now first off know that the error in the following code was entirely intentional. I was looking to see how dart, and Dartboard would handle various errors. Looking to see if I would receive a warning, error or runtime error.

First a link to the dartboard (and I'll paste the code in as well until I can figure out how to embed the dartboard into here).

class States {
  static final ON = 1;
  static final OFF = 0;
}

main() {
  var test = new States();
  print('Give try.dartlang.org a try.');
  print('On is: ${States.ON}');
  if(test is States) print('Test is a State instance');
  // The following never prints?
  print('test.ON is: ${test.ON}');
}

Which produces the following output:

Give try.dartlang.org a try.
On is: 1
Test is a State instance

That's it.. no error, no warning. Just did not ever print anything from the final statement. That struck me as really weird. But what I figured was probably happening is that dartboard was receiving a runtime error but didn't display it at all. Still it seemed off to me.

However, after writing a post on Google+, later in the day the dartboard did start reporting the runtime error that was being generated and produced the following:

NoSuchMethodException - receiver: '' function name: 'ON$getter' arguments: []]

Yay! Errors... but errr huh? NoSuchMethodException.. yeah okay I can see that, it's looking for getter method for a class property. But why is the receiver blank? Receiver should be the 'test' instance of the States class. And the arguments are... err what? Okay I can see maybe showing an empty array for the arguments (thus the '[ ]' ) but why am I seeing the extra ']' ? But I well realize that the VM is still in alpha. I've not had a chance yet to go through the issue trackers to see if these are known bugs but being that they are so prominent I have reason to believe they are.