digitalmars.D.bugs - [Issue 1301] New: CTFE fails for ImportExpressions
- d-bugmail puremagic.com (24/24) Jun 30 2007 http://d.puremagic.com/issues/show_bug.cgi?id=1301
- d-bugmail puremagic.com (22/22) Jun 30 2007 http://d.puremagic.com/issues/show_bug.cgi?id=1301
- d-bugmail puremagic.com (4/4) Jun 30 2007 http://d.puremagic.com/issues/show_bug.cgi?id=1301
- Chris Nicholson-Sauls (21/31) Jun 30 2007 One thing I think should work is hiding the import() in a template, and
- Max Samukha (3/23) Jul 02 2007 Thanks for the idea.
http://d.puremagic.com/issues/show_bug.cgi?id=1301
Summary: CTFE fails for ImportExpressions
Product: D
Version: 1.017
Platform: PC
OS/Version: Windows
Status: NEW
Severity: major
Priority: P2
Component: DMD
AssignedTo: bugzilla digitalmars.com
ReportedBy: samukha voliacable.com
I believe this should to work, as 'path' is known at compile time:
char[] foo(char[] path)
{
char[] t = import(path); //Error: file name argument must be a string, not
(path)
return "";
}
void main(char[][] args)
{
mixin(foo("template"));
}
--
Jun 30 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1301
fvbommel wxs.nl changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |INVALID
Functions to be used in CTFE must still be compilable as normal functions.
Yours doesn't meet that criterion. Try something like:
---
char[] foo(char[] path)()
{
char[] t = import(path); //Error: file name argument must be a string, not
(path)
return "";
}
void main(char[][] args)
{
mixin(foo!("template"));
}
---
--
Jun 30 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1301 Oops. Thanks for pointing that out. --
Jun 30 2007
d-bugmail puremagic.com wrote:http://d.puremagic.com/issues/show_bug.cgi?id=1301 Oops. Thanks for pointing that out.One thing I think should work is hiding the import() in a template, and sending that value off to the CTF. template T_Import (char[] file) { const T_Import = import(file); } template T_Foo (char[] file) { const T_Foo = `foo("`~T_Import!(file)~`")` ; } char[] foo (char[] data) { // ... } void main (char[][] args) { mixin(T_Foo!("template")); } I've used something similar to preload image and font data in an SDL based program. It does work -- and the extra T_Import template maintains one copy of a given file being embedded. (Otherwise fonts at least would sometimes result in two or three copies. Bad bad disc usage, that.) -- Chris Nicholson-Sauls
Jun 30 2007
On Sat, 30 Jun 2007 13:00:44 -0500, Chris Nicholson-Sauls
<ibisbasenji gmail.com> wrote:
One thing I think should work is hiding the import() in a template, and
sending that value off to the CTF.
template T_Import (char[] file) {
const T_Import = import(file);
}
template T_Foo (char[] file) {
const T_Foo = `foo("`~T_Import!(file)~`")` ;
}
char[] foo (char[] data) {
// ...
}
void main (char[][] args) {
mixin(T_Foo!("template"));
}
I've used something similar to preload image and font data in an SDL
based program. It does work -- and the extra T_Import template
maintains one copy of a given file being embedded. (Otherwise fonts at
least would sometimes result in two or three copies. Bad bad disc
usage, that.)
-- Chris Nicholson-Sauls
Thanks for the idea.
Jul 02 2007









d-bugmail puremagic.com 