On Sun, 2006-10-29 at 12:34 +1100, Jonathan Kelly wrote:
> Hi,
> 
> how do I stop felix from optimizing way function calls? I'm playing with 
> using external libraries (ncurses) and unless I do something with the 
> return values, it just elides the calls. It only took me like an hour of 
> trying to find what I'd done wrong before I thought to look at the cpp 
> code. <sigh>

Yes, functions are supposedly transparent. The simple answer
to your question is: use the result!

What should happen to a generator call is
that it is lifted out to a variable assignment:

        var tmp = generator argument;

such variables are not 'usually' substituted into expressions
(the whole point of generators is to lift them out!).

However, if the variable is not used it can still be optimised
away .. along with its initialiser.

It isn't enough to 'use' the variable to initialise some
other variable, which is itself not used .. unused variables
are systematically garbage collected (at least, they're
supposed to be).

A systematic solution is the 'ignore' procedure:

        C_hack::ignore (expr);

This evaluates expr and then throws the result away.
This procedure is just:

        proc ignore[t]: t = "(void)$t;";

It works by a hack: Felix is too dumb (at the moment)
to look inside C lifts (definitions in terms of C code).

Even if the argument 'expr' is lifted out to a temporary,
that temporary IS used in the call to 'ignore'.

Well, it is interesting that the semantics of 
the ignore procedure can be stated as:

        "Do not ignore the argument of ignore"

... :)

> Also, how do I define an external function that takes a "char *" or 
> "const char *".

// in lib/std.flx:

typedef charp = C_hack::ptr[char];
typedef charcp = C_hack::cptr[char];

typedef ucharp = C_hack::ptr[utiny];
typedef ucharcp = C_hack::cptr[utiny];

.....

module C_hack {
  publish "Abstract type for C pointer"
  pod type ptr[t]="?1 *";

  publish "Abstract type for C pointer to const"
  pod type cptr[t]="?1 const *";

....


-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Felix-language mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to