-
-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
InkBin Header #8
Conversation
Looks good so far. I guess maybe Endianness should be read first though? Since that would affect the encoding of the version numbers (for when, someday in the future, we actually do the flip). |
The memory layout of std::tuple is not intuitive and not defined from the standard. There for we will use an explicit read. Check out this example: the output for me was: `42 : 10` where I expect: `10 : 42` compile flags: `--std=c++20` compiler: `g++ 10.2.0` ```cpp struct Foo { static Foo create(const char * data) { Foo foo; foo._data = *reinterpret_cast<const decltype(_data)*>(data); return foo; } int& x = std::get<0>(_data); int& y = std::get<1>(_data); std::tuple<int,int> _data; }; int main(int argc, char *argv[]) { int buffer[] = {10, 42}; auto f = Foo::create((char*)buffer); std::cout << f.x << " : " << f.y << std::endl; return 0; } ```
It's probably better to avoid std::tuple all together for consistency with the rest of the code base. The only STL code I have right now (which is all excluded if you turn off that preprocessor flag) is purely in user-facing code. My intent was that if you were already using STL and you wanted a prettier, STL friendly interface, you could turn on all those functions. Admittedly, my reason for making STL optional in the runtime is not very compelling. Basically, since the project is supposed to work with Unreal, I didn't want to have all these and related STL includes when Unreal's API goes out of its way to implement their own versions of all those classes. |
I see, sorry will chage it. I would like to introduce a Or would it be ok to rewrite the in memeory copy of the inkbin if the endian differs? also we need a kind of logger to warn about it (so he can recompile it to avoid the overhead) Is the inkcpp version number already in a header? |
Eh. Sometimes I try random C++ features just for fun to see how they work. I've never really used tuple much before actually.
In
I don't have a good runtime logger yet! That's something that should be added at some point.
No. There is really no inkcpp version at all right now. Maybe we can make a new header file and define it? The header is written in |
Thanks for the hints. The read function was a nice spot. It's also without STL 😜. |
Hey, no problem.
It looks like right now you're just always writing out "SAME" into the file for the endian encoding. I'm not sure if it makes sense to write SAME or DIFFER into the file, since the compiler doesn't really know who is going to be reading it. I think it made more sense to have what you had before: Big or Small being the enum values. Then the runtime can just check if its endian setting matches the file and if not, swap. I did some googling concerning checking the endianness. Looks like this function works: // source https://stackoverflow.com/questions/1001307/detecting-endianness-programmatically-in-a-c-program
bool is_big_endian(void)
{
union {
uint32_t i;
char c[4];
} bint = {0x01020304};
return bint.c[0] == 1;
} I think you also want the value of the endianness enum to be only a single byte, otherwise the byte order could be wrong if you're reading from a different endianness. |
This was the idea, the compiler write SAME, and when the endian differs the runner reads DIFFER, so i do not care about the actual ending. So we don't realy care about the actual endian. But we can also use explicit big and small endian. |
Ohhhhhh I see now. You were just too clever for me. Awesome!
I might make a few code style tweaks for consistency, then I'll merge this
in.
…On Tue, Feb 2, 2021, 11:56 PM JBenda, ***@***.***> wrote:
This was the idea, the compiler write SAME, and when the endian differs
the runner reads DIFFER, so i do not care about the actual ending.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#8 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAIAEVFWWFSVMSQK6ASMKOLS5D6SHANCNFSM4W5TF7FQ>
.
|
Ok, have you somewhere a written form of you're coding style ^^, than I can adapt, and you can spare time ^^; |
What should be the reaction when the inkcpp version dose not match ? An warning or an exception? |
I think the reaction should be a runtime exception on load. My idea for the inkcpp version number is it should only increment when there are breaking changes to the format.
I'll add a Contributing guide this weekend :) |
Cool :) 👍 Then I will add an exception on load. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the code style guidelines as I mentioned. Mostly it's just casing. I added comments on everything that should change. Hopefully it's not too pedantic lol. I just like a unified naming scheme, whatever scheme it happens to be.
I liked to the corresponding section in each comment, but the full guide is here.
https://github.com/brwarner/inkcpp/blob/master/CONTRIBUTING.md
shared/private/header.h
Outdated
|
||
#include "system.h" | ||
|
||
namespace ink { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be ink::internal
since this is not a user facing type.
https://github.com/brwarner/inkcpp/blob/master/CONTRIBUTING.md#namespaces
shared/private/header.h
Outdated
#include "system.h" | ||
|
||
namespace ink { | ||
struct Header { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be in snake_case (i.e. header
)
https://github.com/brwarner/inkcpp/blob/master/CONTRIBUTING.md#code-style
shared/private/header.h
Outdated
DIFFER = 0x0100 | ||
} endien = ENDENSE::NONE; | ||
uint32_t inkVersionNumber = 0; | ||
uint32_t inkCppVersionNumber = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enum type, values, and struct members should be in snake_case.
https://github.com/brwarner/inkcpp/blob/master/CONTRIBUTING.md#code-style
shared/public/version.h
Outdated
#include "system.h" | ||
|
||
namespace ink { | ||
constexpr uint32_t VERSION = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Compile-time constants should be in PascalCase.
Also maybe name this something a bit more specific like InkBinVersion
perhaps?
https://github.com/brwarner/inkcpp/blob/master/CONTRIBUTING.md#code-style
inkcpp/story_impl.cpp
Outdated
|
||
#ifdef INK_ENABLE_STL | ||
#include <iostream> | ||
#endif | ||
|
||
namespace ink { | ||
// FIXME: find appropriate place to define | ||
Header Header::parse_header(const char *data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe in a new header.cpp
file located in the inkcpp
folder. You can add new cpp files to CMake by adding them to the CMakeLists.txt file in that folder. You'll see a giant list of source files there. Since it's only used by the runtime, the code can live in that folder.
inkcpp/story_impl.cpp
Outdated
|
||
#ifdef INK_ENABLE_STL | ||
#include <iostream> | ||
#endif | ||
|
||
namespace ink { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is a struct internal, it should live in ink::internal
inkcpp_compiler/emitter.h
Outdated
@@ -2,6 +2,7 @@ | |||
|
|||
#include "command.h" | |||
#include "system.h" | |||
#include "version.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like you don't actually use this header here? You can just include it in the relevant cpp file.
Also, if you merge in the master branch you'll get the new GitHub Actions which will automatically test if your branch builds on each of the OSs. |
This sounds awesome :+1 ! But the platform is still not at the master, so I can't merge it there, because my branches based on the platform. Otherwise, I can't run them locale ^^. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
Adding inkcpp version and endianness to InkBin header.
No STL support will come after the PoC finished.