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
86096848
Commit
86096848
authored
Jul 29, 2015
by
Dong-hee,Na
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
using try-catch block for throwing exceptions
and remove raw_ostream for displaying data structure
parent
4c743cb6
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
120 additions
and
64 deletions
+120
-64
src/runtime/dict.cpp
src/runtime/dict.cpp
+20
-10
src/runtime/list.cpp
src/runtime/list.cpp
+27
-19
src/runtime/set.cpp
src/runtime/set.cpp
+38
-15
src/runtime/tuple.cpp
src/runtime/tuple.cpp
+35
-20
No files found.
src/runtime/dict.cpp
View file @
86096848
...
...
@@ -32,21 +32,31 @@ using pyston::ExceptionStyle::ExceptionStyle;
Box
*
dictRepr
(
BoxedDict
*
self
)
{
int
status
=
Py_ReprEnter
((
PyObject
*
)
self
);
std
::
vector
<
char
>
chars
;
if
(
status
!=
0
)
{
if
(
status
<
0
)
return
boxString
(
llvm
::
StringRef
(
&
chars
[
0
],
chars
.
size
()));
try
{
int
status
=
Py_ReprEnter
((
PyObject
*
)
self
);
if
(
status
!=
0
)
{
if
(
status
<
0
)
throwCAPIException
();
chars
.
push_back
(
'{'
);
chars
.
push_back
(
'.'
);
chars
.
push_back
(
'.'
);
chars
.
push_back
(
'.'
);
chars
.
push_back
(
'}'
);
chars
.
push_back
(
'{'
);
chars
.
push_back
(
'.'
);
chars
.
push_back
(
'.'
);
chars
.
push_back
(
'.'
);
chars
.
push_back
(
'}'
);
return
boxString
(
llvm
::
StringRef
(
&
chars
[
0
],
chars
.
size
()));
}
return
boxString
(
llvm
::
StringRef
(
&
chars
[
0
],
chars
.
size
()));
}
catch
(
ExcInfo
e
)
{
setCAPIException
(
e
);
Py_ReprLeave
((
PyObject
*
)
self
);
return
NULL
;
}
chars
.
push_back
(
'{'
);
bool
first
=
true
;
for
(
const
auto
&
p
:
self
->
d
)
{
if
(
!
first
)
{
...
...
src/runtime/list.cpp
View file @
86096848
...
...
@@ -17,8 +17,6 @@
#include <algorithm>
#include <cstring>
#include "llvm/Support/raw_ostream.h"
#include "capi/types.h"
#include "core/ast.h"
#include "core/common.h"
...
...
@@ -63,36 +61,46 @@ extern "C" PyObject* PyList_AsTuple(PyObject* v) noexcept {
}
extern
"C"
Box
*
listRepr
(
BoxedList
*
self
)
{
// TODO highly inefficient with all the string copying
std
::
string
O
(
""
);
llvm
::
raw_string_ostream
os
(
O
);
std
::
vector
<
char
>
chars
;
// Implementing Recursive Print of list in same way from Cpython
int
recursive
=
Py_ReprEnter
((
PyObject
*
)
self
);
if
(
recursive
!=
0
)
{
if
(
recursive
<
0
)
return
boxString
(
os
.
str
());
os
<<
"[...]"
;
return
boxString
(
os
.
str
());
try
{
int
status
=
Py_ReprEnter
((
PyObject
*
)
self
);
if
(
status
!=
0
)
{
if
(
status
<
0
)
throwCAPIException
();
chars
.
push_back
(
'['
);
chars
.
push_back
(
'.'
);
chars
.
push_back
(
'.'
);
chars
.
push_back
(
'.'
);
chars
.
push_back
(
']'
);
return
boxString
(
llvm
::
StringRef
(
&
chars
[
0
],
chars
.
size
()));
}
}
catch
(
ExcInfo
e
)
{
setCAPIException
(
e
);
Py_ReprLeave
((
PyObject
*
)
self
);
return
NULL
;
}
os
<<
'['
;
chars
.
push_back
(
'['
);
for
(
int
i
=
0
;
i
<
self
->
size
;
i
++
)
{
if
(
i
>
0
)
os
<<
", "
;
if
(
i
>
0
)
{
chars
.
push_back
(
','
);
chars
.
push_back
(
' '
);
}
Box
*
r
=
self
->
elts
->
elts
[
i
]
->
reprICAsString
();
assert
(
r
->
cls
==
str_cls
);
BoxedString
*
s
=
static_cast
<
BoxedString
*>
(
r
);
os
<<
s
->
s
(
);
chars
.
insert
(
chars
.
end
(),
s
->
s
().
begin
(),
s
->
s
().
end
()
);
}
os
<<
']'
;
chars
.
push_back
(
']'
)
;
Py_ReprLeave
((
PyObject
*
)
self
);
return
boxString
(
os
.
str
(
));
return
boxString
(
llvm
::
StringRef
(
&
chars
[
0
],
chars
.
size
()
));
}
extern
"C"
Box
*
listNonzero
(
BoxedList
*
self
)
{
...
...
src/runtime/set.cpp
View file @
86096848
...
...
@@ -14,8 +14,6 @@
#include "runtime/set.h"
#include <llvm/Support/raw_ostream.h>
#include "gc/collector.h"
#include "runtime/objmodel.h"
...
...
@@ -96,29 +94,54 @@ Box* setNew(Box* _cls, Box* container) {
}
static
Box
*
_setRepr
(
BoxedSet
*
self
,
const
char
*
type_name
)
{
std
::
string
O
(
""
);
llvm
::
raw_string_ostream
os
(
O
);
int
status
=
Py_ReprEnter
((
PyObject
*
)
self
);
if
(
status
!=
0
)
{
if
(
status
<
0
)
return
boxString
(
os
.
str
());
std
::
vector
<
char
>
chars
;
try
{
int
status
=
Py_ReprEnter
((
PyObject
*
)
self
);
if
(
status
!=
0
)
{
if
(
status
<
0
)
throwCAPIException
();
std
::
string
ty
=
std
::
string
(
type_name
);
chars
.
insert
(
chars
.
end
(),
ty
.
begin
(),
ty
.
end
());
os
<<
type_name
<<
"(...)"
;
return
boxString
(
os
.
str
());
chars
.
push_back
(
'('
);
chars
.
push_back
(
'.'
);
chars
.
push_back
(
'.'
);
chars
.
push_back
(
'.'
);
chars
.
push_back
(
')'
);
return
boxString
(
llvm
::
StringRef
(
&
chars
[
0
],
chars
.
size
()));
}
}
catch
(
ExcInfo
e
)
{
setCAPIException
(
e
);
Py_ReprLeave
((
PyObject
*
)
self
);
return
NULL
;
}
os
<<
type_name
<<
"(["
;
std
::
string
ty
=
std
::
string
(
type_name
);
chars
.
insert
(
chars
.
end
(),
ty
.
begin
(),
ty
.
end
());
chars
.
push_back
(
'('
);
chars
.
push_back
(
'['
);
bool
first
=
true
;
for
(
Box
*
elt
:
self
->
s
)
{
if
(
!
first
)
{
os
<<
", "
;
chars
.
push_back
(
','
);
chars
.
push_back
(
' '
);
}
os
<<
static_cast
<
BoxedString
*>
(
repr
(
elt
))
->
s
();
BoxedString
*
str
=
static_cast
<
BoxedString
*>
(
repr
(
elt
));
chars
.
insert
(
chars
.
end
(),
str
->
s
().
begin
(),
str
->
s
().
end
());
first
=
false
;
}
os
<<
"])"
;
chars
.
push_back
(
']'
);
chars
.
push_back
(
')'
);
Py_ReprLeave
((
PyObject
*
)
self
);
return
boxString
(
os
.
str
(
));
return
boxString
(
llvm
::
StringRef
(
&
chars
[
0
],
chars
.
size
()
));
}
Box
*
setRepr
(
BoxedSet
*
self
)
{
...
...
src/runtime/tuple.cpp
View file @
86096848
...
...
@@ -16,8 +16,6 @@
#include <algorithm>
#include "llvm/Support/raw_ostream.h"
#include "capi/typeobject.h"
#include "core/ast.h"
#include "core/common.h"
...
...
@@ -204,39 +202,56 @@ Box* tupleRepr(BoxedTuple* t) {
assert
(
isSubclass
(
t
->
cls
,
tuple_cls
));
int
n
;
std
::
string
O
(
""
);
llvm
::
raw_string_ostream
os
(
O
);
std
::
vector
<
char
>
chars
;
n
=
t
->
size
();
if
(
n
==
0
)
{
os
<<
"()"
;
return
boxString
(
os
.
str
());
chars
.
push_back
(
'('
);
chars
.
push_back
(
')'
);
return
boxString
(
llvm
::
StringRef
(
&
chars
[
0
],
chars
.
size
()));
}
int
status
=
Py_ReprEnter
((
PyObject
*
)
t
);
if
(
status
!=
0
)
{
if
(
status
<
0
)
return
boxString
(
os
.
str
());
try
{
int
status
=
Py_ReprEnter
((
PyObject
*
)
t
);
if
(
status
!=
0
)
{
if
(
status
<
0
)
throwCAPIException
();
chars
.
push_back
(
'('
);
chars
.
push_back
(
'.'
);
chars
.
push_back
(
'.'
);
chars
.
push_back
(
'.'
);
chars
.
push_back
(
')'
);
return
boxString
(
llvm
::
StringRef
(
&
chars
[
0
],
chars
.
size
()));
}
}
catch
(
ExcInfo
e
)
{
setCAPIException
(
e
);
Py_ReprLeave
((
PyObject
*
)
t
);
os
<<
"(...)"
;
return
boxString
(
os
.
str
());
return
NULL
;
}
os
<<
"("
;
chars
.
push_back
(
'('
)
;
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
if
(
i
)
os
<<
", "
;
if
(
i
)
{
chars
.
push_back
(
','
);
chars
.
push_back
(
' '
);
}
BoxedString
*
elt_repr
=
static_cast
<
BoxedString
*>
(
repr
(
t
->
elts
[
i
]));
os
<<
elt_repr
->
s
(
);
chars
.
insert
(
chars
.
end
(),
elt_repr
->
s
().
begin
(),
elt_repr
->
s
().
end
()
);
}
if
(
n
==
1
)
os
<<
","
;
os
<<
")"
;
chars
.
push_back
(
','
);
chars
.
push_back
(
')'
);
Py_ReprLeave
((
PyObject
*
)
t
);
return
boxString
(
os
.
str
());
return
boxString
(
llvm
::
StringRef
(
&
chars
[
0
],
chars
.
size
()));
}
Box
*
tupleNonzero
(
BoxedTuple
*
self
)
{
...
...
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