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
56d294f7
Commit
56d294f7
authored
Dec 29, 2016
by
Dylan Trotter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove unused name and filename fields from Block.
parent
0d165d59
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
11 additions
and
18 deletions
+11
-18
compiler/util.py
compiler/util.py
+2
-5
runtime/block.go
runtime/block.go
+2
-6
runtime/block_test.go
runtime/block_test.go
+3
-3
runtime/generator_test.go
runtime/generator_test.go
+4
-4
No files found.
compiler/util.py
View file @
56d294f7
...
...
@@ -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:'
)
...
...
runtime/block.go
View file @
56d294f7
...
...
@@ -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.
...
...
runtime/block_test.go
View file @
56d294f7
...
...
@@ -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
)
})
...
...
runtime/generator_test.go
View file @
56d294f7
...
...
@@ -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
...
...
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