AmberVM 0.0.19
Good news everyone!
Murphy from murfy.de and me set together to work on the next release of AmberVM. It was quite an endeavor, he has worked parallel on a different approach on the ECMA interpreter and and we took the time to merge his work into AmberVM itself so combine the best of the two worlds. We worked through a whole night to get everything done but finally every spec is working perfectly again.
The result are a few cool new features in the ECMA interpreter and Amber itself. The main changes are that the whole parser is rewritten from scratch, or rather we decided to merge in Murphy’s parser for the AmberVM ECMA implementation, then another big move is that the namespace for functions and variables are now combined in AmberVM, this allows it to handle functions as variables or even parameters.
A more complete list of new features of AmberVM in version 0.0.19:
- ambervm now supports -s switch to show the source code it executes.
- ambervm now supports -p switch to show a pseudo code that describes the internal representation of the code it executes.
- The Namespace for Functions and Variables is now merged.
- The this keyword is working corectly!
- Objects scope correctly
- Now a big thing, Closures are working, even mostly correct. Only some odd cases brake the systems as using global variables in Closures. But that’s bad style in my eyes so just don’t do it ;).
- Some optimization.
So let’s see how this works. Have fun with it and if you happen to decide to use it, drop me a line ;)
rVM 0.0.17
As promised the new release has a few exciting features!
The ECMA Script (also widely known as Java Script) compiler kind of got the flaggship of rVM for the moment so this (and likely the next few releases as well) will focus on this language. The reason for it is not that we want rVM to become a ECMA Script interpreter but that maintaining more than one language is too much work at this stage – since not even ECMA is fully supported yet.
We redesigned the way rVM programs access rVM Library functions (the stuff written in ruby). While before the functions were accessing for every code executed in the rVM access to them is now limited to core libraries (or everything the compiler declares as such). The advantage of this is to provide a language native interface to those functions. As an example, rVM knows the sin() function, ECMA script does call it Math.sin(), the Math compiler calls them just ‘sin()’ and yet another language might call it ‘sinus()’, now since those functions would be ‘aliased’ in core libraries every lanuage can call them as they want to give a native feeling while writing in it.
That brings a light change in the layout of the language classes along, Language#env will now provide a environment with the core libraries loaded, as long as they exist.
ECMA script got a good bit of the Math library shipped along with this release, meaning that the benchmarks that are used now run the same in rVM and rhino. I would guess that most code that runs in rVM will run out of the box in rhino or other ECMA interpreters since rVM is more strict then most others. The other way round it sadly isn’t guaranteed since the ECMA compiler still misses some features.
To the topic of speed, since we can distinguish now between rVM functions and self implemented functions this gave us a little boost in speed, also some tweaks in the environment handling add a bit speed. Still we can claim to be, as murphy put it so nicely, ‘the slowest ECMA VM around’! Hah! Beat that Google and Mozilla! Even so rVM greatly wins speed with ruby 1.9.1, the benchmarks are nearly twice as fast with the new ruby version!
You can get the new version either via gem (once it is updated at rubyforge), from rubyforge (http://rubyforge.org/frs/?group_id=6626) or directly from here (http://code.licenser.net/projects/list_files/rvm).
Have fun!
rVM's feature
Good news everybody!
rVM started to be a quite actively developped again. A friend of mine murphy from http://murfy.de/ has joined the development team, so we’re two now. I greatly respect him and he is quite knowledgeable when it comes to ruby, but most importantly enough he’s crazy enough to jump in a projekt as this. So he will be a great gain for rVM.
Actually he already was very helpful. We have set down the last to days and worked on it. A few good results have come up, including that we finally got a (somewhat) usable benchmark. rVM is only about 20 times slower then the rhino VM when interpreting ECMA script. That does should slow but hell it is fast enough for the moment (murphy stopped me to optimize and focus on making it work more conform first – which is one of the good things that already came from this cooperation :P).
So the ECMA interpreter is working better and better, meaning that after a few more fixes and additions I’ll release version 0.0.17 soon (in the next days I hope). That release will feature a nice new feature for ECMA, a core library that starts to provide a ECMA-like access to function objects like Math.
rVM envolves
Lately I got some chance to work more on rVM, and there is some good progress.
Just the day before version 0.0.12 was released and it steadily progresses towards the 0.1.0. 0.0.12 ships with some nifty new features which mostly results for the fact that I already got the chance to use rVM in two projects, and I’ve to admint I’d not thought it would really work out that well.
A few words to what is new, 0.0.12 now pretty completely covers ECMA script, of cause there are still some things that do not work like the option to create own objects is still missing and the support for leaving away ’;’s in some places is missing. On the other hand it runs quite stable now and even passes most JSON test from http://json.org. Only some negative tests are not passes as the rVM compiler is too forgiving or implements non required features as allowing expressions within a associative array.
For the goal of making rVM easily usable, which is in my eyes one of the most important tasks, acts_as_rvm_type was added which allows to declare own objects as types for rVM in just a few lines.
Here a short example for that:
class Dog
attr_accessor :race, :name
include RVM::ActsAsRVMType
acts_as_rvm_type
register_variable :race, false # Declares race as a readonly variable in rVM
register_variable :name # Declares name as a writable variable for rVM
register_function :bark # Declares bark as a function of the dog object
def initalize race, name
@race = race
@name = name
end
def bark
puts "#{@name} barks!"
end
endThis is in my opinion a big step forward, and it works pretty smoothly with Rails which is nice, some time in the future I’ll add a rails plug in to make this even easier.
At another note due to adding a good few (still not enough I fear) specs to then rVM implementation lots of bugs were tossed away in the last few releases.
Visions
There are a few things I very much would love to see for rVM, one and perhaps the most ambitious is that with rVM it would be possible to run Tests or Specs over JavaScript code without the need of a browser – given it would take a good bit of effort and certainly some work to make the ECMA implementation more conform but I believe that it /is/ possible. Even now I think that for basic and well written JS code rVM might do the job in parsing and interpreting it correctly. But this is just a crazy idea for me ;) while it would be pretty darn cool to be able to do all tests of a rails app within ruby and no need for any foreign frameworks.
rVM on Rails
Since version 0.0.13 rVM includes rvm/rails which is a easy bridge between rails and rVM that allows to quickly add scripting capabilities to rails applications.
The basics are pretty simple rvm/rails comes in 2 parts: First a plugin for ActiveRecord::Base that makes it easy to use act_as_rvm_type with it and second functions specialized for Rails. Currently this is only print() which is used to generate output.
If you are interested have a look at the Screencast or the API documentation .
rvm on speed?
After finding this link I got the crazy idea to write the core of the VM in C. I am quite certain it would give a good bit of speed boost especially concidering that at this point speed might matter.
What is the downside? Well I can think of two – it is way more likely that I mess up something in C and thus create a bug that allows harm the system the VM runs, the second is … our best friend Microsoft Windows. Also I’ll have to look into how JRuby handles things like ruby extensions.
So I was thinking to package the whole thing with two versions of the VM core, one written in C if you are either trustfully or sure enough bugs won’t harm too much or speed does matter a lot for you. Then a second version written in pure ruby which would likely be a good bit slower but only bugs in the ruby interpreter would be a concern.
Any thoughts?
rVM 0.1.0
Well rVM 0.1.0 is on the way with lots of new features (yea I know 0.0.6 - 0.0.9 were never even released yet) but they might on the way, whenever a part of the functionality is done.
So as part of rVM 0.1.0 I will make a few screen casts about how to use rVM, and what makes it nice - my thoughts and plans on it and all that. Bare with me I am new to this medium and certenly have some way to go before I bring screen casts to a perfection where other are ;) but well we all have to start at one point.
This one is showing the very basic steps about how to include rVM into a project, a few easy steps to get this done.
Second part is the RVM::Library class to load function libraries using RVM into a ruby project.
If you are interested: watch it
next release rVM is coming!
I won’t write too much here, considering I already wrote a news post on the redmine side for it. Non the less if anyone at all reads this blog it’s just fair to keep you up to date right?
As a quick overview what will come:
- ECMA Script / JS - including a lot of functionality but not all features (hence ECMA Scirpt is quite extensive)
- Objects - a object model will join rVM and have it’s debut in the ECMA implementation
- Examples how to use rVM compiled code as libraries
That are only some short notes for a more extensive discussion please have a look at the News Post as I am not going to cheat and post the entire thing again ;).
– Lice