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):
...
@@ -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:'
)
...
...
runtime/block.go
View file @
56d294f7
...
@@ -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.
...
...
runtime/block_test.go
View file @
56d294f7
...
@@ -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
)
})
})
...
...
runtime/generator_test.go
View file @
56d294f7
...
@@ -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
...
...
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