From 72687b7581fd52f13189093242cc73f5659e6dac Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Sat, 10 Jun 2023 15:17:57 +0200 Subject: [PATCH] Add compound literals --- oscar64/Parser.cpp | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/oscar64/Parser.cpp b/oscar64/Parser.cpp index 3ee9031..b6fe314 100644 --- a/oscar64/Parser.cpp +++ b/oscar64/Parser.cpp @@ -1601,11 +1601,30 @@ Expression* Parser::ParseSimpleExpression(void) if (exp->mType == EX_TYPE) { - Expression* nexp = new Expression(mScanner->mLocation, EX_TYPECAST); - nexp->mDecType = exp->mDecType; - nexp->mLeft = exp; - nexp->mRight = ParsePrefixExpression(); - exp = nexp->ConstantFold(mErrors); + if (mScanner->mToken == TK_OPEN_BRACE) + { + Declaration* vdec = new Declaration(mScanner->mLocation, DT_VARIABLE); + vdec->mBase = exp->mDecType; + vdec->mFlags |= DTF_CONST | DTF_STATIC | DTF_GLOBAL; + + Expression* nexp = new Expression(mScanner->mLocation, EX_VARIABLE); + nexp->mDecValue = vdec; + nexp->mDecType = vdec->mBase; + + vdec->mValue = ParseInitExpression(vdec->mBase); + vdec->mSection = mDataSection; + vdec->mSize = vdec->mBase->mSize; + + exp = nexp; + } + else + { + Expression* nexp = new Expression(mScanner->mLocation, EX_TYPECAST); + nexp->mDecType = exp->mDecType; + nexp->mLeft = exp; + nexp->mRight = ParsePrefixExpression(); + exp = nexp->ConstantFold(mErrors); + } } break; case TK_ASM: