opal 0.3.6 → 0.3.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. data/README.md +69 -97
  2. data/bin/opal +2 -2
  3. data/{lib/core → corelib}/array.rb +85 -56
  4. data/corelib/boolean.rb +20 -0
  5. data/corelib/class.rb +58 -0
  6. data/{lib → corelib}/core.rb +2 -50
  7. data/corelib/dir.rb +22 -0
  8. data/{lib/core → corelib}/enumerable.rb +0 -0
  9. data/corelib/error.rb +19 -0
  10. data/{lib/core → corelib}/file.rb +7 -9
  11. data/{lib/core → corelib}/hash.rb +104 -144
  12. data/{lib/core → corelib}/kernel.rb +38 -44
  13. data/corelib/load_order +21 -0
  14. data/{lib/core → corelib}/match_data.rb +0 -0
  15. data/{lib/core → corelib}/module.rb +12 -8
  16. data/{lib/core → corelib}/nil_class.rb +2 -2
  17. data/{lib/core → corelib}/numeric.rb +37 -100
  18. data/corelib/object.rb +37 -0
  19. data/{lib/core → corelib}/proc.rb +3 -3
  20. data/corelib/range.rb +27 -0
  21. data/{lib/core → corelib}/regexp.rb +1 -1
  22. data/{lib/core → corelib}/string.rb +16 -107
  23. data/{lib/core → corelib}/top_self.rb +0 -0
  24. data/lib/opal.rb +7 -0
  25. data/lib/opal/browserify.rb +34 -0
  26. data/{opal_lib → lib}/opal/builder.rb +70 -24
  27. data/lib/opal/command.rb +52 -0
  28. data/lib/opal/context.rb +197 -0
  29. data/{opal_lib/opal/ruby/parser.rb → lib/opal/lexer.rb} +20 -4
  30. data/{opal_lib/opal/ruby → lib/opal}/nodes.rb +238 -127
  31. data/lib/opal/parser.rb +4894 -0
  32. data/{opal_lib/opal/ruby/ruby_parser.y → lib/opal/parser.y} +38 -18
  33. data/lib/rbp.rb +2 -0
  34. data/lib/rbp/package.rb +49 -0
  35. data/runtime/class.js +216 -189
  36. data/runtime/fs.js +2 -2
  37. data/runtime/init.js +242 -244
  38. data/runtime/loader.js +78 -99
  39. data/runtime/module.js +34 -40
  40. data/runtime/post.js +2 -2
  41. data/runtime/pre.js +1 -1
  42. data/runtime/runtime.js +129 -135
  43. data/{lib → stdlib}/dev.rb +10 -10
  44. data/{lib → stdlib}/racc/parser.rb +0 -6
  45. data/{lib → stdlib}/strscan.rb +4 -4
  46. metadata +57 -105
  47. data/lib/core/basic_object.rb +0 -51
  48. data/lib/core/class.rb +0 -38
  49. data/lib/core/dir.rb +0 -26
  50. data/lib/core/error.rb +0 -75
  51. data/lib/core/false_class.rb +0 -81
  52. data/lib/core/object.rb +0 -6
  53. data/lib/core/range.rb +0 -27
  54. data/lib/core/symbol.rb +0 -42
  55. data/lib/core/true_class.rb +0 -41
  56. data/lib/ospec.rb +0 -7
  57. data/lib/ospec/autorun.rb +0 -8
  58. data/lib/ospec/dsl.rb +0 -15
  59. data/lib/ospec/example.rb +0 -11
  60. data/lib/ospec/example/before_and_after_hooks.rb +0 -56
  61. data/lib/ospec/example/errors.rb +0 -17
  62. data/lib/ospec/example/example_group.rb +0 -12
  63. data/lib/ospec/example/example_group_factory.rb +0 -18
  64. data/lib/ospec/example/example_group_hierarchy.rb +0 -21
  65. data/lib/ospec/example/example_group_methods.rb +0 -100
  66. data/lib/ospec/example/example_group_proxy.rb +0 -15
  67. data/lib/ospec/example/example_methods.rb +0 -46
  68. data/lib/ospec/example/example_proxy.rb +0 -18
  69. data/lib/ospec/expectations.rb +0 -19
  70. data/lib/ospec/expectations/errors.rb +0 -8
  71. data/lib/ospec/expectations/fail_with.rb +0 -9
  72. data/lib/ospec/expectations/handler.rb +0 -33
  73. data/lib/ospec/helpers/scratch.rb +0 -18
  74. data/lib/ospec/matchers.rb +0 -24
  75. data/lib/ospec/matchers/be.rb +0 -1
  76. data/lib/ospec/matchers/generated_descriptions.rb +0 -20
  77. data/lib/ospec/matchers/operator_matcher.rb +0 -54
  78. data/lib/ospec/matchers/raise_error.rb +0 -38
  79. data/lib/ospec/runner.rb +0 -90
  80. data/lib/ospec/runner/example_group_runner.rb +0 -41
  81. data/lib/ospec/runner/formatter/html_formatter.rb +0 -139
  82. data/lib/ospec/runner/formatter/terminal_formatter.rb +0 -48
  83. data/lib/ospec/runner/options.rb +0 -34
  84. data/lib/ospec/runner/reporter.rb +0 -82
  85. data/opal_lib/opal.rb +0 -16
  86. data/opal_lib/opal/build_methods.rb +0 -51
  87. data/opal_lib/opal/bundle.rb +0 -70
  88. data/opal_lib/opal/command.rb +0 -68
  89. data/opal_lib/opal/context.rb +0 -81
  90. data/opal_lib/opal/context/console.rb +0 -10
  91. data/opal_lib/opal/context/file_system.rb +0 -34
  92. data/opal_lib/opal/context/loader.rb +0 -135
  93. data/opal_lib/opal/gem.rb +0 -84
  94. data/opal_lib/opal/rake/builder_task.rb +0 -44
  95. data/opal_lib/opal/rake/spec_task.rb +0 -32
  96. data/opal_lib/opal/ruby/ruby_parser.rb +0 -4862
  97. data/opal_lib/opal/version.rb +0 -4
  98. data/runtime/debug.js +0 -84
