Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Xavier Thompson
cython
Commits
9c7b7903
Commit
9c7b7903
authored
Jun 11, 2019
by
gsamain
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Acthon: activated classes, activate methods, method reification still buggy
parent
285fe2f2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
1 deletion
+64
-1
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+26
-0
Cython/Compiler/Symtab.py
Cython/Compiler/Symtab.py
+38
-1
No files found.
Cython/Compiler/ModuleNode.py
View file @
9c7b7903
...
@@ -822,6 +822,9 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
...
@@ -822,6 +822,9 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
if
entry
.
type
.
is_cyp_class
:
if
entry
.
type
.
is_cyp_class
:
# Generate cypclass attr destructor
# Generate cypclass attr destructor
self
.
generate_cyp_class_attrs_destructor_definition
(
entry
,
code
)
self
.
generate_cyp_class_attrs_destructor_definition
(
entry
,
code
)
# Generate acthon-specific classes
self
.
generate_cyp_class_activated_class
(
entry
,
code
)
self
.
generate_cyp_class_activate_function
(
entry
,
code
)
# Generate wrapper constructor
# Generate wrapper constructor
scope
=
entry
.
type
.
scope
scope
=
entry
.
type
.
scope
wrapper
=
scope
.
lookup_here
(
"<constructor>"
)
wrapper
=
scope
.
lookup_here
(
"<constructor>"
)
...
@@ -940,6 +943,9 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
...
@@ -940,6 +943,9 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
has_virtual_methods
=
False
has_virtual_methods
=
False
constructor
=
None
constructor
=
None
destructor
=
None
destructor
=
None
activated_class_entry
=
scope
.
lookup_here
(
"Activated"
)
if
activated_class_entry
:
code
.
putln
(
"struct %s;"
%
activated_class_entry
.
cname
)
for
attr
in
scope
.
var_entries
:
for
attr
in
scope
.
var_entries
:
cname
=
attr
.
cname
cname
=
attr
.
cname
if
attr
.
type
.
is_cfunction
and
attr
.
type
.
is_static_method
:
if
attr
.
type
.
is_cfunction
and
attr
.
type
.
is_static_method
:
...
@@ -1080,6 +1086,26 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
...
@@ -1080,6 +1086,26 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code
.
putln
(
"Cy_XDECREF(this->%s);"
%
attr
.
cname
)
code
.
putln
(
"Cy_XDECREF(this->%s);"
%
attr
.
cname
)
code
.
putln
(
"}"
)
code
.
putln
(
"}"
)
def
generate_cyp_class_activate_function
(
self
,
entry
,
code
):
active_self_entry
=
entry
.
type
.
scope
.
lookup_here
(
"<active_self>"
)
code
.
putln
(
"%s::Activated* %s::activate() {"
%
(
entry
.
type
.
empty_declaration_code
(),
entry
.
type
.
empty_declaration_code
()))
code
.
putln
(
"if (this->%s == NULL) {"
%
active_self_entry
.
cname
)
code
.
putln
(
"this->%s = new %s::Activated(this);"
%
(
active_self_entry
.
cname
,
entry
.
type
.
empty_declaration_code
()))
code
.
putln
(
"}"
)
code
.
putln
(
"Cy_INCREF(this->%s);"
%
active_self_entry
.
cname
)
code
.
putln
(
"return this->%s;"
%
active_self_entry
.
cname
)
code
.
putln
(
"}"
)
def
generate_cyp_class_activated_class
(
self
,
entry
,
code
):
# TODO: handle inheritance
code
.
putln
(
"struct %s::Activated {"
%
entry
.
type
.
empty_declaration_code
())
code
.
putln
(
"%s * _passive_self;"
%
entry
.
type
.
empty_declaration_code
())
code
.
putln
(
"Activated(){} // Used for inheritance, never used for classic instantiation"
)
code
.
putln
(
"Activated(%s * passive_object):_passive_self(passive_object){} // Used by _passive_self.activate()"
%
entry
.
type
.
empty_declaration_code
())
for
reified_entry
in
entry
.
scope
.
reified_entries
:
code
.
putln
(
"// generating reified of %s"
%
reified_entry
.
name
)
code
.
putln
(
"};"
)
def
generate_cyp_class_wrapper_definition
(
self
,
type
,
wrapper_entry
,
constructor_entry
,
new_entry
,
alloc_entry
,
code
):
def
generate_cyp_class_wrapper_definition
(
self
,
type
,
wrapper_entry
,
constructor_entry
,
new_entry
,
alloc_entry
,
code
):
if
type
.
templates
:
if
type
.
templates
:
code
.
putln
(
"template <typename %s>"
%
", class "
.
join
(
code
.
putln
(
"template <typename %s>"
%
", class "
.
join
(
...
...
Cython/Compiler/Symtab.py
View file @
9c7b7903
...
@@ -707,6 +707,21 @@ class Scope(object):
...
@@ -707,6 +707,21 @@ class Scope(object):
alloc_entry
.
is_builtin_cmethod
=
1
alloc_entry
.
is_builtin_cmethod
=
1
alloc_entry
.
func_cname
=
"%s::%s"
%
(
entry
.
type
.
empty_declaration_code
(),
alloc_cname
)
alloc_entry
.
func_cname
=
"%s::%s"
%
(
entry
.
type
.
empty_declaration_code
(),
alloc_cname
)
# === Acthon ===
# Declare activated class
act_scope
=
CppClassScope
(
"Activated"
,
scope
)
act_type
=
PyrexTypes
.
CypClassType
(
"Activated"
,
act_scope
,
"Activated"
,
None
,
templates
=
templates
,
lock_mode
=
"nolock"
)
act_type
.
set_scope
(
act_scope
)
act_type
.
namespace
=
entry
.
type
#scope.declare_cpp_class("Activated", act_scope, pos)
scope
.
declare
(
"Activated"
,
"Activated"
,
act_type
,
pos
,
visibility
)
# Declaring active_self member and activate function (its definition is generated automatically)
act_attr_name
=
Naming
.
builtin_prefix
+
"_active_self"
scope
.
declare_var
(
"<active_self>"
,
act_type
,
pos
,
cname
=
act_attr_name
)
activate_type
=
PyrexTypes
.
CFuncType
(
act_type
,
[])
scope
.
declare_var
(
"__activate__"
,
activate_type
,
pos
,
cname
=
"__activate__"
,
defining
=
1
)
if
self
.
is_cpp_class_scope
:
if
self
.
is_cpp_class_scope
:
entry
.
type
.
namespace
=
self
.
outer_scope
.
lookup
(
self
.
name
).
type
entry
.
type
.
namespace
=
self
.
outer_scope
.
lookup
(
self
.
name
).
type
return
entry
return
entry
...
@@ -2494,6 +2509,7 @@ class CppClassScope(Scope):
...
@@ -2494,6 +2509,7 @@ class CppClassScope(Scope):
self
.
directives
=
outer_scope
.
directives
self
.
directives
=
outer_scope
.
directives
self
.
inherited_var_entries
=
[]
self
.
inherited_var_entries
=
[]
self
.
inherited_type_entries
=
[]
self
.
inherited_type_entries
=
[]
self
.
reified_methods
=
[]
if
templates
is
not
None
:
if
templates
is
not
None
:
for
T
in
templates
:
for
T
in
templates
:
template_entry
=
self
.
declare
(
template_entry
=
self
.
declare
(
...
@@ -2547,11 +2563,24 @@ class CppClassScope(Scope):
...
@@ -2547,11 +2563,24 @@ class CppClassScope(Scope):
wrapper_entry
.
func_cname
=
"%s::%s"
%
(
class_type
.
empty_declaration_code
(),
wrapper_cname
)
wrapper_entry
.
func_cname
=
"%s::%s"
%
(
class_type
.
empty_declaration_code
(),
wrapper_cname
)
return
wrapper_entry
return
wrapper_entry
def
reify_method
(
self
,
name
,
type
,
pos
,
defining
=
0
,
has_varargs
=
0
,
optional_arg_count
=
0
,
op_arg_struct
=
None
):
# TODO: clean argument list
reified_name
=
"reified_"
+
name
reified_cname
=
Naming
.
builtin_prefix
+
reified_name
scope
=
CppClassScope
(
reified_name
,
self
)
reify_base_class
=
[]
reified_entry
=
self
.
declare_cpp_class
(
reified_name
,
scope
,
pos
,
cname
=
reified_cname
,
base_classes
=
(),
cypclass
=
True
,
lock_mode
=
"nolock"
)
self
.
reified_methods
.
append
(
reified_entry
)
def
declare_cfunction
(
self
,
name
,
type
,
pos
,
def
declare_cfunction
(
self
,
name
,
type
,
pos
,
cname
=
None
,
visibility
=
'extern'
,
api
=
0
,
in_pxd
=
0
,
cname
=
None
,
visibility
=
'extern'
,
api
=
0
,
in_pxd
=
0
,
defining
=
0
,
modifiers
=
(),
utility_code
=
None
,
overridable
=
False
):
defining
=
0
,
modifiers
=
(),
utility_code
=
None
,
overridable
=
False
):
reify
=
True
class_name
=
self
.
name
.
split
(
'::'
)[
-
1
]
class_name
=
self
.
name
.
split
(
'::'
)[
-
1
]
if
name
in
(
class_name
,
'__init__'
)
and
cname
is
None
:
if
name
in
(
class_name
,
'__init__'
)
and
cname
is
None
:
reify
=
False
cname
=
"%s__init__%s"
%
(
Naming
.
func_prefix
,
class_name
)
cname
=
"%s__init__%s"
%
(
Naming
.
func_prefix
,
class_name
)
name
=
'<init>'
name
=
'<init>'
type
.
return_type
=
PyrexTypes
.
c_void_type
type
.
return_type
=
PyrexTypes
.
c_void_type
...
@@ -2572,13 +2601,16 @@ class CppClassScope(Scope):
...
@@ -2572,13 +2601,16 @@ class CppClassScope(Scope):
getattr
(
type
,
'op_arg_struct'
,
None
))
getattr
(
type
,
'op_arg_struct'
,
None
))
elif
name
==
'__dealloc__'
and
cname
is
None
:
elif
name
==
'__dealloc__'
and
cname
is
None
:
reify
=
False
cname
=
"%s__dealloc__%s"
%
(
Naming
.
func_prefix
,
class_name
)
cname
=
"%s__dealloc__%s"
%
(
Naming
.
func_prefix
,
class_name
)
name
=
'<del>'
name
=
'<del>'
type
.
return_type
=
PyrexTypes
.
c_void_type
type
.
return_type
=
PyrexTypes
.
c_void_type
elif
name
==
'__alloc__'
and
self
.
type
.
is_cyp_class
:
elif
name
==
'__alloc__'
and
self
.
type
.
is_cyp_class
:
reify
=
False
cname
=
"%s__alloc__%s"
%
(
Naming
.
func_prefix
,
class_name
)
cname
=
"%s__alloc__%s"
%
(
Naming
.
func_prefix
,
class_name
)
name
=
'<alloc>'
name
=
'<alloc>'
elif
name
==
'__new__'
and
self
.
type
.
is_cyp_class
:
elif
name
==
'__new__'
and
self
.
type
.
is_cyp_class
:
reify
=
False
if
name
in
self
.
entries
:
if
name
in
self
.
entries
:
if
self
.
entries
[
name
].
is_inherited
:
if
self
.
entries
[
name
].
is_inherited
:
del
self
.
entries
[
name
]
del
self
.
entries
[
name
]
...
@@ -2595,6 +2627,7 @@ class CppClassScope(Scope):
...
@@ -2595,6 +2627,7 @@ class CppClassScope(Scope):
else
:
else
:
operator
=
self
.
operator_table
.
get
(
name
,
None
)
operator
=
self
.
operator_table
.
get
(
name
,
None
)
if
operator
:
if
operator
:
reify
=
False
name
=
'operator'
+
operator
name
=
'operator'
+
operator
elif
name
.
startswith
(
'__'
)
and
name
.
endswith
(
'__'
):
elif
name
.
startswith
(
'__'
)
and
name
.
endswith
(
'__'
):
stripped_name
=
name
[
2
:
-
2
]
stripped_name
=
name
[
2
:
-
2
]
...
@@ -2618,6 +2651,7 @@ class CppClassScope(Scope):
...
@@ -2618,6 +2651,7 @@ class CppClassScope(Scope):
known_type
=
PyrexTypes
.
simple_c_type
(
signed
,
longness
,
ctypename
)
known_type
=
PyrexTypes
.
simple_c_type
(
signed
,
longness
,
ctypename
)
if
not
known_type
:
if
not
known_type
:
if
stripped_name
==
"bool"
:
if
stripped_name
==
"bool"
:
reify
=
False
# This one is hardcoded because it is declared as an int
# This one is hardcoded because it is declared as an int
# in PyrexTypes
# in PyrexTypes
name
=
'operator bool'
name
=
'operator bool'
...
@@ -2625,6 +2659,7 @@ class CppClassScope(Scope):
...
@@ -2625,6 +2659,7 @@ class CppClassScope(Scope):
else
:
else
:
known_type
=
self
.
lookup_type
(
stripped_name
)
known_type
=
self
.
lookup_type
(
stripped_name
)
if
known_type
:
if
known_type
:
reify
=
False
name
=
'operator '
+
known_type
.
declaration_code
(
''
)
name
=
'operator '
+
known_type
.
declaration_code
(
''
)
type
.
args
=
[]
type
.
args
=
[]
...
@@ -2641,6 +2676,8 @@ class CppClassScope(Scope):
...
@@ -2641,6 +2676,8 @@ class CppClassScope(Scope):
entry
=
self
.
declare_var
(
name
,
type
,
pos
,
entry
=
self
.
declare_var
(
name
,
type
,
pos
,
defining
=
defining
,
defining
=
defining
,
cname
=
cname
,
visibility
=
visibility
)
cname
=
cname
,
visibility
=
visibility
)
if
reify
:
self
.
reify_method
(
name
,
type
,
pos
)
#if prev_entry and not defining:
#if prev_entry and not defining:
# entry.overloaded_alternatives = prev_entry.all_alternatives()
# entry.overloaded_alternatives = prev_entry.all_alternatives()
entry
.
utility_code
=
utility_code
entry
.
utility_code
=
utility_code
...
@@ -2665,7 +2702,7 @@ class CppClassScope(Scope):
...
@@ -2665,7 +2702,7 @@ class CppClassScope(Scope):
#constructor/destructor is not inherited
#constructor/destructor is not inherited
if
base_entry
.
name
==
"<del>"
\
if
base_entry
.
name
==
"<del>"
\
or
base_entry
.
name
==
"<init>"
and
not
self
.
parent_type
.
is_cyp_class
\
or
base_entry
.
name
==
"<init>"
and
not
self
.
parent_type
.
is_cyp_class
\
or
base_entry
.
name
in
(
"<constructor>"
,
"<alloc>"
)
and
self
.
parent_type
.
is_cyp_class
:
or
base_entry
.
name
in
(
"<constructor>"
,
"<alloc>"
,
"<active_self>"
,
"__activate__"
)
and
self
.
parent_type
.
is_cyp_class
:
continue
continue
elif
base_entry
.
name
==
"<init>"
and
not
self
.
lookup_here
(
"__new__"
):
elif
base_entry
.
name
==
"<init>"
and
not
self
.
lookup_here
(
"__new__"
):
wrapper_entry
=
self
.
declare_constructor_wrapper
(
base_entry_type
.
args
,
base_entry
.
pos
,
wrapper_entry
=
self
.
declare_constructor_wrapper
(
base_entry_type
.
args
,
base_entry
.
pos
,
...
...
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