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
08509b08
Commit
08509b08
authored
Nov 14, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
get enough dealloc/traverse/clear functions in to get it to try the GC
parent
05fcd11f
Changes
24
Show whitespace changes
Inline
Side-by-side
Showing
24 changed files
with
247 additions
and
59 deletions
+247
-59
src/runtime/builtin_modules/ast.cpp
src/runtime/builtin_modules/ast.cpp
+3
-2
src/runtime/builtin_modules/builtins.cpp
src/runtime/builtin_modules/builtins.cpp
+11
-3
src/runtime/builtin_modules/thread.cpp
src/runtime/builtin_modules/thread.cpp
+7
-2
src/runtime/classobj.cpp
src/runtime/classobj.cpp
+8
-4
src/runtime/classobj.h
src/runtime/classobj.h
+20
-0
src/runtime/code.cpp
src/runtime/code.cpp
+1
-1
src/runtime/dict.cpp
src/runtime/dict.cpp
+13
-9
src/runtime/dict.h
src/runtime/dict.h
+22
-0
src/runtime/frame.cpp
src/runtime/frame.cpp
+13
-2
src/runtime/generator.cpp
src/runtime/generator.cpp
+14
-10
src/runtime/import.cpp
src/runtime/import.cpp
+1
-1
src/runtime/inline/xrange.cpp
src/runtime/inline/xrange.cpp
+11
-3
src/runtime/iterobject.cpp
src/runtime/iterobject.cpp
+9
-5
src/runtime/iterobject.h
src/runtime/iterobject.h
+26
-0
src/runtime/list.cpp
src/runtime/list.cpp
+6
-4
src/runtime/list.h
src/runtime/list.h
+11
-0
src/runtime/objmodel.cpp
src/runtime/objmodel.cpp
+6
-4
src/runtime/set.cpp
src/runtime/set.cpp
+15
-2
src/runtime/str.cpp
src/runtime/str.cpp
+14
-2
src/runtime/super.cpp
src/runtime/super.cpp
+9
-1
src/runtime/traceback.cpp
src/runtime/traceback.cpp
+3
-2
src/runtime/traceback.h
src/runtime/traceback.h
+10
-0
src/runtime/tuple.cpp
src/runtime/tuple.cpp
+3
-2
src/runtime/tuple.h
src/runtime/tuple.h
+11
-0
No files found.
src/runtime/builtin_modules/ast.cpp
View file @
08509b08
...
...
@@ -71,13 +71,14 @@ void setupAST() {
// ::create takes care of registering the class as a GC root.
#define MAKE_CLS(name, base_cls) \
BoxedClass* name##_cls = BoxedClass::create(type_cls, base_cls, 0, 0, sizeof(BoxedAST), false, STRINGIFY(name)); \
BoxedClass* name##_cls \
= BoxedClass::create(type_cls, base_cls, 0, 0, sizeof(BoxedAST), false, STRINGIFY(name), NULL, NULL, false); \
ast_module->giveAttrBorrowed(STRINGIFY(name), name##_cls); \
type_to_cls[AST_TYPE::name] = name##_cls; \
name##_cls->giveAttr("__module__", boxString("_ast")); \
name##_cls->freeze()
AST_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
0
,
0
,
sizeof
(
BoxedAST
),
false
,
"AST"
);
AST_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
0
,
0
,
sizeof
(
BoxedAST
),
false
,
"AST"
,
NULL
,
NULL
,
false
);
// ::create takes care of registering the class as a GC root.
AST_cls
->
giveAttr
(
"__module__"
,
boxString
(
"_ast"
));
AST_cls
->
freeze
();
...
...
src/runtime/builtin_modules/builtins.cpp
View file @
08509b08
...
...
@@ -1208,6 +1208,13 @@ public:
BoxedEnumerate
*
self
=
static_cast
<
BoxedEnumerate
*>
(
_self
);
return
boxBool
(
self
->
iterator
!=
self
->
iterator_end
);
}
static
void
dealloc
(
Box
*
b
)
noexcept
{
Py_FatalError
(
"unimplemented"
);
}
static
int
traverse
(
Box
*
self
,
visitproc
visit
,
void
*
arg
)
noexcept
{
Py_FatalError
(
"unimplemented"
);
}
};
Box
*
globals
()
{
...
...
@@ -1842,7 +1849,7 @@ void setupBuiltins() {
"Built-in functions, exceptions, and other objects.
\n\n
Noteworthy: None is "
"the `nil' object; Ellipsis represents `...' in slices."
);
ellipsis_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
0
,
0
,
sizeof
(
Box
),
false
,
"ellipsis"
);
ellipsis_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
0
,
0
,
sizeof
(
Box
),
false
,
"ellipsis"
,
NULL
,
NULL
,
false
);
ellipsis_cls
->
giveAttr
(
"__repr__"
,
new
BoxedFunction
(
FunctionMetadata
::
create
((
void
*
)
ellipsisRepr
,
STR
,
1
)));
Ellipsis
=
new
(
ellipsis_cls
)
Box
();
assert
(
Ellipsis
->
cls
);
...
...
@@ -1857,7 +1864,8 @@ void setupBuiltins() {
"print"
,
new
BoxedBuiltinFunctionOrMethod
(
FunctionMetadata
::
create
((
void
*
)
print
,
NONE
,
0
,
true
,
true
),
"print"
,
print_doc
));
notimplemented_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
0
,
0
,
sizeof
(
Box
),
false
,
"NotImplementedType"
);
notimplemented_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
0
,
0
,
sizeof
(
Box
),
false
,
"NotImplementedType"
,
NULL
,
NULL
,
false
);
notimplemented_cls
->
giveAttr
(
"__repr__"
,
new
BoxedFunction
(
FunctionMetadata
::
create
((
void
*
)
notimplementedRepr
,
STR
,
1
)));
notimplemented_cls
->
freeze
();
...
...
@@ -1969,7 +1977,7 @@ void setupBuiltins() {
{
None
,
None
,
None
,
autoDecref
(
boxInt
(
-
1
))
},
NULL
,
import_doc
));
enumerate_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
0
,
0
,
sizeof
(
BoxedEnumerate
),
false
,
"enumerate"
);
false
,
"enumerate"
,
BoxedEnumerate
::
dealloc
,
NULL
,
true
,
BoxedEnumerate
::
traverse
,
NOCLEAR
);
enumerate_cls
->
giveAttr
(
"__new__"
,
new
BoxedFunction
(
FunctionMetadata
::
create
((
void
*
)
BoxedEnumerate
::
new_
,
UNKNOWN
,
3
,
false
,
false
),
{
autoDecref
(
boxInt
(
0
))
}));
...
...
src/runtime/builtin_modules/thread.cpp
View file @
08509b08
...
...
@@ -180,6 +180,10 @@ public:
}
Py_RETURN_TRUE
;
}
static
void
dealloc
(
Box
*
b
)
noexcept
{
Py_FatalError
(
"unimplemented"
);
}
};
...
...
@@ -223,7 +227,8 @@ void setupThread() {
thread_module
->
giveAttr
(
"_count"
,
new
BoxedBuiltinFunctionOrMethod
(
FunctionMetadata
::
create
((
void
*
)
threadCount
,
BOXED_INT
,
0
),
"_count"
));
thread_lock_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
0
,
0
,
sizeof
(
BoxedThreadLock
),
false
,
"lock"
);
thread_lock_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
0
,
0
,
sizeof
(
BoxedThreadLock
),
false
,
"lock"
,
BoxedThreadLock
::
dealloc
,
NULL
,
false
);
thread_lock_cls
->
tp_dealloc
=
BoxedThreadLock
::
threadLockDestructor
;
thread_lock_cls
->
has_safe_tp_dealloc
=
true
;
thread_lock_cls
->
instances_are_nonzero
=
true
;
...
...
@@ -245,7 +250,7 @@ void setupThread() {
thread_lock_cls
->
freeze
();
ThreadError
=
BoxedClass
::
create
(
type_cls
,
Exception
,
Exception
->
attrs_offset
,
Exception
->
tp_weaklistoffset
,
Exception
->
tp_basicsize
,
false
,
"error"
);
Exception
->
tp_basicsize
,
false
,
"error"
,
NULL
,
NULL
,
false
);
ThreadError
->
giveAttr
(
"__module__"
,
boxString
(
"thread"
));
ThreadError
->
freeze
();
...
...
src/runtime/classobj.cpp
View file @
08509b08
...
...
@@ -1641,10 +1641,14 @@ extern "C" int PyMethod_ClearFreeList(void) noexcept {
}
void
setupClassobj
()
{
classobj_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
offsetof
(
BoxedClassobj
,
attrs
),
offsetof
(
BoxedClassobj
,
weakreflist
),
sizeof
(
BoxedClassobj
),
false
,
"classobj"
);
instance_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
offsetof
(
BoxedInstance
,
attrs
),
offsetof
(
BoxedInstance
,
weakreflist
),
sizeof
(
BoxedInstance
),
false
,
"instance"
);
classobj_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
offsetof
(
BoxedClassobj
,
attrs
),
offsetof
(
BoxedClassobj
,
weakreflist
),
sizeof
(
BoxedClassobj
),
false
,
"classobj"
,
(
destructor
)
BoxedClassobj
::
dealloc
,
NULL
,
true
,
(
traverseproc
)
BoxedClassobj
::
traverse
,
(
inquiry
)
BoxedClassobj
::
clear
);
instance_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
offsetof
(
BoxedInstance
,
attrs
),
offsetof
(
BoxedInstance
,
weakreflist
),
sizeof
(
BoxedInstance
),
false
,
"instance"
,
(
destructor
)
BoxedInstance
::
dealloc
,
NULL
,
true
,
(
traverseproc
)
BoxedInstance
::
traverse
,
(
inquiry
)
BoxedInstance
::
clear
);
classobj_cls
->
giveAttr
(
"__new__"
,
new
BoxedFunction
(
FunctionMetadata
::
create
((
void
*
)
classobjNew
,
UNKNOWN
,
4
,
false
,
false
)));
...
...
src/runtime/classobj.h
View file @
08509b08
...
...
@@ -49,6 +49,16 @@ public:
Box
**
weakreflist
;
BoxedClassobj
(
BoxedString
*
name
,
BoxedTuple
*
bases
)
:
bases
(
bases
),
name
(
name
)
{}
static
void
dealloc
(
Box
*
b
)
noexcept
{
Py_FatalError
(
"unimplemented"
);
}
static
int
traverse
(
Box
*
self
,
visitproc
visit
,
void
*
arg
)
noexcept
{
Py_FatalError
(
"unimplemented"
);
}
static
int
clear
(
Box
*
self
)
noexcept
{
Py_FatalError
(
"unimplemented"
);
}
};
class
BoxedInstance
:
public
Box
{
...
...
@@ -62,6 +72,16 @@ public:
BoxedInstance
(
BoxedClassobj
*
inst_cls
)
:
inst_cls
(
inst_cls
)
{}
DEFAULT_CLASS
(
instance_cls
);
static
void
dealloc
(
Box
*
b
)
noexcept
{
Py_FatalError
(
"unimplemented"
);
}
static
int
traverse
(
Box
*
self
,
visitproc
visit
,
void
*
arg
)
noexcept
{
Py_FatalError
(
"unimplemented"
);
}
static
int
clear
(
Box
*
self
)
noexcept
{
Py_FatalError
(
"unimplemented"
);
}
};
Box
*
instance_getattro
(
Box
*
cls
,
Box
*
attr
)
noexcept
;
...
...
src/runtime/code.cpp
View file @
08509b08
...
...
@@ -111,7 +111,7 @@ extern "C" int PyCode_GetArgCount(PyCodeObject* op) noexcept {
}
void
setupCode
()
{
code_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
0
,
0
,
sizeof
(
BoxedCode
),
false
,
"code"
);
code_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
0
,
0
,
sizeof
(
BoxedCode
),
false
,
"code"
,
NULL
,
NULL
,
false
);
code_cls
->
giveAttrBorrowed
(
"__new__"
,
None
);
// Hacky way of preventing users from instantiating this
...
...
src/runtime/dict.cpp
View file @
08509b08
...
...
@@ -812,15 +812,19 @@ void setupDict() {
static
PySequenceMethods
dict_as_sequence
;
dict_cls
->
tp_as_sequence
=
&
dict_as_sequence
;
dict_iterator_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
0
,
0
,
sizeof
(
BoxedDictIterator
),
false
,
"dictionary-itemiterator"
);
dict_keys_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
0
,
0
,
sizeof
(
BoxedDictView
),
false
,
"dict_keys"
);
dict_values_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
0
,
0
,
sizeof
(
BoxedDictView
),
false
,
"dict_values"
);
dict_items_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
0
,
0
,
sizeof
(
BoxedDictView
),
false
,
"dict_items"
);
dict_iterator_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
0
,
0
,
sizeof
(
BoxedDictIterator
),
false
,
"dictionary-itemiterator"
,
(
destructor
)
BoxedDictIterator
::
dealloc
,
NULL
,
true
,
(
traverseproc
)
BoxedDictIterator
::
traverse
,
NOCLEAR
);
dict_keys_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
0
,
0
,
sizeof
(
BoxedDictView
),
false
,
"dict_keys"
,
(
destructor
)
BoxedDictView
::
dealloc
,
NULL
,
true
,
(
traverseproc
)
BoxedDictView
::
traverse
,
NOCLEAR
);
dict_values_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
0
,
0
,
sizeof
(
BoxedDictView
),
false
,
"dict_values"
,
(
destructor
)
BoxedDictView
::
dealloc
,
NULL
,
true
,
(
traverseproc
)
BoxedDictView
::
traverse
,
NOCLEAR
);
dict_items_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
0
,
0
,
sizeof
(
BoxedDictView
),
false
,
"dict_items"
,
(
destructor
)
BoxedDictView
::
dealloc
,
NULL
,
true
,
(
traverseproc
)
BoxedDictView
::
traverse
,
NOCLEAR
);
dict_iterator_cls
->
instances_are_nonzero
=
dict_keys_cls
->
instances_are_nonzero
=
dict_values_cls
->
instances_are_nonzero
=
dict_items_cls
->
instances_are_nonzero
=
true
;
...
...
src/runtime/dict.h
View file @
08509b08
...
...
@@ -37,6 +37,17 @@ public:
BoxedDictIterator
(
BoxedDict
*
d
,
IteratorType
type
);
DEFAULT_CLASS
(
dict_iterator_cls
);
static
void
dealloc
(
BoxedDictIterator
*
o
)
noexcept
{
PyObject_GC_UnTrack
(
o
);
Py_DECREF
(
o
->
d
);
o
->
cls
->
tp_free
(
o
);
}
static
int
traverse
(
BoxedDictIterator
*
self
,
visitproc
visit
,
void
*
arg
)
noexcept
{
Py_VISIT
(
self
->
d
);
return
0
;
}
};
Box
*
dictGetitem
(
BoxedDict
*
self
,
Box
*
k
);
...
...
@@ -55,6 +66,17 @@ class BoxedDictView : public Box {
public:
BoxedDict
*
d
;
BoxedDictView
(
BoxedDict
*
d
);
static
void
dealloc
(
BoxedDictIterator
*
o
)
noexcept
{
PyObject_GC_UnTrack
(
o
);
Py_DECREF
(
o
->
d
);
o
->
cls
->
tp_free
(
o
);
}
static
int
traverse
(
BoxedDictIterator
*
self
,
visitproc
visit
,
void
*
arg
)
noexcept
{
Py_VISIT
(
self
->
d
);
return
0
;
}
};
Box
*
dictViewKeysIter
(
Box
*
self
);
...
...
src/runtime/frame.cpp
View file @
08509b08
...
...
@@ -130,6 +130,16 @@ public:
return
fi
->
frame_obj
;
}
static
void
dealloc
(
Box
*
b
)
noexcept
{
Py_FatalError
(
"unimplemented"
);
}
static
int
traverse
(
Box
*
self
,
visitproc
visit
,
void
*
arg
)
noexcept
{
Py_FatalError
(
"unimplemented"
);
}
static
int
clear
(
Box
*
self
)
noexcept
{
Py_FatalError
(
"unimplemented"
);
}
};
Box
*
getFrame
(
int
depth
)
{
...
...
@@ -141,8 +151,9 @@ Box* getFrame(int depth) {
}
void
setupFrame
()
{
frame_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
0
,
0
,
sizeof
(
BoxedFrame
),
false
,
"frame"
);
frame_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
0
,
0
,
sizeof
(
BoxedFrame
),
false
,
"frame"
,
(
destructor
)
BoxedFrame
::
dealloc
,
NULL
,
true
,
(
traverseproc
)
BoxedFrame
::
traverse
,
(
inquiry
)
BoxedFrame
::
clear
);
frame_cls
->
tp_dealloc
=
BoxedFrame
::
simpleDestructor
;
frame_cls
->
has_safe_tp_dealloc
=
true
;
...
...
src/runtime/generator.cpp
View file @
08509b08
...
...
@@ -423,12 +423,6 @@ Box* generatorName(Box* _self, void* context) {
return
self
->
function
->
md
->
source
->
getName
();
}
void
generatorDestructor
(
Box
*
b
)
{
assert
(
isSubclass
(
b
->
cls
,
generator_cls
));
BoxedGenerator
*
self
=
static_cast
<
BoxedGenerator
*>
(
b
);
freeGeneratorStack
(
self
);
}
extern
"C"
int
PyGen_NeedsFinalizing
(
PyGenObject
*
gen
)
noexcept
{
Py_FatalError
(
"unimplemented"
);
#if 0
...
...
@@ -450,11 +444,21 @@ extern "C" int PyGen_NeedsFinalizing(PyGenObject* gen) noexcept {
#endif
}
static
void
generator_dealloc
(
BoxedGenerator
*
self
)
noexcept
{
assert
(
isSubclass
(
self
->
cls
,
generator_cls
));
freeGeneratorStack
(
self
);
Py_FatalError
(
"unimplemented"
);
}
static
int
generator_traverse
(
BoxedGenerator
*
self
,
visitproc
visit
,
void
*
arg
)
noexcept
{
Py_FatalError
(
"unimplemented"
);
}
void
setupGenerator
()
{
generator_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
0
,
offsetof
(
BoxedGenerator
,
weakreflist
),
sizeof
(
BoxedGenerator
),
false
,
"generator"
);
generator_cls
->
tp_dealloc
=
generatorDestructor
;
generator_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
0
,
offsetof
(
BoxedGenerator
,
weakreflist
),
sizeof
(
BoxedGenerator
),
false
,
"generator"
,
(
destructor
)
generator_dealloc
,
NULL
,
true
,
(
traverseproc
)
generator_traverse
,
NOCLEAR
);
generator_cls
->
has_safe_tp_dealloc
=
true
;
generator_cls
->
giveAttr
(
"__iter__"
,
new
BoxedFunction
(
FunctionMetadata
::
create
((
void
*
)
generatorIter
,
typeFromClass
(
generator_cls
),
1
)));
...
...
src/runtime/import.cpp
View file @
08509b08
...
...
@@ -933,7 +933,7 @@ void setupImport() {
imp_module
->
giveAttr
(
"C_BUILTIN"
,
boxInt
(
SearchResult
::
C_BUILTIN
));
imp_module
->
giveAttr
(
"PY_FROZEN"
,
boxInt
(
SearchResult
::
PY_FROZEN
));
null_importer_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
0
,
0
,
sizeof
(
Box
),
false
,
"NullImporter"
);
null_importer_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
0
,
0
,
sizeof
(
Box
),
false
,
"NullImporter"
,
NULL
,
NULL
,
false
);
null_importer_cls
->
giveAttr
(
"__init__"
,
new
BoxedFunction
(
FunctionMetadata
::
create
((
void
*
)
nullImporterInit
,
NONE
,
2
,
false
,
false
),
{
None
}));
...
...
src/runtime/inline/xrange.cpp
View file @
08509b08
...
...
@@ -130,6 +130,13 @@ public:
static
Box
*
xrangeIteratorNext
(
Box
*
s
)
__attribute__
((
visibility
(
"default"
)))
{
return
boxInt
(
xrangeIteratorNextUnboxed
(
s
));
}
static
void
dealloc
(
Box
*
b
)
noexcept
{
Py_FatalError
(
"unimplemented"
);
}
static
int
traverse
(
Box
*
self
,
visitproc
visit
,
void
*
arg
)
noexcept
{
Py_FatalError
(
"unimplemented"
);
}
};
Box
*
xrange
(
Box
*
cls
,
Box
*
start
,
Box
*
stop
,
Box
**
args
)
{
...
...
@@ -236,9 +243,10 @@ Box* xrangeReduce(Box* self) {
}
void
setupXrange
()
{
xrange_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
0
,
0
,
sizeof
(
BoxedXrange
),
false
,
"xrange"
);
xrange_iterator_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
0
,
0
,
sizeof
(
BoxedXrangeIterator
),
false
,
"rangeiterator"
);
xrange_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
0
,
0
,
sizeof
(
BoxedXrange
),
false
,
"xrange"
,
NULL
,
NULL
,
false
);
xrange_iterator_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
0
,
0
,
sizeof
(
BoxedXrangeIterator
),
false
,
"rangeiterator"
,
BoxedXrangeIterator
::
dealloc
,
NULL
,
true
,
BoxedXrangeIterator
::
traverse
,
NOCLEAR
);
static
PySequenceMethods
xrange_as_sequence
;
xrange_cls
->
tp_as_sequence
=
&
xrange_as_sequence
;
...
...
src/runtime/iterobject.cpp
View file @
08509b08
...
...
@@ -189,7 +189,9 @@ bool calliter_hasnext(Box* b) {
void
setupIter
()
{
seqiter_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
0
,
0
,
sizeof
(
BoxedSeqIter
),
false
,
"iterator"
);
seqiter_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
0
,
0
,
sizeof
(
BoxedSeqIter
),
false
,
"iterator"
,
(
destructor
)
BoxedSeqIter
::
dealloc
,
NULL
,
true
,
(
traverseproc
)
BoxedSeqIter
::
traverse
,
NOCLEAR
);
seqiter_cls
->
giveAttr
(
"next"
,
new
BoxedFunction
(
FunctionMetadata
::
create
((
void
*
)
seqiterNext
,
UNKNOWN
,
1
)));
seqiter_cls
->
giveAttr
(
"__hasnext__"
,
...
...
@@ -201,8 +203,9 @@ void setupIter() {
seqiter_cls
->
tp_iter
=
PyObject_SelfIter
;
seqiter_cls
->
tp_iternext
=
seqiter_next
;
seqreviter_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
0
,
0
,
sizeof
(
BoxedSeqIter
),
false
,
"reversed"
);
seqreviter_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
0
,
0
,
sizeof
(
BoxedSeqIter
),
false
,
"reversed"
,
(
destructor
)
BoxedSeqIter
::
dealloc
,
NULL
,
true
,
(
traverseproc
)
BoxedSeqIter
::
traverse
,
NOCLEAR
);
seqreviter_cls
->
giveAttr
(
"next"
,
new
BoxedFunction
(
FunctionMetadata
::
create
((
void
*
)
seqiterNext
,
UNKNOWN
,
1
)));
seqreviter_cls
->
giveAttr
(
"__hasnext__"
,
...
...
@@ -213,8 +216,9 @@ void setupIter() {
seqreviter_cls
->
tp_iter
=
PyObject_SelfIter
;
seqreviter_cls
->
tp_iternext
=
seqiter_next
;
iterwrapper_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
0
,
0
,
sizeof
(
BoxedIterWrapper
),
false
,
"iterwrapper"
);
iterwrapper_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
0
,
0
,
sizeof
(
BoxedIterWrapper
),
false
,
"iterwrapper"
,
(
destructor
)
BoxedIterWrapper
::
dealloc
,
NULL
,
true
,
(
traverseproc
)
BoxedIterWrapper
::
traverse
,
NOCLEAR
);
iterwrapper_cls
->
giveAttr
(
"next"
,
new
BoxedFunction
(
FunctionMetadata
::
create
((
void
*
)
iterwrapperNext
,
UNKNOWN
,
1
)));
iterwrapper_cls
->
giveAttr
(
"__hasnext__"
,
...
...
src/runtime/iterobject.h
View file @
08509b08
...
...
@@ -36,6 +36,19 @@ public:
BoxedSeqIter
(
Box
*
b
,
int64_t
start
)
:
b
(
b
),
idx
(
start
),
next
(
NULL
)
{}
DEFAULT_CLASS
(
seqiter_cls
);
static
void
dealloc
(
BoxedSeqIter
*
o
)
noexcept
{
PyObject_GC_UnTrack
(
o
);
Py_DECREF
(
o
->
b
);
Py_XDECREF
(
o
->
next
);
o
->
cls
->
tp_free
(
o
);
}
static
int
traverse
(
BoxedSeqIter
*
self
,
visitproc
visit
,
void
*
arg
)
noexcept
{
Py_VISIT
(
self
->
b
);
Py_VISIT
(
self
->
next
);
return
0
;
}
};
extern
BoxedClass
*
iterwrapper_cls
;
...
...
@@ -49,6 +62,19 @@ public:
BoxedIterWrapper
(
Box
*
iter
)
:
iter
(
iter
),
next
(
NULL
)
{}
DEFAULT_CLASS
(
iterwrapper_cls
);
static
void
dealloc
(
BoxedIterWrapper
*
o
)
noexcept
{
PyObject_GC_UnTrack
(
o
);
Py_DECREF
(
o
->
iter
);
Py_XDECREF
(
o
->
next
);
o
->
cls
->
tp_free
(
o
);
}
static
int
traverse
(
BoxedIterWrapper
*
self
,
visitproc
visit
,
void
*
arg
)
noexcept
{
Py_VISIT
(
self
->
iter
);
Py_VISIT
(
self
->
next
);
return
0
;
}
};
bool
calliter_hasnext
(
Box
*
b
);
...
...
src/runtime/list.cpp
View file @
08509b08
...
...
@@ -1321,10 +1321,12 @@ void setupList() {
static
PyMappingMethods
list_as_mapping
;
list_cls
->
tp_as_mapping
=
&
list_as_mapping
;
list_iterator_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
0
,
0
,
sizeof
(
BoxedListIterator
),
false
,
"listiterator"
);
list_reverse_iterator_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
0
,
0
,
sizeof
(
BoxedListIterator
),
false
,
"listreverseiterator"
);
list_iterator_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
0
,
0
,
sizeof
(
BoxedListIterator
),
false
,
"listiterator"
,
(
destructor
)
BoxedListIterator
::
dealloc
,
NULL
,
true
,
(
traverseproc
)
BoxedListIterator
::
traverse
,
NOCLEAR
);
list_reverse_iterator_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
0
,
0
,
sizeof
(
BoxedListIterator
),
false
,
"listreverseiterator"
,
(
destructor
)
BoxedListIterator
::
dealloc
,
NULL
,
true
,
(
traverseproc
)
BoxedListIterator
::
traverse
,
NOCLEAR
);
list_iterator_cls
->
instances_are_nonzero
=
list_reverse_iterator_cls
->
instances_are_nonzero
=
true
;
list_cls
->
giveAttr
(
"__len__"
,
new
BoxedFunction
(
FunctionMetadata
::
create
((
void
*
)
listLen
,
BOXED_INT
,
1
)));
...
...
src/runtime/list.h
View file @
08509b08
...
...
@@ -29,6 +29,17 @@ public:
BoxedListIterator
(
BoxedList
*
l
,
int
start
);
DEFAULT_CLASS
(
list_iterator_cls
);
static
void
dealloc
(
BoxedListIterator
*
o
)
noexcept
{
PyObject_GC_UnTrack
(
o
);
Py_DECREF
(
o
->
l
);
o
->
cls
->
tp_free
(
o
);
}
static
int
traverse
(
BoxedListIterator
*
self
,
visitproc
visit
,
void
*
arg
)
noexcept
{
Py_VISIT
(
self
->
l
);
return
0
;
}
};
Box
*
listIter
(
Box
*
self
)
noexcept
;
...
...
src/runtime/objmodel.cpp
View file @
08509b08
...
...
@@ -414,10 +414,12 @@ BoxedClass::BoxedClass(BoxedClass* base, int attrs_offset, int weaklist_offset,
bool
ok_noclear
=
(
clear
==
NOCLEAR
);
if
(
ok_noclear
)
clear
=
NULL
;
if
(
is_gc
)
{
ASSERT
(
traverse
,
"%s"
,
name
);
ASSERT
(
dealloc
,
"%s"
,
name
);
}
if
(
clear
)
assert
(
traverse
);
if
(
traverse
)
assert
(
dealloc
);
if
(
dealloc
)
assert
(
traverse
||
!
is_gc
);
ASSERT
(((
bool
)
traverse
==
(
bool
)
clear
)
||
ok_noclear
,
"%s"
,
name
);
classes
.
push_back
(
this
);
...
...
src/runtime/set.cpp
View file @
08509b08
...
...
@@ -43,6 +43,17 @@ public:
++
it
;
return
rtn
;
}
static
void
dealloc
(
BoxedSetIterator
*
o
)
noexcept
{
PyObject_GC_UnTrack
(
o
);
Py_DECREF
(
o
->
s
);
o
->
cls
->
tp_free
(
o
);
}
static
int
traverse
(
BoxedSetIterator
*
self
,
visitproc
visit
,
void
*
arg
)
noexcept
{
Py_VISIT
(
self
->
s
);
return
0
;
}
};
Box
*
setiteratorHasnext
(
BoxedSetIterator
*
self
)
{
...
...
@@ -804,6 +815,7 @@ using namespace pyston::set;
void
BoxedSet
::
dealloc
(
Box
*
_o
)
noexcept
{
BoxedSet
*
o
=
(
BoxedSet
*
)
_o
;
PyObject_GC_UnTrack
(
o
);
for
(
auto
p
:
o
->
s
)
{
Py_DECREF
(
p
.
value
);
}
...
...
@@ -852,8 +864,9 @@ void setupSet() {
set_cls
->
tp_dealloc
=
frozenset_cls
->
tp_dealloc
=
BoxedSet
::
dealloc
;
set_cls
->
has_safe_tp_dealloc
=
frozenset_cls
->
has_safe_tp_dealloc
=
true
;
set_iterator_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
0
,
0
,
sizeof
(
BoxedSetIterator
),
false
,
"setiterator"
);
set_iterator_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
0
,
0
,
sizeof
(
BoxedSetIterator
),
false
,
"setiterator"
,
(
destructor
)
BoxedSetIterator
::
dealloc
,
NULL
,
true
,
(
traverseproc
)
BoxedSetIterator
::
traverse
,
NOCLEAR
);
set_iterator_cls
->
giveAttr
(
"__iter__"
,
new
BoxedFunction
(
FunctionMetadata
::
create
(
(
void
*
)
setiteratorIter
,
typeFromClass
(
set_iterator_cls
),
1
)));
set_iterator_cls
->
giveAttr
(
"__hasnext__"
,
...
...
src/runtime/str.cpp
View file @
08509b08
...
...
@@ -2405,6 +2405,17 @@ public:
++
self
->
it
;
return
characters
[
c
&
UCHAR_MAX
];
}
static
void
dealloc
(
BoxedStringIterator
*
o
)
noexcept
{
PyObject_GC_UnTrack
(
o
);
Py_DECREF
(
o
->
s
);
o
->
cls
->
tp_free
(
o
);
}
static
int
traverse
(
BoxedStringIterator
*
self
,
visitproc
visit
,
void
*
arg
)
noexcept
{
Py_VISIT
(
self
->
s
);
return
0
;
}
};
Box
*
strIter
(
BoxedString
*
self
)
noexcept
{
...
...
@@ -2801,8 +2812,9 @@ void setupStr() {
str_cls
->
tp_flags
|=
Py_TPFLAGS_HAVE_NEWBUFFER
;
str_iterator_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
0
,
0
,
sizeof
(
BoxedStringIterator
),
false
,
"striterator"
);
str_iterator_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
0
,
0
,
sizeof
(
BoxedStringIterator
),
false
,
"striterator"
,
(
destructor
)
BoxedStringIterator
::
dealloc
,
NULL
,
true
,
(
traverseproc
)
BoxedStringIterator
::
traverse
,
NOCLEAR
);
str_iterator_cls
->
giveAttr
(
"__hasnext__"
,
new
BoxedFunction
(
FunctionMetadata
::
create
((
void
*
)
BoxedStringIterator
::
hasnext
,
BOXED_BOOL
,
1
)));
str_iterator_cls
->
giveAttr
(
...
...
src/runtime/super.cpp
View file @
08509b08
...
...
@@ -35,6 +35,13 @@ public:
BoxedSuper
(
BoxedClass
*
type
,
Box
*
obj
,
BoxedClass
*
obj_type
)
:
type
(
type
),
obj
(
obj
),
obj_type
(
obj_type
)
{}
DEFAULT_CLASS
(
super_cls
);
static
void
dealloc
(
Box
*
b
)
noexcept
{
Py_FatalError
(
"unimplemented"
);
}
static
int
traverse
(
Box
*
self
,
visitproc
visit
,
void
*
arg
)
noexcept
{
Py_FatalError
(
"unimplemented"
);
}
};
static
const
char
*
class_str
=
"__class__"
;
...
...
@@ -185,7 +192,8 @@ Box* superInit(Box* _self, Box* _type, Box* obj) {
void
setupSuper
()
{
super_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
0
,
0
,
sizeof
(
BoxedSuper
),
false
,
"super"
);
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
0
,
0
,
sizeof
(
BoxedSuper
),
false
,
"super"
,
(
destructor
)
BoxedSuper
::
dealloc
,
NULL
,
true
,
(
traverseproc
)
BoxedSuper
::
traverse
,
NOCLEAR
);
// super_cls->giveAttr("__getattribute__", new BoxedFunction(FunctionMetadata::create((void*)superGetattribute,
// UNKNOWN, 2)));
...
...
src/runtime/traceback.cpp
View file @
08509b08
...
...
@@ -105,8 +105,9 @@ void BoxedTraceback::here(LineInfo lineInfo, Box** tb) {
}
void
setupTraceback
()
{
traceback_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
0
,
0
,
sizeof
(
BoxedTraceback
),
false
,
"traceback"
);
traceback_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
0
,
0
,
sizeof
(
BoxedTraceback
),
false
,
"traceback"
,
(
destructor
)
BoxedTraceback
::
dealloc
,
NULL
,
true
,
(
traverseproc
)
BoxedTraceback
::
traverse
,
(
inquiry
)
BoxedTraceback
::
clear
);
traceback_cls
->
giveAttr
(
"getLines"
,
new
BoxedFunction
(
FunctionMetadata
::
create
((
void
*
)
BoxedTraceback
::
getLines
,
UNKNOWN
,
1
)));
...
...
src/runtime/traceback.h
View file @
08509b08
...
...
@@ -41,6 +41,16 @@ public:
// somewhat equivalent to PyTraceBack_Here
static
void
here
(
LineInfo
lineInfo
,
Box
**
tb
);
static
void
dealloc
(
Box
*
b
)
noexcept
{
Py_FatalError
(
"unimplemented"
);
}
static
int
traverse
(
Box
*
self
,
visitproc
visit
,
void
*
arg
)
noexcept
{
Py_FatalError
(
"unimplemented"
);
}
static
int
clear
(
Box
*
self
)
noexcept
{
Py_FatalError
(
"unimplemented"
);
}
};
void
printTraceback
(
Box
*
b
);
...
...
src/runtime/tuple.cpp
View file @
08509b08
...
...
@@ -675,8 +675,9 @@ void setupTuple() {
static
PyMappingMethods
tuple_as_mapping
;
tuple_cls
->
tp_as_mapping
=
&
tuple_as_mapping
;
tuple_iterator_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
0
,
0
,
sizeof
(
BoxedTupleIterator
),
false
,
"tuple"
);
tuple_iterator_cls
=
BoxedClass
::
create
(
type_cls
,
object_cls
,
0
,
0
,
sizeof
(
BoxedTupleIterator
),
false
,
"tupleiterator"
,
(
destructor
)
BoxedTupleIterator
::
dealloc
,
NULL
,
true
,
(
traverseproc
)
BoxedTupleIterator
::
traverse
,
NOCLEAR
);
tuple_cls
->
giveAttr
(
"__new__"
,
new
BoxedFunction
(
FunctionMetadata
::
create
((
void
*
)
tupleNew
,
UNKNOWN
,
1
,
true
,
true
)));
...
...
src/runtime/tuple.h
View file @
08509b08
...
...
@@ -28,6 +28,17 @@ public:
BoxedTupleIterator
(
BoxedTuple
*
t
);
DEFAULT_CLASS
(
tuple_iterator_cls
);
static
void
dealloc
(
BoxedTupleIterator
*
o
)
noexcept
{
PyObject_GC_UnTrack
(
o
);
Py_DECREF
(
o
->
t
);
o
->
cls
->
tp_free
(
o
);
}
static
int
traverse
(
BoxedTupleIterator
*
self
,
visitproc
visit
,
void
*
arg
)
noexcept
{
Py_VISIT
(
self
->
t
);
return
0
;
}
};
Box
*
tupleIter
(
Box
*
self
)
noexcept
;
...
...
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