@@ -1,9 +1,9 @@
1
- require 'opal/ruby/parser'
1
+ require 'opal/lexer'
2
2
 
3
3
  module Opal
4
4
 
5
5
  def self.compile(source)
6
- res = Opal::RubyParser.new(source).parse!.generate_top :debug => true
6
+ res = Opal::Parser.new(source).parse!.generate_top :debug => true
7
7
  res
8
8
  end
9
9
 
@@ -29,11 +29,13 @@ module Opal
29
29
  xhr.open('GET', filename, true);
30
30
  xhr.onreadystatechange = function() {
31
31
  if (xhr.readyState == 4) {
32
+ opal.run(function() {
32
33
  if (xhr.status == 0 || xhr.status == 200) {
33
34
  #{ run_ruby_content `xhr.responseText`, filename };
34
35
  } else {
35
36
  #{ raise "LoadError: Cannot load: #{filename}" };
36
37
  }
38
+ });
37
39
  }
38
40
  };
39
41
  xhr.send(null);`
@@ -50,7 +52,9 @@ module Opal
50
52
  if (script.src) {
51
53
  #{ run_remote_content `script.src` };
52
54
  } else {
55
+ opal.run(function() {
53
56
  #{ run_ruby_content `script.innerHTML`, "(script-tag)" };
57
+ });
54
58
  }
55
59
  }
56
60
  }`
