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