Add goto and labels in C code

This commit is contained in:
drmortalwombat 2024-06-25 20:45:44 +02:00
parent a71c433fc4
commit 715f295f5e
10 changed files with 263 additions and 95 deletions

View File

@ -28,7 +28,6 @@ There are still several open areas, but most targets have been reached. The cur
### Language ### Language
* Missing warnings for all kind of abuses * Missing warnings for all kind of abuses
* no goto or C label support, but keyword protected
### Linker ### Linker
@ -78,7 +77,7 @@ Supported Features:
### Installing on windows ### Installing on windows
A windows installer is provided with the release, the compiler is installed into "%programfiles(x86)%\oscar64\bin\oscar64". When not using batch or make files, it might be a good idea to add the folder to the path environment variable. A windows installer is provided with the release, the compiler is installed into "%programfiles(x86)%\oscar64\bin\oscar64". When not using batch or make files, it might be a good idea to add the folder to the path environment variable. Windows 10 is the minimum release required for the installer version.
### Building ### Building

View File

@ -73,9 +73,12 @@ static inline bool clock_in(void)
static bool data_check(void) static bool data_check(void)
{ {
char cnt = 100; char cnt = 200;
while (cnt > 0 && data_in()) while (cnt > 0 && data_in())
{
delay(5);
cnt--; cnt--;
}
if (cnt) if (cnt)
return true; return true;
@ -97,7 +100,7 @@ static bool iec_eoib(void)
return data_check(); return data_check();
} }
static bool iec_writeb(char b) static void iec_writeb(char b)
{ {
clock_true(); clock_true();
@ -107,19 +110,17 @@ static bool iec_writeb(char b)
for(char i=0; i<8; i++) for(char i=0; i<8; i++)
{ {
clock_false(); clock_false();
delay(4); delay(5);
if (b & 1) if (b & 1)
data_true(); data_true();
else else
data_false(); data_false();
clock_true(); clock_true();
b >>= 1; b >>= 1;
delay(4); delay(5);
} }
clock_false(); clock_false();
data_true(); data_true();
return data_check();
} }
bool iec_write(char b) bool iec_write(char b)
@ -139,6 +140,8 @@ bool iec_write(char b)
{ {
plp plp
} }
data_check();
} }
if (iec_status < IEC_ERROR) if (iec_status < IEC_ERROR)
{ {
@ -170,7 +173,7 @@ char iec_read(void)
{ {
iec_status = IEC_EOF; iec_status = IEC_EOF;
data_false(); data_false();
delay(4); delay(10);
data_true(); data_true();
cnt = 200; cnt = 200;
@ -226,8 +229,12 @@ void iec_atn(char dev, char sec)
while (data_in()); while (data_in());
iec_writeb(dev); iec_writeb(dev);
data_check();
if (sec != 0xff) if (sec != 0xff)
{
iec_writeb(sec); iec_writeb(sec);
data_check();
}
atn_true(); atn_true();
} }
@ -238,9 +245,24 @@ void iec_talk(char dev, char sec)
iec_status = IEC_OK; iec_status = IEC_OK;
iec_atn(dev | 0x40, sec | 0x60); iec_atn(dev | 0x40, sec | 0x60);
clock_true();
data_false(); data_false();
__asm
{
php
sei
}
clock_true();
char cnt = 200;
while (cnt > 0 && clock_in())
cnt--;
__asm
{
plp
}
delay(10); delay(10);
} }
@ -266,8 +288,10 @@ void iec_unlisten(void)
if (iec_status == IEC_QUEUED) if (iec_status == IEC_QUEUED)
{ {
iec_status = IEC_OK;
iec_eoib(); iec_eoib();
iec_writeb(iec_queue); iec_writeb(iec_queue);
data_check();
} }
iec_atn(0x3f, 0xff); iec_atn(0x3f, 0xff);

View File

@ -313,6 +313,12 @@ void Expression::Dump(int ident) const
case EX_PACK_TYPE: case EX_PACK_TYPE:
printf("PACK_TYPE"); printf("PACK_TYPE");
break; break;
case EX_GOTO:
printf("GOTO %s", mDecValue->mIdent->mString);
break;
case EX_LABEL:
printf("LABEL %s", mDecValue->mIdent->mString);
break;
} }
printf("\n"); printf("\n");

View File

@ -59,6 +59,7 @@ enum DecType
DT_LABEL_REF, DT_LABEL_REF,
DT_NAMESPACE, DT_NAMESPACE,
DT_BASECLASS, DT_BASECLASS,
DT_CLABEL,
DT_TEMPLATE, DT_TEMPLATE,
@ -231,6 +232,8 @@ enum ExpressionType
EX_RESULT, EX_RESULT,
EX_PACK, EX_PACK,
EX_PACK_TYPE, EX_PACK_TYPE,
EX_LABEL,
EX_GOTO
}; };
class Expression class Expression

View File

@ -98,6 +98,7 @@ enum ErrorID
EERR_INVALID_PACK_USAGE, EERR_INVALID_PACK_USAGE,
EERR_INVALID_FOLD_EXPRESSION, EERR_INVALID_FOLD_EXPRESSION,
ERRR_INSTANTIATE_ABSTRACT_CLASS, ERRR_INSTANTIATE_ABSTRACT_CLASS,
ERRR_INVALID_GOTO,
EERR_INVALID_CONSTEXPR, EERR_INVALID_CONSTEXPR,
EERR_DOUBLE_FREE, EERR_DOUBLE_FREE,

View File

