- ACC changes for externally definable functions.

SVN r1576 (trunk)
This commit is contained in:
Christoph Oelckers 2009-05-11 21:07:27 +00:00
parent 7668d75645
commit dc777b74f1
8 changed files with 150 additions and 20 deletions

5
misc.h
View file

@ -46,4 +46,9 @@ boolean MS_IsDirectoryDelimiter(char test);
// PUBLIC DATA DECLARATIONS ------------------------------------------------ // PUBLIC DATA DECLARATIONS ------------------------------------------------
#ifdef _MSC_VER
// Get rid of the annoying deprecation warnings with VC++2005 and newer.
#pragma warning(disable:4996)
#endif
#endif #endif

116
parse.c
View file

@ -93,6 +93,7 @@ static boolean ProcessStatement(statement_t owner);
static void LeadingCompoundStatement(statement_t owner); static void LeadingCompoundStatement(statement_t owner);
static void LeadingVarDeclare(void); static void LeadingVarDeclare(void);
static void LeadingLineSpecial(boolean executewait); static void LeadingLineSpecial(boolean executewait);
static void LeadingFunction();
static void LeadingIdentifier(void); static void LeadingIdentifier(void);
static void BuildPrintString(void); static void BuildPrintString(void);
static void PrintCharArray(void); static void PrintCharArray(void);
@ -1135,9 +1136,17 @@ static void OuterSpecialDef(void)
else else
{ {
do do
{
if (TK_NextToken() == TK_MINUS)
{ {
TK_NextTokenMustBe(TK_NUMBER, ERR_MISSING_SPEC_VAL); TK_NextTokenMustBe(TK_NUMBER, ERR_MISSING_SPEC_VAL);
special = -tk_Number;
}
else
{
TK_TokenMustBe(TK_NUMBER, ERR_MISSING_SPEC_VAL);
special = tk_Number; special = tk_Number;
}
TK_NextTokenMustBe(TK_COLON, ERR_MISSING_SPEC_COLON); TK_NextTokenMustBe(TK_COLON, ERR_MISSING_SPEC_COLON);
TK_NextTokenMustBe(TK_IDENTIFIER, ERR_INVALID_IDENTIFIER); TK_NextTokenMustBe(TK_IDENTIFIER, ERR_INVALID_IDENTIFIER);
sym = SY_InsertGlobalUnique(tk_String, SY_SPECIAL); sym = SY_InsertGlobalUnique(tk_String, SY_SPECIAL);
@ -1263,7 +1272,14 @@ static boolean ProcessStatement(statement_t owner)
LeadingVarDeclare(); LeadingVarDeclare();
break; break;
case TK_LINESPECIAL: case TK_LINESPECIAL:
if (tk_SpecialValue >= 0)
{
LeadingLineSpecial(NO); LeadingLineSpecial(NO);
}
else
{
LeadingFunction();
}
break; break;
case TK_ACSEXECUTEWAIT: case TK_ACSEXECUTEWAIT:
tk_SpecialArgCount = 1 | (5<<16); tk_SpecialArgCount = 1 | (5<<16);
@ -1609,6 +1625,81 @@ static void LeadingLineSpecial(boolean executewait)
TK_NextToken(); TK_NextToken();
} }
//==========================================================================
//
// LeadingLineSpecial
//
//==========================================================================
static void LeadingFunction()
{
int i;
int argCount;
int argCountMin;
int argCountMax;
int specialValue;
MS_Message(MSG_DEBUG, "---- LeadingFunction ----\n");
argCountMin = tk_SpecialArgCount & 0xffff;
argCountMax = tk_SpecialArgCount >> 16;
specialValue = -tk_SpecialValue;
TK_NextTokenMustBe(TK_LPAREN, ERR_MISSING_LPAREN);
i = 0;
if(argCountMax > 0)
{
if(TK_NextToken() == TK_CONST)
{
// Just skip const declarators
TK_NextTokenMustBe(TK_COLON, ERR_MISSING_COLON);
}
else
{
TK_Undo();
}
do
{
if(i == argCountMax)
{
ERR_Error(ERR_BAD_ARG_COUNT, YES);
i = argCountMax+1;
}
TK_NextToken();
EvalExpression();
if(i < argCountMax)
{
i++;
}
} while(tk_Token == TK_COMMA);
if(i < argCountMin)
{
ERR_Error(ERR_BAD_ARG_COUNT, YES);
TK_SkipPast(TK_SEMICOLON);
return;
}
argCount = i;
}
else
{
argCount = 0;
TK_NextToken ();
}
TK_TokenMustBe(TK_RPAREN, ERR_MISSING_RPAREN);
TK_NextTokenMustBe(TK_SEMICOLON, ERR_MISSING_SEMICOLON);
PC_AppendCmd(PCD_CALLFUNC);
if(pc_NoShrink)
{
PC_AppendInt(argCount);
PC_AppendInt(specialValue);
}
else
{
PC_AppendByte(argCount);
PC_AppendWord(specialValue);
}
PC_AppendCmd(PCD_DROP);
TK_NextToken();
}
//========================================================================== //==========================================================================
// //
// LeadingIdentifier // LeadingIdentifier
@ -3159,9 +3250,9 @@ static void ExprLevX(int level)
static void ExprLineSpecial(void) static void ExprLineSpecial(void)
{ {
U_BYTE specialValue = tk_SpecialValue;
int argCountMin = tk_SpecialArgCount & 0xffff; int argCountMin = tk_SpecialArgCount & 0xffff;
int argCountMax = tk_SpecialArgCount >> 16; int argCountMax = tk_SpecialArgCount >> 16;
int specialValue = tk_SpecialValue;
// There are two ways to use a special in an expression: // There are two ways to use a special in an expression:
// 1. The special name by itself returns the special's number. // 1. The special name by itself returns the special's number.
@ -3169,7 +3260,7 @@ static void ExprLineSpecial(void)
TK_NextToken(); TK_NextToken();
if(tk_Token != TK_LPAREN) if(tk_Token != TK_LPAREN)
{ {
PC_AppendPushVal(tk_SpecialValue); PC_AppendPushVal(specialValue);
} }
else else
{ {
@ -3188,9 +3279,11 @@ static void ExprLineSpecial(void)
} }
if(argCount < argCountMin || argCount > argCountMax) if(argCount < argCountMin || argCount > argCountMax)
{ {
ERR_Error(ERR_BAD_LSPEC_ARG_COUNT, YES); ERR_Error(specialValue >=0? ERR_BAD_LSPEC_ARG_COUNT : ERR_BAD_ARG_COUNT, YES);
return; return;
} }
if (specialValue >= 0)
{
for(; argCount < 5; ++argCount) for(; argCount < 5; ++argCount)
{ {
PC_AppendPushVal(0); PC_AppendPushVal(0);
@ -3207,6 +3300,23 @@ static void ExprLineSpecial(void)
PC_AppendByte(specialValue); PC_AppendByte(specialValue);
} }
} }
else
{
TK_TokenMustBe(TK_RPAREN, ERR_MISSING_RPAREN);
TK_NextToken();
PC_AppendCmd(PCD_CALLFUNC);
if(pc_NoShrink)
{
PC_AppendInt(argCount);
PC_AppendInt(-specialValue);
}
else
{
PC_AppendByte(argCount);
PC_AppendWord(-specialValue);
}
}
}
} }
static void ExprFactor(void) static void ExprFactor(void)

