opal 0.3.15 → 0.3.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (236) hide show
  1. data/.gitignore +1 -1
  2. data/Gemfile +8 -2
  3. data/README.md +1 -1
  4. data/Rakefile +51 -57
  5. data/bin/opal +50 -2
  6. data/{runtime/corelib → core}/alpha.rb +6 -1
  7. data/{runtime/corelib → core}/array.rb +38 -42
  8. data/{runtime/corelib → core}/basic_object.rb +6 -17
  9. data/core/boolean.rb +40 -0
  10. data/core/class.rb +69 -0
  11. data/{runtime/corelib → core}/comparable.rb +0 -0
  12. data/core/debug.js +59 -0
  13. data/core/debug.rb +35 -0
  14. data/core/dir.rb +90 -0
  15. data/core/enumerable.rb +331 -0
  16. data/core/enumerator.rb +126 -0
  17. data/core/error.rb +40 -0
  18. data/{runtime/corelib → core}/file.rb +6 -3
  19. data/core/gemlib.rb +30 -0
  20. data/{runtime/corelib → core}/hash.rb +37 -35
  21. data/{runtime/corelib → core}/io.rb +0 -0
  22. data/{runtime/corelib → core}/kernel.rb +26 -21
  23. data/{runtime/corelib → core}/load_order +2 -5
  24. data/{runtime/corelib → core}/match_data.rb +2 -4
  25. data/core/module.rb +204 -0
  26. data/{runtime/corelib → core}/nil_class.rb +1 -7
  27. data/{runtime/corelib → core}/numeric.rb +9 -13
  28. data/core/object.rb +17 -0
  29. data/{runtime/corelib → core}/proc.rb +2 -13
  30. data/{runtime/corelib → core}/range.rb +19 -7
  31. data/{runtime/corelib → core}/rational.rb +0 -0
  32. data/{runtime/corelib → core}/regexp.rb +2 -6
  33. data/core/runtime.js +672 -0
  34. data/{runtime/corelib → core}/string.rb +25 -9
  35. data/{runtime/corelib → core}/struct.rb +0 -0
  36. data/core/time.rb +111 -0
  37. data/{runtime/corelib → core}/top_self.rb +0 -0
  38. data/{runtime/spec → core_spec}/README.md +0 -0
  39. data/{runtime/spec → core_spec}/core/array/allocate_spec.rb +0 -0
  40. data/{runtime/spec → core_spec}/core/array/append_spec.rb +0 -0
  41. data/{runtime/spec → core_spec}/core/array/assoc_spec.rb +0 -0
  42. data/{runtime/spec → core_spec}/core/array/at_spec.rb +0 -0
  43. data/{runtime/spec → core_spec}/core/array/clear_spec.rb +0 -0
  44. data/{runtime/spec → core_spec}/core/array/collect_spec.rb +0 -0
  45. data/{runtime/spec → core_spec}/core/array/compact_spec.rb +0 -0
  46. data/{runtime/spec → core_spec}/core/array/concat_spec.rb +0 -0
  47. data/{runtime/spec → core_spec}/core/array/constructor_spec.rb +0 -0
  48. data/{runtime/spec → core_spec}/core/array/count_spec.rb +0 -0
  49. data/{runtime/spec → core_spec}/core/array/delete_at_spec.rb +0 -0
  50. data/{runtime/spec → core_spec}/core/array/delete_if_spec.rb +0 -0
  51. data/{runtime/spec → core_spec}/core/array/delete_spec.rb +0 -0
  52. data/{runtime/spec → core_spec}/core/array/each_index_spec.rb +0 -0
  53. data/{runtime/spec → core_spec}/core/array/each_spec.rb +0 -0
  54. data/{runtime/spec → core_spec}/core/array/element_reference_spec.rb +0 -0
  55. data/{runtime/spec → core_spec}/core/array/element_set_spec.rb +0 -0
  56. data/{runtime/spec → core_spec}/core/array/empty_spec.rb +0 -0
  57. data/{runtime/spec → core_spec}/core/array/eql_spec.rb +0 -0
  58. data/{runtime/spec → core_spec}/core/array/equal_value_spec.rb +0 -0
  59. data/{runtime/spec → core_spec}/core/array/fetch_spec.rb +0 -0
  60. data/{runtime/spec → core_spec}/core/array/first_spec.rb +0 -0
  61. data/{runtime/spec → core_spec}/core/array/fixtures/classes.rb +0 -0
  62. data/{runtime/spec → core_spec}/core/array/flatten_spec.rb +0 -0
  63. data/{runtime/spec → core_spec}/core/array/include_spec.rb +0 -0
  64. data/{runtime/spec → core_spec}/core/array/insert_spec.rb +0 -0
  65. data/{runtime/spec → core_spec}/core/array/last_spec.rb +0 -0
  66. data/{runtime/spec → core_spec}/core/array/length_spec.rb +0 -0
  67. data/{runtime/spec → core_spec}/core/array/map_spec.rb +0 -0
  68. data/{runtime/spec → core_spec}/core/array/plus_spec.rb +0 -0
  69. data/{runtime/spec → core_spec}/core/array/pop_spec.rb +0 -0
  70. data/{runtime/spec → core_spec}/core/array/push_spec.rb +0 -0
  71. data/{runtime/spec → core_spec}/core/array/rassoc_spec.rb +0 -0
  72. data/{runtime/spec → core_spec}/core/array/reject_spec.rb +0 -0
  73. data/{runtime/spec → core_spec}/core/array/replace_spec.rb +0 -0
  74. data/{runtime/spec → core_spec}/core/array/reverse_each_spec.rb +0 -0
  75. data/{runtime/spec → core_spec}/core/array/reverse_spec.rb +0 -0
  76. data/{runtime/spec → core_spec}/core/array/shared/collect.rb +0 -0
  77. data/{runtime/spec → core_spec}/core/array/shared/eql.rb +0 -0
  78. data/{runtime/spec → core_spec}/core/array/shared/length.rb +0 -0
  79. data/{runtime/spec → core_spec}/core/array/shared/replace.rb +0 -0
  80. data/{runtime/spec → core_spec}/core/class/new_spec.rb +0 -0
  81. data/{runtime/spec → core_spec}/core/enumerable/all_spec.rb +0 -0
  82. data/{runtime/spec → core_spec}/core/enumerable/any_spec.rb +0 -0
  83. data/{runtime/spec → core_spec}/core/enumerable/collect_spec.rb +0 -0
  84. data/{runtime/spec → core_spec}/core/enumerable/count_spec.rb +0 -0
  85. data/{runtime/spec → core_spec}/core/enumerable/detect_spec.rb +0 -0
  86. data/{runtime/spec → core_spec}/core/enumerable/find_spec.rb +0 -0
  87. data/core_spec/core/enumerable/first_spec.rb +3 -0
  88. data/{runtime/spec → core_spec}/core/enumerable/fixtures/classes.rb +0 -0
  89. data/{runtime/spec → core_spec}/core/enumerable/shared/collect.rb +0 -0
  90. data/{runtime/spec → core_spec}/core/enumerable/shared/entries.rb +0 -0
  91. data/{runtime/spec → core_spec}/core/enumerable/shared/find.rb +0 -0
  92. data/core_spec/core/enumerable/shared/take.rb +31 -0
  93. data/{runtime/spec → core_spec}/core/enumerable/to_a_spec.rb +0 -0
  94. data/{runtime/spec → core_spec}/core/false/and_spec.rb +0 -0
  95. data/{runtime/spec → core_spec}/core/false/inspect_spec.rb +0 -0
  96. data/{runtime/spec → core_spec}/core/false/or_spec.rb +0 -0
  97. data/{runtime/spec → core_spec}/core/false/to_s_spec.rb +0 -0
  98. data/{runtime/spec → core_spec}/core/false/xor_spec.rb +0 -0
  99. data/{runtime/spec → core_spec}/core/hash/allocate_spec.rb +0 -0
  100. data/{runtime/spec → core_spec}/core/hash/assoc_spec.rb +0 -0
  101. data/{runtime/spec → core_spec}/core/hash/clear_spec.rb +0 -0
  102. data/{runtime/spec → core_spec}/core/hash/clone_spec.rb +0 -0
  103. data/{runtime/spec → core_spec}/core/hash/default_spec.rb +0 -0
  104. data/{runtime/spec → core_spec}/core/hash/delete_if_spec.rb +0 -0
  105. data/{runtime/spec → core_spec}/core/hash/element_reference_spec.rb +0 -0
  106. data/{runtime/spec → core_spec}/core/hash/element_set_spec.rb +0 -0
  107. data/{runtime/spec → core_spec}/core/hash/new_spec.rb +0 -0
  108. data/{runtime/spec → core_spec}/core/matchdata/to_a_spec.rb +0 -0
  109. data/{runtime/spec → core_spec}/core/nil/and_spec.rb +0 -0
  110. data/{runtime/spec → core_spec}/core/nil/inspect_spec.rb +0 -0
  111. data/{runtime/spec → core_spec}/core/nil/nil_spec.rb +0 -0
  112. data/{runtime/spec → core_spec}/core/nil/or_spec.rb +0 -0
  113. data/{runtime/spec → core_spec}/core/nil/to_a_spec.rb +0 -0
  114. data/{runtime/spec → core_spec}/core/nil/to_f_spec.rb +0 -0
  115. data/{runtime/spec → core_spec}/core/nil/to_i_spec.rb +0 -0
  116. data/{runtime/spec → core_spec}/core/nil/to_s_spec.rb +0 -0
  117. data/{runtime/spec → core_spec}/core/nil/xor_spec.rb +0 -0
  118. data/{runtime/spec → core_spec}/core/numeric/equal_value_spec.rb +0 -0
  119. data/{runtime/spec → core_spec}/core/object/is_a_spec.rb +0 -0
  120. data/{runtime/spec → core_spec}/core/object/shared/kind_of.rb +0 -0
  121. data/{runtime/spec → core_spec}/core/regexp/match_spec.rb +0 -0
  122. data/{runtime/spec → core_spec}/core/regexp/shared/match.rb +0 -0
  123. data/{runtime/spec → core_spec}/core/symbol/to_proc_spec.rb +0 -0
  124. data/{runtime/spec → core_spec}/core/true/and_spec.rb +0 -0
  125. data/{runtime/spec → core_spec}/core/true/inspect_spec.rb +0 -0
  126. data/{runtime/spec → core_spec}/core/true/or_spec.rb +0 -0
  127. data/{runtime/spec → core_spec}/core/true/to_s_spec.rb +0 -0
  128. data/{runtime/spec → core_spec}/core/true/xor_spec.rb +0 -0
  129. data/{runtime/spec → core_spec}/language/alias_spec.rb +0 -0
  130. data/{runtime/spec → core_spec}/language/and_spec.rb +0 -0
  131. data/{runtime/spec → core_spec}/language/array_spec.rb +0 -0
  132. data/{runtime/spec → core_spec}/language/block_spec.rb +0 -0
  133. data/{runtime/spec → core_spec}/language/break_spec.rb +0 -0
  134. data/{runtime/spec → core_spec}/language/case_spec.rb +0 -0
  135. data/{runtime/spec → core_spec}/language/defined_spec.rb +0 -0
  136. data/{runtime/spec → core_spec}/language/ensure_spec.rb +0 -0
  137. data/{runtime/spec → core_spec}/language/fixtures/block.rb +0 -0
  138. data/{runtime/spec → core_spec}/language/fixtures/break.rb +0 -0
  139. data/{runtime/spec → core_spec}/language/fixtures/defined.rb +0 -0
  140. data/{runtime/spec → core_spec}/language/fixtures/ensure.rb +0 -0
  141. data/{runtime/spec → core_spec}/language/fixtures/next.rb +0 -0
  142. data/{runtime/spec → core_spec}/language/fixtures/send.rb +0 -0
  143. data/{runtime/spec → core_spec}/language/fixtures/super.rb +0 -0
  144. data/{runtime/spec → core_spec}/language/hash_spec.rb +0 -0
  145. data/{runtime/spec → core_spec}/language/if_spec.rb +0 -0
  146. data/{runtime/spec → core_spec}/language/loop_spec.rb +0 -0
  147. data/{runtime/spec → core_spec}/language/next_spec.rb +0 -0
  148. data/{runtime/spec → core_spec}/language/or_spec.rb +0 -0
  149. data/{runtime/spec → core_spec}/language/predefined_spec.rb +0 -0
  150. data/{runtime/spec → core_spec}/language/regexp/interpolation_spec.rb +8 -0
  151. data/{runtime/spec → core_spec}/language/regexp_spec.rb +0 -0
  152. data/{runtime/spec → core_spec}/language/send_spec.rb +0 -0
  153. data/{runtime/spec → core_spec}/language/string_spec.rb +0 -0
  154. data/{runtime/spec → core_spec}/language/super_spec.rb +0 -0
  155. data/{runtime/spec → core_spec}/language/symbol_spec.rb +0 -0
  156. data/{runtime/spec → core_spec}/language/undef_spec.rb +0 -0
  157. data/{runtime/spec → core_spec}/language/unless_spec.rb +0 -0
  158. data/{runtime/spec → core_spec}/language/until_spec.rb +0 -0
  159. data/core_spec/language/variables_spec.rb +112 -0
  160. data/{runtime/spec → core_spec}/language/versions/hash_1.9.rb +0 -0
  161. data/{runtime/spec → core_spec}/language/while_spec.rb +0 -0
  162. data/{runtime/spec → core_spec}/opal/opal/defined_spec.rb +0 -0
  163. data/{runtime/spec → core_spec}/opal/opal/function_spec.rb +0 -0
  164. data/{runtime/spec → core_spec}/opal/opal/native_spec.rb +0 -0
  165. data/{runtime/spec → core_spec}/opal/opal/null_spec.rb +0 -0
  166. data/{runtime/spec → core_spec}/opal/opal/number_spec.rb +0 -0
  167. data/{runtime/spec → core_spec}/opal/opal/object_spec.rb +0 -0
  168. data/{runtime/spec → core_spec}/opal/opal/string_spec.rb +0 -0
  169. data/{runtime/spec → core_spec}/opal/opal/typeof_spec.rb +0 -0
  170. data/{runtime/spec → core_spec}/opal/opal/undefined_spec.rb +0 -0
  171. data/{runtime/spec → core_spec}/opal/true/case_compare_spec.rb +0 -0
  172. data/{runtime/spec → core_spec}/opal/true/class_spec.rb +0 -0
  173. data/{docs/spec_runner.html → core_spec/release_runner.html} +4 -3
  174. data/core_spec/runner.html +16 -0
  175. data/core_spec/spec_helper.rb +23 -0
  176. data/lib/opal.rb +85 -2
  177. data/lib/opal/builder.rb +129 -46
  178. data/lib/opal/context.rb +47 -26
  179. data/lib/opal/dependency_builder.rb +113 -14
  180. data/lib/opal/environment.rb +40 -45
  181. data/lib/opal/parser/grammar.rb +2296 -2254
  182. data/lib/opal/parser/grammar.y +27 -8
  183. data/lib/opal/parser/lexer.rb +12 -3
  184. data/lib/opal/parser/parser.rb +117 -30
  185. data/lib/opal/parser/scope.rb +2 -2
  186. data/lib/opal/version.rb +1 -1
  187. data/opal.gemspec +3 -8
  188. data/spec/grammar/masgn_spec.rb +37 -0
  189. metadata +177 -227
  190. data/index.html +0 -434
  191. data/lib/opal/command.rb +0 -73
  192. data/runtime/README.md +0 -25
  193. data/runtime/corelib/boolean.rb +0 -44
  194. data/runtime/corelib/class.rb +0 -43
  195. data/runtime/corelib/complex.rb +0 -2
  196. data/runtime/corelib/dir.rb +0 -29
  197. data/runtime/corelib/enumerable.rb +0 -316
  198. data/runtime/corelib/enumerator.rb +0 -80
  199. data/runtime/corelib/error.rb +0 -25
  200. data/runtime/corelib/module.rb +0 -171
  201. data/runtime/corelib/native.rb +0 -50
  202. data/runtime/corelib/object.rb +0 -21
  203. data/runtime/corelib/time.rb +0 -196
  204. data/runtime/gemlib/alpha.rb +0 -5
  205. data/runtime/gemlib/kernel.rb +0 -17
  206. data/runtime/gemlib/load_order +0 -2
  207. data/runtime/kernel/class.js +0 -256
  208. data/runtime/kernel/debug.js +0 -42
  209. data/runtime/kernel/init.js +0 -114
  210. data/runtime/kernel/load_order +0 -5
  211. data/runtime/kernel/loader.js +0 -151
  212. data/runtime/kernel/runtime.js +0 -414
  213. data/runtime/spec/language/variables_spec.rb +0 -28
  214. data/runtime/spec/library/stringscanner/scan_spec.rb +0 -36
  215. data/runtime/spec/opal/forwardable/def_instance_delegator_spec.rb +0 -49
  216. data/runtime/spec/spec_helper.rb +0 -25
  217. data/runtime/stdlib/base64.rb +0 -91
  218. data/runtime/stdlib/date.rb +0 -4
  219. data/runtime/stdlib/dev.rb +0 -171
  220. data/runtime/stdlib/forwardable.rb +0 -33
  221. data/runtime/stdlib/optparse.rb +0 -0
  222. data/runtime/stdlib/pp.rb +0 -6
  223. data/runtime/stdlib/racc/parser.rb +0 -159
  224. data/runtime/stdlib/rbconfig.rb +0 -0
  225. data/runtime/stdlib/si.rb +0 -17
  226. data/runtime/stdlib/strscan.rb +0 -53
  227. data/runtime/stdlib/uri.rb +0 -111
  228. data/runtime/stdlib/uri/common.rb +0 -1014
  229. data/runtime/stdlib/uri/ftp.rb +0 -261
  230. data/runtime/stdlib/uri/generic.rb +0 -1599
  231. data/runtime/stdlib/uri/http.rb +0 -106
  232. data/runtime/stdlib/uri/https.rb +0 -22
  233. data/runtime/stdlib/uri/ldap.rb +0 -260
  234. data/runtime/stdlib/uri/ldaps.rb +0 -20
  235. data/runtime/stdlib/uri/mailto.rb +0 -280
  236. data/spec/builder/output_path_spec.rb +0 -50
