Conditional Compilation?

Is there any form of conditional compilation, specifically, like the usage of IFNDEF/DEFINE in C++ to prevent redundant inclusion of code?

I suspect not but I figured I should actually ask (my attempt to read the manual only led me to discover unsigned bitshift right is supported in ASH, yay!). Or perhaps someone has some sort of clever workaround for it - aside from mashing everything into a single script file.
 

fronobulax

Developer
Staff member
Is there any form of conditional compilation, specifically, like the usage of IFNDEF/DEFINE in C++ to prevent redundant inclusion of code?

I suspect not but I figured I should actually ask (my attempt to read the manual only led me to discover unsigned bitshift right is supported in ASH, yay!). Or perhaps someone has some sort of clever workaround for it - aside from mashing everything into a single script file.

Not in ash. The desire to exclude redundant code suggests you think it will some some problem. Which problem?
 

Ulti

Member
Mafia can handle multiple imports of the same redundant file such as import <zlib.ash>; and mafia will treat the second import as redundant since it knows it was imported already. But Mafia can't handle the issue of circular inclusion, as you've noticed.

Let's say you had a setup like so:

testy.ash:
Code:
import <testy2.ash>;
import <testy3.ash>;
import <zlib.ash>;
void main()
{
	hello();
	world();
}

testy2.ash:
Code:
import <testy3.ash>;
import <zlib.ash>;
string getWorld()
{
    return 'World';
}
void hello()
{
	print(getHello());
}

testy3.ash:
Code:
import <testy2.ash>;
import <zlib.ash>;
string getHello()
{
    return 'Hello!';
}
void world()
{
	print(getWorld());
}
To solve the circular inclusion problem in the above, the solution is simply to create a dependencies sort of directory. In Ezandora's Guide, she call this directory Support. You'll also need to resolve the issue of the two files testy2.ash and testy3.ash relying on each other's functions. To do this, you'd predefine the functions, which you'll need to do inside an import since you can't predefine functions before an import.

So you can get all the above working with:

testy.ash:
Code:
import <support.ash>;
import <zlib.ash>;
void main()
{
	hello();
	world();
}

support.ash:
Code:
import <support/testy1.ash>;
import <support/testy2.ash>;
import <support/testy3.ash>;

support/testy1.ash:
Code:
string getHello();
string getWorld();

support/testy2.ash:
Code:
import <zlib.ash>;
string getWorld()
{
    return 'World!';
}
void hello()
{
	print(getHello());
}

support/testy3.ash:
Code:
import <zlib.ash>;
string getHello()
{
    return 'Hello!';
}
void world()
{
	print(getWorld());
}

Notice I didn't need to remove the multiple imports to zlib and the above will work fine when you execute call scripts\testy.ash, although you'll still need to wait for zlib to load before seeing its simple Hello! World! output. Then, whenever you need to import testy2.ash, for example, into some other file, simply import support.ash instead. You can import it as a dependency into each file in your project in a redundant fashion, provided you're working around the circular inclusion issue in a similar fashion as I've described.
 
This does pretty much what I want, thanks.

I was hoping it would cause scripts with unresolved functions to fail without waiting for them to actually be called but such is the cost of workarounds. Time to do some Crimbo Code Cleanup(R).
 
Top