Skip to content
Permalink
Browse files

space.send now takes a string, instead of a W_SymbolObject

  • Loading branch information
Alex Gaynor
Alex Gaynor committed May 7, 2013
1 parent 599ac1d commit 04ab62f8431828a427f6fca6fc607bd917ee10f4
@@ -64,7 +64,7 @@ def test_waitpid(self, space, code):
w_res = space.execute("return Process.waitpid %i" % pid)
assert space.int_w(w_res) == pid
w_res = space.execute("return $?")
status = space.send(w_res, space.newsymbol("to_i"), [])
status = space.send(w_res, "to_i", [])
assert space.int_w(status) == code

@pytest.mark.parametrize("code", [0, 1, 173])
@@ -76,5 +76,5 @@ def test_waitpid2(self, space, code):
w_res = space.execute("return Process.waitpid2 %i" % pid)
[returned_pid, returned_code] = space.listview(w_res)
assert space.int_w(returned_pid) == pid
code_to_i = space.send(returned_code, space.newsymbol("to_i"), [])
code_to_i = space.send(returned_code, "to_i", [])
assert space.int_w(code_to_i) == code
@@ -10,7 +10,7 @@ def symbol(space, w_obj):
else:
w_str = space.convert_type(w_obj, space.w_string, "to_str", raise_error=False)
if w_str is space.w_nil:
w_inspect_str = space.send(w_obj, space.newsymbol("inspect"))
w_inspect_str = space.send(w_obj, "inspect")
if not space.is_kind_of(w_inspect_str, space.w_string):
inspect_str = space.any_to_s(w_obj)
else:
@@ -35,7 +35,7 @@ def float(space, w_obj):
if space.is_kind_of(w_obj, space.w_float):
return space.float_w(w_obj)
else:
return space.float_w(space.send(w_obj, space.newsymbol("Float"), [w_obj]))
return space.float_w(space.send(w_obj, "Float", [w_obj]))

@staticmethod
def str(space, w_obj):
@@ -10,7 +10,7 @@ def __str__(self):


