Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
grumpy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
grumpy
Commits
e06bed33
Commit
e06bed33
authored
Dec 29, 2016
by
Dylan Trotter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove globals param from ResolveGlobal() and ResolveClass() in favor of f.Globals().
parent
a2998b94
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
9 deletions
+14
-9
compiler/block.py
compiler/block.py
+2
-2
runtime/core.go
runtime/core.go
+5
-5
runtime/core_test.go
runtime/core_test.go
+7
-2
No files found.
compiler/block.py
View file @
e06bed33
...
@@ -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
...
...
runtime/core.go
View file @
e06bed33
...
@@ -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
())
...
...
runtime/core_test.go
View file @
e06bed33
...
@@ -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
)
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment