Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Merge pull request #705 from krekoten/constant_lookup
- Loading branch information
Oops, something went wrong.
|
@@ -223,20 +223,14 @@ def LOAD_LOCAL_CONSTANT(self, space, bytecode, frame, pc, idx): |
|
|
@jit.unroll_safe |
|
|
def DEFINED_LOCAL_CONSTANT(self, space, bytecode, frame, pc, idx): |
|
|
space.getexecutioncontext().last_instr = pc |
|
|
w_name = bytecode.consts_w[idx] |
|
|
frame.pop() |
|
|
scope = jit.promote(frame.lexical_scope) |
|
|
while scope is not None: |
|
|
w_mod = scope.w_mod |
|
|
if space.is_true(space.send(w_mod, "const_defined?", [w_name])): |
|
|
frame.push(space.newstr_fromstr("constant")) |
|
|
break |
|
|
scope = scope.backscope |
|
|
w_name = bytecode.consts_w[idx] |
|
|
name = space.symbol_w(w_name) |
|
|
w_res = space._find_lexical_const(jit.promote(frame.lexical_scope), name) |
|
|
if w_res is None: |
|
|
frame.push(space.w_nil) |
|
|
else: |
|
|
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) |
|
|
frame.push(space.newstr_fromstr("constant")) |
|
|
|
|
|
def LOAD_INSTANCE_VAR(self, space, bytecode, frame, pc, idx): |
|
|
w_name = bytecode.consts_w[idx] |
|
|
|
@@ -208,6 +208,8 @@ def __init__(self, config): |
|
|
w_cls |
|
|
) |
|
|
|
|
|
self.set_const(self.w_basicobject, "BasicObject", self.w_basicobject) |
|
|
|
|
|
# This is bootstrap. We have to delay sending until true, false and nil |
|
|
# are defined |
|
|
self.send(self.w_object, "include", [self.w_kernel]) |
|
@@ -530,19 +532,45 @@ def set_const(self, module, name, w_value): |
|
|
module.set_const(self, name, w_value) |
|
|
|
|
|
@jit.unroll_safe |
|
|
def find_lexical_const(self, lexical_scope, name): |
|
|
def _find_lexical_const(self, lexical_scope, name): |
|
|
w_res = None |
|
|
scope = lexical_scope |
|
|
# perform lexical search but skip Object |
|
|
while scope is not None: |
|
|
w_mod = scope.w_mod |
|
|
if w_mod is self.w_top_self: |
|
|
break |
|
|
w_res = w_mod.find_local_const(self, name) |
|
|
if w_res is not None: |
|
|
return w_res |
|
|
scope = scope.backscope |
|
|
|
|
|
object_seen = False |
|
|
fallback_scope = self.w_object |
|
|
|
|
|
if lexical_scope is not None: |
|
|
w_res = lexical_scope.w_mod.find_const(self, name) |
|
|
if w_res is None: |
|
|
w_res = self.w_object.find_const(self, name) |
|
|
w_mod = lexical_scope.w_mod |
|
|
while w_mod is not None: |
|
|
object_seen = w_mod is self.w_object |
|
|
# BasicObject was our starting point, do not use Object |
|
|
# as fallback |
|
|
if w_mod is self.w_basicobject and not object_seen: |
|
|
fallback_scope = None |
|
|
w_res = w_mod.find_const(self, name) |
|
|
if w_res is not None: |
|
|
return w_res |
|
|
if isinstance(w_mod, W_ClassObject): |
|
|
w_mod = w_mod.superclass |
|
|
else: |
|
|
break |
|
|
|
|
|
if fallback_scope is not None: |
|
|
w_res = fallback_scope.find_const(self, name) |
|
|
return w_res |
|
|
|
|
|
@jit.unroll_safe |
|
|
def find_lexical_const(self, lexical_scope, name): |
|
|
w_res = self._find_lexical_const(lexical_scope, name) |
|
|
if w_res is None: |
|
|
if lexical_scope is not None: |
|
|
w_mod = lexical_scope.w_mod |
|
|