View file

@ -461,6 +461,7 @@ static char *PCDNames[PCODE_COMMAND_COUNT] =
"PCD_CLASSIFYACTOR", "PCD_CLASSIFYACTOR",
"PCD_PRINTBINARY", "PCD_PRINTBINARY",
"PCD_PRINTHEX", "PCD_PRINTHEX",
"PCD_CALLFUNC",
}; };
// CODE -------------------------------------------------------------------- // CODE --------------------------------------------------------------------

View file

@ -412,6 +412,7 @@ typedef enum
PCD_CLASSIFYACTOR, PCD_CLASSIFYACTOR,
PCD_PRINTBINARY, PCD_PRINTBINARY,
PCD_PRINTHEX, PCD_PRINTHEX,
PCD_CALLFUNC,
PCODE_COMMAND_COUNT PCODE_COMMAND_COUNT
} pcd_t; } pcd_t;

View file

@ -57,7 +57,7 @@ typedef struct
typedef struct typedef struct
{ {
U_BYTE value; int value;
int argCount; int argCount;
} symSpecial_t; } symSpecial_t;

View file

@ -96,7 +96,7 @@ tokenType_t tk_Token;
int tk_Line; int tk_Line;
int tk_Number; int tk_Number;
char *tk_String; char *tk_String;
U_BYTE tk_SpecialValue; int tk_SpecialValue;
int tk_SpecialArgCount; int tk_SpecialArgCount;
char *tk_SourceName; char *tk_SourceName;
int tk_IncludedLines; int tk_IncludedLines;

View file

@ -155,7 +155,7 @@ extern tokenType_t tk_Token;
extern int tk_Line; extern int tk_Line;
extern int tk_Number; extern int tk_Number;
extern char *tk_String; extern char *tk_String;
extern U_BYTE tk_SpecialValue; extern int tk_SpecialValue;
extern int tk_SpecialArgCount; extern int tk_SpecialArgCount;
extern char *tk_SourceName; extern char *tk_SourceName;
extern int tk_IncludedLines; extern int tk_IncludedLines;

View file

@ -212,4 +212,17 @@ special
252:Ceiling_RaiseToNearest(2), 252:Ceiling_RaiseToNearest(2),
253:Ceiling_LowerToLowest(2), 253:Ceiling_LowerToLowest(2),
254:Ceiling_LowerToFloor(2), 254:Ceiling_LowerToFloor(2),
255:Ceiling_CrushRaiseAndStaySilA(4,5); 255:Ceiling_CrushRaiseAndStaySilA(4,5),
// internal functions have negative values
-1:GetLineUDMFInt(2),
-2:GetLineUDMFFixed(2),
-3:GetThingUDMFInt(2),
-4:GetThingUDMFFixed(2),
-5:GetSectorUDMFInt(2),
-6:GetSectorUDMFFixed(2),
-7:GetSideUDMFInt(3),
-8:GetSideUDMFFixed(3),
-1000:__EndOfList__(10);