From a71c433fc49d64b360ff8852f543e036b9489605 Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Mon, 24 Jun 2024 18:14:07 +0200 Subject: [PATCH] Add -D for gcc compliant defines --- README.md | 2 ++ oscar64/Parser.cpp | 5 +++++ oscar64/Scanner.cpp | 3 +++ oscar64/Scanner.h | 1 + oscar64/oscar64.cpp | 25 ++++++++++++++++++++++++- 5 files changed, 35 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index da1c2ae..6445183 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ There are still several open areas, but most targets have been reached. The cur ### Language * Missing warnings for all kind of abuses +* no goto or C label support, but keyword protected ### Linker @@ -104,6 +105,7 @@ The compiler is command line driven, and creates an executable .prg file. * -bc : create byte code for all functions * -n : create pure native code for all functions (now default) * -d : define a symbol (e.g. NOFLOAT or NOLONG to avoid float/long code in printf) +* -D : define a symbol in a gcc compliant way (e.g. -D NAME=VALUE) * -O1 or -O : default optimizations * -O0 : disable optimizations * -O2 : more aggressive speed optimizations including auto inline of small functions diff --git a/oscar64/Parser.cpp b/oscar64/Parser.cpp index dbd6151..d78eccc 100644 --- a/oscar64/Parser.cpp +++ b/oscar64/Parser.cpp @@ -9320,6 +9320,11 @@ Expression* Parser::ParseStatement(void) exp->mLeft = ParseParenthesisExpression(); ConsumeToken(TK_SEMICOLON); break; + case TK_GOTO: + mErrors->Error(mScanner->mLocation, EERR_UNIMPLEMENTED, "'goto' not implemented"); + mScanner->NextToken(); + exp = new Expression(mScanner->mLocation, EX_VOID); + break; default: exp = CleanupExpression(ParseListExpression(true)); diff --git a/oscar64/Scanner.cpp b/oscar64/Scanner.cpp index 0b5dca2..06294c2 100644 --- a/oscar64/Scanner.cpp +++ b/oscar64/Scanner.cpp @@ -29,6 +29,7 @@ const char* TokenNames[] = "'default'", "'break'", "'return'", + "'goto'", "'short'", "'long'", "'continue'", @@ -1702,6 +1703,8 @@ void Scanner::NextRawToken(void) mToken = TK_CONTINUE; else if (!strcmp(tkident, "return")) mToken = TK_RETURN; + else if (!strcmp(tkident, "goto")) + mToken = TK_GOTO; else if (!strcmp(tkident, "void")) mToken = TK_VOID; else if (!strcmp(tkident, "struct")) diff --git a/oscar64/Scanner.h b/oscar64/Scanner.h index 5967e92..a7654e0 100644 --- a/oscar64/Scanner.h +++ b/oscar64/Scanner.h @@ -27,6 +27,7 @@ enum Token TK_DEFAULT, TK_BREAK, TK_RETURN, + TK_GOTO, TK_SHORT, TK_LONG, TK_CONTINUE, diff --git a/oscar64/oscar64.cpp b/oscar64/oscar64.cpp index 04ba2c4..1721938 100644 --- a/oscar64/oscar64.cpp +++ b/oscar64/oscar64.cpp @@ -134,10 +134,29 @@ int main2(int argc, const char** argv) compiler->AddDefine(Ident::Unique("__STDC__"), "1"); compiler->AddDefine(Ident::Unique("__STDC_VERSION__"), "199901L"); + bool defining = false; + for (int i = 1; i < argc; i++) { const char* arg = argv[i]; - if (arg[0] == '-') + if (defining) + { + defining = false; + + char def[100]; + int i = 0; + while (arg[i] && arg[i] != '=') + { + def[i] = arg[i]; + i++; + } + def[i] = 0; + if (arg[i] == '=') + compiler->AddDefine(Ident::Unique(def), _strdup(arg + i + 1)); + else + compiler->AddDefine(Ident::Unique(def), ""); + } + else if (arg[0] == '-') { if (arg[1] == 'i' && arg[2] == '=') { @@ -230,6 +249,10 @@ int main2(int argc, const char** argv) else if (arg[2] == 'b') trace = 1; } + else if (arg[1] == 'D' && !arg[2]) + { + defining = true; + } else if (arg[1] == 'd') { char def[100];