FAQ
- What is Ruby.PHP?
- Ruby.PHP is a compiler of Ruby to PHP.
- Why compile Ruby to PHP?
- Quite frankly, I needed a topic for my master thesis and writing
a compiler of my favorite language seemed like a lot of fun :-)
- More seriously: Hosting PHP websites is easy and often free, which is not
true for Ruby on Rails applications. The compiler (with some supporting tools)
could eventually allow you to compile your Rails application to PHP and host
it almost anywhere. This would make Rails applications much easier to
deploy.
- How does it work?
- Currently, the compiler is able to compile small (one-file only) Ruby
scripts. The compiler simply takes a .rb file, parses it and
translates it to a .php file. This file can be run by PHP.
- The .php file requires a "runtime", which consists of several PHP
files containing some supporting code and implementation of core Ruby
classes.
- What parts of Ruby are already supported?
-
- Literals of almost all Ruby basic types
- Almost all Ruby operators – both built-in (
and,
or, not) and method-based.
- Local, global, instance and class variables
- Constants
- Basic statements:
if/elsif/else (including "tail" form),
unless/else (including "tail" form),
while,
until,
break (without parameters),
next (without parameters),
begin/end
- Method definitions (
def), redefinitions and
undefinitions (undef), along with positional and rest
parameters, return and super statements.
- Exception raising (
raise) and handling
(rescue/else)
- Blocks along with
yield statement
- Class/module definitions and redefinitions (
class,
module)
BEGIN and END blocks
- Some predefined global variables
- Most predefined constants
- Note that some of these language elements are not fully implemented/tested
and may not work in some situations.
- Important functionality of the core library classes (Object, Module,
Class, Fixnum, Bignum, Float, Array, Hash, Range,...) is implemented, however
many methods are still missing.
- Okay, okay – what are the major areas that are not supported?
-
- Literals for regular expressions and
`-delimited
strings
- Some statements:
case/when,
for,
ensure,
redo,
retry and
defined?
- Optional and block parameters for methods
- Method aliasing (
alias)
- Many global variables
- Some predefined constants
- Can I download the compiler? Can I see the source?
- Not now, sorry. The compiler is not yet ready for public consumption.
However, after a bit of cleaning, I plan to publish the compiler for download.
The source code will be released under suitable OSS license.
- If you enter your mail here, you will be notified when this happens:
-
- Can I contribute somehow?
- Not now, sorry. I am writing the compiler as a part of my master thesis,
which should be my own work. After I finish the thesis (late spring/summer
2008), I will publish the source code and I will accept contributions.
Hopefully, Ruby.PHP will transform from one-man show into an open source
project with many contributors.
- What language is the compiler written in?
- Ruby, of course :-)
- What version of Ruby is Ruby.PHP compatible with?
- Ruby.PHP aims to be compatible with Ruby 1.8.6. No work regarding
compatibility with Ruby 1.9 has been done yet.
- And what version of PHP is needed to run the generated code?
- The generated code is compatible with both PHP 4 and 5. No detailed
requirements are specified yet, but 4.4.x or 5.2.x versions should
suffice.
- Are there any parts of Ruby which the compiler would never be able to
grok?
- Unfortunately, yes. Due to limitations of PHP and the runtime
architecture, Ruby.PHP won't ever support continuations and some control-flow
constructs (such as the
retry statement inside the
rescue clause). I also don't think that it is possible to
implement threads correctly in PHP.
- Wouldn't the resulting code/application be slow?
- I don't know. I didn't do any measurements and optimizations yet. I try to
focus on the correct functionality first.