mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-22 19:22:05 +00:00
Merge pull request #490 from ISSOtm/const
Implement `ISCONST`, reporting compile-time constness
This commit is contained in:
@@ -543,6 +543,7 @@ static void strsubUTF8(char *dest, const char *src, uint32_t pos, uint32_t len)
|
||||
%left T_OP_FLOOR
|
||||
|
||||
%token T_OP_HIGH T_OP_LOW
|
||||
%token T_OP_ISCONST
|
||||
|
||||
%left T_OP_STRCMP
|
||||
%left T_OP_STRIN
|
||||
@@ -1301,6 +1302,7 @@ relocexpr_no_str : scoped_id { rpn_Symbol(&$$, $1); }
|
||||
| T_OP_NOT relocexpr %prec NEG { rpn_UNNOT(&$$, &$2); }
|
||||
| T_OP_HIGH '(' relocexpr ')' { rpn_HIGH(&$$, &$3); }
|
||||
| T_OP_LOW '(' relocexpr ')' { rpn_LOW(&$$, &$3); }
|
||||
| T_OP_ISCONST '(' relocexpr ')'{ rpn_ISCONST(&$$, &$3); }
|
||||
| T_OP_BANK '(' scoped_id ')' {
|
||||
/* '@' is also a T_ID, it is handled here. */
|
||||
rpn_BankSymbol(&$$, $3);
|
||||
|
||||
@@ -460,6 +460,7 @@ const struct sLexInitString lexer_strings[] = {
|
||||
|
||||
{"high", T_OP_HIGH},
|
||||
{"low", T_OP_LOW},
|
||||
{"isconst", T_OP_ISCONST},
|
||||
|
||||
{"strcmp", T_OP_STRCMP},
|
||||
{"strin", T_OP_STRIN},
|
||||
|
||||
@@ -553,7 +553,7 @@ which references the same macro, which has the same problem.
|
||||
.Pp
|
||||
One of the best features of an assembler is the ability to write macros for it.
|
||||
Macros also provide a method of passing arguments to them and they can then react to the input using
|
||||
.Sy IF
|
||||
.Ic IF
|
||||
constructs.
|
||||
.Pp
|
||||
.Bd -literal -offset indent
|
||||
@@ -1317,6 +1317,9 @@ For labels, as the linker has to resolve this, it can't be used when the express
|
||||
has been defined.
|
||||
.It Fn HIGH arg Ta Returns the top 8 bits of the operand if Ar arg No is a label or constant, or the top 8-bit register if it is a 16-bit register.
|
||||
.It Fn LOW arg Ta Returns the bottom 8 bits of the operand if Ar arg No is a label or constant, or the bottom 8-bit register if it is a 16-bit register Pq Cm AF No isn't a valid register for this function .
|
||||
.It Fn ISCONST arg Ta Returns 1 if Ar arg Ns No 's value is known by RGBASM (e.g. if it can be an argument to
|
||||
.Ic IF ) ,
|
||||
or 0 if only RGBLINK can compute its value.
|
||||
.El
|
||||
.Sh MISCELLANEOUS
|
||||
.Ss Changing options while assembling
|
||||
|
||||
@@ -506,6 +506,14 @@ void rpn_LOW(struct Expression *expr, const struct Expression *src)
|
||||
}
|
||||
}
|
||||
|
||||
void rpn_ISCONST(struct Expression *expr, const struct Expression *src)
|
||||
{
|
||||
rpn_Init(expr);
|
||||
expr->nVal = rpn_isKnown(src);
|
||||
expr->isKnown = true;
|
||||
expr->isSymbol = false;
|
||||
}
|
||||
|
||||
void rpn_UNNEG(struct Expression *expr, const struct Expression *src)
|
||||
{
|
||||
*expr = *src;
|
||||
|
||||
Reference in New Issue
Block a user