2016-01-14 15:23:33 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1987 Fujitsu
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
2014-05-04 05:20:34 +00:00
|
|
|
/*
|
|
|
|
instantiate.c -- Slinky linker routines to walk expression tree and
|
|
|
|
replace symbol ordinals with symbol pointers.
|
|
|
|
|
|
|
|
Chip Morningstar -- Lucasfilm Ltd.
|
|
|
|
|
|
|
|
11-November-1985
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "slinkyTypes.h"
|
|
|
|
#include "slinkyGlobals.h"
|
|
|
|
#include "slinkyExpressions.h"
|
2016-01-24 06:57:12 +00:00
|
|
|
#include "errorStuff.h"
|
|
|
|
#include "expr.h"
|
|
|
|
#include "instantiate.h"
|
2014-05-04 05:20:34 +00:00
|
|
|
#include "y.tab.h"
|
|
|
|
|
|
|
|
#define overFunction() (pc+=sizeof(functionType *))
|
|
|
|
#define overNumber() (pc+=sizeof(addressType))
|
|
|
|
#define overByte() pc++
|
|
|
|
#define nextByte(byt) (byt = *pc++)
|
|
|
|
|
|
|
|
void
|
2016-01-24 07:13:44 +00:00
|
|
|
putNumber(int number)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i=0; i<sizeof(int); ++i) {
|
|
|
|
*pc++ = number & 0xFF;
|
|
|
|
number >>= 8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-01-24 07:13:44 +00:00
|
|
|
instantiateSymbol(void)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
int index;
|
|
|
|
|
|
|
|
index = evaluateNumber();
|
|
|
|
pc -= sizeof(symbolType *);
|
|
|
|
putNumber(currentSymbolTable[index]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-01-24 07:13:44 +00:00
|
|
|
instantiateFunction(void)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
int index;
|
|
|
|
|
|
|
|
index = evaluateNumber();
|
|
|
|
pc -= sizeof(functionType *);
|
|
|
|
putNumber(&(currentFunctionTable[index]));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-01-24 07:13:44 +00:00
|
|
|
putSymbolPointersIntoArray(void)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
instantiateSymbol();
|
|
|
|
putSymbolPointersIntoExpression();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-01-24 07:13:44 +00:00
|
|
|
putSymbolPointersIntoAssert(void)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
putSymbolPointersIntoExpression();
|
|
|
|
skipString();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-01-24 07:13:44 +00:00
|
|
|
putSymbolPointersIntoBinop(void)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
overByte();
|
|
|
|
putSymbolPointersIntoExpression();
|
|
|
|
putSymbolPointersIntoExpression();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-01-24 07:13:44 +00:00
|
|
|
putSymbolPointersIntoBlock(void)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
while (*pc != END_TAG)
|
|
|
|
putSymbolPointersIntoExpression();
|
|
|
|
overByte();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-01-24 07:13:44 +00:00
|
|
|
putSymbolPointersIntoBuiltinFunctionCall(void)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
int argCount;
|
|
|
|
|
|
|
|
overNumber();
|
|
|
|
nextByte(argCount);
|
|
|
|
while (argCount-- > 0)
|
|
|
|
putSymbolPointersIntoExpression();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-01-24 07:13:44 +00:00
|
|
|
putSymbolPointersIntoFunctionCall(void)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
int argCount;
|
|
|
|
|
|
|
|
instantiateFunction();
|
|
|
|
nextByte(argCount);
|
|
|
|
while (argCount-- > 0)
|
|
|
|
putSymbolPointersIntoExpression();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-01-24 07:13:44 +00:00
|
|
|
putSymbolPointersIntoMdefine(void)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
instantiateSymbol();
|
|
|
|
putSymbolPointersIntoExpression();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-01-24 07:13:44 +00:00
|
|
|
putSymbolPointersIntoMdoUntil(void)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
putSymbolPointersIntoExpression();
|
|
|
|
putSymbolPointersIntoExpression();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-01-24 07:13:44 +00:00
|
|
|
putSymbolPointersIntoMdoWhile(void)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
putSymbolPointersIntoExpression();
|
|
|
|
putSymbolPointersIntoExpression();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-01-24 07:13:44 +00:00
|
|
|
putSymbolPointersIntoMfor(void)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
putSymbolPointersIntoExpression();
|
|
|
|
putSymbolPointersIntoExpression();
|
|
|
|
putSymbolPointersIntoExpression();
|
|
|
|
putSymbolPointersIntoExpression();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-01-24 07:13:44 +00:00
|
|
|
putSymbolPointersIntoMif(void)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
putSymbolPointersIntoExpression();
|
|
|
|
putSymbolPointersIntoExpression();
|
|
|
|
putSymbolPointersIntoExpression();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-01-24 07:13:44 +00:00
|
|
|
putSymbolPointersIntoClause(void)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
while (*pc != BLOCK_TAG)
|
|
|
|
putSymbolPointersIntoExpression();
|
|
|
|
putSymbolPointersIntoBlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-01-24 07:13:44 +00:00
|
|
|
putSymbolPointersIntoMswitch(void)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
putSymbolPointersIntoExpression();
|
|
|
|
while (*pc != END_TAG)
|
|
|
|
putSymbolPointersIntoClause();
|
|
|
|
overByte();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-01-24 07:13:44 +00:00
|
|
|
putSymbolPointersIntoMvariable(void)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
instantiateSymbol();
|
|
|
|
putSymbolPointersIntoExpression();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-01-24 07:13:44 +00:00
|
|
|
putSymbolPointersIntoMwhile(void)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
putSymbolPointersIntoExpression();
|
|
|
|
putSymbolPointersIntoExpression();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-01-24 07:13:44 +00:00
|
|
|
putSymbolPointersIntoPostop(void)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
overByte();
|
|
|
|
putSymbolPointersIntoExpression();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-01-24 07:13:44 +00:00
|
|
|
putSymbolPointersIntoPreop(void)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
overByte();
|
|
|
|
putSymbolPointersIntoExpression();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-01-24 07:13:44 +00:00
|
|
|
putSymbolPointersIntoUnop(void)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
overByte();
|
|
|
|
putSymbolPointersIntoExpression();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-01-24 07:13:44 +00:00
|
|
|
putSymbolPointersIntoExpression(void)
|
2014-05-04 05:20:34 +00:00
|
|
|
{
|
|
|
|
if (pc == NULL)
|
|
|
|
return;
|
|
|
|
switch (*pc++) {
|
|
|
|
case IDENTIFIER_TAG:
|
|
|
|
instantiateSymbol();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FUNCTION_CALL_TAG:
|
|
|
|
putSymbolPointersIntoFunctionCall();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BUILTIN_FUNCTION_CALL_TAG:
|
|
|
|
putSymbolPointersIntoBuiltinFunctionCall();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NUMBER_TAG:
|
|
|
|
case RELOCATABLE_TAG:
|
|
|
|
overNumber();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONDITION_CODE_TAG:
|
|
|
|
overByte();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SUBEXPRESSION_TAG:
|
|
|
|
putSymbolPointersIntoExpression();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UNOP_TAG:
|
|
|
|
putSymbolPointersIntoUnop();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BINOP_TAG:
|
|
|
|
putSymbolPointersIntoBinop();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PREOP_TAG:
|
|
|
|
putSymbolPointersIntoPreop();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case POSTOP_TAG:
|
|
|
|
putSymbolPointersIntoPostop();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HERE_TAG:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case STRING_TAG:
|
|
|
|
skipString();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ARRAY_TAG:
|
|
|
|
putSymbolPointersIntoArray();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VALUE_TAG:
|
|
|
|
overNumber();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NULL_TAG:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BLOCK_TAG:
|
|
|
|
putSymbolPointersIntoBlock();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MDEFINE_TAG:
|
|
|
|
putSymbolPointersIntoMdefine();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MVARIABLE_TAG:
|
|
|
|
putSymbolPointersIntoMvariable();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MIF_TAG:
|
|
|
|
putSymbolPointersIntoMif();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MFOR_TAG:
|
|
|
|
putSymbolPointersIntoMfor();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MWHILE_TAG:
|
|
|
|
putSymbolPointersIntoMwhile();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MDOWHILE_TAG:
|
|
|
|
putSymbolPointersIntoMdoWhile();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MDOUNTIL_TAG:
|
|
|
|
putSymbolPointersIntoMdoUntil();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PERFORM_TAG:
|
|
|
|
putSymbolPointersIntoExpression();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GROUP_TAG:
|
|
|
|
putSymbolPointersIntoBlock();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ASSERT_TAG:
|
|
|
|
putSymbolPointersIntoAssert();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MSWITCH_TAG:
|
|
|
|
putSymbolPointersIntoMswitch();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CLAUSE_TAG:
|
|
|
|
putSymbolPointersIntoClause();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case END_TAG:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|