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
009516c7
Commit
009516c7
authored
Jun 24, 2014
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor fixes, and a new gcj-based benchmark
parent
119ecf1a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
98 additions
and
1 deletion
+98
-1
microbenchmarks/gcj_2014_3_b.py
microbenchmarks/gcj_2014_3_b.py
+88
-0
src/analysis/type_analysis.cpp
src/analysis/type_analysis.cpp
+9
-0
src/runtime/list.cpp
src/runtime/list.cpp
+1
-1
No files found.
microbenchmarks/gcj_2014_3_b.py
0 → 100644
View file @
009516c7
import
sys
if
__name__
==
"__main__"
:
f
=
sys
.
stdin
if
len
(
sys
.
argv
)
>=
2
:
fn
=
sys
.
argv
[
1
]
if
fn
!=
'-'
:
f
=
open
(
fn
)
# test data is from the Google CodeJam site:
s
=
"""1
\
n
22 20 100
\
n
195 649898
\
n
191 583577
\
n
190 70961
\
n
192 608854
\
n
193 43725
\
n
193 647827
\
n
193 339043
\
n
190 270370
\
n
191 68136
\
n
198 505964
\
n
193 20802
\
n
191 285258
\
n
191 80670
\
n
193 183965
\
n
194 16065
\
n
190 76452
\
n
197 91485
\
n
199 170286
\
n
190 445988
\
n
193 324817
\
n
190 87804
\
n
193 6882
\
n
193 226516
\
n
190 465689
\
n
194 146167
\
n
192 127049
\
n
191 176172
\
n
192 396031
\
n
192 398308
\
n
192 108078
\
n
190 13378
\
n
192 38714
\
n
191 589111
\
n
192 437328
\
n
193 618750
\
n
190 14397
\
n
190 704848
\
n
194 48882
\
n
192 574139
\
n
191 480711
\
n
194 357559
\
n
191 63176
\
n
193 175447
\
n
194 258453
\
n
191 706947
\
n
190 12511
\
n
191 181170
\
n
192 21592
\
n
195 359968
\
n
193 92393
\
n
199 116308
\
n
190 352072
\
n
195 402952
\
n
191 135017
\
n
192 277287
\
n
190 129665
\
n
192 428804
\
n
194 51461
\
n
190 171899
\
n
192 69424
\
n
192 638021
\
n
190 224689
\
n
190 118853
\
n
191 82341
\
n
192 172974
\
n
199 8643
\
n
192 34032
\
n
190 166043
\
n
190 228990
\
n
192 79741
\
n
200 183198
\
n
191 348403
\
n
195 22955
\
n
198 258715
\
n
192 389063
\
n
191 283406
\
n
192 519332
\
n
190 40562
\
n
191 62096
\
n
191 475046
\
n
192 22699
\
n
190 39911
\
n
197 268042
\
n
192 170463
\
n
192 108990
\
n
191 357464
\
n
191 144522
\
n
192 461237
\
n
194 327871
\
n
190 67947
\
n
190 748144
\
n
190 106941
\
n
194 44355
\
n
193 81455
\
n
191 65589
\
n
190 486823
\
n
200 375651
\
n
192 636531
\
n
190 18524
\
n
192 38697"""
l
=
s
.
split
(
'
\
n
'
)
T
=
int
(
l
.
pop
(
0
))
for
_T
in
xrange
(
T
):
P
,
Q
,
N
=
map
(
int
,
l
.
pop
(
0
).
split
())
healths
=
[]
golds
=
[]
for
i
in
xrange
(
N
):
h
,
g
=
map
(
int
,
l
.
pop
(
0
).
split
())
healths
.
append
(
h
)
golds
.
append
(
g
)
def
num_hits_to_win
(
h
):
assert
h
>
0
if
P
>
Q
:
return
1
t
=
1
while
True
:
m
=
((
h
-
1
)
%
Q
)
+
1
if
1
<=
m
<=
P
:
return
t
h
-=
P
t
+=
1
# for h in healths:
# print h, num_hits_to_win(h)
cur
=
{
1
:
0
}
for
i
in
xrange
(
N
):
next
=
{}
hits_needed
=
num_hits_to_win
(
healths
[
i
])
would_win
=
golds
[
i
]
# print
# print "On creep %d" % i
for
shots
,
money
in
cur
.
iteritems
():
# print "Could have %d shots and %d gold" % (shots, money)
do_nothing
=
(
healths
[
i
]
+
Q
-
1
)
/
Q
+
shots
# print "do nothing and would have %d shots" % do_nothing
next
[
do_nothing
]
=
max
(
next
.
get
(
do_nothing
,
0
),
money
)
health
=
healths
[
i
]
if
shots
==
0
:
health
-=
Q
shots
+=
1
if
health
<=
0
:
continue
# min_tower_shots = hits_needed - shots
# if min_tower_shots * Q + (hits_needed - 1) * P > health:
# continue
tower_shots
=
max
((
health
-
(
hits_needed
-
1
)
*
P
-
1
)
/
Q
,
0
)
next_shots
=
shots
-
hits_needed
+
tower_shots
# print "tower shoots %d times, we shoot %d times; we'd have %d shots" % (tower_shots, hits_needed, next_shots)
if
next_shots
<
0
:
# print "we only have %d initial shots"
continue
next
[
next_shots
]
=
max
(
next
.
get
(
next_shots
,
0
),
money
+
would_win
)
cur
=
next
# print cur
best
=
max
(
cur
.
itervalues
())
print
"Case #%d: %d"
%
(
_T
+
1
,
best
)
src/analysis/type_analysis.cpp
View file @
009516c7
...
...
@@ -197,9 +197,16 @@ private:
return
rtn
;
}
bool
hasFixedBinops
(
CompilerType
*
type
)
{
// This is non-exhaustive:
return
type
==
STR
||
type
==
INT
||
type
==
FLOAT
||
type
==
LIST
||
type
==
DICT
;
}
virtual
void
*
visit_augbinop
(
AST_AugBinOp
*
node
)
{
CompilerType
*
left
=
getType
(
node
->
left
);
CompilerType
*
right
=
getType
(
node
->
right
);
if
(
!
hasFixedBinops
(
left
)
||
!
hasFixedBinops
(
right
))
return
UNKNOWN
;
// TODO this isn't the exact behavior
std
::
string
name
=
getInplaceOpName
(
node
->
op_type
);
...
...
@@ -227,6 +234,8 @@ private:
virtual
void
*
visit_binop
(
AST_BinOp
*
node
)
{
CompilerType
*
left
=
getType
(
node
->
left
);
CompilerType
*
right
=
getType
(
node
->
right
);
if
(
!
hasFixedBinops
(
left
)
||
!
hasFixedBinops
(
right
))
return
UNKNOWN
;
// TODO this isn't the exact behavior
const
std
::
string
&
name
=
getOpName
(
node
->
op_type
);
...
...
src/runtime/list.cpp
View file @
009516c7
...
...
@@ -559,7 +559,7 @@ void setupList() {
list_cls
->
giveAttr
(
"__delitem__"
,
new
BoxedFunction
(
delitem
));
list_cls
->
giveAttr
(
"insert"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
listInsert
,
NONE
,
3
)));
list_cls
->
giveAttr
(
"__mul__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
listMul
,
NONE
,
2
)));
list_cls
->
giveAttr
(
"__mul__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
listMul
,
LIST
,
2
)));
list_cls
->
giveAttr
(
"__iadd__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
listIAdd
,
UNKNOWN
,
2
)));
list_cls
->
giveAttr
(
"__add__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
listAdd
,
UNKNOWN
,
2
)));
...
...
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