opal 0.3.16 → 0.3.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (251) hide show
  1. data/.gitignore +2 -0
  2. data/CHANGELOG.md +12 -0
  3. data/Gemfile +8 -7
  4. data/README.md +21 -13
  5. data/Rakefile +64 -78
  6. data/bin/opal +18 -29
  7. data/core/alpha.rb +2 -9
  8. data/core/array.rb +106 -50
  9. data/core/basic_object.rb +10 -8
  10. data/core/boolean.rb +2 -0
  11. data/core/class.rb +25 -13
  12. data/core/comparable.rb +6 -6
  13. data/core/enumerable.rb +90 -94
  14. data/core/enumerator.rb +3 -3
  15. data/core/hash.rb +86 -46
  16. data/core/kernel.rb +55 -39
  17. data/core/load_order +2 -5
  18. data/core/match_data.rb +1 -1
  19. data/core/module.rb +45 -20
  20. data/core/nil_class.rb +6 -2
  21. data/core/numeric.rb +20 -10
  22. data/core/proc.rb +2 -2
  23. data/core/range.rb +72 -13
  24. data/core/regexp.rb +5 -3
  25. data/core/runtime.js +228 -287
  26. data/core/string.rb +345 -37
  27. data/core/top_self.rb +1 -1
  28. data/lib/opal.rb +13 -91
  29. data/lib/opal/builder.rb +47 -120
  30. data/lib/opal/builder_task.rb +74 -0
  31. data/lib/opal/{parser/grammar.rb → grammar.rb} +1094 -1083
  32. data/lib/opal/{parser/grammar.y → grammar.y} +7 -0
  33. data/lib/opal/{parser/lexer.rb → lexer.rb} +32 -11
  34. data/lib/opal/{parser/parser.rb → parser.rb} +232 -238
  35. data/lib/opal/{parser/scope.rb → scope.rb} +72 -9
  36. data/lib/opal/version.rb +2 -3
  37. data/opal.gemspec +1 -2
  38. data/{core_spec → spec}/core/array/allocate_spec.rb +1 -3
  39. data/{core_spec → spec}/core/array/append_spec.rb +1 -4
  40. data/{core_spec → spec}/core/array/assoc_spec.rb +1 -4
  41. data/{core_spec → spec}/core/array/at_spec.rb +1 -3
  42. data/{core_spec → spec}/core/array/clear_spec.rb +1 -3
  43. data/spec/core/array/clone_spec.rb +15 -0
  44. data/{core_spec/core/array/shared/collect.rb → spec/core/array/collect_spec.rb} +1 -1
  45. data/{core_spec → spec}/core/array/compact_spec.rb +1 -3
  46. data/{core_spec → spec}/core/array/concat_spec.rb +1 -3
  47. data/{core_spec → spec}/core/array/constructor_spec.rb +9 -3
  48. data/{core_spec → spec}/core/array/count_spec.rb +1 -3
  49. data/{core_spec → spec}/core/array/delete_at_spec.rb +1 -4
  50. data/{core_spec → spec}/core/array/delete_if_spec.rb +1 -4
  51. data/{core_spec → spec}/core/array/delete_spec.rb +1 -4
  52. data/{core_spec → spec}/core/array/each_index_spec.rb +1 -4
  53. data/{core_spec → spec}/core/array/each_spec.rb +1 -4
  54. data/{core_spec → spec}/core/array/element_reference_spec.rb +74 -4
  55. data/{core_spec → spec}/core/array/empty_spec.rb +1 -4
  56. data/{core_spec/core/array/shared/eql.rb → spec/core/array/eql_spec.rb} +1 -1
  57. data/{core_spec → spec}/core/array/fetch_spec.rb +1 -4
  58. data/{core_spec → spec}/core/array/first_spec.rb +1 -3
  59. data/{core_spec → spec}/core/array/flatten_spec.rb +1 -3
  60. data/{core_spec → spec}/core/array/include_spec.rb +1 -3
  61. data/{core_spec → spec}/core/array/insert_spec.rb +1 -4
  62. data/{core_spec → spec}/core/array/last_spec.rb +1 -4
  63. data/{core_spec/core/array/shared/length.rb → spec/core/array/length_spec.rb} +1 -1
  64. data/spec/core/array/map_spec.rb +53 -0
  65. data/{core_spec → spec}/core/array/plus_spec.rb +1 -4
  66. data/{core_spec → spec}/core/array/pop_spec.rb +1 -4
  67. data/{core_spec → spec}/core/array/push_spec.rb +1 -4
  68. data/{core_spec → spec}/core/array/rassoc_spec.rb +1 -4
  69. data/{core_spec → spec}/core/array/reject_spec.rb +1 -4
  70. data/{core_spec/core/array/shared/replace.rb → spec/core/array/replace_spec.rb} +1 -1
  71. data/{core_spec → spec}/core/array/reverse_each_spec.rb +1 -4
  72. data/{core_spec → spec}/core/array/reverse_spec.rb +1 -4
  73. data/spec/core/array/size_spec.rb +6 -0
  74. data/spec/core/array/to_ary_spec.rb +6 -0
  75. data/spec/core/array/uniq_spec.rb +22 -0
  76. data/spec/core/array/zip_spec.rb +20 -0
  77. data/{core_spec → spec}/core/class/new_spec.rb +1 -4
  78. data/{core_spec → spec}/core/enumerable/all_spec.rb +1 -4
  79. data/{core_spec → spec}/core/enumerable/any_spec.rb +1 -4
  80. data/{core_spec/core/enumerable/shared/collect.rb → spec/core/enumerable/collect_spec.rb} +1 -1
  81. data/{core_spec → spec}/core/enumerable/count_spec.rb +2 -5
  82. data/{core_spec → spec}/core/enumerable/fixtures/classes.rb +1 -2
  83. data/{core_spec → spec}/core/false/and_spec.rb +1 -3
  84. data/{core_spec → spec}/core/false/inspect_spec.rb +1 -3
  85. data/{core_spec → spec}/core/false/or_spec.rb +1 -3
  86. data/{core_spec → spec}/core/false/to_s_spec.rb +1 -3
  87. data/{core_spec → spec}/core/false/xor_spec.rb +1 -3
  88. data/{core_spec → spec}/core/hash/allocate_spec.rb +1 -3
  89. data/spec/core/hash/assoc_spec.rb +25 -0
  90. data/{core_spec → spec}/core/hash/clear_spec.rb +1 -3
  91. data/{core_spec → spec}/core/hash/clone_spec.rb +1 -3
  92. data/{core_spec → spec}/core/hash/default_spec.rb +1 -3
  93. data/{core_spec → spec}/core/hash/delete_if_spec.rb +1 -3
  94. data/{core_spec → spec}/core/hash/element_reference_spec.rb +1 -3
  95. data/{core_spec → spec}/core/hash/element_set_spec.rb +1 -3
  96. data/spec/core/hash/merge_spec.rb +37 -0
  97. data/{core_spec → spec}/core/hash/new_spec.rb +1 -3
  98. data/{core_spec → spec}/core/matchdata/to_a_spec.rb +1 -3
  99. data/{core_spec → spec}/core/nil/and_spec.rb +1 -4
  100. data/{core_spec → spec}/core/nil/inspect_spec.rb +1 -4
  101. data/{core_spec → spec}/core/nil/nil_spec.rb +1 -4
  102. data/{core_spec → spec}/core/nil/or_spec.rb +1 -4
  103. data/{core_spec → spec}/core/nil/to_a_spec.rb +1 -4
  104. data/{core_spec → spec}/core/nil/to_f_spec.rb +1 -4
  105. data/{core_spec → spec}/core/nil/to_i_spec.rb +1 -4
  106. data/{core_spec → spec}/core/nil/to_s_spec.rb +1 -4
  107. data/{core_spec → spec}/core/nil/xor_spec.rb +1 -4
  108. data/{core_spec → spec}/core/numeric/equal_value_spec.rb +1 -3
  109. data/{core_spec → spec}/core/regexp/match_spec.rb +10 -3
  110. data/{core_spec → spec}/core/symbol/to_proc_spec.rb +1 -3
  111. data/{core_spec → spec}/core/true/and_spec.rb +1 -3
  112. data/{core_spec → spec}/core/true/inspect_spec.rb +1 -3
  113. data/{core_spec → spec}/core/true/or_spec.rb +1 -3
  114. data/{core_spec → spec}/core/true/to_s_spec.rb +1 -3
  115. data/{core_spec → spec}/core/true/xor_spec.rb +1 -3
  116. data/spec/index.html +11 -0
  117. data/{core_spec → spec}/language/alias_spec.rb +1 -3
  118. data/{core_spec → spec}/language/and_spec.rb +1 -4
  119. data/{core_spec → spec}/language/array_spec.rb +1 -4
  120. data/{core_spec → spec}/language/block_spec.rb +20 -3
  121. data/{core_spec → spec}/language/break_spec.rb +40 -3
  122. data/{core_spec → spec}/language/case_spec.rb +1 -4
  123. data/{core_spec → spec}/language/defined_spec.rb +9 -3
  124. data/{core_spec → spec}/language/ensure_spec.rb +38 -3
  125. data/{core_spec → spec}/language/hash_spec.rb +1 -3
  126. data/{core_spec → spec}/language/if_spec.rb +1 -4
  127. data/{core_spec → spec}/language/loop_spec.rb +1 -3
  128. data/spec/language/metaclass_spec.rb +13 -0
  129. data/{core_spec → spec}/language/next_spec.rb +47 -3
  130. data/{core_spec → spec}/language/or_spec.rb +1 -4
  131. data/{core_spec → spec}/language/predefined_spec.rb +1 -3
  132. data/{core_spec/language/regexp/interpolation_spec.rb → spec/language/regexp_spec.rb} +6 -3
  133. data/{core_spec → spec}/language/send_spec.rb +38 -4
  134. data/spec/language/singleton_class_spec.rb +31 -0
  135. data/spec/language/super_spec.rb +188 -0
  136. data/{core_spec → spec}/language/symbol_spec.rb +1 -3
  137. data/{core_spec → spec}/language/undef_spec.rb +1 -3
  138. data/{core_spec → spec}/language/unless_spec.rb +1 -4
  139. data/{core_spec → spec}/language/until_spec.rb +1 -3
  140. data/{core_spec → spec}/language/variables_spec.rb +1 -3
  141. data/{core_spec → spec}/language/while_spec.rb +1 -3
  142. data/{spec → test}/builder/build_source_spec.rb +0 -0
  143. data/{spec → test}/builder/fixtures/build_source/adam.rb +0 -0
  144. data/{spec → test}/builder/fixtures/build_source/bar/a.rb +0 -0
  145. data/{spec → test}/builder/fixtures/build_source/bar/wow/b.rb +0 -0
  146. data/{spec → test}/builder/fixtures/build_source/bar/wow/cow/c.rb +0 -0
  147. data/{spec → test}/builder/fixtures/build_source/beynon.rb +0 -0
  148. data/{spec → test}/builder/fixtures/build_source/charles.js +0 -0
  149. data/{spec → test}/builder/fixtures/build_source/foo/a.rb +0 -0
  150. data/{spec → test}/builder/fixtures/build_source/foo/b.rb +0 -0
  151. data/{spec → test}/builder/fixtures/build_source/foo/x.js +0 -0
  152. data/{spec → test}/builder/fixtures/build_source/foo/y.js +0 -0
  153. data/{spec → test}/grammar/alias_spec.rb +0 -0
  154. data/{spec → test}/grammar/and_spec.rb +0 -0
  155. data/{spec → test}/grammar/array_spec.rb +0 -0
  156. data/{spec → test}/grammar/attrasgn_spec.rb +0 -0
  157. data/{spec → test}/grammar/begin_spec.rb +0 -0
  158. data/{spec → test}/grammar/block_spec.rb +0 -0
  159. data/{spec → test}/grammar/break_spec.rb +0 -0
  160. data/{spec → test}/grammar/call_spec.rb +0 -0
  161. data/{spec → test}/grammar/class_spec.rb +0 -0
  162. data/{spec → test}/grammar/const_spec.rb +0 -0
  163. data/{spec → test}/grammar/cvar_spec.rb +0 -0
  164. data/{spec → test}/grammar/def_spec.rb +0 -0
  165. data/{spec → test}/grammar/false_spec.rb +0 -0
  166. data/{spec → test}/grammar/file_spec.rb +0 -0
  167. data/{spec → test}/grammar/gvar_spec.rb +0 -0
  168. data/{spec → test}/grammar/hash_spec.rb +0 -0
  169. data/{spec → test}/grammar/iasgn_spec.rb +0 -0
  170. data/{spec → test}/grammar/if_spec.rb +0 -0
  171. data/{spec → test}/grammar/iter_spec.rb +0 -0
  172. data/{spec → test}/grammar/ivar_spec.rb +0 -0
  173. data/{spec → test}/grammar/lasgn_spec.rb +0 -0
  174. data/{spec → test}/grammar/line_spec.rb +0 -0
  175. data/{spec → test}/grammar/lvar_spec.rb +0 -0
  176. data/{spec → test}/grammar/masgn_spec.rb +0 -0
  177. data/{spec → test}/grammar/module_spec.rb +0 -0
  178. data/{spec → test}/grammar/nil_spec.rb +0 -0
  179. data/{spec → test}/grammar/not_spec.rb +0 -0
  180. data/{spec → test}/grammar/op_asgn1_spec.rb +0 -0
  181. data/{spec → test}/grammar/op_asgn2_spec.rb +0 -0
  182. data/{spec → test}/grammar/or_spec.rb +0 -0
  183. data/{spec → test}/grammar/return_spec.rb +0 -0
  184. data/{spec → test}/grammar/sclass_spec.rb +0 -0
  185. data/{spec → test}/grammar/self_spec.rb +0 -0
  186. data/{spec → test}/grammar/str_spec.rb +0 -0
  187. data/{spec → test}/grammar/super_spec.rb +0 -0
  188. data/{spec → test}/grammar/true_spec.rb +0 -0
  189. data/{spec → test}/grammar/undef_spec.rb +0 -0
  190. data/{spec → test}/grammar/unless_spec.rb +0 -0
  191. data/{spec → test}/grammar/while_spec.rb +0 -0
  192. data/{spec → test}/grammar/xstr_spec.rb +0 -0
  193. data/{spec → test}/grammar/yield_spec.rb +0 -0
  194. data/{spec → test}/spec_helper.rb +0 -0
  195. metadata +330 -264
  196. data/core/debug.js +0 -59
  197. data/core/debug.rb +0 -35
  198. data/core/dir.rb +0 -90
  199. data/core/file.rb +0 -83
  200. data/core/gemlib.rb +0 -30
  201. data/core/io.rb +0 -44
  202. data/core_spec/README.md +0 -34
  203. data/core_spec/core/array/collect_spec.rb +0 -3
  204. data/core_spec/core/array/element_set_spec.rb +0 -7
  205. data/core_spec/core/array/eql_spec.rb +0 -3
  206. data/core_spec/core/array/equal_value_spec.rb +0 -3
  207. data/core_spec/core/array/fixtures/classes.rb +0 -8
  208. data/core_spec/core/array/length_spec.rb +0 -3
  209. data/core_spec/core/array/map_spec.rb +0 -3
  210. data/core_spec/core/array/replace_spec.rb +0 -3
  211. data/core_spec/core/enumerable/collect_spec.rb +0 -3
  212. data/core_spec/core/enumerable/detect_spec.rb +0 -3
  213. data/core_spec/core/enumerable/find_spec.rb +0 -3
  214. data/core_spec/core/enumerable/first_spec.rb +0 -3
  215. data/core_spec/core/enumerable/shared/entries.rb +0 -7
  216. data/core_spec/core/enumerable/shared/find.rb +0 -49
  217. data/core_spec/core/enumerable/shared/take.rb +0 -31
  218. data/core_spec/core/enumerable/to_a_spec.rb +0 -7
  219. data/core_spec/core/hash/assoc_spec.rb +0 -29
  220. data/core_spec/core/object/is_a_spec.rb +0 -2
  221. data/core_spec/core/object/shared/kind_of.rb +0 -0
  222. data/core_spec/core/regexp/shared/match.rb +0 -11
  223. data/core_spec/language/fixtures/block.rb +0 -19
  224. data/core_spec/language/fixtures/break.rb +0 -39
  225. data/core_spec/language/fixtures/defined.rb +0 -9
  226. data/core_spec/language/fixtures/ensure.rb +0 -37
  227. data/core_spec/language/fixtures/next.rb +0 -46
  228. data/core_spec/language/fixtures/send.rb +0 -36
  229. data/core_spec/language/fixtures/super.rb +0 -43
  230. data/core_spec/language/regexp_spec.rb +0 -7
  231. data/core_spec/language/string_spec.rb +0 -4
  232. data/core_spec/language/super_spec.rb +0 -18
  233. data/core_spec/language/versions/hash_1.9.rb +0 -20
  234. data/core_spec/opal/opal/defined_spec.rb +0 -15
  235. data/core_spec/opal/opal/function_spec.rb +0 -11
  236. data/core_spec/opal/opal/native_spec.rb +0 -16
  237. data/core_spec/opal/opal/null_spec.rb +0 -10
  238. data/core_spec/opal/opal/number_spec.rb +0 -11
  239. data/core_spec/opal/opal/object_spec.rb +0 -16
  240. data/core_spec/opal/opal/string_spec.rb +0 -11
  241. data/core_spec/opal/opal/typeof_spec.rb +0 -9
  242. data/core_spec/opal/opal/undefined_spec.rb +0 -10
  243. data/core_spec/opal/true/case_compare_spec.rb +0 -12
  244. data/core_spec/opal/true/class_spec.rb +0 -10
  245. data/core_spec/release_runner.html +0 -17
  246. data/core_spec/runner.html +0 -16
  247. data/core_spec/spec_helper.rb +0 -23
  248. data/lib/opal/context.rb +0 -269
  249. data/lib/opal/dependency_builder.rb +0 -133
  250. data/lib/opal/environment.rb +0 -87
  251. data/lib/opal/parser/sexp.rb +0 -17
