From 6a5149c54114916669e303443203b6a7850d2914 Mon Sep 17 00:00:00 2001 From: grosser Date: Fri, 29 Jul 2011 12:05:22 +0200 Subject: [PATCH 1/7] use rack instead of cgi and use rake instead of windows commands --- Gemfile | 6 ++++++ Gemfile.lock | 24 ++++++++++++++++++++++++ Rakefile | 6 ++++++ build.bat | 2 -- web/compileRuby.cgi | 20 -------------------- web/compileRuby_cgi | 20 -------------------- web/config.ru | 16 ++++++++++++++++ 7 files changed, 52 insertions(+), 42 deletions(-) create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100644 Rakefile delete mode 100644 build.bat delete mode 100644 web/compileRuby.cgi delete mode 100644 web/compileRuby_cgi create mode 100644 web/config.ru 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/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/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/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..808237f --- /dev/null +++ b/web/config.ru @@ -0,0 +1,16 @@ +require 'json' + +compile_options = { + :peephole_optimization =>true, + :inline_const_cache =>false, + :specialized_instruction =>false, + :operands_unification =>false, + :instructions_unification =>false, + :stack_caching =>false, +} + +run lambda{|env| + source = Rack::Request.new(env).GET['src'] + compiled = RubyVM::InstructionSequence.compile(source, "src", "", 1, compile_options).to_a.to_json + [200, {'Content-Type'=>'text/plain'}, [compiled]] +} From 4b99192412e5c6b5a03a600f4941e7760adde1fb Mon Sep 17 00:00:00 2001 From: grosser Date: Fri, 29 Jul 2011 12:07:10 +0200 Subject: [PATCH 2/7] rename readme for github highlighting --- README => Readme.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename README => Readme.md (100%) diff --git a/README b/Readme.md similarity index 100% rename from README rename to Readme.md From dfce8ecf6dc5e4615f197218f16d235da3c2b63e Mon Sep 17 00:00:00 2001 From: grosser Date: Fri, 29 Jul 2011 12:13:00 +0200 Subject: [PATCH 3/7] pimp my readme --- Readme.md | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/Readme.md b/Readme.md index 2fab0ee..20c223f 100644 --- a/Readme.md +++ b/Readme.md @@ -1,16 +1,19 @@ -== HotRuby +# 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. +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? +# Github? -It was developed by yukoba ?, the official website is at http://hotruby.accelart.jp/. +It was developed by yukoba ? [official website](http://hotruby.accelart.jp) -The original repository is at http://code.google.com/p/hotruby/, but it seems to be abandoned. +[original repository](http://code.google.com/p/hotruby) seems to be abandoned. -Github to the rescue! \ No newline at end of file +Github to the rescue! From 1c64426719be0e369c8947b6dcf7242af76d7c1d Mon Sep 17 00:00:00 2001 From: grosser Date: Fri, 29 Jul 2011 12:26:21 +0200 Subject: [PATCH 4/7] make the server serve stuff --- web/config.ru | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/web/config.ru b/web/config.ru index 808237f..458e3d9 100644 --- a/web/config.ru +++ b/web/config.ru @@ -1,6 +1,6 @@ require 'json' -compile_options = { +COMPILE_OPTIONS = { :peephole_optimization =>true, :inline_const_cache =>false, :specialized_instruction =>false, @@ -9,8 +9,17 @@ compile_options = { :stack_caching =>false, } +def compile(source) + RubyVM::InstructionSequence.compile(source, "src", "", 1, COMPILE_OPTIONS).to_a.to_json +end + run lambda{|env| - source = Rack::Request.new(env).GET['src'] - compiled = RubyVM::InstructionSequence.compile(source, "src", "", 1, compile_options).to_a.to_json - [200, {'Content-Type'=>'text/plain'}, [compiled]] + 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 } From 6cb2ed56523942c0f9a5d6037ee9281e2925c75f Mon Sep 17 00:00:00 2001 From: grosser Date: Sat, 30 Jul 2011 09:13:37 +0200 Subject: [PATCH 5/7] .project should not be checked in --- .project | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 .project diff --git a/.project b/.project deleted file mode 100644 index ac9605a..0000000 --- a/.project +++ /dev/null @@ -1,11 +0,0 @@ - - - HotRuby - - - - - - - - From b4cc506219416709de41d9b3d4f7f036c46e5e4f Mon Sep 17 00:00:00 2001 From: grosser Date: Sat, 30 Jul 2011 10:00:42 +0200 Subject: [PATCH 6/7] improve debugging --- src/RubyVM.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/RubyVM.js b/src/RubyVM.js index 05bbabf..6d3c1a3 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 } }, From bac9c1848bb4e53f73c8977d67a11f514cf61a9d Mon Sep 17 00:00:00 2001 From: grosser Date: Sat, 30 Jul 2011 10:13:37 +0200 Subject: [PATCH 7/7] fix operator in exception --- src/RubyVM.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/RubyVM.js b/src/RubyVM.js index 6d3c1a3..1502748 100644 --- a/src/RubyVM.js +++ b/src/RubyVM.js @@ -185,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