data/.gitignore CHANGED
@@ -9,5 +9,5 @@ Gemfile.lock
9
9
  pkg/*
10
10
  /runtime/*.js
11
11
  /*.js
12
- /docs/_site
12
+ /docs
13
13
  /gh-pages
data/Gemfile CHANGED
@@ -1,10 +1,16 @@
1
1
  source :rubygems
2
2
 
3
- # Specify your gem's dependencies in opal.gemspec
4
3
  gemspec
5
4
 
5
+ gem "racc"
6
6
  gem "rake"
7
+ gem "therubyracer"
7
8
 
8
- group :test do
9
+ group :opal do
9
10
  gem "opal-spec"
10
11
  end
12
+
13
+ #group :docs do
14
+ # gem "redcarpet", "1.2.0"
15
+ # gem "rocco"
16
+ #end
data/README.md CHANGED
@@ -12,6 +12,6 @@ the hood. The Opal gem includes the compiler used to convert ruby sources
12
12
  into javascript.
13
13
 
14
14
  For docs, visit the website:
15
- [http://adambeynon.github.com/opal](http://adambeynon.github.com/opal)
15
+ [http://opalrb.org](http://opalrb.org)
16
16
 
17
17
  Join the IRC channel on Freenode: `#opal`.
data/Rakefile CHANGED
@@ -1,43 +1,55 @@
1
- require 'bundler/setup'
2
- require 'bundler/gem_tasks'
3
- require 'opal'
4
1
  require 'fileutils'
5
- require 'opal/version'
2
+ require 'bundler'
3
+ Bundler.setup
6
4
 
7
- namespace :browser do
8
- desc "Build opal runtime to opal.js"
9
- task :opal do
10
- File.open("opal.js", 'w+') { |o| o.write build_runtime false }
11
- end
5
+ require 'opal'
12
6
 
13
- desc "Build opal debug runtime to opal.debug.js"
14
- task :debug do
15
- File.open("opal.debug.js", 'w+') { |o| o.write build_runtime true }
16
- end
7
+ begin
8
+ require 'rocco'
9
+ rescue LoadError
10
+ end
11
+
12
+ task :runtime do
13
+ FileUtils.rm_f 'opal.js'
14
+ code = Opal.runtime_code
15
+ File.open('opal.js', 'w+') { |o| o.write code }
16
+ end
17
+
18
+ task :debug_runtime do
19
+ FileUtils.rm_f 'opal.debug.js'
20
+ code = Opal.runtime_debug_code
21
+ File.open('opal.debug.js', 'w+') { |o| o.write code }
22
+ end
17
23
 
24
+ namespace :opal do
18
25
  desc "Tests for browser to opal.test.js"
19
26
  task :test do
20
- Opal::Builder.new('runtime/spec', :join => 'opal.test.js').build
27
+ sh "bundle exec bin/opal build core_spec"
21
28
  end
29
+ end
22
30
 
23
- desc "Build dependencies into runtime/"
24
- task :dependencies do
25
- Opal::DependencyBuilder.new(:out => 'runtime').build
26
- end
31
+ desc "Build dependencies into ."
32
+ task :dependencies do
33
+ sh "bundle exec bin/opal dependencies"
27
34
  end
28
35
 
29
- desc "Build opal and debug opal into runtime/"
30
- task :browser => [:'browser:opal', :'browser:debug']
36
+ desc "Build opal.js and opal.debug.js opal into ."
37
+ task :opal => %w(runtime debug_runtime)
38
+
39
+ desc "Run opal specs (from core_spec/*) in debug mode"
40
+ task :test => :opal do
41
+ Opal::Context.runner 'core_spec/**/*.rb'
42
+ end
31
43
 
32
- desc "Run opal specs (from runtime/spec/*)"
33
- task :test => :browser do
34
- Opal::Context.runner 'runtime/spec/**/*.rb'
44
+ desc "Run core_spec/ in release mode"
45
+ task :test_release => :opal do
46
+ Opal::Context.runner 'core_spec/**/*.rb', false
35
47
  end
36
48
 
37
49
  desc "Check file sizes for core builds"
38
50
  task :sizes do
39
- sizes 'runtime/opal.js'
40
- sizes 'runtime/opal.debug.js'
51
+ sizes 'opal.js'
52
+ sizes 'opal.debug.js'
41
53
  end
42
54
 
43
55
  desc "Rebuild grammar.rb for opal parser"
@@ -59,45 +71,27 @@ namespace :docs do
59
71
  end
60
72
 
61
73
  desc "Copy required files into gh-pages dir"
62
- task :copy => :browser do
74
+ task :copy => :opal do
63
75
  %w[opal.js opal.debug.js index.html].each do |f|
64
76
  FileUtils.cp f, "gh-pages/#{f}"
65
77
  end
66
78
  end
67
- end
68
79
 
69
- HEADER = <<-HEADER
70
- /*!
71
- * opal v#{Opal::VERSION}
72
- * http://adambeynon.github.com/opal
73
- *
74
- * Copyright 2012, Adam Beynon
75
- * Released under the MIT license
76
- */
77
- HEADER
78
-
79
- def build_runtime debug = false
80
- rborder = File.read('runtime/corelib/load_order').strip.split
81
- rbcore = rborder.map { |c| File.read "runtime/corelib/#{c}.rb" }
82
- jsorder = File.read('runtime/kernel/load_order').strip.split
83
- jscore = jsorder.map { |c| File.read "runtime/kernel/#{c}.js" }
84
-
85
- parser = Opal::Parser.new :debug => debug
86
- parsed = parser.parse rbcore.join("\n"), '(corelib)'
87
- methods = Opal::Parser::METHOD_NAMES.map { |f, t| "'#{f}': 'm$#{t}$'" }
88
- result = []
89
-
90
- result << '(function(undefined) {'
91
- result << jscore.join
92
- result << "var method_names = {#{methods.join ', '}};"
93
- result << "var reverse_method_names = {}; for (var id in method_names) {"
94
- result << "reverse_method_names[method_names[id]] = id;}"
95
- result << parsed
96
- result << '}).call(this);'
97
-
98
- HEADER + result.join("\n")
80
+ desc "rocco"
81
+ task :rocco do
82
+ FileUtils.mkdir_p 'docs'
83
+ %w[builder dependency_builder].each do |src|
84
+ path = "lib/opal/#{src}.rb"
85
+ out = "docs/#{src}.html"
86
+
87
+ File.open(out, 'w+') { |o| o.write Rocco.new(path).to_html }
88
+ end
89
+ end
99
90
  end
100
91
 
92
+ # Takes a file path, reads it and prints out the file size as it is, once
93
+ # minified and once minified + gzipped. Depends on uglifyjs being installed
94
+ # for node.js
101
95
  def sizes file
102
96
  o = File.read file
103
97
  m = uglify o
data/bin/opal CHANGED
@@ -1,6 +1,54 @@
1
1
  #! /usr/bin/env ruby
2
2
 
3
+ require 'optparse'
4
+ require 'fileutils'
3
5
  require 'opal'
4
- require 'opal/command'
5
6
 
6
- Opal::Command.new ARGV
7
+ # Parse command line options/files.
8
+ options = {}
9
+
10
+ case ARGV.first
11
+ when 'dependencies'
12
+ options[:dependencies] = true
13
+ ARGV.shift
14
+ when 'build'
15
+ options[:build] = true
16
+ ARGV.shift
17
+ end
18
+
19
+ OptionParser.new do |opts|
20
+ opts.on('-c', '--compile', 'Compile ruby') do |c|
21
+ options[:build] = true
22
+ end
23
+
24
+ opts.on('-o', '--out FILE', 'Output file') do |o|
25
+ options[:out] = o
26
+ end
27
+
28
+ opts.on('-d', '--debug', 'Debug mode') do |d|
29
+ options[:debug] = true
30
+ end
31
+
32
+ opts.on_tail("-v", "--version", "Show version") do
33
+ puts Opal::VERSION
34
+ exit
35
+ end
36
+ end.parse! rescue abort("See `opal --help' for usage information.")
37
+
38
+ if options[:dependencies]
39
+ options.delete :dependencies
40
+ Opal::DependencyBuilder.new(options).build
41
+
42
+ elsif options[:build]
43
+ options[:files] = ARGV.empty? ? ['lib'] : ARGV.dup
44
+ Opal::Builder.new(options).build
45
+
46
+ else
47
+ if ARGV.empty?
48
+ Opal::Context.new.start_repl
49
+ elsif File.exists? ARGV.first
50
+ Opal::Context.runner ARGV.first
51
+ else
52
+ abort "File does not exist: #{ARGV.first}"
53
+ end
54
+ end
@@ -1,10 +1,15 @@
1
1
  # load path getters