data/.gitignore CHANGED
@@ -11,3 +11,5 @@ pkg/*
11
11
  /*.js
12
12
  /docs
13
13
  /gh-pages
14
+ /examples/**/*.js
15
+ /build
data/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ ## Change Log
2
+
3
+ ### Edge
4
+
5
+ * Added HEREDOCS support in parser
6
+ * Parser now handles masgn (mass/multi assignments)
7
+ * More useful DependencyBuilder class to build gems dependencies
8
+ * Blocks no longer passed as an argument in method calls
9
+
10
+ ### 0.3.15
11
+
12
+ Initial Release.
data/Gemfile CHANGED
@@ -2,15 +2,16 @@ source :rubygems
2
2
 
3
3
  gemspec
4
4
 
5
- gem "racc"
6
5
  gem "rake"
7
- gem "therubyracer"
6
+ # gem "racc"
8
7
 
9
- group :opal do
8
+ group :browser do
9
+ gem "opal-racc"
10
10
  gem "opal-spec"
11
+ gem "opal-strscan"
11
12
  end
12
13
 
13
- #group :docs do
14
- # gem "redcarpet", "1.2.0"
15
- # gem "rocco"
16
- #end
14
+ group :documentation do
15
+ gem "redcarpet"
16
+ gem "albino"
17
+ end
data/README.md CHANGED
@@ -1,17 +1,25 @@
1
- Opal
2
- ====
1
+ # Opal
3
2
 
