diff --git a/test/arrays.c0 b/test/arrays.c0 new file mode 100644 index 0000000..116e811 --- /dev/null +++ b/test/arrays.c0 @@ -0,0 +1,12 @@ +#use + +int main() { + int[] A = alloc_array(int, -2); + A[3] = 0; + A[3] = 1; + A[3] = 2; + A[3] = 3; + + printint(A[3]); + return 0; +} diff --git a/test/arrays.c0.bc0 b/test/arrays.c0.bc0 new file mode 100644 index 0000000..380b6e0 --- /dev/null +++ b/test/arrays.c0.bc0 @@ -0,0 +1,52 @@ +C0 C0 FF EE # magic number +00 09 # version 4, arch = 1 (64 bits) + +00 00 # int pool count +# int pool + +00 00 # string pool total size +# string pool + +00 01 # function count +# function_pool + +#
+00 00 # number of arguments = 0 +00 01 # number of local variables = 1 +00 33 # code length = 51 bytes +10 FE # bipush -2 # -2 +BC 04 # newarray 4 # alloc_array(int, -(2)) +36 00 # vstore 0 # A = alloc_array(int, -(2)); +15 00 # vload 0 # A +10 03 # bipush 3 # 3 +63 # aadds # &A[3] +10 00 # bipush 0 # 0 +4E # imstore # A[3] = 0; +15 00 # vload 0 # A +10 03 # bipush 3 # 3 +63 # aadds # &A[3] +10 01 # bipush 1 # 1 +4E # imstore # A[3] = 1; +15 00 # vload 0 # A +10 03 # bipush 3 # 3 +63 # aadds # &A[3] +10 02 # bipush 2 # 2 +4E # imstore # A[3] = 2; +15 00 # vload 0 # A +10 03 # bipush 3 # 3 +63 # aadds # &A[3] +10 03 # bipush 3 # 3 +4E # imstore # A[3] = 3; +15 00 # vload 0 # A +10 03 # bipush 3 # 3 +63 # aadds # &A[3] +2E # imload # A[3] +B7 00 00 # invokenative 0 # printint(A[3]) +57 # pop # (ignore result) +10 00 # bipush 0 # 0 +B0 # return # + +00 01 # native count +# native pool +00 01 00 09 # printint + diff --git a/test/arrays.c0.bc0out b/test/arrays.c0.bc0out new file mode 100644 index 0000000..64bb6b7 --- /dev/null +++ b/test/arrays.c0.bc0out @@ -0,0 +1 @@ +30 diff --git a/test/arrays.c0.c0out b/test/arrays.c0.c0out new file mode 100644 index 0000000..e69de29 diff --git a/test/arrays.c0.ex b/test/arrays.c0.ex new file mode 100755 index 0000000..dcc6996 Binary files /dev/null and b/test/arrays.c0.ex differ diff --git a/test/structs.c0 b/test/structs.c0 new file mode 100644 index 0000000..6e25968 --- /dev/null +++ b/test/structs.c0 @@ -0,0 +1,18 @@ +#use + +struct test { + int a; + string b; + int c; +}; + +int main() { + struct test* t = alloc(struct test); + t->a = 1; + t->b = "potato chip"; + t->c = 23; + print(t->b); + printint(t->a); + printint(t->c); + return 0; +} diff --git a/test/structs.c0.bc0 b/test/structs.c0.bc0 new file mode 100644 index 0000000..1a94959 --- /dev/null +++ b/test/structs.c0.bc0 @@ -0,0 +1,54 @@ +C0 C0 FF EE # magic number +00 09 # version 4, arch = 1 (64 bits) + +00 00 # int pool count +# int pool + +00 0C # string pool total size +# string pool +70 6F 74 61 74 6F 20 63 68 69 70 00 # "potato chip" + +00 01 # function count +# function_pool + +#
+00 00 # number of arguments = 0 +00 01 # number of local variables = 1 +00 38 # code length = 56 bytes +BB 18 # new 24 # alloc(struct test) +36 00 # vstore 0 # t = alloc(struct test); +15 00 # vload 0 # t +62 00 # aaddf 0 # &t->a +10 01 # bipush 1 # 1 +4E # imstore # t->a = 1; +15 00 # vload 0 # t +62 08 # aaddf 8 # &t->b +14 00 00 # aldc 0 # s[0] = "potato chip" +4F # amstore # t->b = "potato chip"; +15 00 # vload 0 # t +62 10 # aaddf 16 # &t->c +10 17 # bipush 23 # 23 +4E # imstore # t->c = 23; +15 00 # vload 0 # t +62 08 # aaddf 8 # &t->b +2F # amload # t->b +B7 00 00 # invokenative 0 # print(t->b) +57 # pop # (ignore result) +15 00 # vload 0 # t +62 00 # aaddf 0 # &t->a +2E # imload # t->a +B7 00 01 # invokenative 1 # printint(t->a) +57 # pop # (ignore result) +15 00 # vload 0 # t +62 10 # aaddf 16 # &t->c +2E # imload # t->c +B7 00 01 # invokenative 1 # printint(t->c) +57 # pop # (ignore result) +10 00 # bipush 0 # 0 +B0 # return # + +00 02 # native count +# native pool +00 01 00 06 # print +00 01 00 09 # printint + diff --git a/test/structs.c0.bc0out b/test/structs.c0.bc0out new file mode 100644 index 0000000..62b3dfa --- /dev/null +++ b/test/structs.c0.bc0out @@ -0,0 +1 @@ +potato chip1230 diff --git a/test/structs.c0.c0out b/test/structs.c0.c0out new file mode 100644 index 0000000..62b3dfa --- /dev/null +++ b/test/structs.c0.c0out @@ -0,0 +1 @@ +potato chip1230 diff --git a/test/structs.c0.ex b/test/structs.c0.ex new file mode 100755 index 0000000..617b699 Binary files /dev/null and b/test/structs.c0.ex differ diff --git a/test/tests.js b/test/tests.js index 6229ddb..0e2116b 100644 --- a/test/tests.js +++ b/test/tests.js @@ -37,3 +37,14 @@ exports.testIF = doTest("testif.c0.bc0", 32); exports.testDSQUARED = doTest("dsquared.c0.bc0", 17068); +exports.testArrays = function(test) { + var result = c0vm.execute(parser.parse("arrays.c0.bc0"), callbacks, false); + test.ok(false, "test.bc0 - Did not print to screen correctly"); + test.done(); +} + +exports.testStructs = function(test) { + var result = c0vm.execute(parser.parse("structs.c0.bc0"), callbacks, false); + test.ok(false, "test.bc0 - Did not print to screen correctly"); + test.done(); +}