Add optimisations

This commit is contained in:
Melon 2022-01-20 00:14:01 +00:00
parent 2eae55e08b
commit aedccb1d30
Signed by: melon
GPG Key ID: B0ADD5395BCDAAB6
6 changed files with 100 additions and 49 deletions

8
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/

7
.idea/discord.xml Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DiscordProjectSettings">
<option name="show" value="PROJECT_FILES" />
<option name="description" value="" />
</component>
</project>

18
.idea/misc.xml Normal file
View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MakefileSettings">
<option name="linkedExternalProjectsSettings">
<MakefileProjectSettings>
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
</set>
</option>
<option name="version" value="2" />
</MakefileProjectSettings>
</option>
</component>
<component name="MakefileWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
</project>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -2,9 +2,9 @@ sourcefiles := $(shell find src/impl/ -name *.c)
all: all:
make build-main make build
build-main: build:
mkdir -p dist/ && \ mkdir -p dist/ && \
gcc -o dist/bf2c -I src/intf/ ${sourcefiles} gcc -o dist/bf2c -I src/intf/ ${sourcefiles}

View File

@ -4,6 +4,9 @@
#include "popen2.h" #include "popen2.h"
int is_arg(int ac, char **argv, char *arg) { int is_arg(int ac, char **argv, char *arg) {
if (ac < 2) return 0; if (ac < 2) return 0;
for(int x=1; x < ac; x++) for(int x=1; x < ac; x++)
if (0 == strcmp(argv[x], arg)) if (0 == strcmp(argv[x], arg))
@ -99,10 +102,18 @@ int main(int argc, char **argv) {
if (c != EOF && b == c && optimise) a++; if (c != EOF && b == c && optimise) a++;
else { else {
switch (b) { switch (b) {
case '>': addValueChange(out, "cell", true, a); break; case '>':
case '<': addValueChange(out, "cell", false, a); break; addValueChange(out, "cell", true, a);
case '+': addValueChange(out, "*cell", true, a); break; break;
case '-': addValueChange(out, "*cell", false, a); break; case '<':
addValueChange(out, "cell", false, a);
break;
case '+':
addValueChange(out, "*cell", true, a);
break;
case '-':
addValueChange(out, "*cell", false, a);
break;
case '.': case '.':
for (int i = 0; i < a; i++) fprintf(out, "putchar(*cell);\n"); for (int i = 0; i < a; i++) fprintf(out, "putchar(*cell);\n");
break; break;
@ -115,7 +126,8 @@ int main(int argc, char **argv) {
case ']': case ']':
for (int i = 0; i < a; i++) fprintf(out, "}\n"); for (int i = 0; i < a; i++) fprintf(out, "}\n");
break; break;
default: break; default:
break;
} }
// Reset for next loop // Reset for next loop