Jonathan Kelly wrote:
> Hi,
>
> I'm not sure how to turn it into a generator. I tried
>
> gen jseek: file * long * int -> int = 'std::fseek($1, $2, $3)';
>
> but it still ellided the call. Changing the val to var didn't help 
> either. It's probably a silly example as I would test the value anyway, 
> but I am  more interested in how to define an external function so even 
> if I ignored the return value, it doesn't optimise away the 
> side-effects, which is what I'm guessing a generator is.

I can only get it to work with using C_hack::ignore:


#import <flx.flxh>

open Long;
type file = "FILE *";
fun jopen: string -> file = 'std::fopen($1.data(), "rw")';
fun jvalid : file -> bool = '$1!=(FILE*)0';
fun jseek: file * long * int -> int = 'std::fseek($1, $2, $3)';
proc jclose: file = '(void)std::fclose($1);';
fun jtell: file -> long = 'std::ftell($1)';

var fil = jopen ("foo.flx");
if jvalid fil do
    print "jopen returned 0\n";
else
    print "jopen returned ... something\n";
done;
C_hack::ignore$ jseek(fil, 0L, 2);
// uncommenting out the following to stop previous being elided
//print "jseek returned ";
//print x;
//endl;
val p = jtell(fil);
print "file size is ";
print p;
endl;
jclose(fil);


John, it does seem like it'd be a bug to optimize away calls that 
involve external functions. Since those calls could be state changing as 
in this case, I don't think they can be safely optimized. Perhaps we 
need another function attribute to mark that it's safe to optimize.

Personally I don't like that. I was thinking the other day about 
generators, functions, and procedures, and I was thinking that we need 
some kind of procedural generator, as modeling external functions as 
function generators implies that the generators won't change state. Of 
course we can't guarantee any external function doesn't change state, 
but having it be by convention would help convey what's going on.

This, of course, requires a lot more thought.

-e

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Felix-language mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to