Skip to content

Adds respond_to_missing? in classes where method_missing is implemented. #65

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/rubex/data_type/type_def.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@ def base_type
@old_type
end

def method_missing(meth, *args, &block)
@old_type.send(meth, *args, &block)
def method_missing(method_name, *args, &block)
return super unless @old_type.respond_to?(method_name)
@old_type.send(method_name, *args, &block)
end

def respond_to_missing?(method_name, *args)
@old_type.respond_to?(method_name) || super
end
end
end
Expand Down
44 changes: 22 additions & 22 deletions lib/rubex/symbol_table/scope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ def declare_var(name: "", c_name: "", type: nil, value: nil, extern: false)
end

def declare_sue name:, c_name:, type:, extern:
entry = Rubex::SymbolTable::Entry.new(
name, c_name, type, nil)
entry = Rubex::SymbolTable::Entry.new(
name, c_name, type, nil)
entry.extern = extern
@entries[name] = entry
@sue_entries << entry
Expand All @@ -71,7 +71,7 @@ def declare_sue name:, c_name:, type:, extern:
end

def declare_type type:, extern:
entry = Rubex::SymbolTable::Entry.new(nil, nil, type, nil)
entry = Rubex::SymbolTable::Entry.new(nil, nil, type, nil)
entry.extern = extern
@type_entries << entry

Expand Down Expand Up @@ -99,7 +99,7 @@ def add_carray name: ,c_name: ,dimension: ,type: ,value: nil

# Add a Ruby class to the current scope.
def add_ruby_class name: , c_name:, scope:, ancestor:, extern:
type = Rubex::DataType::RubyClass.new name, c_name, scope, ancestor
type = Rubex::DataType::RubyClass.new name, c_name, scope, ancestor
entry = Rubex::SymbolTable::Entry.new name, c_name, type, nil
entry.extern = extern
@entries[name] = entry
Expand Down Expand Up @@ -139,7 +139,7 @@ def allocate_temp type
@temp_counter += 1
c_name = Rubex::TEMP_PREFIX + @temp_counter.to_s
entry = Rubex::SymbolTable::Entry.new c_name, c_name, type,
Expression::Literal::CNull.new('NULL')
Expression::Literal::CNull.new('NULL')
@entries[c_name] = entry
@temp_entries << entry
else
Expand All @@ -157,7 +157,7 @@ def release_temp c_name

def [] entry
@entries[entry] or raise(Rubex::SymbolNotFoundError,
"Symbol #{entry} does not exist in this scope.")
"Symbol #{entry} does not exist in this scope.")
end

def has_entry? entry
Expand All @@ -169,7 +169,7 @@ def find name
return recursive_find(name, self)
end

private
private
def recursive_find name, scope
if scope
if scope.has_entry?(name)
Expand Down Expand Up @@ -241,7 +241,7 @@ def initialize name, outer_scope

# args - Rubex::AST::ArgumentList. Creates sym. table entries for args.
def add_arg name:, c_name:, type:, value:
entry = Rubex::SymbolTable::Entry.new name, c_name, type, value
entry = Rubex::SymbolTable::Entry.new name, c_name, type, value
check_entry name
@entries[name] = entry
@arg_entries << entry
Expand Down Expand Up @@ -274,7 +274,7 @@ def upgrade_symbols_to_global
end

remove_global_from_local_entries

@outer_scope.global_entries.each do |entry|
entry.c_name = Rubex::GLOBAL_PREFIX + @name + entry.c_name
end
Expand Down Expand Up @@ -310,22 +310,22 @@ def upgrade_symbols_to_global
# Therefore these variables get declared inside the begin block callback
# as well. So whenever one of these Arrays is called for this particular
# scope, we preturn an empty array so that nothing gets declared.
def method_missing meth, *args, &block
return [] if meth == :var_entries
ret = @outer_scope.send(meth, *args, &block)
if ret.is_a?(Rubex::SymbolTable::Entry)
if !ret.extern?
if !ret.type.c_function? && !ret.type.ruby_method? &&
!ret.type.ruby_class?
@block_entries << ret
end
end
end

def method_missing(method_name, *args, &block)
return super unless @outer_scope.respond_to?(method_name)
return [] if method_name == :var_entries
ret = @outer_scope.send(method_name, *args, &block)
return ret unless ret.is_a?(Rubex::SymbolTable::Entry)
return ret if ret.extern?
return ret if ret.type.c_function? || ret.type.ruby_method? || ret.type.ruby_class?
@block_entries << ret
ret
end

private
def respond_to_missing?(method_name, *args)
@outer_scope.respond_to?(method_name) || super
end

private

def remove_global_from_local_entries
@outer_scope.arg_entries -= @outer_scope.global_entries
Expand Down
3 changes: 2 additions & 1 deletion spec/no_gil_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@

n = Thread.new { work_without_gil(N) }
m = Thread.new { work_without_gil(N) }
n.join; m.join
n.join
m.join
end
end
end
Expand Down