diff --git a/oscar64.md b/oscar64.md index cfe5acb..357f092 100644 --- a/oscar64.md +++ b/oscar64.md @@ -139,6 +139,7 @@ The compiler is command line driven, and creates an executable .prg file. * -xz : extended zero page usage, more zero page space, but no return to basic * -cid : cartridge type ID, used by vice emulator * -pp : compile in C++ mode +* -strict : use strict ANSI C parsing (no C++ goodies) * -psci : use PETSCII encoding for all strings without prefix * -rmp : generate error files .error.map, .error.asm when linker fails diff --git a/oscar64/CompilerTypes.h b/oscar64/CompilerTypes.h index 4d93c9b..64187b5 100644 --- a/oscar64/CompilerTypes.h +++ b/oscar64/CompilerTypes.h @@ -42,6 +42,7 @@ static const uint64 COPT_PETSCII = 1ULL << 53; static const uint64 COPT_ERROR_FILES = 1ULL << 54; static const uint64 COPT_PROFILEINFO = 1ULL << 55; +static const uint64 COPT_STRICT = 1ULL << 56; diff --git a/oscar64/Parser.cpp b/oscar64/Parser.cpp index 03c85e3..b88a7ec 100644 --- a/oscar64/Parser.cpp +++ b/oscar64/Parser.cpp @@ -1447,7 +1447,7 @@ Declaration * Parser::ParseFunctionDeclaration(Declaration* bdec) adec->mSize = adec->mBase->mSize; - if ((mCompilerOptions & COPT_CPLUSPLUS) && ConsumeTokenIf(TK_ASSIGN)) + if (((mCompilerOptions & COPT_CPLUSPLUS) || !(mCompilerOptions & COPT_STRICT)) && ConsumeTokenIf(TK_ASSIGN)) { adec->mValue = ParseExpression(false); } diff --git a/oscar64/oscar64.cpp b/oscar64/oscar64.cpp index c2e8d03..307323d 100644 --- a/oscar64/oscar64.cpp +++ b/oscar64/oscar64.cpp @@ -321,7 +321,13 @@ int main2(int argc, const char** argv) { compiler->mCompilerOptions |= COPT_CPLUSPLUS; compiler->AddDefine(Ident::Unique("__cplusplus"), "1"); + compiler->AddDefine(Ident::Unique("__cplusplus__"), "1"); } + else if (arg[1] == 's' && arg[2] == 't' && arg[3] == 'r' && arg[4] == 'i' && arg[5] == 'c' && arg[6] == 't' && !arg[7]) + { + compiler->mCompilerOptions |= COPT_STRICT; + compiler->AddDefine(Ident::Unique("__strict__"), "1"); + } else if (arg[1] == 'r' && arg[2] == 'm' && arg[3] == 'p' && !arg[4]) { compiler->mCompilerOptions |= COPT_ERROR_FILES; @@ -339,6 +345,7 @@ int main2(int argc, const char** argv) { compiler->mCompilerOptions |= COPT_CPLUSPLUS; compiler->AddDefine(Ident::Unique("__cplusplus"), "1"); + compiler->AddDefine(Ident::Unique("__cplusplus__"), "1"); } compiler->mCompilationUnits->AddUnit(loc, argv[i], nullptr);