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
b6da4171
Commit
b6da4171
authored
Apr 10, 2024
by
Tom Niget
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix str and repr for all objects
parent
4827539e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
2 deletions
+23
-2
typon/include/python/builtins/mutex.hpp
typon/include/python/builtins/mutex.hpp
+9
-1
typon/include/python/builtins/str.hpp
typon/include/python/builtins/str.hpp
+14
-1
No files found.
typon/include/python/builtins/mutex.hpp
View file @
b6da4171
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
namespace
view
=
std
::
views
;
namespace
view
=
std
::
views
;
#include "
print
.hpp"
#include "
str
.hpp"
#include <python/basedef.hpp>
#include <python/basedef.hpp>
namespace
typon
{
namespace
typon
{
...
@@ -24,6 +24,14 @@ struct TyCell__oo : classtype<_Base0, TyCell__oo<>> {
...
@@ -24,6 +24,14 @@ struct TyCell__oo : classtype<_Base0, TyCell__oo<>> {
};
};
template
<
typename
T
>
auto
operator
()(
T
val
)
const
{
return
Obj
<
T
>
{
val
};
}
template
<
typename
T
>
auto
operator
()(
T
val
)
const
{
return
Obj
<
T
>
{
val
};
}
struct
:
method
{
auto
operator
()(
auto
self
)
const
{
std
::
stringstream
s
;
s
<<
"Cell("
<<
repr
(
self
->
val
)
->
value
<<
')'
;
return
typon
::
TyStr__oo
<>::
Obj
(
s
.
str
());
}
}
static
constexpr
oo__str__oo
{};
};
};
template
<
typename
_Base0
=
object
>
template
<
typename
_Base0
=
object
>
...
...
typon/include/python/builtins/str.hpp
View file @
b6da4171
...
@@ -248,6 +248,8 @@ struct TyStr__oo : classtype<_Base0, TyStr__oo<>> {
...
@@ -248,6 +248,8 @@ struct TyStr__oo : classtype<_Base0, TyStr__oo<>> {
constexpr
Obj
()
:
value
()
{}
constexpr
Obj
()
:
value
()
{}
constexpr
Obj
(
std
::
string
value
)
:
value
(
value
)
{}
constexpr
Obj
(
std
::
string
value
)
:
value
(
value
)
{}
constexpr
Obj
(
const
std
::
string_view
&
value
)
:
value
(
value
)
{}
constexpr
Obj
(
const
char
*
value
)
:
value
(
value
)
{}
constexpr
Obj
(
const
char
*
value
,
size_t
count
)
:
value
(
value
,
count
)
{}
constexpr
Obj
(
const
char
*
value
,
size_t
count
)
:
value
(
value
,
count
)
{}
operator
std
::
string
()
const
{
return
value
;
}
operator
std
::
string
()
const
{
return
value
;
}
operator
std
::
string_view
()
const
{
return
value
;
}
operator
std
::
string_view
()
const
{
return
value
;
}
...
@@ -287,14 +289,23 @@ template <NoStr T> auto str(const T &x) {
...
@@ -287,14 +289,23 @@ template <NoStr T> auto str(const T &x) {
*/
*/
template
<
typename
T
>
template
<
typename
T
>
concept
HasStr
=
requires
(
T
x
)
{
dot
(
x
,
oo__str__oo
)()
;
};
concept
HasStr
=
requires
(
T
x
)
{
x
->
oo__str__oo
;
};
template
<
typename
T
>
template
<
typename
T
>
concept
HasRepr
=
requires
(
T
x
)
{
dot
(
x
,
oo__repr__oo
)();
};
concept
HasRepr
=
requires
(
T
x
)
{
dot
(
x
,
oo__repr__oo
)();
};
template
<
typename
T
>
concept
HasRefModelRepresentation
=
requires
{
std
::
declval
<
T
>
()
->
repr
;
};
template
<
typename
T
>
auto
str
(
const
T
&
x
)
{
template
<
typename
T
>
auto
str
(
const
T
&
x
)
{
if
constexpr
(
HasStr
<
T
>
)
{
if
constexpr
(
HasStr
<
T
>
)
{
return
dot
(
x
,
oo__str__oo
)();
return
dot
(
x
,
oo__str__oo
)();
}
else
if
constexpr
(
HasRepr
<
T
>
)
{
return
dot
(
x
,
oo__repr__oo
)();
}
else
if
constexpr
(
HasRefModelRepresentation
<
T
>
)
{
return
"<"
_ps
+
typon
::
TyStr__oo
<>::
Obj
(
x
->
repr
)
+
">"
_ps
;
}
else
{
}
else
{
std
::
stringstream
s
;
std
::
stringstream
s
;
s
<<
x
;
s
<<
x
;
...
@@ -305,6 +316,8 @@ template <typename T> auto str(const T &x) {
...
@@ -305,6 +316,8 @@ template <typename T> auto str(const T &x) {
template
<
typename
T
>
auto
repr
(
const
T
&
x
)
{
template
<
typename
T
>
auto
repr
(
const
T
&
x
)
{
if
constexpr
(
HasRepr
<
T
>
)
{
if
constexpr
(
HasRepr
<
T
>
)
{
return
dot
(
x
,
oo__repr__oo
)();
return
dot
(
x
,
oo__repr__oo
)();
}
else
if
constexpr
(
HasRefModelRepresentation
<
T
>
)
{
return
"<"
_ps
+
typon
::
TyStr__oo
<>::
Obj
(
x
->
repr
)
+
">"
_ps
;
}
else
{
}
else
{
std
::
stringstream
s
;
std
::
stringstream
s
;
s
<<
x
;
s
<<
x
;
...
...
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