gbdev / rgbds

Rednex Game Boy Development System - An assembly toolchain for the Nintendo Game Boy and Game Boy Color

Home Page:https://rgbds.gbdev.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Feature request] Check if a charmap character is defined

Rangi42 opened this issue · comments

We have DEF(somename) to see if somename is defined as a symbol; and DEF("somestring") to see if "somestring" is defined as a section. I've come across at least one use case where it would be convenient to see if some string has a charmap definition.

To avoid a new keyword, I think DEF(CHARMAP "<some>") would be appropriate. It would be 1 if charmap "<some>", $xx is in the current charmap, else 0.

(A sort of workaround is to check whether CHARLEN("<some>") is exactly 1; but that can give an "Unmapped character" warning.)

Using identifiers or keywords inside of DEF is a big footgun, because the lexer has to preemptively disable EQUS expansion... so this usual syntax trick is a liability here.

def chaotic_evil EQUS "charmap"
println DEF(chaotic_evil "c")

The functionality is good, this specific syntax I'm not sold on.

Oh, good point. I wouldn't mind a new keyword then, like DEFCHAR or CHARDEF.

Or, what about CHARMAP("some") assuming that's unambiguous?

Or ISCHAR would go with ISCONST. (My preference is for ISCHAR.)