digitalmars.D.learn - How to import for mixin contents only.
- Taylor Hillegeist (13/13) Mar 09 2016 So i want bitfields for just a little bit. but i dont want its
- Mike Parker (9/22) Mar 09 2016 __ctfe is a runtime construct, not compile-time. It cannot be
- Taylor Hillegeist (5/28) Mar 09 2016 I am running on a MKL25Z development board. The output of the
- Taylor Hillegeist (13/36) Mar 10 2016 I feel like this should do what i want it too. but it doesn't.
- Andrea Fontana (5/17) Mar 10 2016 I wonder if compiler is smart enaugh to undestand that dependency
- Taylor Hillegeist (16/34) Mar 10 2016 well the latest gdc isnt smart enough.
- Taylor Hillegeist (4/15) Mar 10 2016 So interestingly this will work if i add -ffunction-sections to
- Taylor Hillegeist (4/20) Mar 10 2016 However my binary goes from 4kb with static text to 11kb with the
- Taylor Hillegeist (4/25) Mar 10 2016 I suppose the linker optimized the functions away since they are
- Andrea Fontana (20/23) Mar 10 2016 AFAIK assert(0) and other falsey assert have a special meaning
- Taylor Hillegeist (7/30) Mar 10 2016 I'm good with the assert(0), I'm not so happy with the linker not
So i want bitfields for just a little bit. but i dont want its dependencies. How is it done. I have tried this. but it doesnt seem to work on gdc. :( struct Color_t { static if(__ctfe){ import std.bitmanip:bitfields; } mixin(bitfields!( uint, "R", 8, uint, "G", 8, uint, "B", 8, uint, "A", 8)); }
Mar 09 2016
On Thursday, 10 March 2016 at 04:07:54 UTC, Taylor Hillegeist wrote:So i want bitfields for just a little bit. but i dont want its dependencies. How is it done. I have tried this. but it doesnt seem to work on gdc. :( struct Color_t { static if(__ctfe){ import std.bitmanip:bitfields; } mixin(bitfields!( uint, "R", 8, uint, "G", 8, uint, "B", 8, uint, "A", 8)); }__ctfe is a runtime construct, not compile-time. It cannot be used with static if. More over, it's only available *inside* a function that is currently being executed in a compile-time context. It has no role outside of that. What problem are you trying to solve here? I mean, what is the problem with whatever dependencies std.bitmanip:bitfields has that makes you only want to import it during compilation?
Mar 09 2016
On Thursday, 10 March 2016 at 04:56:52 UTC, Mike Parker wrote:On Thursday, 10 March 2016 at 04:07:54 UTC, Taylor Hillegeist wrote:I am running on a MKL25Z development board. The output of the mixin works fine. but the dependencies of the std.bitmanip:bitfields are quite extensive. including std.format..etcSo i want bitfields for just a little bit. but i dont want its dependencies. How is it done. I have tried this. but it doesnt seem to work on gdc. :( struct Color_t { static if(__ctfe){ import std.bitmanip:bitfields; } mixin(bitfields!( uint, "R", 8, uint, "G", 8, uint, "B", 8, uint, "A", 8)); }__ctfe is a runtime construct, not compile-time. It cannot be used with static if. More over, it's only available *inside* a function that is currently being executed in a compile-time context. It has no role outside of that. What problem are you trying to solve here? I mean, what is the problem with whatever dependencies std.bitmanip:bitfields has that makes you only want to import it during compilation?
Mar 09 2016
On Thursday, 10 March 2016 at 04:56:52 UTC, Mike Parker wrote:On Thursday, 10 March 2016 at 04:07:54 UTC, Taylor Hillegeist wrote:I feel like this should do what i want it too. but it doesn't. struct Color_t { static if(1==1){ import std.bitmanip:bitfields; immutable string item = bitfields!( uint, "R", 8, uint, "G", 8, uint, "B", 8, uint, "A", 8); } mixin(item); }So i want bitfields for just a little bit. but i dont want its dependencies. How is it done. I have tried this. but it doesnt seem to work on gdc. :( struct Color_t { static if(__ctfe){ import std.bitmanip:bitfields; } mixin(bitfields!( uint, "R", 8, uint, "G", 8, uint, "B", 8, uint, "A", 8)); }__ctfe is a runtime construct, not compile-time. It cannot be used with static if. More over, it's only available *inside* a function that is currently being executed in a compile-time context. It has no role outside of that. What problem are you trying to solve here? I mean, what is the problem with whatever dependencies std.bitmanip:bitfields has that makes you only want to import it during compilation?
Mar 10 2016
On Thursday, 10 March 2016 at 16:20:42 UTC, Taylor Hillegeist wrote:I feel like this should do what i want it too. but it doesn't. struct Color_t { static if(1==1){ import std.bitmanip:bitfields; immutable string item = bitfields!( uint, "R", 8, uint, "G", 8, uint, "B", 8, uint, "A", 8); } mixin(item); }I wonder if compiler is smart enaugh to undestand that dependency is not needed at runtime in this case: http://dpaste.dzfl.pl/fd3bc2a839a3
Mar 10 2016
On Thursday, 10 March 2016 at 16:51:32 UTC, Andrea Fontana wrote:On Thursday, 10 March 2016 at 16:20:42 UTC, Taylor Hillegeist wrote:well the latest gdc isnt smart enough. immutable(string) BF(){ if(!__ctfe) assert(0); import std.bitmanip:bitfields; return bitfields!( uint, "R", 8, uint, "G", 8, uint, "B", 8, uint, "A", 8); } struct Color_t { mixin(BF()); } is a fair try as well. but neither work.I feel like this should do what i want it too. but it doesn't. struct Color_t { static if(1==1){ import std.bitmanip:bitfields; immutable string item = bitfields!( uint, "R", 8, uint, "G", 8, uint, "B", 8, uint, "A", 8); } mixin(item); }I wonder if compiler is smart enaugh to undestand that dependency is not needed at runtime in this case: http://dpaste.dzfl.pl/fd3bc2a839a3
Mar 10 2016
On Thursday, 10 March 2016 at 17:05:26 UTC, Taylor Hillegeist wrote:On Thursday, 10 March 2016 at 16:51:32 UTC, Andrea Fontana wrote:So interestingly this will work if i add -ffunction-sections to my compiler options? no idea why?On Thursday, 10 March 2016 at 16:20:42 UTC, Taylor Hillegeist wrote:well the latest gdc isnt smart enough.[...]I wonder if compiler is smart enaugh to undestand that dependency is not needed at runtime in this case: http://dpaste.dzfl.pl/fd3bc2a839a3
Mar 10 2016
On Thursday, 10 March 2016 at 17:22:58 UTC, Taylor Hillegeist wrote:On Thursday, 10 March 2016 at 17:05:26 UTC, Taylor Hillegeist wrote:However my binary goes from 4kb with static text to 11kb with the above change.On Thursday, 10 March 2016 at 16:51:32 UTC, Andrea Fontana wrote:So interestingly this will work if i add -ffunction-sections to my compiler options? no idea why?On Thursday, 10 March 2016 at 16:20:42 UTC, Taylor Hillegeist wrote:well the latest gdc isnt smart enough.[...]I wonder if compiler is smart enaugh to undestand that dependency is not needed at runtime in this case: http://dpaste.dzfl.pl/fd3bc2a839a3
Mar 10 2016
On Thursday, 10 March 2016 at 17:24:51 UTC, Taylor Hillegeist wrote:On Thursday, 10 March 2016 at 17:22:58 UTC, Taylor Hillegeist wrote:I suppose the linker optimized the functions away since they are now in their own section. But it seems a hacky way to do this.On Thursday, 10 March 2016 at 17:05:26 UTC, Taylor Hillegeist wrote:However my binary goes from 4kb with static text to 11kb with the above change.On Thursday, 10 March 2016 at 16:51:32 UTC, Andrea Fontana wrote:So interestingly this will work if i add -ffunction-sections to my compiler options? no idea why?On Thursday, 10 March 2016 at 16:20:42 UTC, Taylor Hillegeist wrote:well the latest gdc isnt smart enough.[...]I wonder if compiler is smart enaugh to undestand that dependency is not needed at runtime in this case: http://dpaste.dzfl.pl/fd3bc2a839a3
Mar 10 2016
On Thursday, 10 March 2016 at 17:43:08 UTC, Taylor Hillegeist wrote:I suppose the linker optimized the functions away since they are now in their own section. But it seems a hacky way to do this.AFAIK assert(0) and other falsey assert have a special meaning for compiler. So probably it's not so hacky but just a way to say that case can't happen. It is used also for: auto myfunc(int i) { if (i == 0) return 10; else if (i == 1) return 3; assert(0); } And also with non final switch using switch(var) { case ... ... default: assert(0); }
Mar 10 2016
On Thursday, 10 March 2016 at 22:07:23 UTC, Andrea Fontana wrote:On Thursday, 10 March 2016 at 17:43:08 UTC, Taylor Hillegeist wrote:I'm good with the assert(0), I'm not so happy with the linker not being able to create a binary without the -ffunction-sections option. I think there needs to be a ctimport keyword or something. I should not have to deal with the imports only used during compile time. it is not a good thing.I suppose the linker optimized the functions away since they are now in their own section. But it seems a hacky way to do this.AFAIK assert(0) and other falsey assert have a special meaning for compiler. So probably it's not so hacky but just a way to say that case can't happen. It is used also for: auto myfunc(int i) { if (i == 0) return 10; else if (i == 1) return 3; assert(0); } And also with non final switch using switch(var) { case ... ... default: assert(0); }
Mar 10 2016