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
20a52359
Commit
20a52359
authored
Jul 24, 2014
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add issubclass, and fix 0-arg raise statement
parent
acbc8021
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
37 additions
and
2 deletions
+37
-2
src/codegen/irgen/irgenerator.cpp
src/codegen/irgen/irgenerator.cpp
+14
-1
src/codegen/runtime_hooks.cpp
src/codegen/runtime_hooks.cpp
+1
-0
src/codegen/runtime_hooks.h
src/codegen/runtime_hooks.h
+1
-1
src/core/cfg.cpp
src/core/cfg.cpp
+2
-0
src/runtime/builtin_modules/builtins.cpp
src/runtime/builtin_modules/builtins.cpp
+12
-0
test/tests/inheritance.py
test/tests/inheritance.py
+7
-0
No files found.
src/codegen/irgen/irgenerator.cpp
View file @
20a52359
...
...
@@ -1800,8 +1800,21 @@ private:
}
void
doRaise
(
AST_Raise
*
node
,
ExcInfo
exc_info
)
{
std
::
vector
<
llvm
::
Value
*>
args
;
// It looks like ommitting the second and third arguments are equivalent to passing None,
// but ommitting the first argument is *not* the same as passing None.
if
(
node
->
arg0
==
NULL
)
{
assert
(
!
node
->
arg1
);
assert
(
!
node
->
arg2
);
emitter
.
createCall
(
exc_info
,
g
.
funcs
.
raise0
,
std
::
vector
<
llvm
::
Value
*>
());
emitter
.
getBuilder
()
->
CreateUnreachable
();
endBlock
(
DEAD
);
return
;
}
std
::
vector
<
llvm
::
Value
*>
args
;
for
(
auto
a
:
{
node
->
arg0
,
node
->
arg1
,
node
->
arg2
})
{
if
(
a
)
{
CompilerVariable
*
v
=
evalExpr
(
a
,
exc_info
);
...
...
src/codegen/runtime_hooks.cpp
View file @
20a52359
...
...
@@ -223,6 +223,7 @@ void initGlobalFuncs(GlobalState& g) {
GET
(
__cxa_begin_catch
);
g
.
funcs
.
__cxa_end_catch
=
addFunc
((
void
*
)
__cxa_end_catch
,
g
.
void_
);
GET
(
raise0
);
GET
(
raise3
);
g
.
funcs
.
div_i64_i64
=
getFunc
((
void
*
)
div_i64_i64
,
"div_i64_i64"
);
...
...
src/codegen/runtime_hooks.h
View file @
20a52359
...
...
@@ -45,7 +45,7 @@ struct GlobalFuncs {
llvm
::
Value
*
reoptCompiledFunc
,
*
compilePartialFunc
;
llvm
::
Value
*
__cxa_begin_catch
,
*
__cxa_end_catch
;
llvm
::
Value
*
raise3
;
llvm
::
Value
*
raise
0
,
*
raise
3
;
llvm
::
Value
*
div_i64_i64
,
*
mod_i64_i64
,
*
pow_i64_i64
;
llvm
::
Value
*
div_float_float
,
*
mod_float_float
,
*
pow_float_float
;
...
...
src/core/cfg.cpp
View file @
20a52359
...
...
@@ -1707,6 +1707,7 @@ CFG* computeCFG(SourceInfo* source, std::vector<AST_stmt*> body) {
AST_Assign
*
module_assign
=
new
AST_Assign
();
module_assign
->
targets
.
push_back
(
makeName
(
"__module__"
,
AST_TYPE
::
Store
));
module_assign
->
value
=
new
AST_Str
(
static_cast
<
BoxedString
*>
(
module_name
)
->
s
);
module_assign
->
lineno
=
0
;
visitor
.
push_back
(
module_assign
);
// If the first statement is just a single string, transform it to an assignment to __doc__
...
...
@@ -1716,6 +1717,7 @@ CFG* computeCFG(SourceInfo* source, std::vector<AST_stmt*> body) {
AST_Assign
*
doc_assign
=
new
AST_Assign
();
doc_assign
->
targets
.
push_back
(
makeName
(
"__doc__"
,
AST_TYPE
::
Store
));
doc_assign
->
value
=
first_expr
->
value
;
doc_assign
->
lineno
=
0
;
visitor
.
push_back
(
doc_assign
);
}
}
...
...
src/runtime/builtin_modules/builtins.cpp
View file @
20a52359
...
...
@@ -310,6 +310,14 @@ Box* isinstance_func(Box* obj, Box* cls) {
return
boxBool
(
isinstance
(
obj
,
cls
,
0
));
}
Box
*
issubclass_func
(
Box
*
child
,
Box
*
parent
)
{
RELEASE_ASSERT
(
child
->
cls
==
type_cls
,
""
);
// TODO parent can also be a tuple of classes
RELEASE_ASSERT
(
parent
->
cls
==
type_cls
,
""
);
return
boxBool
(
isSubclass
(
static_cast
<
BoxedClass
*>
(
child
),
static_cast
<
BoxedClass
*>
(
parent
)));
}
Box
*
getattrFunc
(
Box
*
obj
,
Box
*
_str
,
Box
*
default_value
)
{
if
(
_str
->
cls
!=
str_cls
)
{
raiseExcHelper
(
TypeError
,
"getattr(): attribute name must be string"
);
...
...
@@ -463,6 +471,7 @@ void setupBuiltins() {
Warning
=
makeBuiltinException
(
Exception
,
"Warning"
);
/*ImportWarning =*/
makeBuiltinException
(
Warning
,
"ImportWarning"
);
/*PendingDeprecationWarning =*/
makeBuiltinException
(
Warning
,
"PendingDeprecationWarning"
);
/*DeprecationWarning =*/
makeBuiltinException
(
Warning
,
"DeprecationWarning"
);
repr_obj
=
new
BoxedFunction
(
boxRTFunction
((
void
*
)
repr
,
UNKNOWN
,
1
));
builtins_module
->
giveAttr
(
"repr"
,
repr_obj
);
...
...
@@ -499,6 +508,9 @@ void setupBuiltins() {
Box
*
isinstance_obj
=
new
BoxedFunction
(
boxRTFunction
((
void
*
)
isinstance_func
,
BOXED_BOOL
,
2
));
builtins_module
->
giveAttr
(
"isinstance"
,
isinstance_obj
);
Box
*
issubclass_obj
=
new
BoxedFunction
(
boxRTFunction
((
void
*
)
issubclass_func
,
BOXED_BOOL
,
2
));
builtins_module
->
giveAttr
(
"issubclass"
,
issubclass_obj
);
CLFunction
*
sorted_func
=
createRTFunction
(
1
,
0
,
false
,
false
);
addRTFunction
(
sorted_func
,
(
void
*
)
sortedList
,
LIST
,
{
LIST
});
addRTFunction
(
sorted_func
,
(
void
*
)
sorted
,
LIST
,
{
UNKNOWN
});
...
...
test/tests/inheritance.py
View file @
20a52359
...
...
@@ -61,3 +61,10 @@ def f3():
print
a
.
foo
()
f3
()
print
isinstance
(
1
,
int
)
print
isinstance
(
1
,
object
)
print
isinstance
(
1
,
float
)
print
issubclass
(
int
,
int
)
print
issubclass
(
int
,
object
)
print
issubclass
(
int
,
float
)
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