Giter Site home page Giter Site logo

rubyflux's Introduction

RubyFlux: a Ruby to Java compiler

RubyFlux is a compiler that turns a Ruby codebase into a closed set of .java source files suitable for running on any JVM with no additional runtime requirement.

A .java file is produced for the toplevel of each file and for each Ruby class declaration encountered. Methods are emitted as normal Java methods, but with an abstract implementation on RObject so all dynamic calls can simply be Java virtual calls. The rest of Ruby syntax maps to mostly what you'd expect in Java code.

Note that this is a young project and it is not yet considered stable for general use.

On the Net

Github repository: https://github.com/headius/rubyflux

Mailing list: https://groups.google.com/forum/?fromgroups#!forum/ruby_flux

Getting Started

  1. Clone the repository
  2. From the repo dir, run "mvn package". You only need to do this once.
  3. Compile and/or run a target .rb file in one of several ways
    • Generate Java sources directly, compile, and run
      • jruby -I target:src/main/ruby src/main/ruby/ruby\_flux.rb target.rb
      • javac target.java
      • java target
    • Generate Java sources via the Rakefile
      • `rake compile[target.rb]
      • Sources are output to build/ in the same dir as target.rb
    • Generate, compile, and run via the Rakefile
      • `rake run[target.rb]

Usage

Here's an example session for using RubyFlux today:

# The file we want to compile

$ cat fib.rb
def fib(a)
  if a < 2
    a
  else
    fib(a - 1) + fib(a - 2)
  end
end

puts fib(40)

# First need to build the compiler's jar

$ mvn package
<maven noise>

# Provide the target file to 'rake run'.
#
# The Ruby sources are translated to .java and all support code is copied out
# of RubyFlux for the compilation step. That source is then compiled and run.
# to compile

$ rake run[fib.rb]
jruby -I target:src/main/ruby src/main/ruby/ruby_flux.rb fib.rb
javac fib.java
java fib
102334155

rubyflux's People

Contributors

headius avatar ianp avatar shawn42 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  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  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

rubyflux's Issues

hello.rb test produces invalid Java source.

Running your hello.rb test through the compiler produces this:

    public RObject fib(RObject a) {
        RObject __last = RNil;
        __last = if (        __last = a.__LESS_THAN_SIGN(new RFixnum(2));
.toBoolean()) {
        __last = a;
} else {
        __last = fib(a.__HYPHEN_MINUS(new RFixnum(1))).__PLUS_SIGN(fib(a.__HYPHEN_MINUS(new RFixnum(2))));
};
        return __last;
    }

I think (from the state of lib/RString.java) that you've forgotten to git push your latest code.

Demo Fib code does not run.

shawn42@bites ~/code/fastruby (git: master)✗ $ jruby -I target:src/main/ruby src/main/ruby/fast_ruby.rb -e "def fib(a); a < 2 ? a : fib(a - 1) + fib(a - 2); end; puts fib(40)"

shawn42@bites ~/code/fastruby (git: master)✗ $ javac DashE.java
shawn42@bites ~/code/fastruby (git: master)✗ $ java DashE
Exception in thread "main" java.lang.RuntimeException: $plus
at RObject.$plus(RObject.java:13)
at DashE.fib(DashE.java:19)

....

at DashE.fib(DashE.java:19)
at DashE.fib(DashE.java:19)
at DashE.$main(DashE.java:10)
at DashE.main(DashE.java:5)

undefined method `required_args' when running `rake run`

When I run rake run[fib.rb], it failed with the following information: NoMethodError: undefined method `required_args' for #Java::OrgJrubyParser::StaticScope:0x37271612
Here is detailed:

➜  rubyflux git:(master) ✗ pwd
/home/justme0/programs/rubyflux
➜  rubyflux git:(master) ✗ ls
dependency-reduced-pom.xml  fib.rb  LICENSE  pom.xml  Rakefile  README.md  src/  target/
➜  rubyflux git:(master) ✗ cat fib.rb
def fib(a)
  if a < 2
    a
  else
    fib(a - 1) + fib(a - 2)
  end
end

puts fib(40)
➜  rubyflux git:(master) ✗ echo $PATH 
/home/justme0/Downloads/jruby-9.1.2.0/bin /usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin /usr/games /usr/local/games
➜  rubyflux git:(master) ✗ mvn --version
Apache Maven 3.0.5
Maven home: /usr/share/maven
Java version: 1.8.0_45-internal, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-openjdk-amd64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.19.0-59-generic", arch: "amd64", family: "unix"
➜  rubyflux git:(master) ✗ jruby --version
jruby 9.1.2.0 (2.3.0) 2016-05-26 7357c8f OpenJDK 64-Bit Server VM 25.45-b02 on 1.8.0_45-internal-b14 +jit [linux-x86_64]
➜  rubyflux git:(master) ✗ ruby --version
ruby 2.2.4p230 (2015-12-16 revision 53155) [x86_64-linux]
➜  rubyflux git:(master) ✗ rake --version
rake, version 10.4.2
➜  rubyflux git:(master) ✗ echo $SHELL 
/usr/bin/fish
➜  rubyflux git:(master) ✗ rake run[fib.rb]
jruby -I target:src/main/ruby src/main/ruby/ruby_flux.rb fib.rb
NoMethodError: undefined method `required_args' for #<Java::OrgJrubyParser::StaticScope:0x37271612>
             start at /home/justme0/programs/rubyflux/src/main/ruby/ruby_flux/body_compiler.rb:29
             start at /home/justme0/programs/rubyflux/src/main/ruby/ruby_flux/method_compiler.rb:53
             start at /home/justme0/programs/rubyflux/src/main/ruby/ruby_flux/class_compiler.rb:41
  block in compile at /home/justme0/programs/rubyflux/src/main/ruby/ruby_flux/compiler.rb:27
              each at org/jruby/RubyArray.java:1593
           compile at /home/justme0/programs/rubyflux/src/main/ruby/ruby_flux/compiler.rb:19
             <top> at src/main/ruby/ruby_flux.rb:45
rake aborted!
Command failed with status (1): [jruby -I target:src/main/ruby src/main/rub...]
/home/justme0/programs/rubyflux/Rakefile:24:in `block in (root)'
Tasks: TOP => run => compile => generate
(See full trace by running task with --trace)

I guess it is about arguments. Thank you very much!

error

at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)

Caused by: java.lang.ClassNotFoundException: org.sonatype.aether.graph.Dependency
at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
... 65 more
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 10.111 s
[INFO] Finished at: 2017-03-26T14:10:16+02:00
[INFO] Final Memory: 66M/419M

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.