Fix unnamed parameters in function prototype

This commit is contained in:
drmortalwombat 2021-09-11 16:05:31 +02:00
parent 93b6aca8a3
commit 897de02adf
6 changed files with 183 additions and 30 deletions

View File

@ -16,7 +16,7 @@ __asm startup
sta sp
lda StackTop + 1
sta sp + 1
pexec:
ldy #0
exec:
lda (ip), y
@ -38,6 +38,36 @@ incip:
#pragma startup(startup)
__asm bcexec
{
lda ip
pha
lda ip + 1
pha
lda accu
sta ip
lda accu + 1
sta ip + 1
ldy #0
lda #<done
sta (sp), y
iny
lda #>done
sta (sp), y
jmp startup.pexec
done: nop
pla
pla
pla
sta ip + 1
pla
sta ip
rts
}
#pragma runtime(bcexec, bcexec)
__asm negaccu
{
sec
@ -1772,8 +1802,7 @@ __asm inp_call
sta ip
lda addr + 1
sta ip + 1
ldy #0
jmp startup.exec
jmp startup.pexec
}
#pragma bytecode(BC_CALL, inp_call)

View File

@ -29,7 +29,9 @@ enum AsmInsMode
ASMIM_INDIRECT_Y,
ASMIM_RELATIVE,
NUM_ASM_INS_MODES
NUM_ASM_INS_MODES,
ASMIM_IMMEDIATE_ADDRESS
};
struct AsmInsData

View File

@ -53,6 +53,9 @@ static const uint32 DTF_CONST = 0x00000040;
static const uint32 DTF_VOLATILE = 0x00000080;
static const uint32 DTF_EXTERN = 0x00000100;
static const uint32 DTF_NATIVE = 0x00000200;
static const uint32 DTF_UPPER_BYTE = 0x00000400;
static const uint32 DTF_LOWER_BYTE = 0x00000800;
class Declaration;

View File

@ -185,6 +185,26 @@ void InterCodeGenerator::TranslateAssembler(InterCodeModule* mod, Expression * e
case ASMIM_IMPLIED:
break;
case ASMIM_IMMEDIATE:
if (aexp->mType == DT_CONST_INTEGER)
d[offset++] = cexp->mLeft->mDecValue->mInteger & 255;
else if (aexp->mType == DT_LABEL_REF)
{
if (aexp->mBase->mBase->mVarIndex < 0)
TranslateAssembler(mod, aexp->mBase->mBase->mValue);
InterVariable::Reference ref;
ref.mFunction = false;
ref.mUpper = aexp->mFlags & DTF_UPPER_BYTE;
ref.mLower = !(aexp->mFlags & DTF_UPPER_BYTE);
ref.mAddr = offset;
ref.mIndex = aexp->mBase->mBase->mVarIndex;
ref.mOffset = aexp->mOffset + aexp->mBase->mInteger;
references.Push(ref);
offset += 1;
}
break;
case ASMIM_ZERO_PAGE:
case ASMIM_ZERO_PAGE_X:
case ASMIM_INDIRECT_X:

View File

@ -960,7 +960,10 @@ void NativeCodeInstruction::Assemble(NativeCodeBasicBlock* block)
block->PutByte(mAddress);
else
{
block->PutByte(AsmInsOpcodes[mType][mMode]);
if (mMode == ASMIM_IMMEDIATE_ADDRESS)
block->PutByte(AsmInsOpcodes[mType][ASMIM_IMMEDIATE]);
else
block->PutByte(AsmInsOpcodes[mType][mMode]);
switch (mMode)
{
@ -974,11 +977,12 @@ void NativeCodeInstruction::Assemble(NativeCodeBasicBlock* block)
block->PutByte(uint8(mAddress));
break;
case ASMIM_IMMEDIATE:
case ASMIM_IMMEDIATE_ADDRESS:
if (mVarIndex != -1)
{
ByteCodeRelocation rl;
rl.mAddr = block->mCode.Size();
rl.mFunction = false;
rl.mFunction = mFunction;
rl.mLower = mLower;
rl.mUpper = mUpper;
rl.mIndex = mVarIndex;
@ -1144,9 +1148,9 @@ void NativeCodeBasicBlock::LoadConstantToReg(InterCodeProcedure * proc, const In
{
if (ins.mMemory == IM_GLOBAL)
{
mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_IMMEDIATE, ins.mIntValue, ins.mVarIndex, true, false));
mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_IMMEDIATE_ADDRESS, ins.mIntValue, ins.mVarIndex, true, false));
mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, reg));
mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_IMMEDIATE, ins.mIntValue, ins.mVarIndex, false, true));
mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_IMMEDIATE_ADDRESS, ins.mIntValue, ins.mVarIndex, false, true));
mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, reg + 1));
}
else if (ins.mMemory == IM_ABSOLUTE)
@ -3191,44 +3195,49 @@ void NativeCodeBasicBlock::LoadEffectiveAddress(InterCodeProcedure* proc, const
void NativeCodeBasicBlock::CallFunction(InterCodeProcedure* proc, const InterInstruction& ins)
{
#if 0
if (ins.mSTemp[0] < 0)
{
ByteCodeInstruction bins(BC_LEA_ABS);
bins.mRelocate = true;
bins.mFunction = true;
bins.mVIndex = ins.mVarIndex;
bins.mValue = 0;
bins.mRegister = BC_REG_ADDR;
mIns.Push(bins);
NativeCodeInstruction lins(ASMIT_LDA, ASMIM_IMMEDIATE_ADDRESS, ins.mSIntConst[0], ins.mVarIndex, true, false);
lins.mFunction = ins.mMemory == IM_PROCEDURE;
NativeCodeInstruction hins(ASMIT_LDA, ASMIM_IMMEDIATE_ADDRESS, ins.mSIntConst[0], ins.mVarIndex, false, true);
hins.mFunction = ins.mMemory == IM_PROCEDURE;
mIns.Push(lins);
mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, BC_REG_ACCU));
mIns.Push(hins);
mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, BC_REG_ACCU + 1));
}
else
{
ByteCodeInstruction bins(BC_ADDR_REG);
bins.mRegister = BC_REG_TMP + proc->mTempOffset[ins.mSTemp[0]];
bins.mRegisterFinal = ins.mSFinal[0];
mIns.Push(bins);
mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_ZERO_PAGE, BC_REG_TMP + proc->mTempOffset[ins.mSTemp[0]] + 0));
mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, BC_REG_ACCU));
mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_ZERO_PAGE, BC_REG_TMP + proc->mTempOffset[ins.mSTemp[0]] + 1));
mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, BC_REG_ACCU + 1));
}
ByteCodeInstruction cins(BC_CALL);
mIns.Push(cins);
mIns.Push(NativeCodeInstruction("bcexec"));
if (ins.mTTemp >= 0)
{
if (ins.mTType == IT_FLOAT)
{
ByteCodeInstruction bins(BC_STORE_REG_32);
bins.mRegister = BC_REG_TMP + proc->mTempOffset[ins.mTTemp];
mIns.Push(bins);
mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_ZERO_PAGE, BC_REG_ACCU + 0));
mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, BC_REG_TMP + proc->mTempOffset[ins.mTTemp] + 0));
mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_ZERO_PAGE, BC_REG_ACCU + 1));
mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, BC_REG_TMP + proc->mTempOffset[ins.mTTemp] + 1));
mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_ZERO_PAGE, BC_REG_ACCU + 2));
mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, BC_REG_TMP + proc->mTempOffset[ins.mTTemp] + 2));
mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_ZERO_PAGE, BC_REG_ACCU + 3));
mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, BC_REG_TMP + proc->mTempOffset[ins.mTTemp] + 3));
}
else
{
ByteCodeInstruction bins(BC_STORE_REG_16);
bins.mRegister = BC_REG_TMP + proc->mTempOffset[ins.mTTemp];
mIns.Push(bins);
mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_ZERO_PAGE, BC_REG_ACCU + 0));
mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, BC_REG_TMP + proc->mTempOffset[ins.mTTemp] + 0));
mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_ZERO_PAGE, BC_REG_ACCU + 1));
mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, BC_REG_TMP + proc->mTempOffset[ins.mTTemp] + 1));
}
}
#endif
}
void NativeCodeBasicBlock::CallAssembler(InterCodeProcedure* proc, const InterInstruction& ins)

