Removed under-used optimization options

This commit is contained in:
2022-08-19 19:27:23 +01:00
parent 4f0aebc32f
commit 97e72550da
4 changed files with 4 additions and 13 deletions

View File

@@ -1,10 +1,10 @@
DONE: rework type system DONE: rework type system
DONE: var decl with a type, but no value DONE: var decl with a type, but no value
DONE: type casting DONE: type casting
DONE: remove optimization option
TODO: string concat with the + operator TODO: string concat with the + operator
TODO: empty string as falsy? TODO: empty string as falsy?
TODO: remove optimization option
TODO: increment & decrement operators TODO: increment & decrement operators
TODO: a = b = c = 1; TODO: a = b = c = 1;
TODO: are compounds shallow or deep copies? TODO: are compounds shallow or deep copies?

View File

@@ -17,7 +17,6 @@ void initCommand(int argc, const char* argv[]) {
command.outfile = "out.tb"; command.outfile = "out.tb";
command.source = NULL; command.source = NULL;
command.verbose = false; command.verbose = false;
command.optimize = 1;
for (int i = 1; i < argc; i++) { //start at 1 to skip the program name 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 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; 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) { if ((!strcmp(argv[i], "-f") || !strcmp(argv[i], "--sourcefile")) && i + 1 < argc) {
command.sourcefile = (char*)argv[i + 1]; command.sourcefile = (char*)argv[i + 1];
i++; i++;
@@ -89,7 +82,7 @@ void initCommand(int argc, const char* argv[]) {
} }
void usageCommand(int argc, const char* argv[]) { void usageCommand(int argc, const char* argv[]) {
printf("Usage: %s [<file.tb> | -h | -v | [-d][-OX][-f file | -i source | -c file [-o outfile]]]\n\n", argv[0]); printf("Usage: %s [<file.tb> | -h | -v | [-d][-f file | -i source | -c file [-o outfile]]]\n\n", argv[0]);
} }
void helpCommand(int argc, const char* argv[]) { 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("-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("-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("-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("-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("-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"); printf("-c\t| --compile filename\tParse and compile the specified source file into an output file.\n\n");

View File

@@ -20,7 +20,6 @@ typedef struct {
char* outfile; //defaults to out.tb char* outfile; //defaults to out.tb
char* source; char* source;
bool verbose; bool verbose;
int optimize;
} Command; } Command;
extern Command command; extern Command command;

View File

@@ -328,7 +328,7 @@ static Opcode unary(Parser* parser, Node** nodeHandle) {
parsePrecedence(parser, &tmpNode, PREC_TERNARY); //can be a literal parsePrecedence(parser, &tmpNode, PREC_TERNARY); //can be a literal
//check for negative literals (optimisation) //check for negative literals (optimisation)
if (command.optimize >= 1 && tmpNode->type == NODE_LITERAL) { if (tmpNode->type == NODE_LITERAL) {
//negate directly, if int or float //negate directly, if int or float
Literal lit = tmpNode->atomic.literal; 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 const Opcode opcode = infixRule(parser, &rhsNode); //NOTE: infix rule must advance the parser
emitNodeBinary(nodeHandle, rhsNode, opcode); emitNodeBinary(nodeHandle, rhsNode, opcode);
if (command.optimize >= 1 && !calcStaticBinaryArithmetic(parser, nodeHandle)) { if (!calcStaticBinaryArithmetic(parser, nodeHandle)) {
return; return;
} }
} }