tlrobinson / cappruby

A proof-of-concept Ruby implementation on top of JavaScript and the Objective-J runtime

This URL has Read+Write access

mchung (author)
Wed Mar 04 16:52:28 -0800 2009
Tom Robinson (committer)
Thu Mar 05 03:24:36 -0800 2009
cappruby / ruby2objj_server.ru
100755 55 lines (41 sloc) 1.02 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env rackup
 
require "json"
require "ruby2objj"
 
class Ruby2ObjjServer
  
  def initialize(root)
    @root = root
  end
  
  def call(env)
    if env['PATH_INFO'] =~ /\.rb$/
      source = File.read(File.join(@root, env['PATH_INFO']))
      sexp = ParseTree.translate(source)
 
      puts "/*"
      pp sexp
      puts "*/"
 
      puts "\n/*"
      unifier = Unifier.new
      #unifier.processors.each do |p|
      # p.unsupported.delete :cfunc # HACK
      #end
      sexp = unifier.process(sexp)
      pp sexp
      puts "*/"
 
      result = Ruby2Objj.new.process(sexp)
      
      puts result
      
      [200, {"Content-Type" => "application/javascript"}, [result]]
    else
      [404, {"Content-Type" => "text/plain"}, ["Not found"]]
    end
  end
end
 
use Rack::CommonLogger
use Rack::ShowExceptions
use Rack::ShowStatus
# use Rack::Lint
# use Rack::ContentLength
 
puts "[#{ARGV[1]}]"
 
run Rack::Cascade.new([
  Ruby2ObjjServer.new(ARGV[1]),
  Rack::File.new(ARGV[1])
])
 
#run Rack::File.new(ARGV[1])