4
- Opal is a ruby to javascript compiler. Opal aims to take ruby files and generate
5
- efficient javascript that maintains rubys features. Opal will, by default,
6
- generate fast and efficient code in preference to keeping all ruby features.
3
+ Opal is a ruby to javascript compiler and runtime for the browser.
7
4
 
8
- Opal comes with an implementation of the ruby corelib, written in ruby, that
9
- uses a bundled runtime (written in javascript) that tie all the features
10
- together. Whenever possible Opal bridges to native javascript features under
11
- the hood. The Opal gem includes the compiler used to convert ruby sources
12
- into javascript.
5
+ For docs, visit the website [http://opalrb.org](http://opalrb.org), or visit the [github wiki](http://github.com/adambeynon/opal/wiki).
13
6
 
14
- For docs, visit the website:
15
- [http://opalrb.org](http://opalrb.org)
7
+ There is also a [Google group for opal](https://groups.google.com/forum/#!forum/opalrb), or join the IRC channel on Freenode: `#opal`.
16
8
 
17
- Join the IRC channel on Freenode: `#opal`.
9
+ ## Installation And Usage
10
+
11
+ Install via rubygems:
12
+
13
+ gem install opal
14
+
15
+ Or using Bundler:
16
+
17
+ gem "opal"
18
+
19
+ Ruby scripts can be compiled using:
20
+
21
+ opal -c foo.rb -o foo.js
22
+
23
+ ## License
24
+
25
+ Opal is released under the MIT license.
data/Rakefile CHANGED
@@ -3,60 +3,68 @@ require 'bundler'
3
3
  Bundler.setup
4
4
 
5
5
  require 'opal'
6
+ require 'opal/version'
6
7
 
7
- begin
8
- require 'rocco'
9
- rescue LoadError
8
+ desc "Build opal.js runtime into ./build"
9
+ task :opal do
10
+ File.open('build/opal.js', 'w+') do |o|
11
+ o.write Opal::Builder.runtime
12
+ end
10
13
  end
11
14
 
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 }
15
+ Opal::BuilderTask.new do |t|
16
+ t.name = 'opal'
17
+ t.files = []
18
+ t.dependencies = %w[opal-spec opal-racc opal-strscan]
16
19
  end
17
20
 
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
21
+ desc "Check file sizes for opal.js runtime"
22
+ task :sizes do
23
+ o = File.read 'build/opal.js'
24
+ m = uglify o
25
+ g = gzip m
23
26
 
24
- namespace :opal do
25
- desc "Tests for browser to opal.test.js"
26
- task :test do
27
- sh "bundle exec bin/opal build core_spec"
28
- end
27
+ puts "#{opal.js}:"
28
+ puts "development: #{o.size}, minified: #{m.size}, gzipped: #{g.size}"
29
29
  end
30
30
 
31
- desc "Build dependencies into ."
32
- task :dependencies do
33
- sh "bundle exec bin/opal dependencies"
31
+ desc "Rebuild grammar.rb for opal parser"
32
+ task :racc do
33
+ %x(racc -l lib/opal/grammar.y -o lib/opal/grammar.rb)
34
34
  end
35
35
 
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'
36
+ # Used for uglifying source to minify
37
+ def uglify(str)
38
+ IO.popen('uglifyjs -nc', 'r+') do |i|
39
+ i.puts str
40
+ i.close_write
41
+ return i.read
42
+ end
42
43
  end
43
44
 
44
- desc "Run core_spec/ in release mode"
45
- task :test_release => :opal do
46
- Opal::Context.runner 'core_spec/**/*.rb', false
45
+ # Gzip code to check file size
46
+ def gzip(str)
47
+ IO.popen('gzip -f', 'r+') do |i|
48
+ i.puts str
49
+ i.close_write
50
+ return i.read
51
+ end
47
52
  end
48
53
 
49
- desc "Check file sizes for core builds"
50
- task :sizes do
51
- sizes 'opal.js'
52
- sizes 'opal.debug.js'
53
- end
54
+ # Rubygems
55
+ namespace :gem do
56
+ desc "Build opal-#{Opal::VERSION}.gem"
57
+ task :build do
58
+ sh "gem build opal.gemspec"
59
+ end
54
60
 
55
- desc "Rebuild grammar.rb for opal parser"
56
- task :parser do
57
- %x(racc -l lib/opal/parser/grammar.y -o lib/opal/parser/grammar.rb)
61
+ desc "Release opal-#{Opal::VERSION}.gem"
62
+ task :release do
63
+ puts "Need to release opal-#{Opal::VERSION}.gem"
64
+ end
58
65
  end
59
66
 
67
+ # Documentation
60
68
  namespace :docs do
61
69
  task :clone do
62
70
  if File.exists? 'gh-pages'
@@ -70,51 +78,29 @@ namespace :docs do
70
78
  end
71
79
  end
72
80
 
73
- desc "Copy required files into gh-pages dir"
74
- task :copy => :opal do
75
- %w[opal.js opal.debug.js index.html].each do |f|
76
- FileUtils.cp f, "gh-pages/#{f}"
77
- end
78
- end
79
-
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"
81
+ task :index do
82
+ require 'redcarpet'
83
+ require 'albino'
86
84
 
87
- File.open(out, 'w+') { |o| o.write Rocco.new(path).to_html }
85
+ klass = Class.new(Redcarpet::Render::HTML) do
86
+ def block_code(code, language)
87
+ Albino.new(code, language || :text).colorize
88
+ end
88
89
  end
89
- end
90
- end
91
90
 
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
95
- def sizes file
96
- o = File.read file
97
- m = uglify o
98
- g = gzip m
91
+ markdown = Redcarpet::Markdown.new(klass, :fenced_code_blocks => true)
99
92
 
100
- puts "#{file}:"
101
- puts "development: #{o.size}, minified: #{m.size}, gzipped: #{g.size}"
102
- end
103
-
104
- # Used for uglifying source to minify
105
- def uglify(str)
106
- IO.popen('uglifyjs -nc', 'r+') do |i|
107
- i.puts str
108
- i.close_write
109
- return i.read
93
+ File.open('gh-pages/index.html', 'w+') do |o|
94
+ o.write File.read('docs/pre.html')
95
+ o.write markdown.render(File.read 'docs/index.md')
96
+ o.write markdown.render(File.read 'CHANGELOG.md')
97
+ o.write File.read('docs/post.html')
98
+ end
110
99
  end
111
- end
112
100
 
113
- # Gzip code to check file size
114
- def gzip(str)
115
- IO.popen('gzip -f', 'r+') do |i|
116
- i.puts str
117
- i.close_write
118
- return i.read
101
+ task :copy do
102
+ FileUtils.cp 'build/opal.js', 'gh-pages/opal.js'
103
+ FileUtils.cp 'docs/styles.css', 'gh-pages/styles.css'
104
+ FileUtils.cp 'docs/syntax.css', 'gh-pages/syntax.css'
119
105
  end
120
- end
106
+ end
data/bin/opal CHANGED
@@ -1,32 +1,21 @@
1
1
  #! /usr/bin/env ruby
2
2
 
3
3
  require 'optparse'
4
- require 'fileutils'
5
4
  require 'opal'
6
5
 
7
- # Parse command line options/files.
8
6
  options = {}
9
7
 
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
8
  OptionParser.new do |opts|
20
- opts.on('-c', '--compile', 'Compile ruby') do |c|
21
- options[:build] = true
9
+ opts.on('-c', '--compile', 'Compile ruby') do
10
+ options[:compile] = true
22
11
  end
23
12
 
24
13
  opts.on('-o', '--out FILE', 'Output file') do |o|
25
14
  options[:out] = o
26
15
  end
27
16
 
28
- opts.on('-d', '--debug', 'Debug mode') do |d|
29
- options[:debug] = true
17
+ opts.on('-p', '--print', 'Print result') do
18
+ options[:print] = true
30
19
  end
31
20
 
32
21
  opts.on_tail("-v", "--version", "Show version") do
@@ -35,20 +24,20 @@ OptionParser.new do |opts|
35
24
  end
36
25
  end.parse! rescue abort("See `opal --help' for usage information.")
37
26
 
38
- if options[:dependencies]
39
- options.delete :dependencies
40
- Opal::DependencyBuilder.new(options).build
27
+ if options[:compile]
28
+ puts "No sources given" if ARGV.empty?
41
29
 
42
- elsif options[:build]
43
- options[:files] = ARGV.empty? ? ['lib'] : ARGV.dup
44
- Opal::Builder.new(options).build
30
+ ARGV.each do |s|
31
+ puts "need to compile #{s}"
32
+ end
45
33
 
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}"
34
+ elsif options[:print]
35
+ puts "No sources given" if ARGV.empty?
36
+
37
+ ARGV.each do |s|
38
+ puts Opal.parse s
53
39
  end
54
- end
40
+
41
+ else
42
+ puts "No sources given"
43
+ end
data/core/alpha.rb CHANGED
@@ -1,15 +1,8 @@
1
- # load path getters
2
- $LOAD_PATH = $: = `LOADER_PATHS`
3
-
4
- # loaded features
5
- $LOADED_FEATURES = $" = `FEATURES`
6
-
7
1
  # regexp matches
8
2
  $~ = nil
9
3
 
10
4
  $/ = "\n"
11
5
 
12
- RUBY_ENGINE = 'opal-browser'
6
+ RUBY_ENGINE = 'opal'
13
7
  RUBY_PLATFORM = 'opal'
14
- RUBY_VERSION = '1.9.2'
15
- ARGV = []
8
+ RUBY_VERSION = '1.9.2'
data/core/array.rb CHANGED
@@ -13,8 +13,8 @@ class Array
13
13
 
14
14
  def self.allocate
15
15
  %x{
16
- var array = [];
17
- array.$klass = this;
16
+ var array = [];
17
+ array._klass = this;
18
18
 
19
19
  return array;
20
20
  }
@@ -99,7 +99,7 @@ class Array
99
99
 
100
100
  def ==(other)
101
101
  %x{
102
- if (this.length !== other.length) {
102
+ if (!other || (this.length !== other.length)) {
103
103
  return false;
104
104
  }
105
105
 
@@ -118,6 +118,28 @@ class Array
118
118
  %x{
119
119
  var size = this.length;
120
120
 
121
+ if (typeof index !== 'number') {
122
+ if (index._flags & T_RANGE) {
123
+ var exclude = index.exclude;
124
+ length = index.end;
125
+ index = index.begin;
126
+
127
+ if (index > size) {
128
+ return nil;
129
+ }
130
+
131
+ if (length < 0) {
132
+ length += size;
133
+ }
134
+
135
+ if (!exclude) length += 1;
136
+ return this.slice(index, length);
137
+ }
138
+ else {
139
+ throw RubyException.$new('bad arg for Array#[]');
140
+ }
141
+ }
142
+
121
143
  if (index < 0) {
122
144
  index += size;
123
145
  }
@@ -185,7 +207,7 @@ class Array
185
207
  end
186
208
 
187
209
  def clone
188
- `this.slice(0)`
210
+ `this.slice()`
189
211
  end
190
212
 
191
213
  def collect(&block)
@@ -195,8 +217,8 @@ class Array
195
217
  var result = [];
196
218
 
197
219
  for (var i = 0, length = this.length, value; i < length; i++) {
198
- if ((value = $yield.call($context, this[i])) === $breaker) {
199
- return $breaker.$v;
220
+ if ((value = block.call(__context, this[i])) === __breaker) {
221
+ return __breaker.$v;
200
222
  }
201
223
 
202
224
  result.push(value);
@@ -211,8 +233,8 @@ class Array
211
233
 
212
234
  %x{
213
235
  for (var i = 0, length = this.length, val; i < length; i++) {
214
- if ((val = $yield.call($context, this[i])) === $breaker) {
215
- return $breaker.$v;
236
+ if ((val = block.call(__context, this[i])) === __breaker) {
237
+ return __breaker.$v;
216
238
  }
217
239
 
218
240
  this[i] = val;
@@ -321,8 +343,8 @@ class Array
321
343
 
322
344
  %x{
323
345
  for (var i = 0, length = this.length, value; i < length; i++) {
324
- if ((value = $yield.call($context, this[i])) === $breaker) {
325
- return $breaker.$v;
346
+ if ((value = block.call(__context, this[i])) === __breaker) {
347
+ return __breaker.$v;
326
348
  }
327
349
 
328
350
  if (value !== false && value !== nil) {
@@ -346,7 +368,7 @@ class Array
346
368
 
347
369
  %x{
348
370
  for (var i = 0, length = this.length, value; i < length; i++) {
349
- if ((value = $yield.call($context, this[i])) === $breaker) {
371
+ if ((value = block.call(__context, this[i])) === $breaker) {
350
372
  return $breaker.$v;
351
373
  }
352
374
 
@@ -359,13 +381,15 @@ class Array
359
381
  }
360
382
  end
361
383
 
384
+ alias dup clone
385
+
362
386
  def each(&block)
363
387
  return enum_for :each unless block_given?
364
388
 
365
389
  %x{
366
390
  for (var i = 0, length = this.length; i < length; i++) {
367
- if ($yield.call($context, this[i]) === $breaker) {
368
- return $breaker.$v;
391
+ if (block.call(__context, this[i]) === __breaker) {
392
+ return __breaker.$v;
369
393
  }
370
394
  }
371
395
  }
@@ -378,8 +402,8 @@ class Array
378
402
 
379
403
  %x{
380
404
  for (var i = 0, length = this.length; i < length; i++) {
381
- if ($yield.call($context, i) === $breaker) {
382
- return $breaker.$v;
405
+ if (block.call(__context, i) === __breaker) {
406
+ return __breaker.$v;
383
407
  }
384
408
  }
385
409
  }
@@ -392,8 +416,8 @@ class Array
392
416
 
393
417
  %x{
394
418
  for (var i = 0, length = this.length; i < length; i++) {
395
- if ($yield.call($context, this[i], i) === $breaker) {
396
- return $breaker.$v;
419
+ if (block.call(__context, this[i], i) === __breaker) {
420
+ return __breaker.$v;
397
421
  }
398
422
  }
399
423
  }
@@ -421,11 +445,11 @@ class Array
421
445
  return defaults;
422
446
  }
423
447
 
424
- if (block !== nil) {
425
- return $yield.call($context, original);
448
+ if (block !== null) {
449
+ return block.call($context, nil, original);
426
450
  }
427
451
 
428
- raise(RubyIndexError, 'Array#fetch');
452
+ throw RubyIndexError.$new('Array#fetch');
429
453
  }
430
454
  end
431
455
 
@@ -446,7 +470,7 @@ class Array
446
470
  for (var i = 0, length = this.length, item; i < length; i++) {
447
471
  item = this[i];
448
472
 
449
- if (item.$flags & T_ARRAY) {
473
+ if (item._flags & T_ARRAY) {
450
474
  if (level === undefined) {
451
475
  result = result.concat(#{`item`.flatten});
452
476
  }
@@ -492,7 +516,7 @@ class Array
492
516
  end
493
517
 
494
518
  def hash
495
- `this.$id || (this.$id = unique_id++)`
519
+ `this._id || (this._id = unique_id++)`
496
520
  end
497
521
 
498
522
  def include?(member)
@@ -511,13 +535,13 @@ class Array
511
535
  return enum_for :index unless block_given? && object == undefined
512
536
 
513
537
  %x{
514
- if (block !== nil) {
538
+ if (block !== null) {
515
539
  for (var i = 0, length = this.length, value; i < length; i++) {
516
- if ((value = $yield.call($context, this[i])) === $breaker) {
540
+ if ((value = block.call($context, null, this[i])) === $breaker) {
517
541
  return $breaker.$v;
518
542
  }
519
543
 
520
- if (value !== false && value !== nil) {
544
+ if (value !== false && value !== null) {
521
545
  return i;
522
546
  }
523
547
  }
@@ -530,7 +554,7 @@ class Array
530
554
  }
531
555
  }
532
556
 
533
- return nil
557
+ return null
534
558
  }
535
559
  end
536
560
 
@@ -550,7 +574,7 @@ class Array
550
574
  }
551
575
 
552
576
  for (var length = this.length, value; i < length; i++) {
553
- if ((value = $yield.call($context, result, this[i])) === $breaker) {
577
+ if ((value = block.call($context, null, result, this[i])) === $breaker) {
554
578
  return $breaker.$v;
555
579
  }
556
580
 
@@ -568,7 +592,7 @@ class Array
568
592
  index += this.length + 1;
569
593
 
570
594
  if (index < 0) {
571
- raise(RubyIndexError, index + ' is out of bounds');
595
+ throw RubyIndexError.$new(index + ' is out of bounds');
572
596
  }
573
597
  }
574
598
  if (index > this.length) {
@@ -612,11 +636,11 @@ class Array
612
636
  return enum_for :keep_if unless block_given?
613
637
  %x{
614
638
  for (var i = 0, length = this.length, value; i < length; i++) {
615
- if ((value = $yield.call($context, this[i])) === $breaker) {
639
+ if ((value = block.call($context, null, this[i])) === $breaker) {
616
640
  return $breaker.$v;
617
641
  }
618
642
 
619
- if (value === false || value === nil) {
643
+ if (value === false || value === null) {
620
644
  this.splice(i, 1);
621
645
 
622
646
  length--;
@@ -636,7 +660,7 @@ class Array
636
660
  return length === 0 ? nil : this[length - 1];
637
661
  }
638
662
  else if (count < 0) {
639
- raise(RubyArgError, 'negative count given');
663
+ throw RubyArgError.$new('negative count given');
640
664
  }
641
665
 
642
666
  if (count > length) {
@@ -664,7 +688,7 @@ class Array
664
688
  }
665
689
 
666
690
  if (count < 0) {
667
- raise(RubyArgError, 'negative count given');
691
+ throw RubyArgError.$new('negative count given');
668
692
  }
669
693
 
670
694
  return count > length ? this.splice(0) : this.splice(length - count, length);
@@ -704,8 +728,8 @@ class Array
704
728
  var result = [];
705
729
 
706
730
  for (var i = 0, length = this.length, value; i < length; i++) {
707
- if ((value = $yield.call($context, this[i])) === $breaker) {
708
- return $breaker.$v;
731
+ if ((value = block.call(__context, this[i])) === __breaker) {
732
+ return __breaker.$v;
709
733
  }
710
734
 
711
735
  if (value === false || value === nil) {
@@ -723,8 +747,8 @@ class Array
723
747
  var original = this.length;
724
748
 
725
749
  for (var i = 0, length = this.length, value; i < length; i++) {
726
- if ((value = $yield.call($context, this[i])) === $breaker) {
727
- return $breaker.$v;
750
+ if ((value = block.call(__context, this[i])) === __breaker) {
751
+ return __breaker.$v;
728
752
  }
729
753
 
730
754
  if (value !== false && value !== nil) {
@@ -771,13 +795,13 @@ class Array
771
795
  return enum_for :rindex unless block_given? && object == undefined
772
796
 
773
797
  %x{
774
- if (block !== nil) {
798
+ if (block !== null) {
775
799
  for (var i = this.length - 1, value; i >= 0; i--) {
776
- if ((value = $yield.call($context, this[i])) === $breaker) {
800
+ if ((value = block.call($context, null, this[i])) === $breaker) {
777
801
  return $breaker.$v;
778
802
  }
779
803
 
780
- if (value !== false && value !== nil) {
804
+ if (value !== false && value !== null) {
781
805
  return i;
782
806
  }
783
807
  }
@@ -790,7 +814,7 @@ class Array
790
814
  }
791
815
  }
792
816
 
793
- return nil;
817
+ return null;
794
818
  }
795
819
  end
796
820
 
@@ -803,11 +827,11 @@ class Array
803
827
  for (var i = 0, length = this.length, item, value; i < length; i++) {
804
828
  item = this[i];
805
829
 
806
- if ((value = $yield.call($context, item)) === $breaker) {
830
+ if ((value = block.call($context, null, item)) === $breaker) {
807
831
  return $breaker.$v;
808
832
  }
809
833
 
810
- if (value !== false && value !== nil) {
834
+ if (value !== false && value !== null) {
811
835
  result.push(item);
812
836
  }
813
837
  }
@@ -824,11 +848,11 @@ class Array
824
848
  for (var i = 0, length = original, item, value; i < length; i++) {
825
849
  item = this[i];
826
850
 
827
- if ((value = $yield.call($context, item)) === $breaker) {
851
+ if ((value = block.call($context, null, item)) === $breaker) {
828
852
  return $breaker.$v;
829
853
  }
830
854
 
831
- if (value === false || value === nil) {
855
+ if (value === false || value === null) {
832
856
  this.splice(i, 1);
833
857
 
834
858
  length--;
@@ -836,7 +860,7 @@ class Array
836
860
  }
837
861
  }
838
862
 
839
- return this.length === original ? nil : this;
863
+ return this.length === original ? null : this;
840
864
  }
841
865
  end
842
866
 
@@ -855,7 +879,7 @@ class Array
855
879
  }
856
880
 
857
881
  if (index < 0 || index >= this.length) {
858
- return nil;
882
+ return null;
859
883
  }
860
884
 
861
885
  if (length !== undefined) {
@@ -879,11 +903,11 @@ class Array
879
903
  for (var i = 0, length = this.length, item, value; i < length; i++) {
880
904
  item = this[i];
881
905
 
882
- if ((value = $yield.call($context, item)) === $breaker) {
906
+ if ((value = block.call($context, null, item)) === $breaker) {
883
907
  return $breaker.$v;
884
908
  }
885
909
 
886
- if (value === false || value === nil) {
910
+ if (value === false || value === null) {
887
911
  return result;
888
912
  }
889
913
 
@@ -909,7 +933,7 @@ class Array
909
933
 
910
934
  for (var i = 0, length = this.length, item, hash; i < length; i++) {
911
935
  item = this[i];
912
- hash = #{item.hash};
936
+ hash = item.$hash();
913
937
 
914
938
  if (!seen[hash]) {
915
939
  seen[hash] = true;
@@ -929,7 +953,7 @@ class Array
929
953
 
930
954
  for (var i = 0, length = original, item, hash; i < length; i++) {
931
955
  item = this[i];
932
- hash = #{item.hash};
956
+ hash = item.$hash();;
933
957
 
934
958
  if (!seen[hash]) {
935
959
  seen[hash] = true;
@@ -955,4 +979,36 @@ class Array
955
979
  return this;
956
980
  }
957
981
  end
982
+
983
+ def zip(*others, &block)
984
+ %x{
985
+ var result = [], size = this.length, part, o;
986
+
987
+ for (var i = 0; i < size; i++) {
988
+ part = [this[i]];
989
+
990
+ for (var j = 0, jj = others.length; j < jj; j++) {
991
+ o = others[j][i];
992
+
993
+ if (o === undefined) {
994
+ o = nil;
995
+ }
996
+
997
+ part[j + 1] = o;
998
+ }
999
+
1000
+ result[i] = part;
1001
+ }
1002
+
1003
+ if (block) {
1004
+ for (var i = 0; i < size; i++) {
1005
+ block.call(__context, result[i]);
1006
+ }
1007
+
1008
+ return nil;
1009
+ }
1010
+
1011
+ return result;
1012
+ }
1013
+ end
958
1014
  end