codegendecl on a const

2021-07-31 Thread timothee
> I don't really see the 4x factor increase, but actually a 1 to 1 mapping with > my approach. the 3X or 4X increase is in the C file generated, since it contains escape sequences, eg: STRING_LITERAL(TM__1m9cQUY9abSjxCA8ws9b1wH9ag_4, "\317\372\355\376\007\000\ Run d

codegendecl on a const

2021-06-17 Thread vitreo12
I don't really see the 4x factor increase, but actually a 1 to 1 mapping with my approach. The 45mb .tar.xz file is exactly of that size on the resulting executable. The size was blowing up when using the `escape` approach that was mentioned earlier.

codegendecl on a const

2021-06-17 Thread timothee
this is not a good solution for embedding large binaries as the string encoding blows up by a factor 4X. Really, the correct way is to build upon what I wrote in and make it cross-platform and wrapped with an easy to use API , it's possible and not nece

codegendecl on a const

2021-06-17 Thread vitreo12
For anyone coming across this. This is a solution that is working flawlessly for me. I basically split the `const` part that loads the binary into its own module. Then, I overwrite the `STRING_LITERAL` macro in order to contain the `__attribute__((section))` that I need. This way the overwriting

codegendecl on a const

2021-06-17 Thread vitreo12
The more I look at this problem, the more I realize I literally just need to prepend the `__attribute__((section)))` to a `const string`, and these workarounds seem such an overkill for a simple task like this.

codegendecl on a const

2021-06-17 Thread vitreo12
Thanks again, Unfortunately I need to find a portable multiplatform solution. I know have a "builder" file that will output the contents of the binary to a txt file, which is then read in using the `emit` approach. Unfortunately, though, `escape` does not seem to be the right function here, as

codegendecl on a const

2021-06-17 Thread Demos
a backend specific pragma to pick the section for stuff would be kinda nice, most other compilers have it.

codegendecl on a const

2021-06-17 Thread timothee
there are better ways to embed large binary data in an executable. I think it'd be worthwhile adding APIs to make this easier (both to store and retrieve), this can be useful and it's tricky (but doable) to make this work cross-platform (hence the need for an API to implement it) eg, see: *

codegendecl on a const

2021-06-16 Thread vitreo12
Thanks for the answer! Unfortunately my file is quite big (50mb), so the VM bails out on the `escape` call. Do you reckon there is a way to make the string literal of the binary work? I have tried various methods with C preprocessor macros, like: let omni_tar {.importc, nodecl.}:

codegendecl on a const

2021-06-15 Thread timothee
`codegenDecl` is under-specified and should be improved in meantime this works, however ugly: when defined case2: from strutils import escape let myFile2 {.importc, nodecl.}: cstring {.emit: [""" __attribute__((section("DATA,.myFile"))) const char* myFile2 = """,

codegendecl on a const

2021-06-15 Thread vitreo12
Hello, Is it possible to add a `codegendecl` pragma to a `const`? I'm getting a "Cannot attach a custom pragma to 'myFile'" error: const myFile {.codegenDecl:"$# __attribute__((section(\".myFile\")))".} = staticRead("myFile.tar.xz") Run In my use case, I need to read