Closed ghost closed 1 year ago
What do you mean by "use size_t
" ? Introduce the size_t
type in Fusion? Or emit type casts?
What do you mean by "use
size_t
" ? Introduce thesize_t
type in Fusion? Or emit type casts?
Use size_t
in the generated code instead of int
. As you can see, you are currently use int
.
Transpiling all int
s to size_t
is not an option. size_t
is an unsigned type.
Transpiling all
int
s tosize_t
is not an option.size_t
is an unsigned type.
No. I didn't tell you to replace all instances of int
with size_t
. This is nonsense. I don't know where you got this idea because I have never said it. But size_t
should be used for indexes (please read the warnings I posted on this thread) and something related to size like klass->typeParameterCount
and arrayStg->length
on #97.
Oh my bad. If the original Fusion code uses int
then the transpiler just translated them as is. This is the expected behavior.
@pfusik Which language is Fusion written in? I'm confused. Is it written in itself or in C++?
Fusion is self-hosted. It transpiles itself to C++, C# and JavaScript.
I'd like to avoid the C++ compilation warnings, but haven't decided yet how.
Fusion is self-hosted. It transpiles itself to C++, C# and JavaScript.
I'd like to avoid the C++ compilation warnings, but haven't decided yet how.
Done 😄
I don't want to hide the warnings.
One option is emitting std::ssize
, unfortunately that's C++20. Shall we cast to ptrdiff_t
instead?
ssize_t
(in stddef.h
) has been around for quite some time.
(I know that's not proper, canonical C++ in the purist sense, could use cstddef
instead, but not sure re namespacing on those).
Edit: Ah, oops. Misread that. You could just implement ssize
in the boilerplate used by Fusion in this case as seen in https://en.cppreference.com/w/cpp/iterator/size -> The implementation is not that difficult.
template <class C>
constexpr auto ssize(const C& c) -> std::common_type_t<std::ptrdiff_t, std::make_signed_t<decltype(c.size())>>
{
using R = std::common_type_t<std::ptrdiff_t, std::make_signed_t<decltype(c.size())>>;
return static_cast<R>(c.size());
}
I chose std::ssize
. Compilers have been supporting it for some time and fut
requires a C++20 compiler anyway. I know many projects are still not yet on C++20, but that's only a matter of time.
What's left is string length:
libfut.cpp: In member function 'void GenJsNoModule::writeInterpolatedLiteral(std::string_view)':
libfut.cpp:17904:48: warning: comparison of integer expressions of different signedness: 'int' and
'std::basic_string_view<char>::size_type' {aka 'long long unsigned int'} [-Wsign-compare]
17904 | if (c == '`' || (c == '$' && i < s.length() && s[i] == '{'))
| ~~^~~~~~~~~~~~
This will get rid of these warnings: