Jump to page: 1 2
Thread overview
How to import for mixin contents only.
Mar 10, 2016
Taylor Hillegeist
Mar 10, 2016
Mike Parker
Mar 10, 2016
Taylor Hillegeist
Mar 10, 2016
Taylor Hillegeist
Mar 10, 2016
Andrea Fontana
Mar 10, 2016
Taylor Hillegeist
Mar 10, 2016
Taylor Hillegeist
Mar 10, 2016
Taylor Hillegeist
Mar 10, 2016
Taylor Hillegeist
Mar 10, 2016
Andrea Fontana
Mar 10, 2016
Taylor Hillegeist
March 10, 2016
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));
}
March 10, 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?
March 10, 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:
>> 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?

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..etc
March 10, 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:
>> 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?

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);
}
March 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

March 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:
>> 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

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.
March 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:
>> On Thursday, 10 March 2016 at 16:20:42 UTC, Taylor Hillegeist wrote:
>>> [...]
>>
>> I wonder if compiler is smart enaugh to undestand that dependency is not needed at runtime in this case:
>>
>> http://dpaste.dzfl.pl/fd3bc2a839a3
>
> well the latest gdc isnt smart enough.

So interestingly this will work if i add -ffunction-sections  to my compiler options? no idea why?


March 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:
>> 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:
>>>> [...]
>>>
>>> I wonder if compiler is smart enaugh to undestand that dependency is not needed at runtime in this case:
>>>
>>> http://dpaste.dzfl.pl/fd3bc2a839a3
>>
>> well the latest gdc isnt smart enough.
>
> So interestingly this will work if i add -ffunction-sections  to my compiler options? no idea why?

However my binary goes from 4kb with static text to 11kb with the above change.
March 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:
>> 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:
>>>> On Thursday, 10 March 2016 at 16:20:42 UTC, Taylor Hillegeist wrote:
>>>>> [...]
>>>>
>>>> I wonder if compiler is smart enaugh to undestand that dependency is not needed at runtime in this case:
>>>>
>>>> http://dpaste.dzfl.pl/fd3bc2a839a3
>>>
>>> well the latest gdc isnt smart enough.
>>
>> So interestingly this will work if i add -ffunction-sections  to my compiler options? no idea why?
>
> However my binary goes from 4kb with static text to 11kb with the above change.

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.
March 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);
}
« First   ‹ Prev
1 2