def format_traceback(space, exc, top_filepath):
w_bt = space.send(exc, space.newsymbol("backtrace"))
w_bt = space.send(exc, "backtrace")
bt_w = space.listview(w_bt)
if bt_w:
yield "%s: %s (%s)\n" % (space.str_w(bt_w[0]), exc.msg, space.getclass(exc).name)
@@ -54,7 +54,7 @@ def invoke_trace_proc(self, space, event, scope_id, classname, frame=None):
try:
if frame is None:
frame = self.gettoprubyframe()
space.send(self.w_trace_proc, space.newsymbol("call"), [
space.send(self.w_trace_proc, "call", [
space.newstr_fromstr(event),
space.newstr_fromstr(frame.bytecode.filepath),
space.newint(frame.bytecode.lineno_table[frame.last_instr]),
@@ -211,7 +211,7 @@ def DEFINED_CONSTANT(self, space, bytecode, frame, pc, idx):
space.getexecutioncontext().last_instr = pc
w_name = bytecode.consts_w[idx]
w_scope = frame.pop()
if space.is_true(space.send(w_scope, space.newsymbol("const_defined?"), [w_name])):
if space.is_true(space.send(w_scope, "const_defined?", [w_name])):
frame.push(space.newstr_fromstr("constant"))
else:
frame.push(space.w_nil)
@@ -231,12 +231,12 @@ def DEFINED_LOCAL_CONSTANT(self, space, bytecode, frame, pc, idx):
scope = jit.promote(frame.lexical_scope)
while scope is not None:
w_mod = scope.w_mod
if space.is_true(space.send(w_mod, space.newsymbol("const_defined?"), [w_name])):
if space.is_true(space.send(w_mod, "const_defined?", [w_name])):
frame.push(space.newstr_fromstr("constant"))
break
scope = scope.backscope
else:
if space.is_true(space.send(space.w_object, space.newsymbol("const_defined?"), [w_name])):
if space.is_true(space.send(space.w_object, "const_defined?", [w_name])):
frame.push(space.newstr_fromstr("constant"))
else:
frame.push(space.w_nil)
@@ -258,7 +258,7 @@ def DEFINED_INSTANCE_VAR(self, space, bytecode, frame, pc, idx):
space.getexecutioncontext().last_instr = pc
w_name = bytecode.consts_w[idx]
w_obj = frame.pop()
if space.is_true(space.send(w_obj, space.newsymbol("instance_variable_defined?"), [w_name])):
if space.is_true(space.send(w_obj, "instance_variable_defined?", [w_name])):
frame.push(space.newstr_fromstr("instance-variable"))
else:
frame.push(space.w_nil)
@@ -282,7 +282,7 @@ def DEFINED_CLASS_VAR(self, space, bytecode, frame, pc, idx):
space.getexecutioncontext().last_instr = pc
w_name = bytecode.consts_w[idx]
w_obj = frame.pop()
if space.is_true(space.send(w_obj, space.newsymbol("class_variable_defined?"), [w_name])):
if space.is_true(space.send(w_obj, "class_variable_defined?", [w_name])):
frame.push(space.newstr_fromstr("class variable"))
else:
frame.push(space.w_nil)
@@ -423,10 +423,10 @@ def COERCE_ARRAY(self, space, bytecode, frame, pc, nil_is_empty):
frame.push(w_obj)
else:
space.getexecutioncontext().last_instr = pc
if space.respond_to(w_obj, space.newsymbol("to_a")):
w_res = space.send(w_obj, space.newsymbol("to_a"))
elif space.respond_to(w_obj, space.newsymbol("to_ary")):
w_res = space.send(w_obj, space.newsymbol("to_ary"))
if space.respond_to(w_obj, "to_a"):
w_res = space.send(w_obj, "to_a")
elif space.respond_to(w_obj, "to_ary"):
w_res = space.send(w_obj, "to_ary")
else:
w_res = space.newarray([w_obj])
if not isinstance(w_res, W_ArrayObject):
@@ -439,7 +439,7 @@ def COERCE_BLOCK(self, space, bytecode, frame, pc):
frame.push(w_block)
elif isinstance(w_block, W_ProcObject):
frame.push(w_block)
elif space.respond_to(w_block, space.newsymbol("to_proc")):
elif space.respond_to(w_block, "to_proc"):
space.getexecutioncontext().last_instr = pc
# Proc implements to_proc, too, but MRI doesn't call it
w_res = space.convert_type(w_block, space.w_proc, "to_proc")
@@ -515,7 +515,7 @@ def SEND(self, space, bytecode, frame, pc, meth_idx, num_args):
space.getexecutioncontext().last_instr = pc
args_w = frame.popitemsreverse(num_args)
w_receiver = frame.pop()
w_res = space.send(w_receiver, bytecode.consts_w[meth_idx], args_w)
w_res = space.send(w_receiver, space.symbol_w(bytecode.consts_w[meth_idx]), args_w)
frame.push(w_res)

def SEND_BLOCK(self, space, bytecode, frame, pc, meth_idx, num_args):
@@ -527,7 +527,7 @@ def SEND_BLOCK(self, space, bytecode, frame, pc, meth_idx, num_args):
w_block = None
else:
assert isinstance(w_block, W_ProcObject)
w_res = space.send(w_receiver, bytecode.consts_w[meth_idx], args_w, block=w_block)
w_res = space.send(w_receiver, space.symbol_w(bytecode.consts_w[meth_idx]), args_w, block=w_block)
frame.push(w_res)

@jit.unroll_safe
@@ -544,7 +544,7 @@ def SEND_SPLAT(self, space, bytecode, frame, pc, meth_idx, num_args):
args_w[pos:pos + len(array_w)] = array_w
pos += len(array_w)
w_receiver = frame.pop()
w_res = space.send(w_receiver, bytecode.consts_w[meth_idx], args_w)
w_res = space.send(w_receiver, space.symbol_w(bytecode.consts_w[meth_idx]), args_w)
frame.push(w_res)

@jit.unroll_safe
@@ -560,13 +560,13 @@ def SEND_BLOCK_SPLAT(self, space, bytecode, frame, pc, meth_idx, num_args):
w_block = None
else:
assert isinstance(w_block, W_ProcObject)
w_res = space.send(w_receiver, bytecode.consts_w[meth_idx], args_w, block=w_block)
w_res = space.send(w_receiver, space.symbol_w(bytecode.consts_w[meth_idx]), args_w, block=w_block)
frame.push(w_res)

def DEFINED_METHOD(self, space, bytecode, frame, pc, meth_idx):
space.getexecutioncontext().last_instr = pc
w_obj = frame.pop()
if space.respond_to(w_obj, bytecode.consts_w[meth_idx]):
if space.respond_to(w_obj, space.symbol_w(bytecode.consts_w[meth_idx])):
frame.push(space.newstr_fromstr("method"))
else:
frame.push(space.w_nil)
@@ -580,7 +580,7 @@ def SEND_SUPER_BLOCK(self, space, bytecode, frame, pc, meth_idx, num_args):
w_block = None
else:
assert isinstance(w_block, W_ProcObject)
w_res = space.send_super(frame.lexical_scope.w_mod, w_receiver, bytecode.consts_w[meth_idx], args_w, block=w_block)
w_res = space.send_super(frame.lexical_scope.w_mod, w_receiver, space.symbol_w(bytecode.consts_w[meth_idx]), args_w, block=w_block)
frame.push(w_res)

@jit.unroll_safe
@@ -596,7 +596,7 @@ def SEND_SUPER_BLOCK_SPLAT(self, space, bytecode, frame, pc, meth_idx, num_args)
w_block = None
else:
assert isinstance(w_block, W_ProcObject)
w_res = space.send_super(frame.lexical_scope.w_mod, w_receiver, bytecode.consts_w[meth_idx], args_w, block=w_block)
w_res = space.send_super(frame.lexical_scope.w_mod, w_receiver, space.symbol_w(bytecode.consts_w[meth_idx]), args_w, block=w_block)
frame.push(w_res)

def DEFINED_SUPER(self, space, bytecode, frame, pc, meth_idx):
@@ -110,7 +110,7 @@ def _parse_argv(space, argv):
raise ShortCircuitError("%s\n" % space.str_w(
space.send(
space.w_object,
space.newsymbol("const_get"),
"const_get",
[space.newstr_fromstr("RUBY_DESCRIPTION")]
)
))
@@ -233,13 +233,13 @@ def _entry_point(space, argv):
for path_entry in load_path_entries:
space.send(
space.w_load_path,
space.newsymbol("<<"),
"<<",
[space.newstr_fromstr(path_entry)]
)
for required_lib in reqs:
space.send(
space.w_kernel,
space.newsymbol("require"),
"require",
[space.newstr_fromstr(required_lib)]
)

@@ -302,13 +302,13 @@ def _entry_point(space, argv):
bc = space.compile(source, path)
frame = space.create_frame(bc)
while True:
w_line = space.send(space.w_kernel, space.newsymbol("gets"))
w_line = space.send(space.w_kernel, "gets")
if w_line is space.w_nil:
break
with space.getexecutioncontext().visit_frame(frame):
w_res = space.execute_frame(frame, bc)
if print_after:
space.send(space.w_kernel, space.newsymbol("print"), [w_res])
space.send(space.w_kernel, "print", [w_res])
else:
space.execute(source, filepath=path)
except RubyError as e:
@@ -146,7 +146,7 @@ def _build(self, classdef):

for mod in reversed(classdef.includes):
w_mod = self.space.getmoduleobject(mod.moduledef)
self.space.send(w_class, self.space.newsymbol("include"), [w_mod])
self.space.send(w_class, "include", [w_mod])

if classdef.setup_class_func is not None:
classdef.setup_class_func(classdef.cls, self.space, w_class)
@@ -92,7 +92,7 @@ def function_require(self, space, path):

w_loaded_features = space.globals.get(space, '$"')
w_already_loaded = space.send(
w_loaded_features, space.newsymbol("include?"), [space.newstr_fromstr(path)]
w_loaded_features, "include?", [space.newstr_fromstr(path)]
)
if space.is_true(w_already_loaded):
return space.w_false
@@ -123,15 +123,15 @@ def method_raise(self, space, w_str_or_exception=None, w_string=None, w_array=No
else:
w_exception = w_str_or_exception

if not space.respond_to(w_exception, space.newsymbol("exception")):
if not space.respond_to(w_exception, "exception"):
raise space.error(space.w_TypeError,
"exception class/object expected"
)

if w_string is not None:
w_exc = space.send(w_exception, space.newsymbol("exception"), [w_string])
w_exc = space.send(w_exception, "exception", [w_string])
else:
w_exc = space.send(w_exception, space.newsymbol("exception"))
w_exc = space.send(w_exception, "exception")

if w_array is not None:
raise NotImplementedError("custom backtrace for Kernel#raise")
@@ -147,7 +147,7 @@ def method_raise(self, space, w_str_or_exception=None, w_string=None, w_array=No
def method_exit(self, space, status=0):
return space.send(
space.getmoduleobject(Process.moduledef),
space.newsymbol("exit"),
"exit",
[space.newint(status)]
)

@@ -170,13 +170,13 @@ def method_method(self, space):

@moduledef.function("exec")
def method_exec(self, space, args_w):
if len(args_w) > 1 and space.respond_to(args_w[0], space.newsymbol("to_hash")):
if len(args_w) > 1 and space.respond_to(args_w[0], "to_hash"):
raise space.error(space.w_NotImplementedError, "exec with environment")

if len(args_w) > 1 and space.respond_to(args_w[-1], space.newsymbol("to_hash")):
if len(args_w) > 1 and space.respond_to(args_w[-1], "to_hash"):
raise space.error(space.w_NotImplementedError, "exec with options")

if space.respond_to(args_w[0], space.newsymbol("to_ary")):
if space.respond_to(args_w[0], "to_ary"):
w_cmd = space.convert_type(args_w[0], space.w_array, "to_ary")
cmd, argv0 = [
space.str0_w(space.convert_type(
@@ -214,9 +214,7 @@ def method_exec(self, space, args_w):
@moduledef.function("fork")
def method_fork(self, space, block):
return space.send(
space.getmoduleobject(Process.moduledef),
space.newsymbol("fork"),
block=block
space.getmoduleobject(Process.moduledef), "fork", block=block
)

@moduledef.function("at_exit")
@@ -230,7 +228,7 @@ def method_match(self, space, w_other):

@moduledef.function("!~")
def method_not_match(self, space, w_other):
return space.newbool(not space.is_true(space.send(self, space.newsymbol("=~"), [w_other])))
return space.newbool(not space.is_true(space.send(self, "=~", [w_other])))

@moduledef.function("eql?")
def method_eqlp(self, space, w_other):
@@ -242,12 +240,12 @@ def method_instance_variable_definedp(self, space, name):

@moduledef.method("respond_to?", include_private="bool")
def method_respond_top(self, space, w_name, include_private=False):
if space.respond_to(self, w_name):
if space.respond_to(self, space.symbol_w(w_name)):
return space.newbool(True)

w_found = space.send(
self,
space.newsymbol("respond_to_missing?"),
"respond_to_missing?",
[w_name, space.newbool(include_private)]
)
return space.newbool(space.is_true(w_found))
@@ -262,11 +260,11 @@ def method_dup(self, space):
self is space.w_false or space.is_kind_of(self, space.w_symbol) or
space.is_kind_of(self, space.w_fixnum)):
raise space.error(space.w_TypeError, "can't dup %s" % space.getclass(self).name)
w_dup = space.send(space.getnonsingletonclass(self), space.newsymbol("allocate"))
w_dup = space.send(space.getnonsingletonclass(self), "allocate")
w_dup.copy_instance_vars(space, self)
w_dup.copy_flags(space, self)
w_dup.unset_flag(space, "frozen?")
space.send(w_dup, space.newsymbol("initialize_dup"), [self])
space.send(w_dup, "initialize_dup", [self])
return w_dup

@moduledef.method("clone")
@@ -275,11 +273,11 @@ def method_clone(self, space):
self is space.w_false or space.is_kind_of(self, space.w_symbol) or
space.is_kind_of(self, space.w_fixnum)):
raise space.error(space.w_TypeError, "can't dup %s" % space.getclass(self).name)
w_dup = space.send(space.getnonsingletonclass(self), space.newsymbol("allocate"))
w_dup = space.send(space.getnonsingletonclass(self), "allocate")
w_dup.copy_instance_vars(space, self)
w_dup.copy_flags(space, self)
w_dup.copy_singletonclass(space, space.getsingletonclass(self))
space.send(w_dup, space.newsymbol("initialize_clone"), [self])
space.send(w_dup, "initialize_clone", [self])
return w_dup

@moduledef.method("sleep")
@@ -293,7 +291,7 @@ def method_sleep(self, space, w_duration=None):
@moduledef.method("initialize_clone")
@moduledef.method("initialize_dup")
def method_initialize_dup(self, space, w_other):
space.send(self, space.newsymbol("initialize_copy"), [w_other])
space.send(self, "initialize_copy", [w_other])
return self

@moduledef.method("initialize_copy")
@@ -337,7 +335,7 @@ def method_eval(self, space, w_source, w_binding=None):
raise space.error(space.w_TypeError,
"wrong argument type %s (expected Binding)" % space.getclass(w_binding).name
)
return space.send(w_binding, space.newsymbol("eval"), [w_source])
return space.send(w_binding, "eval", [w_source])

@moduledef.method("set_trace_func")
def method_set_trace_func(self, space, w_proc):
@@ -108,8 +108,7 @@ def method_lgamma(self, space, value):
except (ValueError, OverflowError):
res = rfloat.INFINITY
gamma = (1 if value == -1 or math.isnan(value) else
space.float_w(space.send(self, space.newsymbol("gamma"),
[space.newfloat(value)])))
space.float_w(space.send(self, "gamma", [space.newfloat(value)])))
sign = 1 if gamma > 0 else -1 if gamma < 0 else 0
return space.newarray([space.newfloat(res), space.newint(sign)])

@@ -24,7 +24,7 @@ class ObjectSpace(object):
@moduledef.function("each_object")
def method_each_object(self, space, w_mod, block):
if block is None:
return space.send(self, space.newsymbol("enum_for"), [space.newsymbol("each_object"), w_mod], block)
return space.send(self, "enum_for", [space.newsymbol("each_object"), w_mod], block)
match_w = []
roots = [gcref for gcref in rgc.get_rpy_roots() if gcref]
pending = roots[:]

0 comments on commit 04ab62f

Please sign in to comment.
You can’t perform that action at this time.