forked from VU-Programming/copp-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
179 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
.constant | ||
.end-constant | ||
|
||
.main | ||
|
||
L1: | ||
BIPUSH 0x05 | ||
L2: | ||
DUP | ||
BIPUSH 0x30 | ||
IADD | ||
OUT | ||
BIPUSH 0x01 | ||
ISUB | ||
DUP | ||
IFEQ L3 | ||
GOTO L2 | ||
L3: | ||
BIPUSH 0x65 | ||
BIPUSH 0x6E | ||
BIPUSH 0x6F | ||
BIPUSH 0x64 | ||
OUT | ||
OUT | ||
OUT | ||
OUT | ||
.end-main |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
.constant | ||
.end-constant | ||
|
||
.main | ||
|
||
L1: | ||
BIPUSH 0x00 | ||
IFLT L6 | ||
L2: | ||
BIPUSH 0x01 | ||
IFLT L6 | ||
L3: | ||
BIPUSH 0x02 | ||
IFLT L6 | ||
L4: | ||
BIPUSH 0x10 | ||
BIPUSH 0x11 | ||
ISUB | ||
IFLT L6 | ||
L5: | ||
BIPUSH 0x00 | ||
BIPUSH 0x00 | ||
BIPUSH 0x00 | ||
BIPUSH 0x00 | ||
BIPUSH 0x00 | ||
HALT | ||
L6: | ||
BIPUSH 0x37 | ||
HALT | ||
.end-main | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include "ijvm.h" | ||
#include "testutil.h" | ||
|
||
void run_calc_inp(char *input, char *expected) | ||
{ | ||
int res = init_ijvm("files/advanced/SimpleCalc.ijvm"); | ||
assert(res != -1); | ||
|
||
char buf[128]; | ||
FILE *f = tmpfile(); | ||
fprintf(f, "%s", input); | ||
rewind(f); | ||
set_input(f); | ||
|
||
FILE *out_file = tmpfile(); | ||
set_output(out_file); | ||
|
||
// Run program | ||
run(); | ||
|
||
rewind(out_file); | ||
memset(buf, '\0', 128); | ||
fread(buf, 1, 127, out_file); | ||
|
||
// Compare output | ||
assert(strncmp(buf, expected, strlen(expected)) == 0); | ||
|
||
destroy_ijvm(); | ||
|
||
} | ||
|
||
void test_calc_1() | ||
{ | ||
run_calc_inp("0 0 + ? .", "0\n"); | ||
run_calc_inp("0 9 + ? .", "9\n"); | ||
run_calc_inp("9 0 + ? .", "9\n"); | ||
run_calc_inp("9 9 - ? .", "0\n"); | ||
} | ||
|
||
void test_calc_2() | ||
{ | ||
run_calc_inp(" 5 4 -?.", "1\n"); | ||
run_calc_inp(" 8 8 8 - + ?.", "8\n"); | ||
} | ||
|
||
void test_calc_3() | ||
{ | ||
run_calc_inp("1 1 + 1 1 + 1 1 + 1 1 + 1 1 + +-++?.", "2\n"); | ||
run_calc_inp("9 8 -9 7-9 6-9 5-9 4-9 3-9 2-9 1-9 0- -+-+-+-+?.", "1\n"); | ||
} | ||
|
||
int main() | ||
{ | ||
RUN_TEST(test_calc_1); | ||
RUN_TEST(test_calc_2); | ||
RUN_TEST(test_calc_3); | ||
return END_TEST(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include "ijvm.h" | ||
#include "testutil.h" | ||
|
||
void run_calc_inp(char *input, char *expected) | ||
{ | ||
int res = init_ijvm("files/advanced/SimpleCalc.ijvm"); | ||
assert(res != -1); | ||
|
||
char buf[128]; | ||
FILE *f = tmpfile(); | ||
fprintf(f, "%s", input); | ||
rewind(f); | ||
set_input(f); | ||
|
||
FILE *out_file = tmpfile(); | ||
set_output(out_file); | ||
|
||
// Run program | ||
run(); | ||
|
||
rewind(out_file); | ||
memset(buf, '\0', 128); | ||
fread(buf, 1, 127, out_file); | ||
|
||
// Compare output | ||
assert(strncmp(buf, expected, strlen(expected)) == 0); | ||
|
||
destroy_ijvm(); | ||
|
||
} | ||
|
||
void test_rec_1() | ||
{ | ||
run_calc_inp("2!?.", "2\n"); | ||
} | ||
|
||
void test_rec_2() | ||
{ | ||
run_calc_inp("7!?.", "5040\n"); | ||
} | ||
|
||
void test_rec_3() | ||
{ | ||
run_calc_inp("8!?.", "40320\n"); | ||
} | ||
|
||
int main() | ||
{ | ||
RUN_TEST(test_rec_1); | ||
RUN_TEST(test_rec_2); | ||
RUN_TEST(test_rec_3); | ||
return END_TEST(); | ||
} |