Commit 56d294f7 authored by Dylan Trotter's avatar Dylan Trotter

Remove unused name and filename fields from Block.

parent 0d165d59
......@@ -65,11 +65,8 @@ class Writer(object):
self.write('var πE *πg.BaseException\n_ = πE')
self.write_temp_decls(block_)
# Write the function body.
self.write_tmpl('πBlock := πg.NewBlock($name, $filename, '
'func(πF *πg.Frame, πSent *πg.Object) '
'(*πg.Object, *πg.BaseException) {',
name=go_str(block_.name),
filename=go_str(block_.filename))
self.write('πBlock := πg.NewBlock(func(πF *πg.Frame, πSent *πg.Object) '
'(*πg.Object, *πg.BaseException) {')
with self.indent_block():
self.write('switch πF.State() {')
self.write('case 0:')
......
......@@ -17,18 +17,14 @@ package grumpy
// Block is a handle to code that runs in a new scope such as a function, class
// or module.
type Block struct {
// name is the name of the compiled function or class, or "<module>".
name string
// filename is the path of the file where the Python code originated.
filename string
// fn is a closure that executes the body of the code block. It may be
// re-entered multiple times, e.g. for exception handling.
fn func(*Frame, *Object) (*Object, *BaseException)
}
// NewBlock creates a Block object.
func NewBlock(name, filename string, fn func(*Frame, *Object) (*Object, *BaseException)) *Block {
return &Block{name, filename, fn}
func NewBlock(fn func(*Frame, *Object) (*Object, *BaseException)) *Block {
return &Block{fn}
}
// Exec runs b in the context of a new child frame of back.
......
......@@ -25,7 +25,7 @@ func TestBlockExecTryExcept(t *testing.T) {
e *BaseException
}
args := []blockArgs{}
b := NewBlock("<test>", "foo.py", func(f *Frame, _ *Object) (*Object, *BaseException) {
b := NewBlock(func(f *Frame, _ *Object) (*Object, *BaseException) {
e, _ := f.ExcInfo()
switch f.State() {
case 0:
......@@ -60,11 +60,11 @@ func TestBlockExecTryExcept(t *testing.T) {
func TestBlockExecRaises(t *testing.T) {
var f1, f2 *Frame
globals := NewDict()
b1 := NewBlock("<b1>", "foo.py", func(f *Frame, _ *Object) (*Object, *BaseException) {
b1 := NewBlock(func(f *Frame, _ *Object) (*Object, *BaseException) {
f1 = f
return nil, f.RaiseType(ValueErrorType, "bar")
})
b2 := NewBlock("<b2>", "foo.py", func(f *Frame, _ *Object) (*Object, *BaseException) {
b2 := NewBlock(func(f *Frame, _ *Object) (*Object, *BaseException) {
f2 = f
return b1.Exec(f, globals)
})
......
......@@ -20,7 +20,7 @@ import (
func TestGeneratorNext(t *testing.T) {
var recursive *Object
recursiveBlock := NewBlock("<test>", "test.py", func(f *Frame, _ *Object) (*Object, *BaseException) {
recursiveBlock := NewBlock(func(f *Frame, _ *Object) (*Object, *BaseException) {
next, raised := GetAttr(f, recursive, NewStr("next"), nil)
if raised != nil {
return nil, raised
......@@ -28,7 +28,7 @@ func TestGeneratorNext(t *testing.T) {
return next.Call(f, nil, nil)
})
recursive = NewGenerator(recursiveBlock, NewDict()).ToObject()
empty := NewBlock("<test>", "test.py", func(f *Frame, _ *Object) (*Object, *BaseException) {
empty := NewBlock(func(f *Frame, _ *Object) (*Object, *BaseException) {
return nil, f.Raise(StopIterationType.ToObject(), nil, nil)
})
exhausted := NewGenerator(empty, NewDict()).ToObject()
......@@ -45,7 +45,7 @@ func TestGeneratorNext(t *testing.T) {
}
func TestGeneratorSend(t *testing.T) {
empty := NewBlock("<test>", "test.py", func(f *Frame, _ *Object) (*Object, *BaseException) {
empty := NewBlock(func(f *Frame, _ *Object) (*Object, *BaseException) {
return nil, f.Raise(StopIterationType.ToObject(), nil, nil)
})
cases := []invokeTestCase{
......@@ -60,7 +60,7 @@ func TestGeneratorSend(t *testing.T) {
}
func TestGeneratorSimple(t *testing.T) {
b := NewBlock("<test>", "test.py", func(f *Frame, _ *Object) (*Object, *BaseException) {
b := NewBlock(func(f *Frame, _ *Object) (*Object, *BaseException) {
switch f.State() {
case 0:
goto Start
......
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