Skip to content

Commit

Permalink
More refactoring for readability.
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Brannan committed Dec 12, 2009
1 parent 7c1b760 commit 053af0b
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions lib/ludicrous/scope.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'ludicrous/local_variable'
require 'ludicrous/debug_output'

module Ludicrous

Expand Down Expand Up @@ -179,26 +180,32 @@ def self.scope_type(local_names)
)
end

# Create a JIT::Function to mark all the local variables in an addressable scope.
#
# Returns the new function
def self.mark_function
return JIT::Function.build([ :VOID_PTR ] => :VOID) do |f|
scope_ptr = f.get_param(0)
scope_size = f.insn_load_relative(scope_ptr, 0, JIT::Type::UINT)
start_ptr = scope_ptr + f.const(JIT::Type::UINT, 4) # TODO: not 64-bit safe
end_ptr = scope_ptr + scope_size
f.if(start_ptr < end_ptr) {
f.rb_gc_mark_locations(start_ptr, end_ptr)
} .end
f.insn_return()
end
end

##
# A JIT::Function to mark all the local variables in an addressable scope.
MARK_FUNCTION = JIT::Function.build([ :VOID_PTR ] => :VOID) do |f|
scope_ptr = f.get_param(0)
scope_size = f.insn_load_relative(scope_ptr, 0, JIT::Type::UINT)
start_ptr = scope_ptr + f.const(JIT::Type::UINT, 4) # TODO: not 64-bit safe
end_ptr = scope_ptr + scope_size
f.if(start_ptr < end_ptr) {
f.rb_gc_mark_locations(start_ptr, end_ptr)
} .end
f.insn_return()
end
MARK_FUNCTION = mark_function()

##
# A C function to mark all the local variables in an addressable
# scope.
MARK_CLOSURE = MARK_FUNCTION.to_closure


=begin
JIT::Context.build do |context|
signature = JIT::Type.create_signature(
JIT::ABI::CDECL,
Expand All @@ -214,7 +221,6 @@ def self.scope_type(local_names)
end

FREE_CLOSURE = FREE_FUNCTION.to_closure
=end

# Create a new inner scope from an outer scope, for use with
# +rb_iterate+.
Expand Down Expand Up @@ -255,6 +261,10 @@ def self.load(function, scope_obj, local_names, args, rest_arg)
# +scope_obj+:: an object reference to the underlying scope object (as
# returned by #scope_obj in the outer scope)
def initialize(function, local_names, locals=nil, args=[], rest_arg=nil, scope_ptr=nil, scope_obj=nil)
# TODO: this is really two separate methods:
# 1) if we are wrapping a scope
# 2) if we are creating a new scope

if locals then
need_init = false
else
Expand All @@ -279,6 +289,7 @@ def initialize(function, local_names, locals=nil, args=[], rest_arg=nil, scope_p

init_locals(scope_type, need_init)
@scope_obj = scope_obj || wrap_scope(scope_size)
@scope_obj.volatile = true
end

def create_locals(function, local_names)
Expand Down

0 comments on commit 053af0b

Please sign in to comment.