@@ -110,8 +114,9 @@ opal.browser_repl = function() {
110
114
  setTimeout(function() { stdin.focus(); }, 0);
111
115
 
112
116
  var puts_content = function(str) {
113
- var elem = document.createElement('div');
117
+ var elem = document.createElement('pre');
114
118
  elem.textContent == null ? elem.innerText = str : elem.textContent = str;
119
+ elem.style.margin = "0px";
115
120
  stdout.appendChild(elem);
116
121
  };
117
122
 
@@ -124,14 +129,9 @@ opal.browser_repl = function() {
124
129
  stdin.value = '';
125
130
  puts_content(">> " + ruby);
126
131
 
127
- try {
132
+ opal.run(function() {
128
133
  puts_content("=> " + #{Opal.run_ruby_content(`ruby`, '(irb)').inspect}.toString());
129
- }
130
- catch (err) {
131
- // if (err.stack) puts_content(err.stack);
132
- //else puts_content("=> " + err.message);
133
- puts_content("=> " + err.$klass.__classid__ + ": " + err['@message']);
134
- }
134
+ });
135
135
 
136
136
  opal_repl.scrollTop = opal_repl.scrollHeight;
137
137
  }
@@ -1,11 +1,5 @@
1
1
  # Opal port of racc/parser.rb.
2
2
  #
3
- # This is the runtime for racc generated parsers inside opal. It is a port
4
- # of racc/parser.rb from ruby stdlib but with optimizations to make it run
5
- # faster on opal, which is ecspecially important in the browser. This
6
- # implementation also has a pure js routine for extra speeds gains which is
7
- # used in preference to the ruby implementation.
8
- #
9
3
  # Original license:
10
4
  #
11
5
  # $originalId: parser.rb,v 1.8 2006/07/06 11:42:07 aamine Exp $
@@ -14,7 +14,7 @@ class StringScanner
14
14
 
15
15
  if (res == null) {
16
16
  self.matched = "";
17
- return Qfalse;
17
+ return false;
18
18
  }
19
19
  else if (typeof res == 'object') {
20
20
  self._at += res[0].length;
@@ -28,13 +28,13 @@ class StringScanner
28
28
  return res;
29
29
  }
30
30
  else {
31
- return Qfalse;
31
+ return false;
32
32
  }`
33
33
  end
34
34
 
35
35
  def check(reg)
36
36
  `reg = new RegExp('^' + reg.toString().substr(1, reg.toString().length - 2));
37
- return reg.exec(self._working_string) ? Qtrue : Qfalse;`
37
+ return reg.exec(self._working_string) ? true : false;`
38
38
  end
39
39
 
40
40
  def peek(len)
@@ -42,7 +42,7 @@ class StringScanner
42
42
  end
43
43
 
44
44
  def eos?
45
- `return self._working_string.length == 0 ? Qtrue : Qfalse;`
45
+ `return self._working_string.length == 0;`
46
46
  end
47
47
 
48
48
  def matched
metadata CHANGED
@@ -1,104 +1,37 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: opal
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.9
4
5
  prerelease:
5
- version: 0.3.6
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Adam Beynon
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-07-07 00:00:00 +01:00
14
- default_executable:
12
+ date: 2011-09-16 00:00:00.000000000Z
15
13
  dependencies: []
16
-
17
- description:
18
- email:
14
+ description: Ruby runtime and core library for javascript
15
+ email:
19
16
  - adam@adambeynon.com
20
- executables:
17
+ executables:
21
18
  - opal
22
19
  extensions: []
23
-
24
20
  extra_rdoc_files: []
25
-
26
- files:
21
+ files:
27
22
  - bin/opal
28
- - lib/core/array.rb
29
- - lib/core/basic_object.rb
30
- - lib/core/class.rb
31
- - lib/core/dir.rb
32
- - lib/core/enumerable.rb
33
- - lib/core/error.rb
34
- - lib/core/false_class.rb
35
- - lib/core/file.rb
36
- - lib/core/hash.rb
37
- - lib/core/kernel.rb
38
- - lib/core/match_data.rb
39
- - lib/core/module.rb
40
- - lib/core/nil_class.rb
41
- - lib/core/numeric.rb
42
- - lib/core/object.rb
43
- - lib/core/proc.rb
44
- - lib/core/range.rb
45
- - lib/core/regexp.rb
46
- - lib/core/string.rb
47
- - lib/core/symbol.rb
48
- - lib/core/top_self.rb
49
- - lib/core/true_class.rb
50
- - lib/core.rb
51
- - lib/dev.rb
52
- - lib/ospec/autorun.rb
53
- - lib/ospec/dsl.rb
54
- - lib/ospec/example/before_and_after_hooks.rb
55
- - lib/ospec/example/errors.rb
56
- - lib/ospec/example/example_group.rb
57
- - lib/ospec/example/example_group_factory.rb
58
- - lib/ospec/example/example_group_hierarchy.rb
59
- - lib/ospec/example/example_group_methods.rb
60
- - lib/ospec/example/example_group_proxy.rb
61
- - lib/ospec/example/example_methods.rb
62
- - lib/ospec/example/example_proxy.rb
63
- - lib/ospec/example.rb
64
- - lib/ospec/expectations/errors.rb
65
- - lib/ospec/expectations/fail_with.rb
66
- - lib/ospec/expectations/handler.rb
67
- - lib/ospec/expectations.rb
68
- - lib/ospec/helpers/scratch.rb
69
- - lib/ospec/matchers/be.rb
70
- - lib/ospec/matchers/generated_descriptions.rb
71
- - lib/ospec/matchers/operator_matcher.rb
72
- - lib/ospec/matchers/raise_error.rb
73
- - lib/ospec/matchers.rb
74
- - lib/ospec/runner/example_group_runner.rb
75
- - lib/ospec/runner/formatter/html_formatter.rb
76
- - lib/ospec/runner/formatter/terminal_formatter.rb
77
- - lib/ospec/runner/options.rb
78
- - lib/ospec/runner/reporter.rb
79
- - lib/ospec/runner.rb
80
- - lib/ospec.rb
81
- - lib/racc/parser.rb
82
- - lib/strscan.rb
83
- - opal_lib/opal/build_methods.rb
84
- - opal_lib/opal/builder.rb
85
- - opal_lib/opal/bundle.rb
86
- - opal_lib/opal/command.rb
87
- - opal_lib/opal/context/console.rb
88
- - opal_lib/opal/context/file_system.rb
89
- - opal_lib/opal/context/loader.rb
90
- - opal_lib/opal/context.rb
91
- - opal_lib/opal/gem.rb
92
- - opal_lib/opal/rake/builder_task.rb
93
- - opal_lib/opal/rake/spec_task.rb
94
- - opal_lib/opal/ruby/nodes.rb
95
- - opal_lib/opal/ruby/parser.rb
96
- - opal_lib/opal/ruby/ruby_parser.rb
97
- - opal_lib/opal/ruby/ruby_parser.y
98
- - opal_lib/opal/version.rb
99
- - opal_lib/opal.rb
23
+ - lib/opal/browserify.rb
24
+ - lib/opal/builder.rb
25
+ - lib/opal/command.rb
26
+ - lib/opal/context.rb
27
+ - lib/opal/lexer.rb
28
+ - lib/opal/nodes.rb
29
+ - lib/opal/parser.rb
30
+ - lib/opal/parser.y
31
+ - lib/opal.rb
32
+ - lib/rbp/package.rb
33
+ - lib/rbp.rb
100
34
  - runtime/class.js
101
- - runtime/debug.js
102
35
  - runtime/fs.js
103
36
  - runtime/init.js
104
37
  - runtime/loader.js
@@ -106,34 +39,53 @@ files:
106
39
  - runtime/post.js
107
40
  - runtime/pre.js
108
41
  - runtime/runtime.js
42
+ - corelib/array.rb
43
+ - corelib/boolean.rb
44
+ - corelib/class.rb
45
+ - corelib/core.rb
46
+ - corelib/dir.rb
47
+ - corelib/enumerable.rb
48
+ - corelib/error.rb
49
+ - corelib/file.rb
50
+ - corelib/hash.rb
51
+ - corelib/kernel.rb
52
+ - corelib/load_order
53
+ - corelib/match_data.rb
54
+ - corelib/module.rb
55
+ - corelib/nil_class.rb
56
+ - corelib/numeric.rb
57
+ - corelib/object.rb
58
+ - corelib/proc.rb
59
+ - corelib/range.rb
60
+ - corelib/regexp.rb
61
+ - corelib/string.rb
62
+ - corelib/top_self.rb
63
+ - stdlib/dev.rb
64
+ - stdlib/racc/parser.rb
65
+ - stdlib/strscan.rb
109
66
  - README.md
110
- has_rdoc: true
111
67
  homepage: http://opalscript.org
112
68
  licenses: []
113
-
114
69
  post_install_message:
115
70
  rdoc_options: []
116
-
117
- require_paths:
118
- - opal_lib
119
- required_ruby_version: !ruby/object:Gem::Requirement
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
120
74
  none: false
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: "0"
125
- required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
80
  none: false
127
- requirements:
128
- - - ">="
129
- - !ruby/object:Gem::Version
130
- version: "0"
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
131
85
  requirements: []
132
-
133
86
  rubyforge_project:
134
- rubygems_version: 1.6.2
87
+ rubygems_version: 1.8.10
135
88
  signing_key:
136
89
  specification_version: 3
137
90
  summary: Ruby runtime and core library for javascript
138
91
  test_files: []
139
-
@@ -1,51 +0,0 @@
1
- # BasicObject is the root object in opal. Even {Object} inherits from
2
- # {BasicObject}. Instances of BasicObject (or subclasses of) are useful
3
- # as they give almost a clean interface in which the absolute minimum of
4
- # methods are defined on it. It therefore becomes useful for such
5
- # applications as HashStructs.
6
- class BasicObject
7
-
8
- def initialize(*a)
9
- # ...
10
- end
11
-
12
- def ==(other)
13
- `if (self == other) return Qtrue;
14
- return Qfalse;`
15
- end
16
-
17
- def equal?(other)
18
- self == other
19
- end
20
-
21
- def !()
22
- self ? false : true
23
- end
24
-
25
- def !=(obj)
26
- self == obj ? false : true
27
- end
28
-
29
- def __send__(method_id, *args, &block)
30
- `var method = self.$m[#{method_id.to_s}];
31
-
32
- if ($B.f == arguments.callee) {
33
- $B.f = method;
34
- }
35
-
36
- args.unshift(self);
37
-
38
- return method.apply(self, args);`
39
- end
40
-
41
- def instance_eval(&block)
42
- raise ArgumentError, "block not supplied" unless block_given?
43
- `block(self);`
44
- self
45
- end
46
-
47
- def method_missing(sym, *args)
48
- raise NoMethodError, "undefined method `#{sym}` for #{self.inspect}"
49
- end
50
- end
51
-
data/lib/core/class.rb DELETED
@@ -1,38 +0,0 @@
1
- class Class < Module
2
-
3
- def allocate
4
- `return new $rb.RObject(self);`
5
- end
6
-
7
- def new(*args)
8
- obj = allocate
9
-
10
- `if ($B.f == arguments.callee) {
11
- $B.f = obj.$m.initialize;
12
- }`
13
-
14
- obj.initialize *args
15
- obj
16
- end
17
-
18
- def inherited(cls)
19
- nil
20
- end
21
-
22
- def superclass
23
- `var sup = self.$super;
24
-
25
- if (!sup) {
26
- if (self == $rb.BasicObject) return nil;
27
- throw new Error('RuntimeError: uninitialized class');
28
- }
29
-
30
- return sup;`
31
- end
32
-
33
- def native_prototype(proto)
34
- `$rb.native_prototype(self, proto);`
35
- nil
36
- end
37
- end
38
-
data/lib/core/dir.rb DELETED
@@ -1,26 +0,0 @@
1
-
2
- class Dir
3
- # OPAL_FS simply points to the main opal.fs namespace. This might be the
4
- # default fs in the browser, or may be overriden within the opal build tools
5
- # when running on top of the gem runtime. Both are compatible interfaces.
6
- `var OPAL_FS = $rb.opal.fs;`
7
-
8
- # Returns a string that is the current working directory for this process.
9
- #
10
- # @return [String]
11
- def self.getwd
12
- `return OPAL_FS.cwd;`
13
- end
14
-
15
- # Returns a string that is the current working directory for this process.
16
- #
17
- # @return [String]
18
- def self.pwd
19
- `return OPAL_FS.cwd;`
20
- end
21
-
22
- def self.[](*a)
23
- `return OPAL_FS.glob.apply(OPAL_FS, a);`
24
- end
25
- end
26
-
data/lib/core/error.rb DELETED
@@ -1,75 +0,0 @@
1
- # Instances of {Exception} and its subclasses are used to hold error
2
- # information between `raise` calls, `begin` blocks and `rescue` statements.
3
- # `Exceptions` will hold an optional `message`, which is a description
4
- # of the error that occured. The exception `type` is also useful, and is
5
- # just the name of the class that is a decendant of `Exception`.
6
- # Subclasses are generally made of `StandardError`, but a subclass of
7
- # any core `Exception` class is valid.
8
- #
9
- # Implementation details
10
- # ----------------------
11
- #
12
- # Inside opal, exceptions are instances of the native javascript `Error`
13
- # objects. This allows an efficient means to "piggy-back" the javascript
14
- # try/catch/finally statements, as well as the `throw` statement for
15
- # actually raising exceptions.
16
- #
17
- # Subclasses of `Exception` can also be used on top of `Error`, and the
18
- # correct class and method tables for these subclasses are set in
19
- # {.allocate}.
20
- #
21
- # Exceptions cannot be altered once created, so their message is
22
- # permanently fixed. To improve debugging opal, once an exception it
23
- # {#initialize}, the native error has its `.message` property set to a
24
- # descriptive name with the format `ErrorClassName: error_message`. This
25
- # helps to observe top level error statements appearing in debug tools.
26
- # The original error message may be received using the standard
27
- # {#message} or {#to_s} methods.
28
- #
29
- # Accessing the `backtrace` of an exception is platform dependant. It is
30
- # fully supported on the server side v8 context, but differs in the
31
- # browser context as some browsers have better support than others. The
32
- # backtrace should not be relied on, and is supported purely on a
33
- # platform to platform basis.
34
- class Exception
35
-
36
- def self.allocate
37
- `var err = new Error();
38
- err.$klass = self;
39
- err.$m = self.$m_tbl;
40
- return err;`
41
- end
42
-
43
- def initialize(message = '')
44
- @message = message
45
- end
46
-
47
- def message
48
- @message || `self.message`
49
- end
50
-
51
- def inspect
52
- `return "#<" + self.$klass.__classid__ + ": '" + #{@message} + "'>";`
53
- end
54
-
55
- def to_s
56
- @message
57
- end
58
- end
59
-
60
- class StandardError < Exception; end
61
- class RuntimeError < Exception; end
62
- class LocalJumpError < StandardError; end
63
- class TypeError < StandardError; end
64
-
65
- class NameError < StandardError; end
66
- class NoMethodError < NameError; end
67
- class ArgumentError < StandardError; end
68
-
69
- class ScriptError < Exception; end
70
- class LoadError < ScriptError; end
71
-
72
- class IndexError < StandardError; end
73
- class KeyError < IndexError; end
74
- class RangeError < StandardError; end
75
-