Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Compile-time GML function execution (functions that are exposed to Catspeak) #117

Open
tabularelf opened this issue May 25, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request low priority Not important optimisation Related to optimising Catspeak code

Comments

@tabularelf
Copy link
Contributor

tabularelf commented May 25, 2024

What is your feature request?

It'd be nice if we could have certain functions automatically call and create a value during the compiler stage, if assuming they wre compile time runnable.

A good example is something like this.

var ir = gmlspeak.parseString(@'return string_concat("My name is ", "TabularElf!");');
var getMessage = gmlspeak.compileGML(ir);
show_debug_message(getMessage());    

Right now the compiler is doing program -> call -> fetch argument values -> call function -> return result
But it could easily be program -> return value. (Obviously, concating in the first place is better)

Please describe in detail how you expect this new feature to behave.

The compiler should be able to evaluate and determine if a function (Catspeak or GML) is a compile time function, and all of it's arguments (whether valid compile-time function or value) also meet the criteria.

This should be achieved by applying a list of conditions that the compiler can use to check and evaluate each argument (whether a compile-time function or value). Compile-time functions as arguments are daisy-chainable and will check each function call to ensure that they are too compile-time callable.

If it's not a value that is defined (such as a global), is not a compile-time function or a value (such as 2 or "Hello World" ), the compiler will treat it as a normal function call instead.

Such a great example is

var ir = gmlspeak.parseString(@'return string_concat("My name is ", real(string(get_timer())));');
var getMessage = gmlspeak.compileGML(ir);
show_debug_message(getMessage());    

In this case, string_concat, string and real are all compile-time functions. But get_timer is not.
So the compiler will have it as program -> call -> fetch argument values -> call function -> return result.
But applying get_timer with a compile-time flag as well, will collapse the whole program down to program -> return value. In this case, the value of get_timer at the time. (It will never change once compiled)

Bonus: I already written it in my own GML interpreter project, that uses Catspeak as the backbone. All handled via the interface + compiler.

@tabularelf tabularelf added the enhancement New feature or request label May 25, 2024
@tabularelf
Copy link
Contributor Author

tabularelf commented May 25, 2024

It should be stated here, my current system doesn't apply that optimisation all the way through. (It cannot compile-time if/else statements out, if a compile-time function is used. Though the values that were there will be optimized, the if/else will also still be there. Might require some additional checks on the compilers end).

@tabularelf tabularelf changed the title Compile-time function execution Compile-time GML function execution (functions that are exposed to Catspeak) May 25, 2024
@katsaii katsaii added low priority Not important optimisation Related to optimising Catspeak code labels May 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request low priority Not important optimisation Related to optimising Catspeak code
Projects
None yet
Development

No branches or pull requests

2 participants