-
Notifications
You must be signed in to change notification settings - Fork 552
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
[WIP/feedbacks] Add magic constants #482
base: main
Are you sure you want to change the base?
Conversation
__LINE__ for the current line __MODULE__ for the name of the module
Wouldn't it be better to nest them under a single top level constant instead of adding several? |
What kind of "single"? I chose "several" because it's the easiest, it's just a "detect and replace" idiom like the keywords. |
I believe it would be best to place it under the existing optional "Meta" class. |
Another note, in the context of scripting a line/file can be variable. For instance if a "script" is just a loose file, but is merged with several loose files into one wren module, this would report incorrect line numbers. This is a common issue for languages that are like this, see for instance #line directive in glsl. I'd also note that it would make more sense to me in meta since the module/line is available for a callstack usually, it should be fairly easily available as a regular function. This too has the same concern about module/line. |
I've tried to put module and line as getter inside a class called "Location" (because why not?). The line number of each bytecode is inside Also, the reason I chose variables is because it's a simple "replace" at compile time, while a function call has cost at runtime. And what to do with that kind of code? Will it print 1 or 2? (Both can be considered valid, and everybody has a different opinion) System.print(Location.
line) |
It would be nice having such a feature! But this kind of makes me wonder where the error-callback, which can be supplied to a VM config, is getting it's line from? Couldn't you use a similiar method to how that stack trace is being built to fill `LINE``? I can see how this could become a problem with concatenated files, actually. However, it should at least be an optional thing people can include if they would like to. That is at least my opinion. Therefore I support the idea of adding this to
|
Maybe this could also be augmented with a 'FUNCTION' variable (or what ever the name) to inform about the current function/method name. |
The one thing that I learned from these macros, and similar things in other languages, is that they useful for one thing: tracking the location of an error. For that, we have #868, which will display you the full stack trace. If for some strange reason you still need that, you can parse the stack trace. This is the worst idea ever because the stack trace isn't guaranteed to be stable to parse but just easy for humans to read. |
Disclaimer: it's more to have feedbacks/tweaks (e.g. on the syntax) or ideas (e.g. of new constants) than actually get this PR merged "as-is".
Hello there,
Many languages have a way to print the current filename or the current line (like the C preprocessor with
__FILE__
and__LINE__
). So I told to myself "why not add them to wren?" and went with the same syntax.Since the filename is not known from the VM, I chose to print the module name. So now you have
__LINE__
and__MODULE__
.Here's some code with what is printed when you do
wren test.wren
:mymod.wren:
test.wren:
minirop