Section External - stop functions from being optimised out?

Mildred Ki'Lya ml.mildred593 at online.fr
Fri Nov 14 23:48:15 UTC 2008


Le Thu 13/11/2008 à 19:52 Xavier Oswald à écrit:
>
> You can do this whithout using your tips.
> 
> Have a look in the manual about external usage, there is a comment
> about lisaac removing function. If I well remember, you could use a
> return parameter between parenthesis and thus, the code will not be
> removed.
> 
> Greetings,

Well, it doesn't have anything to do with what he wants, does it?

The trick to talk about is about optimizing out ta C external is the
result is not used. But he is talking about External slots (from the
Section External). And there, the trick he used is to my knowledge the
only possibility.


Look at the code



	Section External

	  - callback <- ( "Hello, World!\n".print; );

	Section Public

	  - main_1 <-
	  ( + res :INTEGER;
	    res := `setup_callback(callback)`:INTEGER;
	  );

	  - main_2 <-
	  ( + res :INTEGER;
	    res := `setup_callback(callback)`:(INTEGER);
	  );

If there is only main_1, then you are right, the function call
`setup_callback(callback)` will be optimized away since the result is
not used.

Now, if we only have the main_2, the `setup_callback(callback)` won't
be optimized away but that doesn't help the problem at all. The Lisaac
compiler is unable to parse the C code between backquotes (`) and so is
unable to see that the slot callback is in fact used.

So, in both cases, seeing that the slot callback isn't used, the function

	void callback() {
	  print_CF5("Hello, World!\n");
	}

won't be generated.

The only solution available at the present is to use the following trick

	  - main_3 <-
	  ( + res :INTEGER;

	    // Make the slot `callback' alive
	    `
	    #if 0
	    `;
	    callback;
	    `
	    #endif
	    `;

	    // Setup the callback
	    res := `setup_callback(callback)`:(INTEGER);
	  );

Mildred

-- 
Mildred Ki'Lya
╭───────── mildred593@online.fr ──────────
│ Jabber, GoogleTalk: <mildred at jabber.fr>
│ Site: <http://ki.lya.online.fr>              GPG ID: 9A7D 2E2B
│ Fingerprint: 197C A7E6 645B 4299 6D37 684B 6F9D A8D6 9A7D 2E2B



More information about the Lisaac-devel mailing list