From 97e72550dada79d473eb6421b6f6851a471b10a4 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Fri, 19 Aug 2022 19:27:23 +0100 Subject: [PATCH] Removed under-used optimization options --- docs/TODO.txt | 2 +- source/common.c | 10 +--------- source/common.h | 1 - source/parser.c | 4 ++-- 4 files changed, 4 insertions(+), 13 deletions(-) diff --git a/docs/TODO.txt b/docs/TODO.txt index eb82529..1d46b6b 100644 --- a/docs/TODO.txt +++ b/docs/TODO.txt @@ -1,10 +1,10 @@ DONE: rework type system DONE: var decl with a type, but no value DONE: type casting +DONE: remove optimization option TODO: string concat with the + operator TODO: empty string as falsy? -TODO: remove optimization option TODO: increment & decrement operators TODO: a = b = c = 1; TODO: are compounds shallow or deep copies? diff --git a/source/common.c b/source/common.c index f002b9d..7da9f15 100644 --- a/source/common.c +++ b/source/common.c @@ -17,7 +17,6 @@ void initCommand(int argc, const char* argv[]) { command.outfile = "out.tb"; command.source = NULL; command.verbose = false; - command.optimize = 1; for (int i = 1; i < argc; i++) { //start at 1 to skip the program name command.error = true; //error state by default, set to false by successful flags @@ -40,12 +39,6 @@ void initCommand(int argc, const char* argv[]) { continue; } - if (!strncmp(argv[i], "-O", 2)) { - sscanf(argv[i], "-O%d", &command.optimize); - command.error = false; - continue; - } - if ((!strcmp(argv[i], "-f") || !strcmp(argv[i], "--sourcefile")) && i + 1 < argc) { command.sourcefile = (char*)argv[i + 1]; i++; @@ -89,7 +82,7 @@ void initCommand(int argc, const char* argv[]) { } void usageCommand(int argc, const char* argv[]) { - printf("Usage: %s [ | -h | -v | [-d][-OX][-f file | -i source | -c file [-o outfile]]]\n\n", argv[0]); + printf("Usage: %s [ | -h | -v | [-d][-f file | -i source | -c file [-o outfile]]]\n\n", argv[0]); } void helpCommand(int argc, const char* argv[]) { @@ -99,7 +92,6 @@ void helpCommand(int argc, const char* argv[]) { printf("-h\t| --help\t\tShow this help then exit.\n\n"); printf("-v\t| --version\t\tShow version and copyright information then exit.\n\n"); printf("-d\t| --debug\t\tBe verbose when operating.\n\n"); - printf("-OX\t\t\t\tUse level X optimization (default 1)\n\n"); printf("-f\t| --file filename\tParse, compile and execute the source file.\n\n"); printf("-i\t| --input source\tParse, compile and execute this given string of source code.\n\n"); printf("-c\t| --compile filename\tParse and compile the specified source file into an output file.\n\n"); diff --git a/source/common.h b/source/common.h index 13b6481..551641b 100644 --- a/source/common.h +++ b/source/common.h @@ -20,7 +20,6 @@ typedef struct { char* outfile; //defaults to out.tb char* source; bool verbose; - int optimize; } Command; extern Command command; diff --git a/source/parser.c b/source/parser.c index 83ad4f2..90e036a 100644 --- a/source/parser.c +++ b/source/parser.c @@ -328,7 +328,7 @@ static Opcode unary(Parser* parser, Node** nodeHandle) { parsePrecedence(parser, &tmpNode, PREC_TERNARY); //can be a literal //check for negative literals (optimisation) - if (command.optimize >= 1 && tmpNode->type == NODE_LITERAL) { + if (tmpNode->type == NODE_LITERAL) { //negate directly, if int or float Literal lit = tmpNode->atomic.literal; @@ -725,7 +725,7 @@ static void parsePrecedence(Parser* parser, Node** nodeHandle, PrecedenceRule ru const Opcode opcode = infixRule(parser, &rhsNode); //NOTE: infix rule must advance the parser emitNodeBinary(nodeHandle, rhsNode, opcode); - if (command.optimize >= 1 && !calcStaticBinaryArithmetic(parser, nodeHandle)) { + if (!calcStaticBinaryArithmetic(parser, nodeHandle)) { return; } }