diff --git a/.project b/.project deleted file mode 100644 index ac9605a..0000000 --- a/.project +++ /dev/null @@ -1,11 +0,0 @@ - - - HotRuby - - - - - - - - diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..a828a2a --- /dev/null +++ b/Gemfile @@ -0,0 +1,6 @@ +source :rubygems + +gem 'json' +gem 'rack' +gem 'rake' +gem 'rspec', '~>2' diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..2a1b6cc --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,24 @@ +GEM + remote: http://rubygems.org/ + specs: + diff-lcs (1.1.2) + json (1.5.3) + rack (1.3.2) + rake (0.9.2) + rspec (2.6.0) + rspec-core (~> 2.6.0) + rspec-expectations (~> 2.6.0) + rspec-mocks (~> 2.6.0) + rspec-core (2.6.4) + rspec-expectations (2.6.0) + diff-lcs (~> 1.1.2) + rspec-mocks (2.6.0) + +PLATFORMS + ruby + +DEPENDENCIES + json + rack + rake + rspec (~> 2) diff --git a/README b/README deleted file mode 100644 index 2fab0ee..0000000 --- a/README +++ /dev/null @@ -1,16 +0,0 @@ -== HotRuby - -HotRuby is Ruby on JavaScript and Flash. - -HotRuby runs opcode, compiled by YARV(Yet Another Ruby VM) on Ruby. To be precise, HotRuby is Ruby VM on JavaScript and Flash. - -Most of the grammars are implemented. However, exceptions are not implemented. Most of the build-in functions and build-in classes are not implemented. - - -== Github? - -It was developed by yukoba ?, the official website is at http://hotruby.accelart.jp/. - -The original repository is at http://code.google.com/p/hotruby/, but it seems to be abandoned. - -Github to the rescue! \ No newline at end of file diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..6749738 --- /dev/null +++ b/Rakefile @@ -0,0 +1,6 @@ +task :build do + File.open(File.join('web','js','HotRuby.js'),'w') do |f| + f.write File.read(File.join('src','RubyVM.js')) + + File.read(File.join('src','RubyNative.js')) + end +end diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..20c223f --- /dev/null +++ b/Readme.md @@ -0,0 +1,19 @@ +# HotRuby + +HotRuby is a Ruby VM build with JavaScript and Flash, that runs opcode compiled by Ruby 1.9+ + +Most of the grammars are implemented. However, exceptions are not implemented. Most of the build-in functions and build-in classes are not implemented. + +# Running it + + rake build + cd web + rackup + +# Github? + +It was developed by yukoba ? [official website](http://hotruby.accelart.jp) + +[original repository](http://code.google.com/p/hotruby) seems to be abandoned. + +Github to the rescue! diff --git a/build.bat b/build.bat deleted file mode 100644 index cf6d6fb..0000000 --- a/build.bat +++ /dev/null @@ -1,2 +0,0 @@ -@echo off -copy /b src\RubyVM.js + src\RubyNative.js web\js\HotRuby.js diff --git a/src/RubyVM.js b/src/RubyVM.js index 05bbabf..1502748 100644 --- a/src/RubyVM.js +++ b/src/RubyVM.js @@ -122,6 +122,7 @@ HotRuby.prototype = { this.runOpcode(opcode, this.classes.Object, null, this.topObject, [], null, false, null); } catch(e) { alert(e); + if(console) console.log(e) // more details than alert } }, @@ -184,7 +185,7 @@ HotRuby.prototype = { */ mainLoop : function(opcode, sf) { // Create label to ip - if(!("label2ip" in opcode)) { + if(typeof(opcode.label2ip) != 'undefined') { // label2ip in opcode would throw exception opcode.label2ip = {}; for (var ip = 0;ip < opcode.length; ip++) { // If "cmd is a String then it is a jump label diff --git a/web/compileRuby.cgi b/web/compileRuby.cgi deleted file mode 100644 index d93ec5a..0000000 --- a/web/compileRuby.cgi +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/local/bin/ruby -# Requires Ruby 1.9.0 -# The license of this source is "Ruby License" - -require 'json' -require 'cgi' - -OutputCompileOption = { - :peephole_optimization =>true, - :inline_const_cache =>false, - :specialized_instruction =>false, - :operands_unification =>false, - :instructions_unification =>false, - :stack_caching =>false, -} - -cgi = CGI.new - -puts "Content-type: text/plain\n\n" -puts VM::InstructionSequence.compile(cgi['src'], "src", 1, OutputCompileOption).to_a.to_json diff --git a/web/compileRuby_cgi b/web/compileRuby_cgi deleted file mode 100644 index f777461..0000000 --- a/web/compileRuby_cgi +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/local/bin/ruby -# Requires Ruby 1.9.0 -# The license of this source is "Ruby License" - -require 'json' -require 'cgi' - -OutputCompileOption = { - :peephole_optimization =>true, - :inline_const_cache =>false, - :specialized_instruction =>false, - :operands_unification =>false, - :instructions_unification =>false, - :stack_caching =>false, -} - -cgi = CGI.new - -puts "Content-type: text/plain\n\n" -puts VM::InstructionSequence.compile(cgi['src'], "src", 1, OutputCompileOption).to_a.to_json diff --git a/web/config.ru b/web/config.ru new file mode 100644 index 0000000..458e3d9 --- /dev/null +++ b/web/config.ru @@ -0,0 +1,25 @@ +require 'json' + +COMPILE_OPTIONS = { + :peephole_optimization =>true, + :inline_const_cache =>false, + :specialized_instruction =>false, + :operands_unification =>false, + :instructions_unification =>false, + :stack_caching =>false, +} + +def compile(source) + RubyVM::InstructionSequence.compile(source, "src", "", 1, COMPILE_OPTIONS).to_a.to_json +end + +run lambda{|env| + if env['REQUEST_PATH'] == '/compileRuby.cgi' # TODO legacy url, gsub all js files to change it + source = Rack::Request.new(env).params['src'] + [200, {'Content-Type'=>'text/plain'}, [compile(source)]] + elsif env['REQUEST_PATH'] == '/' + [200, {'Content-Type' => 'text/html'}, [File.read('index.html')]] + else + Rack::File.new('.').call(env) + end +}