Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

C like conditional compilation and suggested features #406

Open
ScriptExec opened this issue Apr 4, 2023 · 2 comments
Open

C like conditional compilation and suggested features #406

ScriptExec opened this issue Apr 4, 2023 · 2 comments

Comments

@ScriptExec
Copy link

Are there any plans to add macros such as #define, #if, #elif and #endif or some other alternative to allow conditional compilation?
Also is this project still continued since there weren't any updates lately?

@marcobambini
Copy link
Owner

It is a feature that I'd like to add to Gravity, but I don't want to increase the complexity of the code.
For example, the C preprocessor is bigger than the C itself (as codebase), so I need to carefully balance what to do about macro support.

@ScriptExec ScriptExec changed the title C like conditional compilation C like conditional compilation and suggested features Apr 6, 2023
@ScriptExec
Copy link
Author

I agree that keeping it simple is the way to go and yeah fully recreating C like macros would be overkill. I was thinking that there should be #define IDENTIFIER value macro like in C and for conditional compilation #ifdef, #ifndef, #if, #else and #endif but I would allow #if to only receive an identifier that is set to either true or false fe.

//I wouldn't allow this (simplified platform macros)
#define IS_COMPATIBLE OS_WINDOWS && OS_64BIT

//I would only allow this
#define IS_COMPATIBLE 1 //or 0, true and false keywords should also work
//Setting macro values should also be possible via gravity vm's functions

#if IS_COMPATIBLE
	//...
#else
	//...
#endif

//Should other operations be allowed? like:
#if COMPILER_VERSION < 1000
#if COMPILER_VERSION != 1000
//etc

Personally I would also add #warning "message" and #error "message" (they wouldn't be too hard to implement) which would also benefit from the above macros.
Another nice thing that the language could have might be attributes like in C#.

//C# version
[Serializable]
public class SampleClass
{
    // Objects of this type can be serialized.
}
//Example Gravity version
@serializable
class SampleClass
{
	//...
}

Also is it possible to save bytecode and then run it via some function or does the API only allow loading the source?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants