Commit e06bed33 authored by Dylan Trotter's avatar Dylan Trotter

Remove globals param from ResolveGlobal() and ResolveClass() in favor of f.Globals().

parent a2998b94
...@@ -195,7 +195,7 @@ class Block(object): ...@@ -195,7 +195,7 @@ class Block(object):
def _resolve_global(self, writer, name): def _resolve_global(self, writer, name):
result = self.alloc_temp() result = self.alloc_temp()
writer.write_checked_call2( writer.write_checked_call2(
result, 'πg.ResolveGlobal(πF, πF.Globals(), {})', self.intern(name)) result, 'πg.ResolveGlobal(πF, {})', self.intern(name))
return result return result
...@@ -264,7 +264,7 @@ class ClassBlock(Block): ...@@ -264,7 +264,7 @@ class ClassBlock(Block):
block = block.parent_block block = block.parent_block
result = self.alloc_temp() result = self.alloc_temp()
writer.write_checked_call2( writer.write_checked_call2(
result, 'πg.ResolveClass(πF, πClass, {}, πF.Globals(), {})', result, 'πg.ResolveClass(πF, πClass, {}, {})',
local, self.intern(name)) local, self.intern(name))
return result return result
......
...@@ -599,7 +599,7 @@ func Repr(f *Frame, o *Object) (*Str, *BaseException) { ...@@ -599,7 +599,7 @@ func Repr(f *Frame, o *Object) (*Str, *BaseException) {
// definition. If the class definition occurs in a closure in which a local of // definition. If the class definition occurs in a closure in which a local of
// the given name is present then local will be non-nil, otherwise it will be // the given name is present then local will be non-nil, otherwise it will be
// nil. // nil.
func ResolveClass(f *Frame, class *Dict, local *Object, globals *Dict, name *Str) (*Object, *BaseException) { func ResolveClass(f *Frame, class *Dict, local *Object, name *Str) (*Object, *BaseException) {
if value, raised := class.GetItem(f, name.ToObject()); raised != nil || value != nil { if value, raised := class.GetItem(f, name.ToObject()); raised != nil || value != nil {
return value, raised return value, raised
} }
...@@ -609,13 +609,13 @@ func ResolveClass(f *Frame, class *Dict, local *Object, globals *Dict, name *Str ...@@ -609,13 +609,13 @@ func ResolveClass(f *Frame, class *Dict, local *Object, globals *Dict, name *Str
} }
return local, nil return local, nil
} }
return ResolveGlobal(f, globals, name) return ResolveGlobal(f, name)
} }
// ResolveGlobal looks up name in the given dict of global variables or in // ResolveGlobal looks up name in the frame's dict of global variables or in
// the Builtins dict if absent. It raises NameError when absent from both. // the Builtins dict if absent. It raises NameError when absent from both.
func ResolveGlobal(f *Frame, globals *Dict, name *Str) (*Object, *BaseException) { func ResolveGlobal(f *Frame, name *Str) (*Object, *BaseException) {
if value, raised := globals.GetItem(f, name.ToObject()); raised != nil || value != nil { if value, raised := f.Globals().GetItem(f, name.ToObject()); raised != nil || value != nil {
return value, raised return value, raised
} }
value, raised := Builtins.GetItem(f, name.ToObject()) value, raised := Builtins.GetItem(f, name.ToObject())
......
...@@ -740,7 +740,8 @@ func TestResolveClass(t *testing.T) { ...@@ -740,7 +740,8 @@ func TestResolveClass(t *testing.T) {
{NewDict(), nil, NewDict(), "foo", nil, mustCreateException(NameErrorType, "name 'foo' is not defined")}, {NewDict(), nil, NewDict(), "foo", nil, mustCreateException(NameErrorType, "name 'foo' is not defined")},
} }
for _, cas := range cases { for _, cas := range cases {
got, raised := ResolveClass(f, cas.class, cas.local, cas.globals, NewStr(cas.name)) f.globals = cas.globals
got, raised := ResolveClass(f, cas.class, cas.local, NewStr(cas.name))
switch checkResult(got, cas.want, raised, cas.wantExc) { switch checkResult(got, cas.want, raised, cas.wantExc) {
case checkInvokeResultExceptionMismatch: case checkInvokeResultExceptionMismatch:
t.Errorf("ResolveClass(%v, %q) raised %v, want %v", cas.globals, cas.name, raised, cas.wantExc) t.Errorf("ResolveClass(%v, %q) raised %v, want %v", cas.globals, cas.name, raised, cas.wantExc)
...@@ -751,13 +752,17 @@ func TestResolveClass(t *testing.T) { ...@@ -751,13 +752,17 @@ func TestResolveClass(t *testing.T) {
} }
func TestResolveGlobal(t *testing.T) { func TestResolveGlobal(t *testing.T) {
fun := wrapFuncForTest(func(f *Frame, globals *Dict, name *Str) (*Object, *BaseException) {
f.globals = globals
return ResolveGlobal(f, name)
})
cases := []invokeTestCase{ cases := []invokeTestCase{
{args: wrapArgs(newStringDict(map[string]*Object{"foo": NewStr("bar").ToObject()}), "foo"), want: NewStr("bar").ToObject()}, {args: wrapArgs(newStringDict(map[string]*Object{"foo": NewStr("bar").ToObject()}), "foo"), want: NewStr("bar").ToObject()},
{args: wrapArgs(NewDict(), "str"), want: StrType.ToObject()}, {args: wrapArgs(NewDict(), "str"), want: StrType.ToObject()},
{args: wrapArgs(NewDict(), "foo"), wantExc: mustCreateException(NameErrorType, "name 'foo' is not defined")}, {args: wrapArgs(NewDict(), "foo"), wantExc: mustCreateException(NameErrorType, "name 'foo' is not defined")},
} }
for _, cas := range cases { for _, cas := range cases {
if err := runInvokeTestCase(wrapFuncForTest(ResolveGlobal), &cas); err != "" { if err := runInvokeTestCase(fun, &cas); err != "" {
t.Error(err) t.Error(err)
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment