Fix linux build

This commit is contained in:
drmortalwombat 2023-08-02 16:52:45 +02:00
parent ec15336174
commit f3eb6e19cf
5 changed files with 83 additions and 59 deletions

View File

@ -7,20 +7,20 @@ bool mouse_lb, mouse_rb;
static char mouse_px, mouse_py;
static char mouse_port;
inline signed char dpos(char * old, char new)
inline signed char dpos(char * old, char mnew)
{
new = (new & 0x7f) >> 1;
mnew = (mnew & 0x7f) >> 1;
char diff = (new - *old) & 0x3f;
char diff = (mnew - *old) & 0x3f;
if (diff >= 0x20)
{
*old = new;
*old = mnew;
return diff | 0xe0;
}
else if (diff)
{
*old = new;
*old = mnew;
return diff;
}

View File

@ -4523,6 +4523,11 @@ void InterCodeBasicBlock::Append(InterInstruction * code)
{
assert(code->mDst.mType == code->mConst.mType);
}
if (code->mCode == IC_CONSTANT && code->mConst.mType == IT_POINTER && code->mConst.mMemory == IM_GLOBAL && code->mConst.mVarIndex >= 0)
{
assert(code->mConst.mVarIndex < mProc->mModule->mGlobalVars.Size());
assert(mProc->mModule->mGlobalVars[code->mConst.mVarIndex]);
}
for (int i = 0; i < code->mNumOperands; i++)
assert(code->mSrc[i].mType != IT_NONE);
@ -11370,10 +11375,12 @@ bool InterCodeBasicBlock::CheckStaticStack(void)
return true;
}
void ApplyStaticStack(InterOperand & iop, const GrowingVariableArray& localVars)
void InterCodeBasicBlock::ApplyStaticStack(InterOperand & iop, const GrowingVariableArray& localVars)
{
if (iop.mMemory == IM_LOCAL)
{
assert(localVars[iop.mVarIndex]->mIndex < mProc->mModule->mGlobalVars.Size());
iop.mMemory = IM_GLOBAL;
iop.mLinkerObject = localVars[iop.mVarIndex]->mLinkerObject;
iop.mVarIndex = localVars[iop.mVarIndex]->mIndex;
@ -11419,6 +11426,7 @@ void PromoteStaticStackParam(InterOperand& iop, LinkerObject* paramlobj)
iop.mMemory = IM_GLOBAL;
iop.mIntConst += offset;
iop.mLinkerObject = paramlobj;
iop.mVarIndex = -1;
paramlobj->EnsureSpace(int(iop.mIntConst), iop.mOperandSize);
}
}

View File

@ -569,6 +569,7 @@ public:
bool DropUnreachable(void);
bool CheckStaticStack(void);
void ApplyStaticStack(InterOperand& iop, const GrowingVariableArray& localVars);
void CollectStaticStack(LinkerObject * lobj, const GrowingVariableArray& localVars);
void PromoteStaticStackParams(LinkerObject* paramlobj);

View File

@ -1288,7 +1288,7 @@ void InterCodeGenerator::CopyStruct(InterCodeProcedure* proc, Expression* exp, I
pcins->mConst.mVarIndex = ccdec->mVarIndex;
pcins->mConst.mIntConst = 0;
pcins->mConst.mOperandSize = 2;
pcins->mConst.mMemory = IM_GLOBAL;
pcins->mConst.mMemory = IM_PROCEDURE;
pcins->mConst.mLinkerObject = ccdec->mLinkerObject;
block->Append(pcins);

View File

@ -4717,6 +4717,8 @@ int Parser::OverloadDistance(Declaration* fdec, Expression* pexp)
dist += 1;
else if (ptype->mType == DT_TYPE_POINTER && etype->mType == DT_TYPE_FUNCTION && ptype->mBase->IsSame(etype))
dist += 0;
else if (ptype->mType == DT_TYPE_POINTER && etype->mType == DT_TYPE_POINTER && etype->mBase->mType == DT_TYPE_VOID)
dist += 0;
else if (ptype->IsSubType(etype))
dist += 256;
else if (ptype->mType == DT_TYPE_REFERENCE && ptype->mBase->IsSame(etype))
@ -5233,31 +5235,40 @@ Expression* Parser::ParsePrefixExpression(bool lhs)
if (mScanner->mToken == TK_OPEN_PARENTHESIS || dec->mDefaultConstructor)
{
Declaration* vdec = new Declaration(mScanner->mLocation, DT_VARIABLE);
vdec->mVarIndex = mLocalIndex++;
vdec->mBase = nexp->mDecType;
vdec->mSize = 2;
Expression* vexp = new Expression(mScanner->mLocation, EX_VARIABLE);
vexp->mDecType = vdec->mBase;
vexp->mDecValue = vdec;
Expression* iexp = new Expression(mScanner->mLocation, EX_INITIALIZATION);
iexp->mToken = TK_ASSIGN;
iexp->mLeft = vexp;
iexp->mRight = nexp;
iexp->mDecType = nexp->mDecType;
Declaration* mdec = dec->mDefaultConstructor;
Expression* pexp = vexp;
bool plist = false;
if (ConsumeTokenIf(TK_OPEN_PARENTHESIS))
{
if (!ConsumeTokenIf(TK_CLOSE_PARENTHESIS))
{
pexp = ParseListExpression(false);
plist = true;
mdec = dec->mScope->Lookup(dec->mIdent->PreMangle("+"));
}
}
if (mdec)
{
Declaration* vdec = new Declaration(mScanner->mLocation, DT_VARIABLE);
vdec->mVarIndex = mLocalIndex++;
vdec->mBase = nexp->mDecType;
vdec->mSize = 2;
Expression* vexp = new Expression(mScanner->mLocation, EX_VARIABLE);
vexp->mDecType = vdec->mBase;
vexp->mDecValue = vdec;
Expression* iexp = new Expression(mScanner->mLocation, EX_INITIALIZATION);
iexp->mToken = TK_ASSIGN;
iexp->mLeft = vexp;
iexp->mRight = nexp;
iexp->mDecType = nexp->mDecType;
Expression* pexp = vexp;
if (plist)
{
pexp = ParseListExpression(false);
ConsumeToken(TK_CLOSE_PARENTHESIS);
@ -5266,41 +5277,45 @@ Expression* Parser::ParsePrefixExpression(bool lhs)
lexp->mRight = pexp;
pexp = lexp;
}
Expression* cexp = new Expression(mScanner->mLocation, EX_CONSTANT);
cexp->mDecValue = mdec;
cexp->mDecType = cexp->mDecValue->mBase;
Expression* dexp = new Expression(mScanner->mLocation, EX_CALL);
dexp->mLeft = cexp;
dexp->mRight = pexp;
dexp = ResolveOverloadCall(dexp);
Expression* sexp = new Expression(mScanner->mLocation, EX_SEQUENCE);
sexp->mLeft = dexp;
sexp->mRight = vexp;
sexp->mDecType = vexp->mDecType;
Expression* coexp = nexp = new Expression(mScanner->mLocation, EX_CONDITIONAL);
coexp->mLeft = new Expression(mScanner->mLocation, EX_RELATIONAL);
coexp->mLeft->mDecType = TheBoolTypeDeclaration;
coexp->mLeft->mToken = TK_EQUAL;
coexp->mLeft->mLeft = vexp;
coexp->mLeft->mRight = nuexp;
coexp->mRight = new Expression(mScanner->mLocation, EX_LIST);
coexp->mRight->mLeft = vexp;
coexp->mRight->mRight = new Expression(mScanner->mLocation, EX_SEQUENCE);
coexp->mRight->mRight->mLeft = dexp;
coexp->mRight->mRight->mRight = vexp;
coexp->mDecType = vexp->mDecType;
nexp = new Expression(mScanner->mLocation, EX_SEQUENCE);
nexp->mLeft = iexp;
nexp->mRight = coexp;
nexp->mDecType = coexp->mDecType;
}
else if (plist)
{
mErrors->Error(mScanner->mLocation, ERRO_NO_MATCHING_FUNCTION_CALL, "No matching constructor", dec->mIdent);
}
Expression* cexp = new Expression(mScanner->mLocation, EX_CONSTANT);
cexp->mDecValue = mdec;
cexp->mDecType = cexp->mDecValue->mBase;
Expression* dexp = new Expression(mScanner->mLocation, EX_CALL);
dexp->mLeft = cexp;
dexp->mRight = pexp;
dexp = ResolveOverloadCall(dexp);
Expression* sexp = new Expression(mScanner->mLocation, EX_SEQUENCE);
sexp->mLeft = dexp;
sexp->mRight = vexp;
sexp->mDecType = vexp->mDecType;
Expression * coexp = nexp = new Expression(mScanner->mLocation, EX_CONDITIONAL);
coexp->mLeft = new Expression(mScanner->mLocation, EX_RELATIONAL);
coexp->mLeft->mDecType = TheBoolTypeDeclaration;
coexp->mLeft->mToken = TK_EQUAL;
coexp->mLeft->mLeft = vexp;
coexp->mLeft->mRight = nuexp;
coexp->mRight = new Expression(mScanner->mLocation, EX_LIST);
coexp->mRight->mLeft = vexp;
coexp->mRight->mRight = new Expression(mScanner->mLocation, EX_SEQUENCE);
coexp->mRight->mRight->mLeft = dexp;
coexp->mRight->mRight->mRight = vexp;
coexp->mDecType = vexp->mDecType;
nexp = new Expression(mScanner->mLocation, EX_SEQUENCE);
nexp->mLeft = iexp;
nexp->mRight = coexp;
nexp->mDecType = coexp->mDecType;
}
}
}