2
2
  $LOAD_PATH = $: = `LOADER_PATHS`
3
3
 
4
+ # loaded features
5
+ $LOADED_FEATURES = $" = `FEATURES`
6
+
4
7
  # regexp matches
5
8
  $~ = nil
6
9
 
10
+ $/ = "\n"
11
+
7
12
  RUBY_ENGINE = 'opal-browser'
8
13
  RUBY_PLATFORM = 'opal'
9
14
  RUBY_VERSION = '1.9.2'
10
- ARGV = []
15
+ ARGV = []
@@ -53,7 +53,7 @@ class Array
53
53
 
54
54
  def *(other)
55
55
  %x{
56
- if (#{Opal.string?(other)}) {
56
+ if (typeof(other) === 'string') {
57
57
  return this.join(other);
58
58
  }
59
59
 
@@ -195,7 +195,7 @@ class Array
195
195
  var result = [];
196
196
 
197
197
  for (var i = 0, length = this.length, value; i < length; i++) {
198
- if ((value = $yield.call($context, null, this[i])) === $breaker) {
198
+ if ((value = $yield.call($context, this[i])) === $breaker) {
199
199
  return $breaker.$v;
200
200
  }
201
201
 
@@ -211,7 +211,7 @@ class Array
211
211
 
212
212
  %x{
213
213
  for (var i = 0, length = this.length, val; i < length; i++) {
214
- if ((val = $yield.call($context, null, this[i])) === $breaker) {
214
+ if ((val = $yield.call($context, this[i])) === $breaker) {
215
215
  return $breaker.$v;
216
216
  }
217
217
 
@@ -321,7 +321,7 @@ class Array
321
321
 
322
322
  %x{
323
323
  for (var i = 0, length = this.length, value; i < length; i++) {
324
- if ((value = $yield.call($context, null, this[i])) === $breaker) {
324
+ if ((value = $yield.call($context, this[i])) === $breaker) {
325
325
  return $breaker.$v;
326
326
  }
327
327
 
@@ -338,7 +338,7 @@ class Array
338
338
  end
339
339
 
340
340
  def drop(number)
341
- `number > this.length ? [] : this.slice(number)`
341
+ `this.slice(number)`
342
342
  end
343
343
 
344
344
  def drop_while(&block)
@@ -346,7 +346,7 @@ class Array
346
346
 
347
347
  %x{
348
348
  for (var i = 0, length = this.length, value; i < length; i++) {
349
- if ((value = $yield.call($context, null, this[i])) === $breaker) {
349
+ if ((value = $yield.call($context, this[i])) === $breaker) {
350
350
  return $breaker.$v;
351
351
  }
352
352
 
@@ -364,7 +364,7 @@ class Array
364
364
 
365
365
  %x{
366
366
  for (var i = 0, length = this.length; i < length; i++) {
367
- if ($yield.call($context, null, this[i]) === $breaker) {
367
+ if ($yield.call($context, this[i]) === $breaker) {
368
368
  return $breaker.$v;
369
369
  }
370
370
  }
@@ -378,7 +378,7 @@ class Array
378
378
 
379
379
  %x{
380
380
  for (var i = 0, length = this.length; i < length; i++) {
381
- if ($yield.call($context, null, i) === $breaker) {
381
+ if ($yield.call($context, i) === $breaker) {
382
382
  return $breaker.$v;
383
383
  }
384
384
  }
@@ -392,7 +392,7 @@ class Array
392
392
 
393
393
  %x{
394
394
  for (var i = 0, length = this.length; i < length; i++) {
395
- if ($yield.call($context, null, this[i], i) === $breaker) {
395
+ if ($yield.call($context, this[i], i) === $breaker) {
396
396
  return $breaker.$v;
397
397
  }
398
398
  }
@@ -422,7 +422,7 @@ class Array
422
422
  }
423
423
 
424
424
  if (block !== nil) {
425
- return $yield.call($context, null, original);
425
+ return $yield.call($context, original);
426
426
  }
427
427
 
428
428
  raise(RubyIndexError, 'Array#fetch');
@@ -468,17 +468,10 @@ class Array
468
468
 
469
469
  def flatten!(level = undefined)
470
470
  %x{
471
- var flattenable = false;
472
-
473
- for (var i = 0, length = this.length; i < length; i++) {
474
- if (this[i].$flags & T_ARRAY) {
475
- flattenable = true;
476
-
477
- break;
478
- }
479
- }
471
+ var size = this.length;
472
+ #{replace flatten level};
480
473
 
481
- return flattenable ? #{replace flatten level} : nil;
474
+ return size === this.length ? nil : this;
482
475
  }
483
476
  end
484
477
 
@@ -520,7 +513,7 @@ class Array
520
513
  %x{
521
514
  if (block !== nil) {
522
515
  for (var i = 0, length = this.length, value; i < length; i++) {
523
- if ((value = $yield.call($context, null, this[i])) === $breaker) {
516
+ if ((value = $yield.call($context, this[i])) === $breaker) {
524
517
  return $breaker.$v;
525
518
  }
526
519
 
@@ -557,7 +550,7 @@ class Array
557
550
  }
558
551
 
559
552
  for (var length = this.length, value; i < length; i++) {
560
- if ((value = $yield.call($context, null, result, this[i])) === $breaker) {
553
+ if ((value = $yield.call($context, result, this[i])) === $breaker) {
561
554
  return $breaker.$v;
562
555
  }
563
556
 
@@ -619,7 +612,7 @@ class Array
619
612
  return enum_for :keep_if unless block_given?
620
613
  %x{
621
614
  for (var i = 0, length = this.length, value; i < length; i++) {
622
- if ((value = $yield.call($context, null, this[i])) === $breaker) {
615
+ if ((value = $yield.call($context, this[i])) === $breaker) {
623
616
  return $breaker.$v;
624
617
  }
625
618
 
@@ -658,9 +651,9 @@ class Array
658
651
  `this.length`
659
652
  end
660
653
 
661
- alias_method :map, :collect
654
+ alias map collect
662
655
 
663
- alias_method :map!, :collect!
656
+ alias map! collect!
664
657
 
665
658
  def pop(count = undefined)
666
659
  %x{
@@ -711,7 +704,7 @@ class Array
711
704
  var result = [];
712
705
 
713
706
  for (var i = 0, length = this.length, value; i < length; i++) {
714
- if ((value = $yield.call($context, null, this[i])) === $breaker) {
707
+ if ((value = $yield.call($context, this[i])) === $breaker) {
715
708
  return $breaker.$v;
716
709
  }
717
710
 
@@ -730,7 +723,7 @@ class Array
730
723
  var original = this.length;
731
724
 
732
725
  for (var i = 0, length = this.length, value; i < length; i++) {
733
- if ((value = $yield.call($context, null, this[i])) === $breaker) {
726
+ if ((value = $yield.call($context, this[i])) === $breaker) {
734
727
  return $breaker.$v;
735
728
  }
736
729
 
@@ -747,8 +740,11 @@ class Array
747
740
  end
748
741
 
749
742
  def replace(other)
750
- clear
751
- concat other
743
+ %x{
744
+ this.splice(0);
745
+ this.push.apply(this, other);
746
+ return this;
747
+ }
752
748
  end
753
749
 
754
750
  def reverse
@@ -756,7 +752,11 @@ class Array
756
752
  end
757
753
 
758
754
  def reverse!
759
- replace(reverse)
755
+ %x{
756
+ this.splice(0);
757
+ this.push.apply(this, #{reverse});
758
+ return this;
759
+ }
760
760
  end
761
761
 
762
762
  def reverse_each(&block)
@@ -773,7 +773,7 @@ class Array
773
773
  %x{
774
774
  if (block !== nil) {
775
775
  for (var i = this.length - 1, value; i >= 0; i--) {
776
- if ((value = $yield.call($context, null, this[i])) === $breaker) {
776
+ if ((value = $yield.call($context, this[i])) === $breaker) {
777
777
  return $breaker.$v;
778
778
  }
779
779
 
@@ -803,7 +803,7 @@ class Array
803
803
  for (var i = 0, length = this.length, item, value; i < length; i++) {
804
804
  item = this[i];
805
805
 
806
- if ((value = $yield.call($context, null, item)) === $breaker) {
806
+ if ((value = $yield.call($context, item)) === $breaker) {
807
807
  return $breaker.$v;
808
808
  }
809
809
 
@@ -824,7 +824,7 @@ class Array
824
824
  for (var i = 0, length = original, item, value; i < length; i++) {
825
825
  item = this[i];
826
826
 
827
- if ((value = $yield.call($context, null, item)) === $breaker) {
827
+ if ((value = $yield.call($context, item)) === $breaker) {
828
828
  return $breaker.$v;
829
829
  }
830
830
 
@@ -844,9 +844,9 @@ class Array
844
844
  `count === undefined ? this.shift() : this.splice(0, count)`
845
845
  end
846
846
 
847
- alias_method :size, :length
847
+ alias size length
848
848
 
849
- alias_method :slice, :[]
849
+ alias slice :[]
850
850
 
851
851
  def slice!(index, length = undefined)
852
852
  %x{
@@ -879,7 +879,7 @@ class Array
879
879
  for (var i = 0, length = this.length, item, value; i < length; i++) {
880
880
  item = this[i];
881
881
 
882
- if ((value = $yield.call($context, null, item)) === $breaker) {
882
+ if ((value = $yield.call($context, item)) === $breaker) {
883
883
  return $breaker.$v;
884
884
  }
885
885
 
@@ -898,13 +898,9 @@ class Array
898
898
  self
899
899
  end
900
900
 
901
- alias_method :to_ary, :to_a
902
-
903
- def to_native
904
- map { |obj| Opal.object?(obj) ? obj.to_native : obj }
905
- end
901
+ alias to_ary to_a
906
902
 
907
- alias_method :to_s, :inspect
903
+ alias to_s inspect
908
904
 
909
905
  def uniq
910
906
  %x{