Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makes it compile as a lib #6

Draft
wants to merge 28 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
CFLAGS = -Wall -std=c99 -O3
CFLAGSDEBUG = -g -Wall -std=c99 -O0
OUTFILE = hac
SOURCES = src/main.c src/lex.c src/grammar.c src/tree.c src/lextest.c src/symbolTable.c src/codeGen.c src/testbfi.c src/compilerFunctions.c src/codeEss.c src/optimizer.c src/expander.c src/highlight.c
OBJS = temp/codeGen.o temp/symbolTable.o temp/grammar.o temp/tree.o temp/main.o temp/lex.o temp/lextest.o temp/testbfi.o temp/compilerFunctions.o temp/codeEss.o temp/optimizer.o temp/expander.o temp/highlight.o
SOURCES = src/main.c src/lex.c src/grammar.c src/tree.c src/lextest.c src/symbolTable.c src/codeGen.c src/testbfi.c src/compilerFunctions.c src/codeEss.c src/optimizer.c src/expander.c src/highlight.c src/codellvm.c
OBJS = temp/codeGen.o temp/symbolTable.o temp/grammar.o temp/tree.o temp/main.o temp/lex.o temp/lextest.o temp/testbfi.o temp/compilerFunctions.o temp/codeEss.o temp/optimizer.o temp/expander.o temp/highlight.o temp/codellvm.o

ZIGCC = zig cc
WINCC = x86_64-w64-mingw32-gcc-11.1.0 #old one was i686-w64-mingw32-gcc; changed because false positives
Expand Down Expand Up @@ -189,20 +189,27 @@ temp/grammar.o: src/grammar.c
cc -o temp/grammar.o -Wall -O3 -c src/grammar.c
temp/tree.o: src/tree.c
cc -o temp/tree.o -Wall -O3 -c src/tree.c
temp/lib.o:
cc -DHACLIB -o temp/lib.o -Wall -O3 -c src/main.c
temp/main.o: src/main.c
cc -o temp/main.o -Wall -O3 -c src/main.c
temp/lex.o: src/lex.c
cc -o temp/lex.o -Wall -O3 -c src/lex.c
temp/highlight.o: src/highlight.c
cc -o temp/highlight.o -Wall -O3 -c src/highlight.c
temp/codellvm.o: src/codellvm.c
cc -o temp/codellvm.o -Wall -O3 -c src/codellvm.c

## LIBS
hac.a: $(OBJS)
hac.a: $(OBJS) temp/lib.o
rm -f temp/main.o
ar ruv hac.a temp/*.o
ranlib hac.a

hac.so: $(OBJS)
cc -shared temp/*.o -o hac.s
hac.so: $(OBJS) temp/lib.o
rm -f temp/main.o
cc -shared temp/*.o -o hac.so



## ZIG CC EXPERIMENT
Expand Down
2 changes: 1 addition & 1 deletion examples/calculator.ha
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//Interactive Calculator program
void main() {
char operator;
byte a,b;
short a,b;
print "Enter first number:\n";
read a;
print "Received number "; print a; print "\n";
Expand Down
32 changes: 32 additions & 0 deletions examples/collatz.ha
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
short mod2(short a){
short r,q;
q = a/(2 as short);
r = a - (2 as short)*q;
print "(a,2)"; @"= ("; @a; @","; @2; @")";
print "(r,q)"; @"= ("; @r; @","; @q; @")";
return r;
}

void main() {
short x,y,z;
print "Enter a number:\n";

read x;
print "got "; @x; @" \n";
y = x - (1 as short);
while(y){
z = mod2(x);
print "z is "; @z; @"\n";
if(z == 0) {
print "even\n";
x = x/(2 as short);
}
else {
print "odd\n";
x = (3 as short)*x+(1 as short);
}
print "=> "; @x; @"\n";
y--;

}
}
6 changes: 4 additions & 2 deletions examples/countext.ha
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ void main() {
@"Enter an limit\n";
#end;
@"Start:\n";
for(i=0;i<=end;i++){
i=0;
while(i<=end){
@i;@"\n";
i++;
}
//@"End\n";
@"End\n";

}
13 changes: 13 additions & 0 deletions examples/countext2.ha
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
void main() {
short i,end;
@"Enter an limit\n";
#end;
@"Start:\n";
i=0;
while(i<=end){
@i;@"\n";
i++;
}
@"End\n";

}
2 changes: 1 addition & 1 deletion examples/example.ha
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

void main() {
@"Headache compiles to 8 bit Brainfuck\n";
print "Headache compiles to 8 bit Brainfuck\n";
}
2 changes: 1 addition & 1 deletion examples/experimental/sincos.ha
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ short cos(short x){
short i;
short sum;

//sum = (x - x*x/2 + pow(x,4)/factorial(4))*100;
sum = (x - x*x/2 + pow(x,4)/factorial(4))*100;
return sum;
}
void main() {
Expand Down
28 changes: 28 additions & 0 deletions examples/factor.ha
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
byte modulus8(byte a, byte b){
byte r,q;
q = a/b;
r = a - b*q;
return r;
}

void factor(byte n) {
byte x,i;
print n; @"! = ";
x = n;
i = 2;
while (x > 1) {
if (modulus8(x,i) == 0) {
print " "; @i;
x = x / i;
i = 1;
}
i++;
}
print "\n";
}
void main() {
byte n;
print "Enter number:\n";
read n;
factor(n);
}
5 changes: 2 additions & 3 deletions examples/factorial.ha
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
}
return z;
}

void main(){
short x;
@"Calculate x!\n";
@"Enter x:\n";
read x;
@"x! is "; @factorial(x); @"\n";
}
@x; @"! is "; @factorial(x); @"\n";
}
13 changes: 0 additions & 13 deletions examples/foraMaia.ha

This file was deleted.

2 changes: 1 addition & 1 deletion examples/masoque.ha
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
void main() {
void hello() {
print "Hello, World!\n";
}

Expand Down
4 changes: 3 additions & 1 deletion src/codeGen.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static int currentBrIndex = 0;

static int currentStringConstant = 0;
static int declareTop = 0;
char* stringsToDeclare[100];
static char* stringsToDeclare[100];


extern char forceExpand;
Expand Down Expand Up @@ -669,6 +669,8 @@ static void codeCellValuePrintAnySize(int start, int end){
popCells(10);
}

void outputToBuffer(){}


void setCodeOutput(FILE* out) {
setOutput(out);
Expand Down
Loading
Loading