Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
Pyston
Commits
09d084d1
Commit
09d084d1
authored
May 20, 2014
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add some a new test (a gcj solution) and start making it work
parent
cb37b376
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
150 additions
and
5 deletions
+150
-5
src/Makefile
src/Makefile
+1
-0
src/codegen/parser.cpp
src/codegen/parser.cpp
+1
-1
src/core/cfg.cpp
src/core/cfg.cpp
+22
-4
test/tests/exceptions_controlflow.py
test/tests/exceptions_controlflow.py
+11
-0
test/tests/gcj_2014_1a_b.py
test/tests/gcj_2014_1a_b.py
+115
-0
No files found.
src/Makefile
View file @
09d084d1
...
...
@@ -668,6 +668,7 @@ define make_search
$(eval
\
$1
:
../test/tests/$1 ;
$1
:
../microbenchmarks/$1 ;
$1
:
../millibenchmarks/$1 ;
$1
:
../benchmarks/$1 ;
)
endef
...
...
src/codegen/parser.cpp
View file @
09d084d1
...
...
@@ -135,7 +135,7 @@ template <class T> static void readMiscVector(std::vector<T*>& vec, BufferedRead
static
int
readColOffset
(
BufferedReader
*
reader
)
{
int
rtn
=
reader
->
readULL
();
// offsets out of this range are almost certainly parse bugs:
ASSERT
(
rtn
>=
0
&&
rtn
<
100000
,
"%d"
,
rtn
);
ASSERT
(
rtn
>=
-
1
&&
rtn
<
100000
,
"%d"
,
rtn
);
return
rtn
;
}
...
...
src/core/cfg.cpp
View file @
09d084d1
...
...
@@ -301,6 +301,11 @@ private:
// Probably better to create an AST_Callattr type, and solidify the
// idea that a callattr is a single expression.
rtn
->
func
=
remapAttribute
(
ast_cast
<
AST_Attribute
>
(
node
->
func
));
}
else
if
(
node
->
func
->
type
==
AST_TYPE
::
ClsAttribute
)
{
// TODO this is a cludge to make sure that "callattrs" stick together.
// Probably better to create an AST_Callattr type, and solidify the
// idea that a callattr is a single expression.
rtn
->
func
=
remapClsAttribute
(
ast_cast
<
AST_ClsAttribute
>
(
node
->
func
));
}
else
{
rtn
->
func
=
remapExpr
(
node
->
func
);
}
...
...
@@ -320,6 +325,14 @@ private:
return
rtn
;
}
AST_expr
*
remapClsAttribute
(
AST_ClsAttribute
*
node
)
{
AST_ClsAttribute
*
rtn
=
new
AST_ClsAttribute
();
rtn
->
attr
=
node
->
attr
;
rtn
->
value
=
remapExpr
(
node
->
value
);
return
rtn
;
}
AST_expr
*
remapCompare
(
AST_Compare
*
node
)
{
AST_Compare
*
rtn
=
new
AST_Compare
();
rtn
->
lineno
=
node
->
lineno
;
...
...
@@ -461,7 +474,7 @@ private:
push_back
(
j
);
curblock
=
test_block
;
AST_expr
*
test_call
=
makeCall
(
hasnext_attr
);
AST_expr
*
test_call
=
remapExpr
(
makeCall
(
hasnext_attr
)
);
CFGBlock
*
body_block
=
cfg
->
addBlock
();
body_block
->
info
=
"listcomp_body"
;
...
...
@@ -623,6 +636,9 @@ private:
case
AST_TYPE
:
:
Call
:
rtn
=
remapCall
(
ast_cast
<
AST_Call
>
(
node
));
break
;
case
AST_TYPE
:
:
ClsAttribute
:
rtn
=
remapClsAttribute
(
ast_cast
<
AST_ClsAttribute
>
(
node
));
break
;
case
AST_TYPE
:
:
Compare
:
rtn
=
remapCompare
(
ast_cast
<
AST_Compare
>
(
node
));
break
;
...
...
@@ -709,7 +725,7 @@ public:
if
(
type
==
AST_TYPE
::
Branch
)
{
AST_TYPE
::
AST_TYPE
test_type
=
ast_cast
<
AST_Branch
>
(
node
)
->
test
->
type
;
assert
(
test_type
==
AST_TYPE
::
Name
||
test_type
==
AST_TYPE
::
Num
);
ASSERT
(
test_type
==
AST_TYPE
::
Name
||
test_type
==
AST_TYPE
::
Num
,
"%d"
,
test_type
);
curblock
->
push_back
(
node
);
return
;
}
...
...
@@ -1147,7 +1163,7 @@ public:
curblock
=
test_block
;
AST_expr
*
test_call
=
makeCall
(
hasnext_attr
);
AST_Branch
*
test_br
=
makeBranch
(
test_call
);
AST_Branch
*
test_br
=
makeBranch
(
remapExpr
(
test_call
)
);
push_back
(
test_br
);
CFGBlock
*
test_true
=
cfg
->
addBlock
();
...
...
@@ -1187,7 +1203,7 @@ public:
if
(
curblock
)
{
AST_expr
*
end_call
=
makeCall
(
hasnext_attr
);
AST_Branch
*
end_br
=
makeBranch
(
end_call
);
AST_Branch
*
end_br
=
makeBranch
(
remapExpr
(
end_call
)
);
push_back
(
end_br
);
CFGBlock
*
end_true
=
cfg
->
addBlock
();
...
...
@@ -1487,6 +1503,8 @@ CFG* computeCFG(AST_TYPE::AST_TYPE root_type, std::vector<AST_stmt*> body) {
return_stmt
->
value
=
NULL
;
visitor
.
push_back
(
return_stmt
);
// rtn->print();
#ifndef NDEBUG
////
// Check some properties expected by later stages:
...
...
test/tests/exceptions_controlflow.py
0 → 100644
View file @
09d084d1
# expected: fail
# - working on it
# Regression test:
for
i
in
xrange
(
5
):
try
:
for
j
in
xrange
(
5
):
print
i
,
j
except
:
pass
test/tests/gcj_2014_1a_b.py
0 → 100644
View file @
09d084d1
# expected: fail
# - working on it
import
sys
def
compact
(
s
):
i
=
0
while
i
<
len
(
s
)
-
1
:
if
s
[
i
]
==
s
[
i
+
1
]:
s
=
s
[:
i
]
+
s
[
i
+
1
:]
else
:
i
+=
1
return
s
class
NotPossible
(
Exception
):
pass
P
=
1000000007
def
fact
(
n
):
t
=
1
for
i
in
xrange
(
1
,
n
+
1
):
t
=
(
t
*
i
)
%
P
return
t
if
__name__
==
"__main__"
:
s
=
"""
3
3
ab bbbc cd
4
aa aa bc c
2
abc bcd
"""
.
strip
()
l
=
s
.
split
(
'
\
n
'
)
T
=
int
(
l
.
pop
(
0
))
for
_T
in
xrange
(
T
):
N
=
int
(
l
.
pop
(
0
))
trains
=
l
.
pop
(
0
).
split
()
trains
=
map
(
compact
,
trains
)
try
:
for
s
in
trains
:
if
s
[
0
]
in
s
[
1
:]:
raise
NotPossible
if
s
[
-
1
]
in
s
[:
-
1
]:
raise
NotPossible
for
c
in
s
[
1
:
-
1
]:
cnt
=
sum
([
s2
.
count
(
c
)
for
s2
in
trains
])
assert
cnt
>=
1
if
cnt
!=
1
:
raise
NotPossible
()
# print trains
singles
=
{}
chunks
=
[]
for
i
in
xrange
(
N
):
if
len
(
trains
[
i
])
==
1
:
singles
[
trains
[
i
]]
=
singles
.
get
(
trains
[
i
],
0
)
+
1
else
:
chunks
.
append
(
trains
[
i
][
0
]
+
trains
[
i
][
-
1
])
# print singles, chunks
mult
=
1
left
=
0
while
chunks
:
# print mult, left, singles, chunks
first
=
chunks
.
pop
()
assert
len
(
set
(
first
))
==
len
(
first
)
mult
=
(
mult
*
fact
(
singles
.
pop
(
first
[
0
],
0
)))
%
P
mult
=
(
mult
*
fact
(
singles
.
pop
(
first
[
-
1
],
0
)))
%
P
for
ch
in
chunks
:
assert
len
(
set
(
ch
))
==
len
(
ch
)
if
ch
[
0
]
in
first
:
if
ch
[
0
]
in
first
[:
-
1
]:
raise
NotPossible
()
# assert not any(c == ch[0] for c in ch[1:])
if
any
([
c
in
first
for
c
in
ch
[
1
:]]):
raise
NotPossible
()
assert
ch
[
0
]
==
first
[
-
1
]
chunks
.
remove
(
ch
)
chunks
.
append
(
first
+
ch
[
1
:])
break
if
ch
[
-
1
]
in
first
:
if
ch
[
-
1
]
in
first
[
1
:]:
raise
NotPossible
()
# assert not any(c == ch[-1] for c in ch[:-1])
if
any
([
c
in
first
for
c
in
ch
[:
-
1
]]):
raise
NotPossible
()
assert
ch
[
-
1
]
==
first
[
0
]
chunks
.
remove
(
ch
)
chunks
.
append
(
ch
+
first
[
1
:])
break
else
:
left
+=
1
continue
# print mult, left, singles, chunks
for
k
,
v
in
singles
.
iteritems
():
left
+=
1
mult
=
(
mult
*
fact
(
v
))
%
P
assert
left
>=
0
while
left
:
mult
=
(
mult
*
left
)
%
P
left
=
left
-
1
print
"Case #%d: %d"
%
(
_T
+
1
,
mult
)
except
NotPossible
:
print
"Case #%d: 0"
%
(
_T
+
1
,)
assert
not
l
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