Add "-strict" command line option, to loosen C syntax and allow default arguments when not set

This commit is contained in:
drmortalwombat 2024-12-03 09:03:43 +01:00
parent cfe2c7bed5
commit fac53cfd54
4 changed files with 10 additions and 1 deletions

View File

@ -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

View File

@ -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;

View File

@ -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);
}

View File

@ -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);