-
Notifications
You must be signed in to change notification settings - Fork 50
macros are TOO safe #74
Comments
I think it's the other way around, defmacro SOMETHING 69 end or since you used a seperate keyword default macro SOMETHING 69 end in regards to default definition. std.porth isdefined if
...
end which could be used to macro ifndefined isdefined 0 = if end
macro ifndef ifndefined end
macro ifdefined isdefined if end
macro ifdef ifdefined end std.porth ifdefined
...
end if it weren't for #72 |
@IHateYourCode currently the lexer will try to expand the word as soon as it is found. So But the point in this issue is not about introducing a new keyword or not, is just about if we should be able to redefine or not an already defined macro. If the author understands that it is worth to enable this behavior to redefine a macro, he or someone with a PR should just comment the following line: - if token.value in macros:
- print("%s:%d:%d: ERROR: redefinition of already existing macro `%s`" % (token.loc + (token.value, )), file=sys.stderr)
- print("%s:%d:%d: NOTE: the first definition is located here" % macros[token.value].loc, file=sys.stderr)
- exit(1)
+ # if token.value in macros:
+ # print("%s:%d:%d: ERROR: redefinition of already existing macro `%s`" % (token.loc + (token.value, )), file=sys.stderr)
+ # print("%s:%d:%d: NOTE: the first definition is located here" % macros[token.value].loc, file=sys.stderr)
+ # exit(1) Something like this. |
The lexer doesn't look ahead at all .. O.O Anyways, on the topic of macro redefinition, yes, Being able to do so not only allows you to safely |
That's exactly what I said, and that's is the reason your example elif token.value == Keyword.DEFINED:
token = rtokens.pop() # looking ahead for the next token
if token.value in macros or token.value in INTRINSIC_NAMES or token.value in KEYWORD_NAMES:
# word is defined as macro or intrinsic or keyword
else:
# word is not defined at all This is exactly the same approach the keyword But anyway, this is not the point discussed in this issue. Lets wait for the author point of view on macro redefinition. |
I know, I was just acknowledging it with
Yeah, hopefully he sees this soon. |
Isn't the compiler structured in a way where redefinition would |
there is a much more severe problem that is macros are defined in the compilation step that is before the program is executed so this wouldn't make any sense. you need a way to have something like preprocessor macros/keywords. |
Recently I was playing with a new keyword
defined
so we can check up front if aword
is already defined, so we can for example avoid including a file twice or change the library behavior if some macro is already defined.But for this happen I should have the ability to redefine a macro, something like this.
or
I don't know if this new keyword will be useful, but I think the ability to redefine a
macro
should be possible. What you guys think about it? Should macros behave like a constant expression?The text was updated successfully, but these errors were encountered: