Merge pull request #160 from Movax12/definedinstr

.DEFINEDINSTR
This commit is contained in:
Oliver Schmidt 2015-06-04 22:05:00 +02:00
commit a13284a792
5 changed files with 55 additions and 0 deletions

View File

@ -2316,6 +2316,24 @@ Here's a list of all control commands and a description, what they do:
</verb></tscreen>
<sect1><tt>.ISMNEM, .ISMNEMONIC</tt><label id=".ISMNEMONIC"><p>
Builtin function. The function expects an identifier as argument in braces.
The argument is evaluated, and the function yields "true" if the identifier
is defined as an instruction mnemonic that is recognized by the assembler.
Example:
<tscreen><verb>
.if .not .ismnemonic(ina)
.macro ina
clc
adc #$01
.endmacro
.endif
</verb></tscreen>
<sect1><tt>.DESTRUCTOR</tt><label id=".DESTRUCTOR"><p>
Export a symbol and mark it as a module destructor. This may be used

View File

@ -62,6 +62,7 @@
#include "symtab.h"
#include "toklist.h"
#include "ulabel.h"
#include "macro.h"
@ -417,6 +418,34 @@ static ExprNode* FuncDefined (void)
static ExprNode* FuncIsMnemonic (void)
/* Handle the .ISMNEMONIC, .ISMNEM builtin function */
{
int Instr = -1;
/* Check for a macro or an instruction depending on UbiquitousIdents */
if (CurTok.Tok == TOK_IDENT) {
if (UbiquitousIdents) {
/* Macros CAN be instructions, so check for them first */
if (FindMacro (&CurTok.SVal) == 0) {
Instr = FindInstruction (&CurTok.SVal);
}
} else {
/* Macros and symbols may NOT use the names of instructions, so just check for the instruction */
Instr = FindInstruction (&CurTok.SVal);
}
} else {
Error ("Identifier expected.");
}
/* Skip the name */
NextTok ();
return GenLiteralExpr (Instr > 0);
}
ExprNode* FuncHiByte (void)
/* Handle the .HIBYTE builtin function */
{
@ -1065,6 +1094,10 @@ static ExprNode* Factor (void)
N = Function (FuncDefined);
break;
case TOK_ISMNEMONIC:
N = Function (FuncIsMnemonic);
break;
case TOK_HIBYTE:
N = Function (FuncHiByte);
break;

View File

@ -2040,6 +2040,7 @@ static CtrlDesc CtrlCmdTab [] = {
{ ccNone, DoIncBin },
{ ccNone, DoInclude },
{ ccNone, DoInterruptor },
{ ccNone, DoUnexpected }, /* .ISMNEMONIC */
{ ccNone, DoInvalid }, /* .LEFT */
{ ccNone, DoLineCont },
{ ccNone, DoList },

View File

@ -223,6 +223,8 @@ struct DotKeyword {
{ ".INCBIN", TOK_INCBIN },
{ ".INCLUDE", TOK_INCLUDE },
{ ".INTERRUPTOR", TOK_INTERRUPTOR },
{ ".ISMNEM", TOK_ISMNEMONIC },
{ ".ISMNEMONIC", TOK_ISMNEMONIC },
{ ".LEFT", TOK_LEFT },
{ ".LINECONT", TOK_LINECONT },
{ ".LIST", TOK_LIST },

View File

@ -199,6 +199,7 @@ typedef enum token_t {
TOK_INCBIN,
TOK_INCLUDE,
TOK_INTERRUPTOR,
TOK_ISMNEMONIC,
TOK_LEFT,
TOK_LINECONT,
TOK_LIST,