@ -21034,7 +21034,7 @@ void InterCodeProcedure::Close(void)
{ {
GrowingTypeArray tstack(IT_NONE); GrowingTypeArray tstack(IT_NONE);
CheckFunc = !strcmp(mIdent->mString, "draw_face"); CheckFunc = !strcmp(mIdent->mString, "main");
CheckCase = false; CheckCase = false;
mEntryBlock = mBlocks[0]; mEntryBlock = mBlocks[0];

View File

@ -718,7 +718,8 @@ void InterCodeGenerator::InitGlobalVariable(InterCodeModule * mod, Declaration*
else if (dec->mValue->mType == EX_CONSTRUCT) else if (dec->mValue->mType == EX_CONSTRUCT)
{ {
DestructStack* destack = nullptr; DestructStack* destack = nullptr;
TranslateExpression(nullptr, mMainInitProc, mMainInitBlock, dec->mValue, destack, BranchTarget(), BranchTarget(), nullptr); GotoNode* gotos = nullptr;
TranslateExpression(nullptr, mMainInitProc, mMainInitBlock, dec->mValue, destack, gotos, BranchTarget(), BranchTarget(), nullptr);
} }
else if (dec->mValue->mType == EX_VARIABLE && dec->mValue->mDecType->mType == DT_TYPE_ARRAY && dec->mBase->mType == DT_TYPE_POINTER && dec->mBase->CanAssign(dec->mValue->mDecType)) else if (dec->mValue->mType == EX_VARIABLE && dec->mValue->mDecType->mType == DT_TYPE_ARRAY && dec->mBase->mType == DT_TYPE_POINTER && dec->mBase->CanAssign(dec->mValue->mDecType))
{ {
@ -1336,7 +1337,8 @@ void InterCodeGenerator::UnwindDestructStack(Declaration* procType, InterCodePro
if (stack->mDestruct) if (stack->mDestruct)
{ {
DestructStack* destack = nullptr; DestructStack* destack = nullptr;
TranslateExpression(procType, proc, block, stack->mDestruct, destack, BranchTarget(), BranchTarget(), inlineMapper); GotoNode* gotos = nullptr;
TranslateExpression(procType, proc, block, stack->mDestruct, destack, gotos, BranchTarget(), BranchTarget(), inlineMapper);
} }
stack = stack->mNext; stack = stack->mNext;
@ -1357,6 +1359,7 @@ Location InterCodeGenerator::MapLocation(Expression* exp, InlineMapper* inlineMa
InterCodeGenerator::ExValue InterCodeGenerator::TranslateInline(Declaration* procType, InterCodeProcedure* proc, InterCodeBasicBlock*& block, Expression* exp, const BranchTarget& breakBlock, const BranchTarget& continueBlock, InlineMapper* inlineMapper, bool inlineConstexpr, ExValue* lrexp) InterCodeGenerator::ExValue InterCodeGenerator::TranslateInline(Declaration* procType, InterCodeProcedure* proc, InterCodeBasicBlock*& block, Expression* exp, const BranchTarget& breakBlock, const BranchTarget& continueBlock, InlineMapper* inlineMapper, bool inlineConstexpr, ExValue* lrexp)
{ {
DestructStack* destack = nullptr; DestructStack* destack = nullptr;
GotoNode* gotos = nullptr;
ExValue vl, vr; ExValue vl, vr;
@ -1427,9 +1430,9 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateInline(Declaration* pro
ExValue vp(pdec ? pdec->mBase : TheSignedIntTypeDeclaration, ains->mDst.mTemp, 1); ExValue vp(pdec ? pdec->mBase : TheSignedIntTypeDeclaration, ains->mDst.mTemp, 1);
if (pdec && (pdec->mBase->mType == DT_TYPE_STRUCT || pdec->mBase->mType == DT_TYPE_UNION)) if (pdec && (pdec->mBase->mType == DT_TYPE_STRUCT || pdec->mBase->mType == DT_TYPE_UNION))
vr = TranslateExpression(procType, proc, block, texp, destack, breakBlock, continueBlock, inlineMapper, &vp); vr = TranslateExpression(procType, proc, block, texp, destack, gotos, breakBlock, continueBlock, inlineMapper, &vp);
else else
vr = TranslateExpression(procType, proc, block, texp, destack, breakBlock, continueBlock, inlineMapper, nullptr); vr = TranslateExpression(procType, proc, block, texp, destack, gotos, breakBlock, continueBlock, inlineMapper, nullptr);
if (!(pdec && pdec->mBase->IsReference()) && (vr.mType->mType == DT_TYPE_STRUCT || vr.mType->mType == DT_TYPE_UNION)) if (!(pdec && pdec->mBase->IsReference()) && (vr.mType->mType == DT_TYPE_STRUCT || vr.mType->mType == DT_TYPE_UNION))
{ {
@ -1522,8 +1525,9 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateInline(Declaration* pro
} }
DestructStack* idestack = nullptr; DestructStack* idestack = nullptr;
GotoNode* igotos = nullptr;
vl = TranslateExpression(ftype, proc, block, fexp, idestack, BranchTarget(), BranchTarget(), &nmapper); vl = TranslateExpression(ftype, proc, block, fexp, idestack, igotos, BranchTarget(), BranchTarget(), &nmapper);
InterInstruction* jins = new InterInstruction(MapLocation(exp, inlineMapper), IC_JUMP); InterInstruction* jins = new InterInstruction(MapLocation(exp, inlineMapper), IC_JUMP);
block->Append(jins); block->Append(jins);
@ -1663,6 +1667,7 @@ void InterCodeGenerator::CopyStruct(InterCodeProcedure* proc, Expression* exp, I
if (doInline) if (doInline)
{ {
DestructStack* destack = nullptr; DestructStack* destack = nullptr;
GotoNode* gotos = nullptr;
Expression* fexp = ccdec->mValue; Expression* fexp = ccdec->mValue;
Declaration* ftype = ccdec->mBase; Declaration* ftype = ccdec->mBase;
@ -1743,7 +1748,7 @@ void InterCodeGenerator::CopyStruct(InterCodeProcedure* proc, Expression* exp, I
if (!(pdec->mFlags & DTF_FPARAM_UNUSED)) if (!(pdec->mFlags & DTF_FPARAM_UNUSED))
block->Append(wins); block->Append(wins);
TranslateExpression(ftype, proc, block, fexp, destack, BranchTarget(), BranchTarget(), &nmapper); TranslateExpression(ftype, proc, block, fexp, destack, gotos, BranchTarget(), BranchTarget(), &nmapper);
InterInstruction* jins = new InterInstruction(MapLocation(exp, inlineMapper), IC_JUMP); InterInstruction* jins = new InterInstruction(MapLocation(exp, inlineMapper), IC_JUMP);
block->Append(jins); block->Append(jins);
@ -1831,7 +1836,7 @@ void InterCodeGenerator::CopyStruct(InterCodeProcedure* proc, Expression* exp, I
CopyStructSimple(proc, exp, block, inlineMapper, vl, vr); CopyStructSimple(proc, exp, block, inlineMapper, vl, vr);
} }
InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* procType, InterCodeProcedure* proc, InterCodeBasicBlock*& block, Expression* exp, DestructStack*& destack, const BranchTarget& breakBlock, const BranchTarget& continueBlock, InlineMapper* inlineMapper, ExValue* lrexp) InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* procType, InterCodeProcedure* proc, InterCodeBasicBlock*& block, Expression* exp, DestructStack*& destack, GotoNode*& gotos, const BranchTarget& breakBlock, const BranchTarget& continueBlock, InlineMapper* inlineMapper, ExValue* lrexp)
{ {
Declaration* dec; Declaration* dec;
ExValue vl, vr; ExValue vl, vr;
@ -1847,7 +1852,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
case EX_LIST: case EX_LIST:
case EX_COMMA: case EX_COMMA:
if (exp->mLeft) if (exp->mLeft)
vr = TranslateExpression(procType, proc, block, exp->mLeft, destack, breakBlock, continueBlock, inlineMapper); vr = TranslateExpression(procType, proc, block, exp->mLeft, destack, gotos, breakBlock, continueBlock, inlineMapper);
exp = exp->mRight; exp = exp->mRight;
if (!exp) if (!exp)
return ExValue(TheVoidTypeDeclaration); return ExValue(TheVoidTypeDeclaration);
@ -1856,7 +1861,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
case EX_CONSTRUCT: case EX_CONSTRUCT:
{ {
if (exp->mLeft->mLeft) if (exp->mLeft->mLeft)
TranslateExpression(procType, proc, block, exp->mLeft->mLeft, destack, breakBlock, continueBlock, inlineMapper, lrexp); TranslateExpression(procType, proc, block, exp->mLeft->mLeft, destack, gotos, breakBlock, continueBlock, inlineMapper, lrexp);
if (exp->mLeft->mRight) if (exp->mLeft->mRight)
{ {
@ -1935,8 +1940,8 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
} }
case EX_CLEANUP: case EX_CLEANUP:
{ {
vl = TranslateExpression(procType, proc, block, exp->mLeft, destack, breakBlock, continueBlock, inlineMapper); vl = TranslateExpression(procType, proc, block, exp->mLeft, destack, gotos, breakBlock, continueBlock, inlineMapper);
TranslateExpression(procType, proc, block, exp->mRight, destack, breakBlock, continueBlock, inlineMapper); TranslateExpression(procType, proc, block, exp->mRight, destack, gotos, breakBlock, continueBlock, inlineMapper);
return vl; return vl;
} }
@ -2069,7 +2074,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
case DT_CONST_POINTER: case DT_CONST_POINTER:
{ {
vl = TranslateExpression(procType, proc, block, dec->mValue, destack, breakBlock, continueBlock, inlineMapper); vl = TranslateExpression(procType, proc, block, dec->mValue, destack, gotos, breakBlock, continueBlock, inlineMapper);
vl.mReference--; vl.mReference--;
vl.mType = exp->mDecType; vl.mType = exp->mDecType;
return vl; return vl;
@ -2243,19 +2248,19 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
{ {
if (exp->mLeft->mDecType && exp->mLeft->mDecType->mType == DT_TYPE_STRUCT) if (exp->mLeft->mDecType && exp->mLeft->mDecType->mType == DT_TYPE_STRUCT)
{ {
vl = TranslateExpression(procType, proc, block, exp->mLeft, destack, breakBlock, continueBlock, inlineMapper); vl = TranslateExpression(procType, proc, block, exp->mLeft, destack, gotos, breakBlock, continueBlock, inlineMapper);
vr = TranslateExpression(procType, proc, block, exp->mRight, destack, breakBlock, continueBlock, inlineMapper, &vl); vr = TranslateExpression(procType, proc, block, exp->mRight, destack, gotos, breakBlock, continueBlock, inlineMapper, &vl);
} }
else if (exp->mType == EX_INITIALIZATION && exp->mLeft->mDecType && exp->mLeft->mDecType->IsReference()) else if (exp->mType == EX_INITIALIZATION && exp->mLeft->mDecType && exp->mLeft->mDecType->IsReference())
{ {
vr = TranslateExpression(procType, proc, block, exp->mRight, destack, breakBlock, continueBlock, inlineMapper); vr = TranslateExpression(procType, proc, block, exp->mRight, destack, gotos, breakBlock, continueBlock, inlineMapper);
vl = TranslateExpression(procType, proc, block, exp->mLeft, destack, breakBlock, continueBlock, inlineMapper); vl = TranslateExpression(procType, proc, block, exp->mLeft, destack, gotos, breakBlock, continueBlock, inlineMapper);
vl.mType = exp->mLeft->mDecType; vl.mType = exp->mLeft->mDecType;
} }
else else
{ {
vr = TranslateExpression(procType, proc, block, exp->mRight, destack, breakBlock, continueBlock, inlineMapper); vr = TranslateExpression(procType, proc, block, exp->mRight, destack, gotos, breakBlock, continueBlock, inlineMapper);
vl = TranslateExpression(procType, proc, block, exp->mLeft, destack, breakBlock, continueBlock, inlineMapper); vl = TranslateExpression(procType, proc, block, exp->mLeft, destack, gotos, breakBlock, continueBlock, inlineMapper);
} }
if (exp->mType == EX_ASSIGNMENT) if (exp->mType == EX_ASSIGNMENT)
@ -2497,8 +2502,8 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
case EX_INDEX: case EX_INDEX:
{ {
vl = TranslateExpression(procType, proc, block, exp->mLeft, destack, breakBlock, continueBlock, inlineMapper); vl = TranslateExpression(procType, proc, block, exp->mLeft, destack, gotos, breakBlock, continueBlock, inlineMapper);
vr = TranslateExpression(procType, proc, block, exp->mRight, destack, breakBlock, continueBlock, inlineMapper); vr = TranslateExpression(procType, proc, block, exp->mRight, destack, gotos, breakBlock, continueBlock, inlineMapper);
vl = ToValue(proc, exp, block, inlineMapper, vl); vl = ToValue(proc, exp, block, inlineMapper, vl);
vr = ToValue(proc, exp, block, inlineMapper, vr); vr = ToValue(proc, exp, block, inlineMapper, vr);
@ -2561,7 +2566,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
case EX_QUALIFY: case EX_QUALIFY:
{ {
vl = TranslateExpression(procType, proc, block, exp->mLeft, destack, breakBlock, continueBlock, inlineMapper); vl = TranslateExpression(procType, proc, block, exp->mLeft, destack, gotos, breakBlock, continueBlock, inlineMapper);
vl = ToValue(proc, exp, block, inlineMapper, vl); vl = ToValue(proc, exp, block, inlineMapper, vl);
@ -2595,8 +2600,8 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
case EX_BINARY: case EX_BINARY:
{ {
vl = TranslateExpression(procType, proc, block, exp->mLeft, destack, breakBlock, continueBlock, inlineMapper); vl = TranslateExpression(procType, proc, block, exp->mLeft, destack, gotos, breakBlock, continueBlock, inlineMapper);
vr = TranslateExpression(procType, proc, block, exp->mRight, destack, breakBlock, continueBlock, inlineMapper); vr = TranslateExpression(procType, proc, block, exp->mRight, destack, gotos, breakBlock, continueBlock, inlineMapper);
vl = ToValue(proc, exp, block, inlineMapper, vl); vl = ToValue(proc, exp, block, inlineMapper, vl);
vr = ToValue(proc, exp, block, inlineMapper, vr); vr = ToValue(proc, exp, block, inlineMapper, vr);
@ -2928,7 +2933,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
case EX_PREINCDEC: case EX_PREINCDEC:
{ {
vl = TranslateExpression(procType, proc, block, exp->mLeft, destack, breakBlock, continueBlock, inlineMapper); vl = TranslateExpression(procType, proc, block, exp->mLeft, destack, gotos, breakBlock, continueBlock, inlineMapper);
vl = ToValue(proc, exp, block, inlineMapper, vl); vl = ToValue(proc, exp, block, inlineMapper, vl);
vl = Dereference(proc, exp, block, inlineMapper, vl, 1); vl = Dereference(proc, exp, block, inlineMapper, vl, 1);
@ -2998,7 +3003,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
case EX_POSTINCDEC: case EX_POSTINCDEC:
{ {
vl = TranslateExpression(procType, proc, block, exp->mLeft, destack, breakBlock, continueBlock, inlineMapper); vl = TranslateExpression(procType, proc, block, exp->mLeft, destack, gotos, breakBlock, continueBlock, inlineMapper);
vl = ToValue(proc, exp, block, inlineMapper, vl); vl = ToValue(proc, exp, block, inlineMapper, vl);
vl = Dereference(proc, exp, block, inlineMapper, vl, 1); vl = Dereference(proc, exp, block, inlineMapper, vl, 1);
@ -3065,7 +3070,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
case EX_PREFIX: case EX_PREFIX:
{ {
vl = TranslateExpression(procType, proc, block, exp->mLeft, destack, breakBlock, continueBlock, inlineMapper); vl = TranslateExpression(procType, proc, block, exp->mLeft, destack, gotos, breakBlock, continueBlock, inlineMapper);
vl = ToValue(proc, exp, block, inlineMapper, vl); vl = ToValue(proc, exp, block, inlineMapper, vl);
InterInstruction * ins = new InterInstruction(MapLocation(exp, inlineMapper), IC_UNARY_OPERATOR); InterInstruction * ins = new InterInstruction(MapLocation(exp, inlineMapper), IC_UNARY_OPERATOR);
@ -3174,10 +3179,10 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
case EX_RELATIONAL: case EX_RELATIONAL:
{ {
vl = TranslateExpression(procType, proc, block, exp->mLeft, destack, breakBlock, continueBlock, inlineMapper); vl = TranslateExpression(procType, proc, block, exp->mLeft, destack, gotos, breakBlock, continueBlock, inlineMapper);
vl = ToValue(proc, exp, block, inlineMapper, vl); vl = ToValue(proc, exp, block, inlineMapper, vl);
vl = Dereference(proc, exp, block, inlineMapper, vl, vl.mType->mType == DT_TYPE_ARRAY ? 1 : 0); vl = Dereference(proc, exp, block, inlineMapper, vl, vl.mType->mType == DT_TYPE_ARRAY ? 1 : 0);
vr = TranslateExpression(procType, proc, block, exp->mRight, destack, breakBlock, continueBlock, inlineMapper); vr = TranslateExpression(procType, proc, block, exp->mRight, destack, gotos, breakBlock, continueBlock, inlineMapper);
vr = ToValue(proc, exp, block, inlineMapper, vr); vr = ToValue(proc, exp, block, inlineMapper, vr);
vr = Dereference(proc, exp, block, inlineMapper, vr, vr.mType->mType == DT_TYPE_ARRAY ? 1 : 0); vr = Dereference(proc, exp, block, inlineMapper, vr, vr.mType->mType == DT_TYPE_ARRAY ? 1 : 0);
@ -3293,7 +3298,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
if (!strcmp(iname->mString, "fabs")) if (!strcmp(iname->mString, "fabs"))
{ {
vr = TranslateExpression(procType, proc, block, exp->mRight, destack, breakBlock, continueBlock, inlineMapper); vr = TranslateExpression(procType, proc, block, exp->mRight, destack, gotos, breakBlock, continueBlock, inlineMapper);
vr = Dereference(proc, exp, block, inlineMapper, vr); vr = Dereference(proc, exp, block, inlineMapper, vr);
if (decf->mBase->mParams->CanAssign(vr.mType)) if (decf->mBase->mParams->CanAssign(vr.mType))
@ -3312,7 +3317,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
} }
else if (!strcmp(iname->mString, "floor")) else if (!strcmp(iname->mString, "floor"))
{ {
vr = TranslateExpression(procType, proc, block, exp->mRight, destack, breakBlock, continueBlock, inlineMapper); vr = TranslateExpression(procType, proc, block, exp->mRight, destack, gotos, breakBlock, continueBlock, inlineMapper);
vr = Dereference(proc, exp, block, inlineMapper, vr); vr = Dereference(proc, exp, block, inlineMapper, vr);
if (decf->mBase->mParams->CanAssign(vr.mType)) if (decf->mBase->mParams->CanAssign(vr.mType))
@ -3331,7 +3336,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
} }
else if (!strcmp(iname->mString, "ceil")) else if (!strcmp(iname->mString, "ceil"))
{ {
vr = TranslateExpression(procType, proc, block, exp->mRight, destack, breakBlock, continueBlock, inlineMapper); vr = TranslateExpression(procType, proc, block, exp->mRight, destack, gotos, breakBlock, continueBlock, inlineMapper);
vr = Dereference(proc, exp, block, inlineMapper, vr); vr = Dereference(proc, exp, block, inlineMapper, vr);
if (decf->mBase->mParams->CanAssign(vr.mType)) if (decf->mBase->mParams->CanAssign(vr.mType))
@ -3359,7 +3364,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
} }
else if (!strcmp(iname->mString, "malloc")) else if (!strcmp(iname->mString, "malloc"))
{ {
vr = TranslateExpression(procType, proc, block, exp->mRight, destack, breakBlock, continueBlock, inlineMapper); vr = TranslateExpression(procType, proc, block, exp->mRight, destack, gotos, breakBlock, continueBlock, inlineMapper);
vr = Dereference(proc, exp, block, inlineMapper, vr); vr = Dereference(proc, exp, block, inlineMapper, vr);
if (decf->mBase->mParams->CanAssign(vr.mType)) if (decf->mBase->mParams->CanAssign(vr.mType))
@ -3379,7 +3384,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
} }
else if (!strcmp(iname->mString, "free")) else if (!strcmp(iname->mString, "free"))
{ {
vr = TranslateExpression(procType, proc, block, exp->mRight, destack, breakBlock, continueBlock, inlineMapper); vr = TranslateExpression(procType, proc, block, exp->mRight, destack, gotos, breakBlock, continueBlock, inlineMapper);
vr = Dereference(proc, exp, block, inlineMapper, vr); vr = Dereference(proc, exp, block, inlineMapper, vr);
if (decf->mBase->mParams->CanAssign(vr.mType)) if (decf->mBase->mParams->CanAssign(vr.mType))
@ -3402,13 +3407,13 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
if ((tex->mDecType->mType == DT_TYPE_ARRAY && tex->mDecType->mSize <= 256) || if ((tex->mDecType->mType == DT_TYPE_ARRAY && tex->mDecType->mSize <= 256) ||
(sex->mDecType->mType == DT_TYPE_ARRAY && sex->mDecType->mSize <= 256)) (sex->mDecType->mType == DT_TYPE_ARRAY && sex->mDecType->mSize <= 256))
{ {
vl = TranslateExpression(procType, proc, block, tex, destack, breakBlock, continueBlock, inlineMapper); vl = TranslateExpression(procType, proc, block, tex, destack, gotos, breakBlock, continueBlock, inlineMapper);
if (vl.mType->mType == DT_TYPE_ARRAY) if (vl.mType->mType == DT_TYPE_ARRAY)
vl = Dereference(proc, exp, block, inlineMapper, vl, 1); vl = Dereference(proc, exp, block, inlineMapper, vl, 1);
else else
vl = Dereference(proc, exp, block, inlineMapper, vl); vl = Dereference(proc, exp, block, inlineMapper, vl);
vr = TranslateExpression(procType, proc, block, sex, destack, breakBlock, continueBlock, inlineMapper); vr = TranslateExpression(procType, proc, block, sex, destack, gotos, breakBlock, continueBlock, inlineMapper);
if (vr.mType->mType == DT_TYPE_ARRAY) if (vr.mType->mType == DT_TYPE_ARRAY)
vr = Dereference(proc, exp, block, inlineMapper, vr, 1); vr = Dereference(proc, exp, block, inlineMapper, vr, 1);
else else
@ -3441,13 +3446,13 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
Expression* tex = exp->mRight->mLeft, * sex = exp->mRight->mRight->mLeft, * nex = exp->mRight->mRight->mRight; Expression* tex = exp->mRight->mLeft, * sex = exp->mRight->mRight->mLeft, * nex = exp->mRight->mRight->mRight;
if (nex && nex->mType == EX_CONSTANT && nex->mDecValue->mType == DT_CONST_INTEGER && nex->mDecValue->mInteger < 512) if (nex && nex->mType == EX_CONSTANT && nex->mDecValue->mType == DT_CONST_INTEGER && nex->mDecValue->mInteger < 512)
{ {
vl = TranslateExpression(procType, proc, block, tex, destack, breakBlock, continueBlock, inlineMapper); vl = TranslateExpression(procType, proc, block, tex, destack, gotos, breakBlock, continueBlock, inlineMapper);
if (vl.mType->mType == DT_TYPE_ARRAY) if (vl.mType->mType == DT_TYPE_ARRAY)
vl = Dereference(proc, exp, block, inlineMapper, vl, 1); vl = Dereference(proc, exp, block, inlineMapper, vl, 1);
else else
vl = Dereference(proc, exp, block, inlineMapper, vl); vl = Dereference(proc, exp, block, inlineMapper, vl);
vr = TranslateExpression(procType, proc, block, sex, destack, breakBlock, continueBlock, inlineMapper); vr = TranslateExpression(procType, proc, block, sex, destack, gotos, breakBlock, continueBlock, inlineMapper);
if (vr.mType->mType == DT_TYPE_ARRAY) if (vr.mType->mType == DT_TYPE_ARRAY)
vr = Dereference(proc, exp, block, inlineMapper, vr, 1); vr = Dereference(proc, exp, block, inlineMapper, vr, 1);
else else
@ -3483,13 +3488,13 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
Expression* tex = exp->mRight->mLeft, * sex = exp->mRight->mRight->mLeft, * nex = exp->mRight->mRight->mRight; Expression* tex = exp->mRight->mLeft, * sex = exp->mRight->mRight->mLeft, * nex = exp->mRight->mRight->mRight;
if (nex && nex->mType == EX_CONSTANT && nex->mDecValue->mType == DT_CONST_INTEGER && nex->mDecValue->mInteger <= 1024) if (nex && nex->mType == EX_CONSTANT && nex->mDecValue->mType == DT_CONST_INTEGER && nex->mDecValue->mInteger <= 1024)
{ {
vl = TranslateExpression(procType, proc, block, tex, destack, breakBlock, continueBlock, inlineMapper); vl = TranslateExpression(procType, proc, block, tex, destack, gotos, breakBlock, continueBlock, inlineMapper);
if (vl.mType->mType == DT_TYPE_ARRAY) if (vl.mType->mType == DT_TYPE_ARRAY)
vl = Dereference(proc, exp, block, inlineMapper, vl, 1); vl = Dereference(proc, exp, block, inlineMapper, vl, 1);
else else
vl = Dereference(proc, exp, block, inlineMapper, vl); vl = Dereference(proc, exp, block, inlineMapper, vl);
vr = TranslateExpression(procType, proc, block, sex, destack, breakBlock, continueBlock, inlineMapper); vr = TranslateExpression(procType, proc, block, sex, destack, gotos, breakBlock, continueBlock, inlineMapper);
vr = Dereference(proc, exp, block, inlineMapper, vr); vr = Dereference(proc, exp, block, inlineMapper, vr);
if (!TheVoidPointerTypeDeclaration->CanAssign(vl.mType)) if (!TheVoidPointerTypeDeclaration->CanAssign(vl.mType))
@ -3521,7 +3526,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
Expression* tex = exp->mRight->mLeft, * nex = exp->mRight->mRight; Expression* tex = exp->mRight->mLeft, * nex = exp->mRight->mRight;
if (nex && nex->mType == EX_CONSTANT && nex->mDecValue->mType == DT_CONST_INTEGER && nex->mDecValue->mInteger <= 1024) if (nex && nex->mType == EX_CONSTANT && nex->mDecValue->mType == DT_CONST_INTEGER && nex->mDecValue->mInteger <= 1024)
{ {
vl = TranslateExpression(procType, proc, block, tex, destack, breakBlock, continueBlock, inlineMapper); vl = TranslateExpression(procType, proc, block, tex, destack, gotos, breakBlock, continueBlock, inlineMapper);
if (vl.mType->mType == DT_TYPE_ARRAY) if (vl.mType->mType == DT_TYPE_ARRAY)
vl = Dereference(proc, exp, block, inlineMapper, vl, 1); vl = Dereference(proc, exp, block, inlineMapper, vl, 1);
else else
@ -3615,7 +3620,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
{ {
Expression * funcexp = exp->mLeft; Expression * funcexp = exp->mLeft;
vl = TranslateExpression(procType, proc, block, funcexp, destack, breakBlock, continueBlock, inlineMapper); vl = TranslateExpression(procType, proc, block, funcexp, destack, gotos, breakBlock, continueBlock, inlineMapper);
vl = Dereference(proc, exp, block, inlineMapper, vl); vl = Dereference(proc, exp, block, inlineMapper, vl);
@ -3797,9 +3802,9 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
} }
if (ptype && (ptype->mType == DT_TYPE_STRUCT || ptype->mType == DT_TYPE_UNION)) if (ptype && (ptype->mType == DT_TYPE_STRUCT || ptype->mType == DT_TYPE_UNION))
vr = TranslateExpression(procType, proc, block, texp, destack, breakBlock, continueBlock, inlineMapper, &vp); vr = TranslateExpression(procType, proc, block, texp, destack, gotos, breakBlock, continueBlock, inlineMapper, &vp);
else else
vr = TranslateExpression(procType, proc, block, texp, destack, breakBlock, continueBlock, inlineMapper, nullptr); vr = TranslateExpression(procType, proc, block, texp, destack, gotos, breakBlock, continueBlock, inlineMapper, nullptr);
if (!(pdec && pdec->mBase->IsReference()) && (vr.mType->mType == DT_TYPE_STRUCT || vr.mType->mType == DT_TYPE_UNION)) if (!(pdec && pdec->mBase->IsReference()) && (vr.mType->mType == DT_TYPE_STRUCT || vr.mType->mType == DT_TYPE_UNION))
{ {
@ -4082,7 +4087,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
{ {
if (procType->mBase->IsReference()) if (procType->mBase->IsReference())
{ {
vr = TranslateExpression(procType, proc, block, exp->mLeft, destack, breakBlock, continueBlock, inlineMapper); vr = TranslateExpression(procType, proc, block, exp->mLeft, destack, gotos, breakBlock, continueBlock, inlineMapper);
if (vr.mType->IsReference()) if (vr.mType->IsReference())
{ {
@ -4206,7 +4211,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
ExValue rvr(procType->mBase, ains->mDst.mTemp, 1); ExValue rvr(procType->mBase, ains->mDst.mTemp, 1);
vr = TranslateExpression(procType, proc, block, exp->mLeft, destack, breakBlock, continueBlock, inlineMapper, &rvr); vr = TranslateExpression(procType, proc, block, exp->mLeft, destack, gotos, breakBlock, continueBlock, inlineMapper, &rvr);
vr = Dereference(proc, exp, block, inlineMapper, vr, 1); vr = Dereference(proc, exp, block, inlineMapper, vr, 1);
@ -4318,7 +4323,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
} }
else else
{ {
vr = TranslateExpression(procType, proc, block, exp->mLeft, destack, breakBlock, continueBlock, inlineMapper); vr = TranslateExpression(procType, proc, block, exp->mLeft, destack, gotos, breakBlock, continueBlock, inlineMapper);
if (procType->mBase->mType == DT_TYPE_POINTER && (vr.mType->mType == DT_TYPE_ARRAY || vr.mType->mType == DT_TYPE_FUNCTION)) if (procType->mBase->mType == DT_TYPE_POINTER && (vr.mType->mType == DT_TYPE_ARRAY || vr.mType->mType == DT_TYPE_FUNCTION))
{ {
@ -4461,7 +4466,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
InterCodeBasicBlock* tblock = new InterCodeBasicBlock(proc); InterCodeBasicBlock* tblock = new InterCodeBasicBlock(proc);
InterCodeBasicBlock* fblock = new InterCodeBasicBlock(proc); InterCodeBasicBlock* fblock = new InterCodeBasicBlock(proc);
TranslateLogic(procType, proc, block, tblock, fblock, exp->mLeft, destack, inlineMapper); TranslateLogic(procType, proc, block, tblock, fblock, exp->mLeft, destack, gotos, inlineMapper);
InterInstruction* ins = new InterInstruction(MapLocation(exp, inlineMapper), IC_UNREACHABLE); InterInstruction* ins = new InterInstruction(MapLocation(exp, inlineMapper), IC_UNREACHABLE);
ins->mNumOperands = 0; ins->mNumOperands = 0;
@ -4474,7 +4479,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
} }
case EX_LOGICAL_NOT: case EX_LOGICAL_NOT:
{ {
vl = TranslateExpression(procType, proc, block, exp->mLeft, destack, breakBlock, continueBlock, inlineMapper); vl = TranslateExpression(procType, proc, block, exp->mLeft, destack, gotos, breakBlock, continueBlock, inlineMapper);
vl = Dereference(proc, exp, block, inlineMapper, vl); vl = Dereference(proc, exp, block, inlineMapper, vl);
InterInstruction * zins = new InterInstruction(MapLocation(exp, inlineMapper), IC_CONSTANT); InterInstruction * zins = new InterInstruction(MapLocation(exp, inlineMapper), IC_CONSTANT);
@ -4502,10 +4507,10 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
#if 1 #if 1
if (!exp->mRight->mLeft->HasSideEffects() && !exp->mRight->mRight->HasSideEffects()) if (!exp->mRight->mLeft->HasSideEffects() && !exp->mRight->mRight->HasSideEffects())
{ {
ExValue vc = TranslateExpression(procType, proc, block, exp->mLeft, destack, breakBlock, continueBlock, inlineMapper); ExValue vc = TranslateExpression(procType, proc, block, exp->mLeft, destack, gotos, breakBlock, continueBlock, inlineMapper);
vl = TranslateExpression(procType, proc, block, exp->mRight->mLeft, destack, breakBlock, continueBlock, inlineMapper); vl = TranslateExpression(procType, proc, block, exp->mRight->mLeft, destack, gotos, breakBlock, continueBlock, inlineMapper);
vr = TranslateExpression(procType, proc, block, exp->mRight->mRight, destack, breakBlock, continueBlock, inlineMapper); vr = TranslateExpression(procType, proc, block, exp->mRight->mRight, destack, gotos, breakBlock, continueBlock, inlineMapper);
vc = Dereference(proc, exp, block, inlineMapper, vc); vc = Dereference(proc, exp, block, inlineMapper, vc);
@ -4615,10 +4620,10 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
InterCodeBasicBlock* fblock = new InterCodeBasicBlock(proc); InterCodeBasicBlock* fblock = new InterCodeBasicBlock(proc);
InterCodeBasicBlock* eblock = new InterCodeBasicBlock(proc); InterCodeBasicBlock* eblock = new InterCodeBasicBlock(proc);
TranslateLogic(procType, proc, block, tblock, fblock, exp->mLeft, destack, inlineMapper); TranslateLogic(procType, proc, block, tblock, fblock, exp->mLeft, destack, gotos, inlineMapper);
vl = TranslateExpression(procType, proc, tblock, exp->mRight->mLeft, destack, breakBlock, continueBlock, inlineMapper); vl = TranslateExpression(procType, proc, tblock, exp->mRight->mLeft, destack, gotos, breakBlock, continueBlock, inlineMapper);
vr = TranslateExpression(procType, proc, fblock, exp->mRight->mRight, destack, breakBlock, continueBlock, inlineMapper); vr = TranslateExpression(procType, proc, fblock, exp->mRight->mRight, destack, gotos, breakBlock, continueBlock, inlineMapper);
int ttemp; int ttemp;
InterType ttype, stypel, styper; InterType ttype, stypel, styper;
@ -4713,7 +4718,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
case EX_TYPECAST: case EX_TYPECAST:
{ {
vr = TranslateExpression(procType, proc, block, exp->mLeft, destack, breakBlock, continueBlock, inlineMapper); vr = TranslateExpression(procType, proc, block, exp->mLeft, destack, gotos, breakBlock, continueBlock, inlineMapper);
InterInstruction * ins = new InterInstruction(MapLocation(exp, inlineMapper), IC_CONVERSION_OPERATOR); InterInstruction * ins = new InterInstruction(MapLocation(exp, inlineMapper), IC_CONVERSION_OPERATOR);
@ -4836,7 +4841,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
InterCodeBasicBlock* fblock = new InterCodeBasicBlock(proc); InterCodeBasicBlock* fblock = new InterCodeBasicBlock(proc);
InterCodeBasicBlock* eblock = new InterCodeBasicBlock(proc); InterCodeBasicBlock* eblock = new InterCodeBasicBlock(proc);
TranslateLogic(procType, proc, block, tblock, fblock, exp, destack, inlineMapper); TranslateLogic(procType, proc, block, tblock, fblock, exp, destack, gotos, inlineMapper);
int ttemp = proc->AddTemporary(IT_BOOL); int ttemp = proc->AddTemporary(IT_BOOL);
@ -4870,7 +4875,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
{ {
DestructStack* odestack = destack; DestructStack* odestack = destack;
TranslateExpression(procType, proc, block, exp->mLeft, destack, breakBlock, continueBlock, inlineMapper); TranslateExpression(procType, proc, block, exp->mLeft, destack, gotos, breakBlock, continueBlock, inlineMapper);
UnwindDestructStack(procType, proc, block, destack, odestack, inlineMapper); UnwindDestructStack(procType, proc, block, destack, odestack, inlineMapper);
destack = odestack; destack = odestack;
@ -4881,7 +4886,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
case EX_DISPATCH: case EX_DISPATCH:
{ {
vl = TranslateExpression(procType, proc, block, exp->mLeft, destack, breakBlock, continueBlock, inlineMapper); vl = TranslateExpression(procType, proc, block, exp->mLeft, destack, gotos, breakBlock, continueBlock, inlineMapper);
vl = Dereference(proc, exp, block, inlineMapper, vl); vl = Dereference(proc, exp, block, inlineMapper, vl);
InterInstruction* ins = new InterInstruction(MapLocation(exp, inlineMapper), IC_DISPATCH); InterInstruction* ins = new InterInstruction(MapLocation(exp, inlineMapper), IC_DISPATCH);
@ -4919,11 +4924,11 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
block->Append(jins0); block->Append(jins0);
block->Close(cblock, nullptr); block->Close(cblock, nullptr);
TranslateLogic(procType, proc, cblock, bblock, eblock, exp->mLeft, destack, inlineMapper); TranslateLogic(procType, proc, cblock, bblock, eblock, exp->mLeft, destack, gotos, inlineMapper);
DestructStack* idestack = destack; DestructStack* idestack = destack;
vr = TranslateExpression(procType, proc, bblock, exp->mRight, destack, BranchTarget(eblock, odestack), BranchTarget(lblock, idestack), inlineMapper); vr = TranslateExpression(procType, proc, bblock, exp->mRight, destack, gotos, BranchTarget(eblock, odestack), BranchTarget(lblock, idestack), inlineMapper);
UnwindDestructStack(procType, proc, bblock, destack, idestack, inlineMapper); UnwindDestructStack(procType, proc, bblock, destack, idestack, inlineMapper);
destack = idestack; destack = idestack;
@ -4950,10 +4955,10 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
InterCodeBasicBlock* fblock = new InterCodeBasicBlock(proc); InterCodeBasicBlock* fblock = new InterCodeBasicBlock(proc);
InterCodeBasicBlock* eblock = new InterCodeBasicBlock(proc); InterCodeBasicBlock* eblock = new InterCodeBasicBlock(proc);
TranslateLogic(procType, proc, block, tblock, fblock, exp->mLeft, destack, inlineMapper); TranslateLogic(procType, proc, block, tblock, fblock, exp->mLeft, destack, gotos, inlineMapper);
DestructStack* itdestack = destack; DestructStack* itdestack = destack;
vr = TranslateExpression(procType, proc, tblock, exp->mRight->mLeft, destack, breakBlock, continueBlock, inlineMapper); vr = TranslateExpression(procType, proc, tblock, exp->mRight->mLeft, destack, gotos, breakBlock, continueBlock, inlineMapper);
UnwindDestructStack(procType, proc, tblock, destack, itdestack, inlineMapper); UnwindDestructStack(procType, proc, tblock, destack, itdestack, inlineMapper);
destack = itdestack; destack = itdestack;
@ -4963,7 +4968,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
if (exp->mRight->mRight) if (exp->mRight->mRight)
{ {
DestructStack* ifdestack = destack; DestructStack* ifdestack = destack;
vr = TranslateExpression(procType, proc, fblock, exp->mRight->mRight, destack, breakBlock, continueBlock, inlineMapper); vr = TranslateExpression(procType, proc, fblock, exp->mRight->mRight, destack, gotos, breakBlock, continueBlock, inlineMapper);
UnwindDestructStack(procType, proc, fblock, destack, ifdestack, inlineMapper); UnwindDestructStack(procType, proc, fblock, destack, ifdestack, inlineMapper);
destack = ifdestack; destack = ifdestack;
} }
@ -4984,7 +4989,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
// assignment // assignment
if (exp->mLeft->mRight) if (exp->mLeft->mRight)
TranslateExpression(procType, proc, block, exp->mLeft->mRight, destack, breakBlock, continueBlock, inlineMapper); TranslateExpression(procType, proc, block, exp->mLeft->mRight, destack, gotos, breakBlock, continueBlock, inlineMapper);
InterInstruction* jins0 = new InterInstruction(MapLocation(exp, inlineMapper), IC_JUMP); InterInstruction* jins0 = new InterInstruction(MapLocation(exp, inlineMapper), IC_JUMP);
InterInstruction* jins1 = new InterInstruction(MapLocation(exp, inlineMapper), IC_JUMP); InterInstruction* jins1 = new InterInstruction(MapLocation(exp, inlineMapper), IC_JUMP);
@ -5002,7 +5007,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
// condition // condition
if (exp->mLeft->mLeft->mLeft) if (exp->mLeft->mLeft->mLeft)
TranslateLogic(procType, proc, cblock, bblock, eblock, exp->mLeft->mLeft->mLeft, destack, inlineMapper); TranslateLogic(procType, proc, cblock, bblock, eblock, exp->mLeft->mLeft->mLeft, destack, gotos, inlineMapper);
else else
{ {
cblock->Append(jins1); cblock->Append(jins1);
@ -5013,7 +5018,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
DestructStack* idestack = destack; DestructStack* idestack = destack;
vr = TranslateExpression(procType, proc, bblock, exp->mRight, destack, BranchTarget(eblock, odestack), BranchTarget(iblock, idestack), inlineMapper); vr = TranslateExpression(procType, proc, bblock, exp->mRight, destack, gotos, BranchTarget(eblock, odestack), BranchTarget(iblock, idestack), inlineMapper);
UnwindDestructStack(procType, proc, bblock, destack, idestack, inlineMapper); UnwindDestructStack(procType, proc, bblock, destack, idestack, inlineMapper);
destack = idestack; destack = idestack;
@ -5023,7 +5028,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
// increment // increment
if (exp->mLeft->mLeft->mRight) if (exp->mLeft->mLeft->mRight)
TranslateExpression(procType, proc, iblock, exp->mLeft->mLeft->mRight, destack, breakBlock, continueBlock, inlineMapper); TranslateExpression(procType, proc, iblock, exp->mLeft->mLeft->mRight, destack, gotos, breakBlock, continueBlock, inlineMapper);
iblock->Append(jins3); iblock->Append(jins3);
iblock->Close(lblock, nullptr); iblock->Close(lblock, nullptr);
@ -5051,12 +5056,12 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
DestructStack* idestack = destack; DestructStack* idestack = destack;
vr = TranslateExpression(procType, proc, cblock, exp->mRight, destack, BranchTarget(eblock, odestack), BranchTarget(cblock, idestack), inlineMapper); vr = TranslateExpression(procType, proc, cblock, exp->mRight, destack, gotos, BranchTarget(eblock, odestack), BranchTarget(cblock, idestack), inlineMapper);
UnwindDestructStack(procType, proc, cblock, destack, idestack, inlineMapper); UnwindDestructStack(procType, proc, cblock, destack, idestack, inlineMapper);
destack = idestack; destack = idestack;
TranslateLogic(procType, proc, cblock, lblock, eblock, exp->mLeft, destack, inlineMapper); TranslateLogic(procType, proc, cblock, lblock, eblock, exp->mLeft, destack, gotos, inlineMapper);
block = eblock; block = eblock;
@ -5066,11 +5071,41 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
return ExValue(TheVoidTypeDeclaration); return ExValue(TheVoidTypeDeclaration);
} }
case EX_LABEL:
{
GotoNode* g = new GotoNode();
g->mNext = gotos;
g->mExpr = exp;
g->mBlock = new InterCodeBasicBlock(proc);
g->mDestruct = destack;
InterInstruction* jins = new InterInstruction(MapLocation(exp, inlineMapper), IC_JUMP);
block->Append(jins);
block->Close(g->mBlock, nullptr);
block = g->mBlock;
gotos = g;
return ExValue(TheVoidTypeDeclaration);
}
case EX_GOTO:
{
GotoNode* g = new GotoNode();
g->mNext = gotos;
g->mExpr = exp;
g->mBlock = block;
g->mDestruct = destack;
InterInstruction* jins = new InterInstruction(MapLocation(exp, inlineMapper), IC_JUMP);
block->Append(jins);
block = new InterCodeBasicBlock(proc);
gotos = g;
return ExValue(TheVoidTypeDeclaration);
}
case EX_SWITCH: case EX_SWITCH:
{ {
DestructStack* odestack = destack; DestructStack* odestack = destack;
vl = TranslateExpression(procType, proc, block, exp->mLeft, destack, breakBlock, continueBlock, inlineMapper); vl = TranslateExpression(procType, proc, block, exp->mLeft, destack, gotos, breakBlock, continueBlock, inlineMapper);
vl = Dereference(proc, exp, block, inlineMapper, vl); vl = Dereference(proc, exp, block, inlineMapper, vl);
int vleft = 0, vright = 65535; int vleft = 0, vright = 65535;
@ -5178,7 +5213,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
} }
if (cexp->mRight) if (cexp->mRight)
TranslateExpression(procType, proc, block, cexp->mRight, destack, BranchTarget(eblock, odestack), continueBlock, inlineMapper); TranslateExpression(procType, proc, block, cexp->mRight, destack, gotos, BranchTarget(eblock, odestack), continueBlock, inlineMapper);
sexp = sexp->mRight; sexp = sexp->mRight;
} }
@ -5386,30 +5421,30 @@ void InterCodeGenerator::BuildInitializer(InterCodeModule * mod, uint8* dp, int
} }
} }
void InterCodeGenerator::TranslateLogic(Declaration* procType, InterCodeProcedure* proc, InterCodeBasicBlock* block, InterCodeBasicBlock* tblock, InterCodeBasicBlock* fblock, Expression* exp, DestructStack*& destack, InlineMapper* inlineMapper) void InterCodeGenerator::TranslateLogic(Declaration* procType, InterCodeProcedure* proc, InterCodeBasicBlock* block, InterCodeBasicBlock* tblock, InterCodeBasicBlock* fblock, Expression* exp, DestructStack*& destack, GotoNode*& gotos, InlineMapper* inlineMapper)
{ {
switch (exp->mType) switch (exp->mType)
{ {
case EX_LOGICAL_NOT: case EX_LOGICAL_NOT:
TranslateLogic(procType, proc, block, fblock, tblock, exp->mLeft, destack, inlineMapper); TranslateLogic(procType, proc, block, fblock, tblock, exp->mLeft, destack, gotos, inlineMapper);
break; break;
case EX_LOGICAL_AND: case EX_LOGICAL_AND:
{ {
InterCodeBasicBlock* ablock = new InterCodeBasicBlock(proc); InterCodeBasicBlock* ablock = new InterCodeBasicBlock(proc);
TranslateLogic(procType, proc, block, ablock, fblock, exp->mLeft, destack, inlineMapper); TranslateLogic(procType, proc, block, ablock, fblock, exp->mLeft, destack, gotos, inlineMapper);
TranslateLogic(procType, proc, ablock, tblock, fblock, exp->mRight, destack, inlineMapper); TranslateLogic(procType, proc, ablock, tblock, fblock, exp->mRight, destack, gotos, inlineMapper);
break; break;
} }
case EX_LOGICAL_OR: case EX_LOGICAL_OR:
{ {
InterCodeBasicBlock* oblock = new InterCodeBasicBlock(proc); InterCodeBasicBlock* oblock = new InterCodeBasicBlock(proc);
TranslateLogic(procType, proc, block, tblock, oblock, exp->mLeft, destack, inlineMapper); TranslateLogic(procType, proc, block, tblock, oblock, exp->mLeft, destack, gotos, inlineMapper);
TranslateLogic(procType, proc, oblock, tblock, fblock, exp->mRight, destack, inlineMapper); TranslateLogic(procType, proc, oblock, tblock, fblock, exp->mRight, destack, gotos, inlineMapper);
break; break;
} }
default: default:
{ {
ExValue vr = TranslateExpression(procType, proc, block, exp, destack, BranchTarget(), BranchTarget(), inlineMapper); ExValue vr = TranslateExpression(procType, proc, block, exp, destack, gotos, BranchTarget(), BranchTarget(), inlineMapper);
if (vr.mType->mType == DT_TYPE_ARRAY) if (vr.mType->mType == DT_TYPE_ARRAY)
vr = Dereference(proc, exp, block, inlineMapper, vr, 1); vr = Dereference(proc, exp, block, inlineMapper, vr, 1);
@ -5431,13 +5466,31 @@ void InterCodeGenerator::TranslateLogic(Declaration* procType, InterCodeProcedur
} }
} }
static InterCodeGenerator::DestructStack* FindBase(InterCodeGenerator::DestructStack* sfrom, InterCodeGenerator::DestructStack* sto)
{
while (sfrom)
{
InterCodeGenerator::DestructStack* s = sto;
while (s)
{
if (s == sfrom)
return s;
s = s->mNext;
}
sfrom = sfrom->mNext;
}
return sfrom;
}
InterCodeProcedure* InterCodeGenerator::TranslateProcedure(InterCodeModule * mod, Expression* exp, Declaration * dec) InterCodeProcedure* InterCodeGenerator::TranslateProcedure(InterCodeModule * mod, Expression* exp, Declaration * dec)
{ {
InterCodeProcedure* proc = new InterCodeProcedure(mod, dec->mLocation, dec->mQualIdent, mLinker->AddObject(dec->mLocation, dec->mQualIdent, dec->mSection, LOT_BYTE_CODE, dec->mAlignment)); InterCodeProcedure* proc = new InterCodeProcedure(mod, dec->mLocation, dec->mQualIdent, mLinker->AddObject(dec->mLocation, dec->mQualIdent, dec->mSection, LOT_BYTE_CODE, dec->mAlignment));
proc->mLinkerObject->mFullIdent = dec->FullIdent(); proc->mLinkerObject->mFullIdent = dec->FullIdent();
#if 0 #if 0
if (proc->mIdent && !strcmp(proc->mIdent->mString, "zombies_splash")) if (proc->mIdent && !strcmp(proc->mIdent->mString, "main"))
exp->Dump(0); exp->Dump(0);
#endif #endif
#if 0 #if 0
@ -5587,8 +5640,44 @@ InterCodeProcedure* InterCodeGenerator::TranslateProcedure(InterCodeModule * mod
#endif #endif
DestructStack* destack = nullptr; DestructStack* destack = nullptr;
GotoNode* gotos = nullptr;
TranslateExpression(dec->mBase, proc, exitBlock, exp, destack, BranchTarget(), BranchTarget(), nullptr); TranslateExpression(dec->mBase, proc, exitBlock, exp, destack, gotos, BranchTarget(), BranchTarget(), nullptr);
GotoNode* gl = gotos;
while (gl)
{
GotoNode* g = gotos;
while (g && !(g != gl && g->mExpr->mType == EX_LABEL && g->mExpr->mDecValue->mIdent == gl->mExpr->mDecValue->mIdent))
g = g->mNext;
if (gl->mExpr->mType == EX_LABEL)
{
if (g)
mErrors->Error(gl->mExpr->mLocation, EERR_DUPLICATE_DEFINITION, "Label defined twice", gl->mExpr->mDecValue->mIdent);
}
else
{
if (g)
{
if (gl->mDestruct)
{
DestructStack* s = gl->mDestruct;
while (s && s != g->mDestruct)
s = s->mNext;
if (s == g->mDestruct)
UnwindDestructStack(dec->mBase, proc, gl->mBlock, gl->mDestruct, s, nullptr);
else
mErrors->Error(gl->mExpr->mLocation, ERRR_INVALID_GOTO, "Invalid got bypass constructor");
}
gl->mBlock->Close(g->mBlock, nullptr);
}
else
mErrors->Error(gl->mExpr->mLocation, EERR_UNDEFINED_OBJECT, "Undefined label", gl->mExpr->mDecValue->mIdent);
}
gl = gl->mNext;
}
UnwindDestructStack(dec->mBase, proc, exitBlock, destack, nullptr, nullptr); UnwindDestructStack(dec->mBase, proc, exitBlock, destack, nullptr, nullptr);

View File

@ -76,6 +76,14 @@ protected:
typedef GrowingArray<SwitchNode> SwitchNodeArray; typedef GrowingArray<SwitchNode> SwitchNodeArray;
struct GotoNode
{
GotoNode * mNext;
InterCodeBasicBlock * mBlock;
Expression * mExpr;
DestructStack * mDestruct;
};
InterCodeProcedure* mMainInitProc; InterCodeProcedure* mMainInitProc;
InterCodeBasicBlock* mMainInitBlock; InterCodeBasicBlock* mMainInitBlock;
@ -86,8 +94,8 @@ protected:
ExValue ToValue(InterCodeProcedure* proc, Expression* exp, InterCodeBasicBlock*& block, InlineMapper* inlineMapper, ExValue v); ExValue ToValue(InterCodeProcedure* proc, Expression* exp, InterCodeBasicBlock*& block, InlineMapper* inlineMapper, ExValue v);
ExValue Dereference(InterCodeProcedure* proc, Expression* exp, InterCodeBasicBlock*& block, InlineMapper* inlineMapper, ExValue v, int level = 0); ExValue Dereference(InterCodeProcedure* proc, Expression* exp, InterCodeBasicBlock*& block, InlineMapper* inlineMapper, ExValue v, int level = 0);
ExValue CoerceType(InterCodeProcedure* proc, Expression* exp, InterCodeBasicBlock*& block, InlineMapper* inlineMapper, ExValue v, Declaration * type, bool checkTrunc = true); ExValue CoerceType(InterCodeProcedure* proc, Expression* exp, InterCodeBasicBlock*& block, InlineMapper* inlineMapper, ExValue v, Declaration * type, bool checkTrunc = true);
ExValue TranslateExpression(Declaration * procType, InterCodeProcedure * proc, InterCodeBasicBlock*& block, Expression* exp, DestructStack*& destack, const BranchTarget & breakBlock, const BranchTarget& continueBlock, InlineMapper * inlineMapper, ExValue * lrexp = nullptr); ExValue TranslateExpression(Declaration * procType, InterCodeProcedure * proc, InterCodeBasicBlock*& block, Expression* exp, DestructStack*& destack, GotoNode*& gotos, const BranchTarget & breakBlock, const BranchTarget& continueBlock, InlineMapper * inlineMapper, ExValue * lrexp = nullptr);
void TranslateLogic(Declaration* procType, InterCodeProcedure* proc, InterCodeBasicBlock* block, InterCodeBasicBlock* tblock, InterCodeBasicBlock* fblock, Expression* exp, DestructStack*& destack, InlineMapper* inlineMapper); void TranslateLogic(Declaration* procType, InterCodeProcedure* proc, InterCodeBasicBlock* block, InterCodeBasicBlock* tblock, InterCodeBasicBlock* fblock, Expression* exp, DestructStack*& destack, GotoNode*& gotos, InlineMapper* inlineMapper);
ExValue TranslateInline(Declaration* procType, InterCodeProcedure* proc, InterCodeBasicBlock*& block, Expression* exp, const BranchTarget& breakBlock, const BranchTarget& continueBlock, InlineMapper* inlineMapper, bool inlineConstexpr, ExValue* lrexp); ExValue TranslateInline(Declaration* procType, InterCodeProcedure* proc, InterCodeBasicBlock*& block, Expression* exp, const BranchTarget& breakBlock, const BranchTarget& continueBlock, InlineMapper* inlineMapper, bool inlineConstexpr, ExValue* lrexp);
void CopyStruct(InterCodeProcedure* proc, Expression* exp, InterCodeBasicBlock*& block, ExValue vl, ExValue vr, InlineMapper* inlineMapper, bool moving); void CopyStruct(InterCodeProcedure* proc, Expression* exp, InterCodeBasicBlock*& block, ExValue vl, ExValue vr, InlineMapper* inlineMapper, bool moving);
void CopyStructSimple(InterCodeProcedure* proc, Expression* exp, InterCodeBasicBlock * block, InlineMapper* inlineMapper, ExValue vl, ExValue vr); void CopyStructSimple(InterCodeProcedure* proc, Expression* exp, InterCodeBasicBlock * block, InlineMapper* inlineMapper, ExValue vl, ExValue vr);

View File

@ -48363,6 +48363,15 @@ void NativeCodeBasicBlock::BuildPlacement(ExpandingArray<NativeCodeBasicBlock*>&
placement.Push(mTrueJump->mTrueJump); placement.Push(mTrueJump->mTrueJump);
} }
} }
if (mTrueJump->mEntryBlocks.Size() == 2 && this == mTrueJump->mEntryBlocks[0] && !mTrueJump->mEntryBlocks[1]->mFalseJump)
{
if (!mTrueJump->mEntryBlocks[1]->mPlaced && mTrueJump->mEntryBlocks[1]->mCode.Size() + mTrueJump->mCode.Size() < 40)
{
mTrueJump->mEntryBlocks[1]->mPlaced = true;
mTrueJump->mEntryBlocks[1]->mPlace = placement.Size();
placement.Push(mTrueJump->mEntryBlocks[1]);
}
}
} }
mTrueJump->BuildPlacement(placement); mTrueJump->BuildPlacement(placement);

View File

@ -5031,8 +5031,16 @@ Declaration* Parser::ParseQualIdent(void)
} }
else else
{ {
mErrors->Error(mScanner->mLocation, EERR_OBJECT_NOT_FOUND, "Unknown identifier", mScanner->mTokenIdent); const Ident* ident = mScanner->mTokenIdent;
Location loc = mScanner->mLocation;
mScanner->NextToken(); mScanner->NextToken();
if (ConsumeTokenIf(TK_COLON))
{
dec = new Declaration(loc, DT_CLABEL);
dec->mIdent = ident;
}
else
mErrors->Error(loc, EERR_OBJECT_NOT_FOUND, "Unknown identifier", ident);
} }
return dec; return dec;
@ -5734,6 +5742,11 @@ Expression* Parser::ParseSimpleExpression(bool lhs, bool tid)
{ {
mErrors->Error(mScanner->mLocation, EERR_NON_STATIC_MEMBER, "Non static member access", mScanner->mTokenIdent); mErrors->Error(mScanner->mLocation, EERR_NON_STATIC_MEMBER, "Non static member access", mScanner->mTokenIdent);
} }
else if (dec->mType == DT_CLABEL)
{
exp = new Expression(dec->mLocation, EX_LABEL);
exp->mDecValue = dec;
}
else else
{ {
mErrors->Error(mScanner->mLocation, EERR_INVALID_IDENTIFIER, "Invalid identifier", mScanner->mTokenIdent); mErrors->Error(mScanner->mLocation, EERR_INVALID_IDENTIFIER, "Invalid identifier", mScanner->mTokenIdent);
@ -9321,14 +9334,30 @@ Expression* Parser::ParseStatement(void)
ConsumeToken(TK_SEMICOLON); ConsumeToken(TK_SEMICOLON);
break; break;
case TK_GOTO: case TK_GOTO:
#if 1
exp = new Expression(mScanner->mLocation, EX_GOTO);
mScanner->NextToken();
if (mScanner->mToken == TK_IDENT)
{
Declaration* dl = new Declaration(mScanner->mLocation, DT_CLABEL);
dl->mIdent = mScanner->mTokenIdent;
exp->mDecValue = dl;
mScanner->NextToken();
}
else
mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "Identifier expected");
#else
mErrors->Error(mScanner->mLocation, EERR_UNIMPLEMENTED, "'goto' not implemented"); mErrors->Error(mScanner->mLocation, EERR_UNIMPLEMENTED, "'goto' not implemented");
mScanner->NextToken(); mScanner->NextToken();
exp = new Expression(mScanner->mLocation, EX_VOID); exp = new Expression(mScanner->mLocation, EX_VOID);
#endif
break; break;
default: default:
exp = CleanupExpression(ParseListExpression(true)); exp = CleanupExpression(ParseListExpression(true));
if (exp->mType != EX_LABEL)
ConsumeToken(TK_SEMICOLON); ConsumeToken(TK_SEMICOLON);
break;
} }
} }