Add support for assembler function as const initialiser

This commit is contained in:
drmortalwombat 2021-09-19 17:24:48 +02:00
parent fae377132f
commit c5d1e2351e
4 changed files with 27 additions and 2 deletions

View File

@ -455,6 +455,10 @@ bool Declaration::CanAssign(const Declaration* fromType) const
{ {
return mBase->IsSame(fromType); return mBase->IsSame(fromType);
} }
else if (mBase->mType == DT_TYPE_VOID && fromType->mType == DT_TYPE_ASSEMBLER)
{
return true;
}
} }
return false; return false;

View File

@ -2243,6 +2243,20 @@ void InterCodeGenerator::BuildInitializer(InterCodeModule * mod, uint8* dp, int
t >>= 8; t >>= 8;
} }
} }
else if (data->mType == DT_CONST_ASSEMBLER)
{
if (data->mVarIndex < 0)
TranslateAssembler(mod, data->mValue);
InterVariable::Reference ref;
ref.mAddr = offset;
ref.mUpper = true;
ref.mLower = true;
ref.mFunction = false;
ref.mIndex = data->mVarIndex;
ref.mOffset = 0;
references.Push(ref);
}
else if (data->mType == DT_CONST_FUNCTION) else if (data->mType == DT_CONST_FUNCTION)
{ {
if (data->mVarIndex < 0) if (data->mVarIndex < 0)

View File

@ -4708,6 +4708,13 @@ void NativeCodeProcedure::CompileInterBlock(InterCodeProcedure* iproc, InterCode
block->mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, BC_REG_TMP + iproc->mTempOffset[ins->mTTemp])); block->mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, BC_REG_TMP + iproc->mTempOffset[ins->mTTemp]));
block->mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_ZERO_PAGE, BC_REG_TMP + iproc->mTempOffset[ins->mSTemp[0]] + 1)); block->mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_ZERO_PAGE, BC_REG_TMP + iproc->mTempOffset[ins->mSTemp[0]] + 1));
block->mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, BC_REG_TMP + iproc->mTempOffset[ins->mTTemp] + 1)); block->mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, BC_REG_TMP + iproc->mTempOffset[ins->mTTemp] + 1));
if (ins->mSType[0] == IT_FLOAT)
{
block->mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_ZERO_PAGE, BC_REG_TMP + iproc->mTempOffset[ins->mSTemp[0]] + 2));
block->mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, BC_REG_TMP + iproc->mTempOffset[ins->mTTemp] + 2));
block->mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_ZERO_PAGE, BC_REG_TMP + iproc->mTempOffset[ins->mSTemp[0]] + 3));
block->mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, BC_REG_TMP + iproc->mTempOffset[ins->mTTemp] + 3));
}
} }
} break; } break;
case IC_BINARY_OPERATOR: case IC_BINARY_OPERATOR:

View File

@ -751,7 +751,7 @@ Declaration* Parser::ParseDeclaration(bool variable)
} }
} }
if (mGlobals == mScope) if (mGlobals == mScope || (ndec->mFlags & DTF_STATIC))
{ {
ndec->mFlags |= DTF_GLOBAL; ndec->mFlags |= DTF_GLOBAL;
ndec->mVarIndex = -1; ndec->mVarIndex = -1;
@ -962,7 +962,7 @@ Expression* Parser::ParseSimpleExpression(void)
dec = mScope->Lookup(mScanner->mTokenIdent); dec = mScope->Lookup(mScanner->mTokenIdent);
if (dec) if (dec)
{ {
if (dec->mType == DT_CONST_INTEGER || dec->mType == DT_CONST_FLOAT || dec->mType == DT_CONST_FUNCTION) if (dec->mType == DT_CONST_INTEGER || dec->mType == DT_CONST_FLOAT || dec->mType == DT_CONST_FUNCTION || dec->mType == DT_CONST_ASSEMBLER || dec->mType == DT_LABEL || dec->mType == DT_LABEL_REF)
{ {
exp = new Expression(mScanner->mLocation, EX_CONSTANT); exp = new Expression(mScanner->mLocation, EX_CONSTANT);
exp->mDecValue = dec; exp->mDecValue = dec;