Skip to content

Commit

Permalink
Replace all iterator try/catch with faster checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Beynon committed Jun 27, 2011
1 parent 989578e commit 9a65c08
Show file tree
Hide file tree
Showing 8 changed files with 288 additions and 262 deletions.
7 changes: 5 additions & 2 deletions lib/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ module Kernel
# @param [String] path The path to load
# @return [true, false]
def require(path)
`return $rb.require(path) ? Qtrue : Qfalse;`
puts "running #{path}"
`$rb.require(path) ? Qtrue : Qfalse;`
puts "done #{path}"
true
end

# Prints the message to `STDOUT`.
Expand Down Expand Up @@ -59,7 +62,7 @@ class Object

class Symbol
def to_s
`return self.toString();`
`return self.$value;`
end
end

Expand Down
17 changes: 2 additions & 15 deletions lib/core/class.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Class < Module

def allocate
`return new $rb.RObject(self, $rb.T_OBJECT);`
`return new self.allocator();`
end

# This needs to support forwaring blocks to .initialize
Expand All @@ -14,7 +14,7 @@ def new(*args)
obj = allocate

`if ($B.f == arguments.callee) {
$B.f = obj.$m.initialize;
$B.f = obj.m$initialize;
}`

obj.initialize *args
Expand All @@ -36,18 +36,5 @@ def superclass
return sup;`
end

# Use the receiver class as a wrapper around the given native
# prototype. This should be the actual prototype itself rather than
# the constructor function. For example, the core Array class may use
# this like so:
#
# class Array
# native_prototype `Array.prototype`
# end
#
# @return [Class] Returns the receiver
def native_prototype(prototype)
`return $rb.native_prototype(prototype, self);`
end
end

1 change: 0 additions & 1 deletion lib/core/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class Exception
def self.allocate
`var err = new Error();
err.$klass = self;
err.$m = self.$m_tbl;
return err;`
end

Expand Down
12 changes: 7 additions & 5 deletions lib/core/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ def ===(obj)
end

def define_method(method_id, &block)
puts "defining method...#{method_id}"
raise LocalJumpError, "no block given" unless block_given?
puts "got here."
`$rb.define_method(self, #{method_id.to_s}, block)`
nil
end
Expand All @@ -25,8 +27,8 @@ def attr_accessor(*attrs)
def attr_reader(*attrs)
attrs.each do |a|
method_id = a.to_s
`$rb.define_method(self, method_id, function(self) {
var iv = self['@' + method_id];
`$rb.define_method(self, method_id, function() {
var iv = this['@' + method_id];
return iv == undefined ? nil : iv;
});`
end
Expand All @@ -36,8 +38,8 @@ def attr_reader(*attrs)
def attr_writer(*attrs)
attrs.each do |a|
method_id = a.to_s
`$rb.define_method(self, method_id + '=', function(self, val) {
return self['@' + method_id] = val;
`$rb.define_method(self, method_id + '=', function(val) {
return this['@' + method_id] = val;
});`
end
nil
Expand All @@ -58,7 +60,7 @@ def const_set(id, value)

def class_eval(str = nil, &block)
if block_given?
`block(self)`
`block.call(self)`
else
raise "need to compile str"
end
Expand Down
4 changes: 2 additions & 2 deletions lib/ospec/example/example_group_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
module Spec
module Example
class ExampleGroupProxy

attr_reader :description, :examples

def initialize(example_group)
@description = example_group.description
@examples = example_group.example_proxies
Expand Down
2 changes: 1 addition & 1 deletion opal_lib/opal/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def eval_ruby(content, line = "")
# puts code
self['$opal_irb_result'] = eval code, line
# self['$code'].to_s + "ww"
eval "!$opal_irb_result.$m.inspect.$rbMM ? $opal_irb_result.$m.inspect($opal_irb_result) : '(Object doesnt support #inspect)'"
eval "!$opal_irb_result.m$inspect.$rbMM ? $opal_irb_result.m$inspect() : '(Object doesnt support #inspect)'"
rescue => e
puts e
puts("\t" + e.backtrace.join("\n\t"))
Expand Down

0 comments on commit 9a65c08

Please sign in to comment.