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

Adding a way of tagging compiled Catspeak programs with a filename #139

Open
tabularelf opened this issue Sep 18, 2024 · 0 comments
Open
Labels
enhancement New feature or request

Comments

@tabularelf
Copy link
Contributor

tabularelf commented Sep 18, 2024

What is your feature request?

I'm slowly thinking about what ways Catspeak could be extended slightly to include an artificial stacktrace of potential files or other place/s where the end user might end up doing something that's wrong or invalid.
I already have a system in my own project, where I can generate a stacktrace from my own files, and push/pop them. But if you any Catspeak code that also makes functions, the stacktrace part itself gets trickier.

Assuming we have this as our Catspeak program

add = fun(a, b) {
  return a + b;
}

And our GML code

var filename = "gamecode.meow";
var str = load_string_from_file(filename);
var ast = Catspeak.parseString(str);
var mainProgram = Catspeak.compile(ast);

program();
var add = mainProgram.getGlobals().add;
 add(undefined, 2); // Errors as undefined cannot be added together with 2

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

I have some ideas I could experiment with, but I might just do it as my own modifications to Catspeak itself for my own project. Since I can't think of a real universal solution for this. The closest idea I have so far involves modifying how __catspeak_function__ works slightly (to implement a catch callback handler), providing .compile() with some optional arguments for a stacktrace_name (so one could provide "game_code.meow" or "https://gamewebsite.com/game_assets/game_code.meow" or whatever as a name to refer it to for debugging purposes), and appending .getStacktraceName() to each and every Catspeak function.

All of this is something I'll experiment with anyway, but the idea I have in code:

Catspeak.setCatchCallback(function(ex, program) {
  ex.longMessage += $"\nIn {program.getStacktraceName()}";
  // I'd return or throw ex, but my idea would be that Catspeak handles throwing ex still, so no need to do anything else here.
});

// Compiling
var filename = "gamecode.meow";
var str = load_string_from_file(filename);
var ast = Catspeak.parseString(str);
var mainProgram = Catspeak.compile(ast, filename);

program();
var add = mainProgram.getGlobals().add;
add(undefined, 2); // Errors as undefined cannot be added together with 2, but also __catspeak_function__ runs 
// our catch callback function, allowing us to append our stacktrace on top of it. So we end up with "In gamecode.meow" at the end.
@tabularelf tabularelf added the enhancement New feature or request label Sep 18, 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
Projects
None yet
Development

No branches or pull requests

1 participant