Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
typon-compiler
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
typon
typon-compiler
Commits
420d71ea
Commit
420d71ea
authored
Nov 03, 2023
by
Tom Niget
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add bindings for methods and fields
parent
1e3fcd78
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
5 deletions
+18
-5
typon/trans/transpiler/phases/emit_cpp/module.py
typon/trans/transpiler/phases/emit_cpp/module.py
+18
-5
No files found.
typon/trans/transpiler/phases/emit_cpp/module.py
View file @
420d71ea
...
...
@@ -6,7 +6,7 @@ from dataclasses import dataclass, field
from
transpiler.phases.typing
import
FunctionType
from
transpiler.phases.typing.scope
import
Scope
from
transpiler.phases.emit_cpp
import
CoroutineMode
,
FunctionEmissionKind
,
NodeVisitor
from
transpiler.phases.emit_cpp
import
CoroutineMode
,
FunctionEmissionKind
,
NodeVisitor
,
join
from
transpiler.phases.emit_cpp.block
import
BlockVisitor
from
transpiler.phases.emit_cpp.class_
import
ClassVisitor
from
transpiler.phases.emit_cpp.function
import
FunctionVisitor
...
...
@@ -127,13 +127,26 @@ class ModuleVisitorExt(NodeVisitor):
init
=
node
.
type
.
fields
[
"__init__"
].
type
.
resolve
().
remove_self
()
init_params
=
init
.
parameters
yield
".def(py::init<"
for
i
,
argty
in
enumerate
(
init_params
):
if
i
!=
0
:
yield
", "
yield
from
self
.
visit
(
argty
)
yield
from
join
(
", "
,
map
(
self
.
visit
,
init_params
))
yield
">())"
yield
f'.def("__repr__", [](const PROGRAMNS::
{
node
.
name
}
_s::py_type& self)'
yield
"{ return repr(self); })"
for
f
,
v
in
node
.
type
.
fields
.
items
():
if
f
==
"__init__"
:
continue
if
isinstance
(
v
.
type
,
FunctionType
):
meth
=
v
.
type
.
remove_self
()
yield
f'.def("
{
f
}
", [](const PROGRAMNS::
{
node
.
name
}
_s::py_type& a'
if
meth
.
parameters
:
yield
","
vis
=
BlockVisitor
(
node
.
scope
)
yield
from
vis
.
visit_func_params
(((
f"arg
{
i
}
"
,
ty
,
None
)
for
i
,
ty
in
enumerate
(
meth
.
parameters
)),
FunctionEmissionKind
.
LAMBDA
)
yield
f') {{ return dotp(&a,
{
f
}
)('
if
meth
.
parameters
:
yield
from
join
(
", "
,
(
f"arg
{
i
}
"
for
i
,
_
in
enumerate
(
meth
.
parameters
)))
yield
').call(); })'
else
:
yield
f'.def_readwrite("
{
f
}
", &PROGRAMNS::
{
node
.
name
}
_s::py_type::
{
f
}
)'
yield
";"
pass
...
...
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