View File

@ -677,6 +677,21 @@ Declaration* Parser::ParseDeclaration(bool variable)
{
if (!ndec->mBase->IsSame(pdec->mBase))
mErrors->Error(ndec->mLocation, "Function declaration differs");
else
{
//
// Take parameter names from new declaration
//
Declaration* npdec = ndec->mBase->mParams, *ppdec = pdec->mBase->mParams;
while (npdec && ppdec)
{
if (npdec->mIdent)
ppdec->mIdent = npdec->mIdent;
npdec = npdec->mNext;
ppdec = ppdec->mNext;
}
}
ndec = pdec;
}
else
@ -1818,7 +1833,82 @@ Expression* Parser::ParseAssemblerAddOperand(void)
Expression* Parser::ParseAssemblerOperand(void)
{
return ParseAssemblerAddOperand();
if (mScanner->mToken == TK_LESS_THAN)
{
mScanner->NextToken();
Expression* exp = ParseAssemblerOperand();
if (exp->mType == EX_CONSTANT)
{
if (exp->mDecValue->mType == DT_CONST_INTEGER)
{
Declaration* dec = new Declaration(mScanner->mLocation, DT_CONST_INTEGER);
dec->mInteger = exp->mDecValue->mInteger & 0xff;
dec->mBase = TheUnsignedIntTypeDeclaration;
exp->mDecValue = dec;
}
else if (exp->mDecValue->mType == DT_LABEL)
{
Declaration* ndec = new Declaration(mScanner->mLocation, DT_LABEL_REF);
ndec->mBase = exp->mDecValue;
ndec->mOffset = 0;
ndec->mFlags |= DTF_LOWER_BYTE;
exp->mDecValue = ndec;
}
else if (exp->mDecValue->mType == DT_LABEL_REF)
{
Declaration* ndec = new Declaration(mScanner->mLocation, DT_LABEL_REF);
ndec->mBase = exp->mDecValue->mBase;
ndec->mOffset = exp->mDecValue->mOffset;
ndec->mFlags |= DTF_LOWER_BYTE;
exp->mDecValue = ndec;
}
else
mErrors->Error(mScanner->mLocation, "Label or integer value for lower byte operator expected");
}
else
mErrors->Error(mScanner->mLocation, "Constant for lower byte operator expected");
return exp;
}
else if (mScanner->mToken == TK_GREATER_THAN)
{
mScanner->NextToken();
Expression* exp = ParseAssemblerOperand();
if (exp->mType == EX_CONSTANT)
{
if (exp->mDecValue->mType == DT_CONST_INTEGER)
{
Declaration* dec = new Declaration(mScanner->mLocation, DT_CONST_INTEGER);
dec->mInteger = (exp->mDecValue->mInteger >> 8) & 0xff;
dec->mBase = TheUnsignedIntTypeDeclaration;
exp->mDecValue = dec;
}
else if (exp->mDecValue->mType == DT_LABEL)
{
Declaration* ndec = new Declaration(mScanner->mLocation, DT_LABEL_REF);
ndec->mBase = exp->mDecValue;
ndec->mOffset = 0;
ndec->mFlags |= DTF_UPPER_BYTE;
exp->mDecValue = ndec;
}
else if (exp->mDecValue->mType == DT_LABEL_REF)
{
Declaration* ndec = new Declaration(mScanner->mLocation, DT_LABEL_REF);
ndec->mBase = exp->mDecValue->mBase;
ndec->mOffset = exp->mDecValue->mOffset;
ndec->mFlags |= DTF_UPPER_BYTE;
exp->mDecValue = ndec;
}
else
mErrors->Error(mScanner->mLocation, "Label or integer value for lower byte operator expected");
}
else
mErrors->Error(mScanner->mLocation, "Constant for upper byte operator expected");
}
else
return ParseAssemblerAddOperand();
}
Expression* Parser::ParseAssembler(void)