From 6e4841f0c1ff8a3b17f7fc01d69755fe604c296a Mon Sep 17 00:00:00 2001 From: Scarlett Date: Fri, 25 Apr 2025 23:26:50 -0400 Subject: [PATCH] Big testing update --- src/codegen.c | 2 +- src/grammar.y | 2 +- test.sh | 4 ++-- tests/sprint2/test/sp2_llnode.alpha | 2 +- .../sp3_integer_binary_op_typecheck.alpha | 6 +++--- tests/sprint4/expected/sp4_cg_add.expected | 12 +++++++++++ tests/sprint4/expected/sp4_cg_and.expected | 20 ++++++++++++++++++ tests/sprint4/expected/sp4_cg_div.expected | 12 +++++++++++ .../sprint4/expected/sp4_cg_equal_to.expected | 13 ++++++++++++ .../expected/sp4_cg_less_than.expected | 13 ++++++++++++ tests/sprint4/expected/sp4_cg_mod.expected | 12 +++++++++++ tests/sprint4/expected/sp4_cg_mult.expected | 11 ++++++++++ tests/sprint4/expected/sp4_cg_neg.expected | 8 +++++++ tests/sprint4/expected/sp4_cg_not.expected | 13 ++++++++++++ tests/sprint4/expected/sp4_cg_or.expected | 21 +++++++++++++++++++ tests/sprint4/expected/sp4_cg_sub.expected | 11 ++++++++++ tests/sprint4/test/sp4_cg_add.alpha | 10 +++++++++ tests/sprint4/test/sp4_cg_and.alpha | 10 +++++++++ tests/sprint4/test/sp4_cg_div.alpha | 10 +++++++++ tests/sprint4/test/sp4_cg_equal_to.alpha | 10 +++++++++ tests/sprint4/test/sp4_cg_less_than.alpha | 10 +++++++++ tests/sprint4/test/sp4_cg_mod.alpha | 10 +++++++++ tests/sprint4/test/sp4_cg_mult.alpha | 10 +++++++++ tests/sprint4/test/sp4_cg_neg.alpha | 9 ++++++++ tests/sprint4/test/sp4_cg_not.alpha | 9 ++++++++ tests/sprint4/test/sp4_cg_or.alpha | 10 +++++++++ tests/sprint4/test/sp4_cg_sub.alpha | 10 +++++++++ 27 files changed, 262 insertions(+), 8 deletions(-) create mode 100644 tests/sprint4/expected/sp4_cg_add.expected create mode 100644 tests/sprint4/expected/sp4_cg_and.expected create mode 100644 tests/sprint4/expected/sp4_cg_div.expected create mode 100644 tests/sprint4/expected/sp4_cg_equal_to.expected create mode 100644 tests/sprint4/expected/sp4_cg_less_than.expected create mode 100644 tests/sprint4/expected/sp4_cg_mod.expected create mode 100644 tests/sprint4/expected/sp4_cg_mult.expected create mode 100644 tests/sprint4/expected/sp4_cg_neg.expected create mode 100644 tests/sprint4/expected/sp4_cg_not.expected create mode 100644 tests/sprint4/expected/sp4_cg_or.expected create mode 100644 tests/sprint4/expected/sp4_cg_sub.expected create mode 100644 tests/sprint4/test/sp4_cg_add.alpha create mode 100644 tests/sprint4/test/sp4_cg_and.alpha create mode 100644 tests/sprint4/test/sp4_cg_div.alpha create mode 100644 tests/sprint4/test/sp4_cg_equal_to.alpha create mode 100644 tests/sprint4/test/sp4_cg_less_than.alpha create mode 100644 tests/sprint4/test/sp4_cg_mod.alpha create mode 100644 tests/sprint4/test/sp4_cg_mult.alpha create mode 100644 tests/sprint4/test/sp4_cg_neg.alpha create mode 100644 tests/sprint4/test/sp4_cg_not.alpha create mode 100644 tests/sprint4/test/sp4_cg_or.alpha create mode 100644 tests/sprint4/test/sp4_cg_sub.alpha diff --git a/src/codegen.c b/src/codegen.c index 825fd55..250d2a4 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -118,7 +118,7 @@ CGNode *findCG(TableNode *tn) { CGNode *addCG(TableNode *tn, int sp) { CGNode *cg = calloc(1, sizeof(CGNode)); cg->tn = tn; - offset += getPrimSize(getTypeEntry(tn)); + offset += 4; // <- quick fix getPrimSize(getTypeEntry(tn)) cg->address = offset; cg->next = cgList; cgList = cg; diff --git a/src/grammar.y b/src/grammar.y index 9f96a6c..7060c94 100644 --- a/src/grammar.y +++ b/src/grammar.y @@ -1214,7 +1214,7 @@ void yyerror(const char *err) { insert_code_line(error_message, line); } else { - fprintf(stderr, " LINE (%d:%d) ** SYNTAX ERROR: Incorrect syntax at token %s\n\n", line, column, yytext); + fprintf(stderr, " LINE (%d:%d) ** SYNTAX ERROR: Incorrect syntax at token %s\n", line, column, yytext); } } } diff --git a/test.sh b/test.sh index 8443215..3f6f5a9 100755 --- a/test.sh +++ b/test.sh @@ -84,7 +84,7 @@ if [ $# -eq 0 ]; then if [ -f "$file" ]; then filename=$(basename -- "$file") echo -e "- ${SWITCH}Running test: ${LIGHTBLUE}$filename ${SWITCH}-----${WHITE}" - ./alpha -st -debug "$file" + ./alpha -cg "$file" echo -e "${SWITCH}----- End of test: ${LIGHTBLUE}$filename ${SWITCH}-${WHITE}\n${WHITE}" switchfunc fi @@ -154,7 +154,7 @@ else if [[ "$file" == *"$1"* ]]; then filename=$(basename -- "$file") echo -e "- ${SWITCH}Running test: ${LIGHTBLUE}$filename ${SWITCH}-----${WHITE}" - ./alpha -st -debug "$file" + ./alpha -cg -debug "$file" echo -e "${SWITCH}----- End of test: ${LIGHTBLUE}$filename ${SWITCH}-${WHITE}\n" switchfunc fi diff --git a/tests/sprint2/test/sp2_llnode.alpha b/tests/sprint2/test/sp2_llnode.alpha index c611b3c..3ecfb11 100644 --- a/tests/sprint2/test/sp2_llnode.alpha +++ b/tests/sprint2/test/sp2_llnode.alpha @@ -21,7 +21,7 @@ make_list (a) := { } else { ret := reserve ret; ret.prev := null; - ret.next :s= null;g + ret.next := null; ret.val := a; while (0 < a) { temp := reserve temp; diff --git a/tests/sprint3/test/sp3_integer_binary_op_typecheck.alpha b/tests/sprint3/test/sp3_integer_binary_op_typecheck.alpha index a804c23..2adb394 100644 --- a/tests/sprint3/test/sp3_integer_binary_op_typecheck.alpha +++ b/tests/sprint3/test/sp3_integer_binary_op_typecheck.alpha @@ -8,12 +8,12 @@ entry (arg) := { x := 3 + 2 * 8; x := 3 - 2 / 8; - x := a * 2 % 8;s + x := a * 2 % 8; b2 := 3 * 2 % 8; x := 3 % 2 * 8; x := 3 + arr - 8; - x := r.x; - x := a.x; + x := r.x; + x := a.x; return 0; } diff --git a/tests/sprint4/expected/sp4_cg_add.expected b/tests/sprint4/expected/sp4_cg_add.expected new file mode 100644 index 0000000..4764400 --- /dev/null +++ b/tests/sprint4/expected/sp4_cg_add.expected @@ -0,0 +1,12 @@ + movl $1, -4(%rbp) #constant assign + movl -4(%rbp), %eax #assign start + movl %eax, -8(%rbp) #assign end + movl $3, -12(%rbp) #constant assign + movl -12(%rbp), %eax #assign start + movl %eax, -16(%rbp) #assign end + movl -16(%rbp), %eax #addition start + movl -16(%rbp), %eax + addl %edx, %eax + movl %eax, -20(%rbp) #addition end + movl -20(%rbp), %eax #assign start + movl %eax, -8(%rbp) #assign end diff --git a/tests/sprint4/expected/sp4_cg_and.expected b/tests/sprint4/expected/sp4_cg_and.expected new file mode 100644 index 0000000..be6a53e --- /dev/null +++ b/tests/sprint4/expected/sp4_cg_and.expected @@ -0,0 +1,20 @@ + movl $-1, -4(%rbp) #constant assign + movl -4(%rbp), %eax #assign start + movl %eax, -8(%rbp) #assign end + movl $-1, -12(%rbp) #constant assign + movl -12(%rbp), %eax #assign start + movl %eax, -16(%rbp) #assign end + cmpl $0, -8(%rbp) #start and + je .L1or2 + cmpl $0, -16(%rbp) + je .L1or2 + movl $1, %eax + jmp .L1or3 +.L1or2: + movl $0, %eax +.L1or3: + movb %al, -20(%rbp) + andb $1, -20(%rbp) #and end + movl -20(%rbp), %eax #assign start + movl %eax, -16(%rbp) #assign end + movl $1, -24(%rbp) #constant assign diff --git a/tests/sprint4/expected/sp4_cg_div.expected b/tests/sprint4/expected/sp4_cg_div.expected new file mode 100644 index 0000000..1a71c6e --- /dev/null +++ b/tests/sprint4/expected/sp4_cg_div.expected @@ -0,0 +1,12 @@ + movl $1, -4(%rbp) #constant assign + movl -4(%rbp), %eax #assign start + movl %eax, -8(%rbp) #assign end + movl $3, -12(%rbp) #constant assign + movl -12(%rbp), %eax #assign start + movl %eax, -16(%rbp) #assign end + movl -16(%rbp), %eax #division start + cltd + idivl -8(%rbp) + movl %eax, -20(%rbp) #division end + movl -20(%rbp), %eax #assign start + movl %eax, -8(%rbp) #assign end diff --git a/tests/sprint4/expected/sp4_cg_equal_to.expected b/tests/sprint4/expected/sp4_cg_equal_to.expected new file mode 100644 index 0000000..e29c6c1 --- /dev/null +++ b/tests/sprint4/expected/sp4_cg_equal_to.expected @@ -0,0 +1,13 @@ + movl $1, -4(%rbp) #constant assign + movl -4(%rbp), %eax #assign start + movl %eax, -8(%rbp) #assign end + movl $2, -12(%rbp) #constant assign + movl -12(%rbp), %eax #assign start + movl %eax, -16(%rbp) #assign end + movl -8(%rbp), %eax #equal to start + cmpl -16(%rbp), %eax + sete %al + movb %al, -20(%rbp) #equal to end + movl -20(%rbp), %eax #assign start + movl %eax, -24(%rbp) #assign end + movl $1, -28(%rbp) #constant assign diff --git a/tests/sprint4/expected/sp4_cg_less_than.expected b/tests/sprint4/expected/sp4_cg_less_than.expected new file mode 100644 index 0000000..b8d8904 --- /dev/null +++ b/tests/sprint4/expected/sp4_cg_less_than.expected @@ -0,0 +1,13 @@ + movl $1, -4(%rbp) #constant assign + movl -4(%rbp), %eax #assign start + movl %eax, -8(%rbp) #assign end + movl $2, -12(%rbp) #constant assign + movl -12(%rbp), %eax #assign start + movl %eax, -16(%rbp) #assign end + movl -8(%rbp), %eax #less than start + cmpl -16(%rbp), %eax + setl %al + movb %al, -20(%rbp) #less than end + movl -20(%rbp), %eax #assign start + movl %eax, -24(%rbp) #assign end + movl $1, -28(%rbp) #constant assign diff --git a/tests/sprint4/expected/sp4_cg_mod.expected b/tests/sprint4/expected/sp4_cg_mod.expected new file mode 100644 index 0000000..97d4259 --- /dev/null +++ b/tests/sprint4/expected/sp4_cg_mod.expected @@ -0,0 +1,12 @@ + movl $1, -4(%rbp) #constant assign + movl -4(%rbp), %eax #assign start + movl %eax, -8(%rbp) #assign end + movl $3, -12(%rbp) #constant assign + movl -12(%rbp), %eax #assign start + movl %eax, -16(%rbp) #assign end + movl -16(%rbp), %eax #mod start + cltd + idivl -8(%rbp) + movl %edx, -20(%rbp) #mod end + movl -20(%rbp), %eax #assign start + movl %eax, -8(%rbp) #assign end diff --git a/tests/sprint4/expected/sp4_cg_mult.expected b/tests/sprint4/expected/sp4_cg_mult.expected new file mode 100644 index 0000000..20b0a57 --- /dev/null +++ b/tests/sprint4/expected/sp4_cg_mult.expected @@ -0,0 +1,11 @@ + movl $1, -4(%rbp) #constant assign + movl -4(%rbp), %eax #assign start + movl %eax, -8(%rbp) #assign end + movl $3, -12(%rbp) #constant assign + movl -12(%rbp), %eax #assign start + movl %eax, -16(%rbp) #assign end + movl -16(%rbp), %eax #multiplication start + imull -16(%rbp), %eax + movl %eax, -20(%rbp) #multiplication end + movl -20(%rbp), %eax #assign start + movl %eax, -8(%rbp) #assign end diff --git a/tests/sprint4/expected/sp4_cg_neg.expected b/tests/sprint4/expected/sp4_cg_neg.expected new file mode 100644 index 0000000..5f61770 --- /dev/null +++ b/tests/sprint4/expected/sp4_cg_neg.expected @@ -0,0 +1,8 @@ + movl $3, -4(%rbp) #constant assign + movl -4(%rbp), %eax #assign start + movl %eax, -8(%rbp) #assign end + movl -8(%rbp), %eax #negation start + negl %eax + movl %eax, -12(%rbp) #negation end + movl -12(%rbp), %eax #assign start + movl %eax, -16(%rbp) #assign end diff --git a/tests/sprint4/expected/sp4_cg_not.expected b/tests/sprint4/expected/sp4_cg_not.expected new file mode 100644 index 0000000..b2e4bda --- /dev/null +++ b/tests/sprint4/expected/sp4_cg_not.expected @@ -0,0 +1,13 @@ + movl $-1, -4(%rbp) #constant assign + movl -4(%rbp), %eax #assign start + movl %eax, -8(%rbp) #assign end + movzbl -8(%rbp), %eax #not start + testl %eax, %eax + setne %al + xorl $1, %eax + movzbl %al, %eax + movb %al, -12(%rbp) + andb $1, -12(%rbp) #not end + movl -12(%rbp), %eax #assign start + movl %eax, -16(%rbp) #assign end + movl $1, -20(%rbp) #constant assign diff --git a/tests/sprint4/expected/sp4_cg_or.expected b/tests/sprint4/expected/sp4_cg_or.expected new file mode 100644 index 0000000..120058f --- /dev/null +++ b/tests/sprint4/expected/sp4_cg_or.expected @@ -0,0 +1,21 @@ + movl $-1, -4(%rbp) #constant assign + movl -4(%rbp), %eax #assign start + movl %eax, -8(%rbp) #assign end + movl $-1, -12(%rbp) #constant assign + movl -12(%rbp), %eax #assign start + movl %eax, -16(%rbp) #assign end + cmpl $0, -8(%rbp) #start or + jne .L1or2 + cmpl $0, -16(%rbp) + je .L1or3 +.L1or2: + movl $1, %eax + jmp .L1or4 +.L1or3: + movl $0, %eax +.L1or4: + movb %al, -20(%rbp) + andb $1, -20(%rbp) #or end + movl -20(%rbp), %eax #assign start + movl %eax, -16(%rbp) #assign end + movl $1, -24(%rbp) #constant assign diff --git a/tests/sprint4/expected/sp4_cg_sub.expected b/tests/sprint4/expected/sp4_cg_sub.expected new file mode 100644 index 0000000..743ef59 --- /dev/null +++ b/tests/sprint4/expected/sp4_cg_sub.expected @@ -0,0 +1,11 @@ + movl $1, -4(%rbp) #constant assign + movl -4(%rbp), %eax #assign start + movl %eax, -8(%rbp) #assign end + movl $3, -12(%rbp) #constant assign + movl -12(%rbp), %eax #assign start + movl %eax, -16(%rbp) #assign end + movl -16(%rbp), %eax #subtraction start + subl -8(%rbp), %eax + movl %eax, -20(%rbp) #subtraction end + movl -20(%rbp), %eax #assign start + movl %eax, -8(%rbp) #assign end diff --git a/tests/sprint4/test/sp4_cg_add.alpha b/tests/sprint4/test/sp4_cg_add.alpha new file mode 100644 index 0000000..f4f8138 --- /dev/null +++ b/tests/sprint4/test/sp4_cg_add.alpha @@ -0,0 +1,10 @@ +type main: integer -> integer +function test: main + +test (a) := { + [integer:x; integer:y] + y := 1; + x := 3; + y := x + y; + return y; +} \ No newline at end of file diff --git a/tests/sprint4/test/sp4_cg_and.alpha b/tests/sprint4/test/sp4_cg_and.alpha new file mode 100644 index 0000000..5017e35 --- /dev/null +++ b/tests/sprint4/test/sp4_cg_and.alpha @@ -0,0 +1,10 @@ +type main: integer -> integer +function test: main + +test (a) := { + [Boolean:b; Boolean: c; Boolean: d] + c := true; + d := false; + d := c & d; + return 1; +} \ No newline at end of file diff --git a/tests/sprint4/test/sp4_cg_div.alpha b/tests/sprint4/test/sp4_cg_div.alpha new file mode 100644 index 0000000..32d3537 --- /dev/null +++ b/tests/sprint4/test/sp4_cg_div.alpha @@ -0,0 +1,10 @@ +type main: integer -> integer +function test: main + +test (a) := { + [integer:x; integer:y] + y := 1; + x := 3; + y := x / y; + return y; +} \ No newline at end of file diff --git a/tests/sprint4/test/sp4_cg_equal_to.alpha b/tests/sprint4/test/sp4_cg_equal_to.alpha new file mode 100644 index 0000000..a3da50c --- /dev/null +++ b/tests/sprint4/test/sp4_cg_equal_to.alpha @@ -0,0 +1,10 @@ +type main: integer -> integer +function test: main + +test (a) := { + [Boolean: b; integer: x; integer: y] + x := 1; + y := 2; + b := x = y; + return 1; +} \ No newline at end of file diff --git a/tests/sprint4/test/sp4_cg_less_than.alpha b/tests/sprint4/test/sp4_cg_less_than.alpha new file mode 100644 index 0000000..8f41ced --- /dev/null +++ b/tests/sprint4/test/sp4_cg_less_than.alpha @@ -0,0 +1,10 @@ +type main: integer -> integer +function test: main + +test (a) := { + [Boolean: b; integer: x; integer: y] + x := 1; + y := 2; + b := x < y; + return 1; +} \ No newline at end of file diff --git a/tests/sprint4/test/sp4_cg_mod.alpha b/tests/sprint4/test/sp4_cg_mod.alpha new file mode 100644 index 0000000..1b579d5 --- /dev/null +++ b/tests/sprint4/test/sp4_cg_mod.alpha @@ -0,0 +1,10 @@ +type main: integer -> integer +function test: main + +test (a) := { + [integer:x; integer:y] + y := 1; + x := 3; + y := x % y; + return y; +} \ No newline at end of file diff --git a/tests/sprint4/test/sp4_cg_mult.alpha b/tests/sprint4/test/sp4_cg_mult.alpha new file mode 100644 index 0000000..c151a6b --- /dev/null +++ b/tests/sprint4/test/sp4_cg_mult.alpha @@ -0,0 +1,10 @@ +type main: integer -> integer +function test: main + +test (a) := { + [integer:x; integer:y] + y := 1; + x := 3; + y := x * x; + return y; +} \ No newline at end of file diff --git a/tests/sprint4/test/sp4_cg_neg.alpha b/tests/sprint4/test/sp4_cg_neg.alpha new file mode 100644 index 0000000..345980b --- /dev/null +++ b/tests/sprint4/test/sp4_cg_neg.alpha @@ -0,0 +1,9 @@ +type main: integer -> integer +function test: main + +test (a) := { + [integer:x; integer:y] + x := 3; + y := -x; + return y; +} \ No newline at end of file diff --git a/tests/sprint4/test/sp4_cg_not.alpha b/tests/sprint4/test/sp4_cg_not.alpha new file mode 100644 index 0000000..40252f9 --- /dev/null +++ b/tests/sprint4/test/sp4_cg_not.alpha @@ -0,0 +1,9 @@ +type main: integer -> integer +function test: main + +test (a) := { + [Boolean: c; Boolean: d] + c := true; + d := !c; + return 1; +} \ No newline at end of file diff --git a/tests/sprint4/test/sp4_cg_or.alpha b/tests/sprint4/test/sp4_cg_or.alpha new file mode 100644 index 0000000..b6d6766 --- /dev/null +++ b/tests/sprint4/test/sp4_cg_or.alpha @@ -0,0 +1,10 @@ +type main: integer -> integer +function test: main + +test (a) := { + [Boolean:b; Boolean: c; Boolean: d] + c := true; + d := false; + d := c | d; + return 1; +} \ No newline at end of file diff --git a/tests/sprint4/test/sp4_cg_sub.alpha b/tests/sprint4/test/sp4_cg_sub.alpha new file mode 100644 index 0000000..f280c9d --- /dev/null +++ b/tests/sprint4/test/sp4_cg_sub.alpha @@ -0,0 +1,10 @@ +type main: integer -> integer +function test: main + +test (a) := { + [integer:x; integer:y] + y := 1; + x := 3; + y := x - y; + return y; +} \ No newline at end of file