From 2bf840925ba7781d16406ac28438f8bdc5f7d08c Mon Sep 17 00:00:00 2001 From: Leo Tenenbaum Date: Tue, 3 Mar 2020 17:05:28 -0500 Subject: new, better test system --- tests/.gitignore | 2 + tests/arr.toc | 70 ++++++++++++++++ tests/arr/arr.toc | 70 ---------------- tests/arr/expected | 200 ---------------------------------------------- tests/arr/test.sh | 3 - tests/arr2.toc | 71 ++++++++++++++++ tests/arr2/arr2.toc | 71 ---------------- tests/arr2/expected | 200 ---------------------------------------------- tests/arr2/test.sh | 3 - tests/arr2_expected | 200 ++++++++++++++++++++++++++++++++++++++++++++++ tests/arr3.toc | 54 +++++++++++++ tests/arr3/arr3.toc | 54 ------------- tests/arr3/expected | 200 ---------------------------------------------- tests/arr3/io.toc | 57 ------------- tests/arr3/test.sh | 3 - tests/arr3_expected | 200 ++++++++++++++++++++++++++++++++++++++++++++++ tests/arr_expected | 200 ++++++++++++++++++++++++++++++++++++++++++++++ tests/bf.toc | 120 ++++++++++++++++++++++++++++ tests/bf/bf.toc | 114 -------------------------- tests/bf/hw0.bf | 1 - tests/bf/hw1.bf | 2 - tests/bf/test.sh | 9 --- tests/bf_expected | 2 + tests/bf_hw0 | 1 + tests/bf_hw1 | 2 + tests/foreign.toc | 25 ++++++ tests/foreign/expected | 1 - tests/foreign/foreign.toc | 25 ------ tests/foreign/test.sh | 3 - tests/foreign_expected | 1 + tests/io.toc | 39 +++++++++ tests/nms.toc | 20 +++++ tests/nms/expected | 4 - tests/nms/io.toc | 57 ------------- tests/nms/nms.toc | 20 ----- tests/nms/test.sh | 3 - tests/nms_expected | 4 + tests/params.toc | 40 ++++++++++ tests/params/expected | 15 ---- tests/params/params.toc | 40 ---------- tests/params/test.sh | 3 - tests/params_expected | 15 ++++ tests/test.sh | 28 ++++--- 43 files changed, 1081 insertions(+), 1171 deletions(-) create mode 100644 tests/.gitignore create mode 100644 tests/arr.toc delete mode 100644 tests/arr/arr.toc delete mode 100644 tests/arr/expected delete mode 100755 tests/arr/test.sh create mode 100644 tests/arr2.toc delete mode 100644 tests/arr2/arr2.toc delete mode 100644 tests/arr2/expected delete mode 100755 tests/arr2/test.sh create mode 100644 tests/arr2_expected create mode 100644 tests/arr3.toc delete mode 100644 tests/arr3/arr3.toc delete mode 100644 tests/arr3/expected delete mode 100644 tests/arr3/io.toc delete mode 100755 tests/arr3/test.sh create mode 100644 tests/arr3_expected create mode 100644 tests/arr_expected create mode 100644 tests/bf.toc delete mode 100644 tests/bf/bf.toc delete mode 100644 tests/bf/hw0.bf delete mode 100644 tests/bf/hw1.bf delete mode 100755 tests/bf/test.sh create mode 100644 tests/bf_expected create mode 100644 tests/bf_hw0 create mode 100644 tests/bf_hw1 create mode 100644 tests/foreign.toc delete mode 100644 tests/foreign/expected delete mode 100644 tests/foreign/foreign.toc delete mode 100755 tests/foreign/test.sh create mode 100644 tests/foreign_expected create mode 100644 tests/io.toc create mode 100644 tests/nms.toc delete mode 100644 tests/nms/expected delete mode 100644 tests/nms/io.toc delete mode 100644 tests/nms/nms.toc delete mode 100755 tests/nms/test.sh create mode 100644 tests/nms_expected create mode 100644 tests/params.toc delete mode 100644 tests/params/expected delete mode 100644 tests/params/params.toc delete mode 100755 tests/params/test.sh create mode 100644 tests/params_expected (limited to 'tests') diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 0000000..d0c3d10 --- /dev/null +++ b/tests/.gitignore @@ -0,0 +1,2 @@ +got +out.c diff --git a/tests/arr.toc b/tests/arr.toc new file mode 100644 index 0000000..eee514a --- /dev/null +++ b/tests/arr.toc @@ -0,0 +1,70 @@ +puti ::= fn(x: int) { +//tcc's giving me "incompatible types for redefinition of 'printf'" for some reason (even though the declarations have the exact same type) + #C("#ifndef __TINYC__ +extern int printf(const char *fmt, ...); +#endif +"); + #C("printf(\"%ld\\n\", (long)x);"); +}; +putf ::= fn(x: float) { + #C("#ifndef __TINYC__ +extern int printf(const char *fmt, ...); +#endif +"); + #C("printf(\"%f\\n\", (double)x);"); +}; + +// it would be nice if Arr.data.len == Arr.len (: but this will require some C code... +Arr ::= fn (t :: Type) Type { + struct { + data : []t; + len, cap : int; + } +}; + +arr_add ::= fn(t :: Type, a : &Arr(t), x : t) { + if a.len >= a.cap { + a.cap = a.cap * 2 + 2; + new_data := new(t, a.cap); + for i := 0..a.len-1 { + new_data[i] = a.data[i]; + } + a.data = new_data; + } + a.data[a.len] = x; + a.len += 1; +}; + +square ::= fn(t :: Type, x : t) t { + a : Arr(t); + for i := 1,2..2*x-1 { + arr_add(t, &a, i); + }; + sum := 0 as t; + for i := 0..a.len-1 { + sum += a.data[i]; + }; + sum +}; + + +ArrInt ::= Arr(int); + +inc ::= fn(t :: Type, x : t) t { + x + 1 +}; + +main ::= fn() { + arr : ArrInt; + farr : Arr(float); + for i := 1..100 { + arr_add(int, &arr, inc(int, square(int, i))); + arr_add(float, &farr, inc(float, square(float, i as float))); + } + for i := 0..arr.len - 1 { + puti(arr.data[i]); + } + for i := 0..farr.len - 1 { + putf(farr.data[i]); + } +}; diff --git a/tests/arr/arr.toc b/tests/arr/arr.toc deleted file mode 100644 index eee514a..0000000 --- a/tests/arr/arr.toc +++ /dev/null @@ -1,70 +0,0 @@ -puti ::= fn(x: int) { -//tcc's giving me "incompatible types for redefinition of 'printf'" for some reason (even though the declarations have the exact same type) - #C("#ifndef __TINYC__ -extern int printf(const char *fmt, ...); -#endif -"); - #C("printf(\"%ld\\n\", (long)x);"); -}; -putf ::= fn(x: float) { - #C("#ifndef __TINYC__ -extern int printf(const char *fmt, ...); -#endif -"); - #C("printf(\"%f\\n\", (double)x);"); -}; - -// it would be nice if Arr.data.len == Arr.len (: but this will require some C code... -Arr ::= fn (t :: Type) Type { - struct { - data : []t; - len, cap : int; - } -}; - -arr_add ::= fn(t :: Type, a : &Arr(t), x : t) { - if a.len >= a.cap { - a.cap = a.cap * 2 + 2; - new_data := new(t, a.cap); - for i := 0..a.len-1 { - new_data[i] = a.data[i]; - } - a.data = new_data; - } - a.data[a.len] = x; - a.len += 1; -}; - -square ::= fn(t :: Type, x : t) t { - a : Arr(t); - for i := 1,2..2*x-1 { - arr_add(t, &a, i); - }; - sum := 0 as t; - for i := 0..a.len-1 { - sum += a.data[i]; - }; - sum -}; - - -ArrInt ::= Arr(int); - -inc ::= fn(t :: Type, x : t) t { - x + 1 -}; - -main ::= fn() { - arr : ArrInt; - farr : Arr(float); - for i := 1..100 { - arr_add(int, &arr, inc(int, square(int, i))); - arr_add(float, &farr, inc(float, square(float, i as float))); - } - for i := 0..arr.len - 1 { - puti(arr.data[i]); - } - for i := 0..farr.len - 1 { - putf(farr.data[i]); - } -}; diff --git a/tests/arr/expected b/tests/arr/expected deleted file mode 100644 index c0a3e45..0000000 --- a/tests/arr/expected +++ /dev/null @@ -1,200 +0,0 @@ -2 -5 -10 -17 -26 -37 -50 -65 -82 -101 -122 -145 -170 -197 -226 -257 -290 -325 -362 -401 -442 -485 -530 -577 -626 -677 -730 -785 -842 -901 -962 -1025 -1090 -1157 -1226 -1297 -1370 -1445 -1522 -1601 -1682 -1765 -1850 -1937 -2026 -2117 -2210 -2305 -2402 -2501 -2602 -2705 -2810 -2917 -3026 -3137 -3250 -3365 -3482 -3601 -3722 -3845 -3970 -4097 -4226 -4357 -4490 -4625 -4762 -4901 -5042 -5185 -5330 -5477 -5626 -5777 -5930 -6085 -6242 -6401 -6562 -6725 -6890 -7057 -7226 -7397 -7570 -7745 -7922 -8101 -8282 -8465 -8650 -8837 -9026 -9217 -9410 -9605 -9802 -10001 -2.000000 -5.000000 -10.000000 -17.000000 -26.000000 -37.000000 -50.000000 -65.000000 -82.000000 -101.000000 -122.000000 -145.000000 -170.000000 -197.000000 -226.000000 -257.000000 -290.000000 -325.000000 -362.000000 -401.000000 -442.000000 -485.000000 -530.000000 -577.000000 -626.000000 -677.000000 -730.000000 -785.000000 -842.000000 -901.000000 -962.000000 -1025.000000 -1090.000000 -1157.000000 -1226.000000 -1297.000000 -1370.000000 -1445.000000 -1522.000000 -1601.000000 -1682.000000 -1765.000000 -1850.000000 -1937.000000 -2026.000000 -2117.000000 -2210.000000 -2305.000000 -2402.000000 -2501.000000 -2602.000000 -2705.000000 -2810.000000 -2917.000000 -3026.000000 -3137.000000 -3250.000000 -3365.000000 -3482.000000 -3601.000000 -3722.000000 -3845.000000 -3970.000000 -4097.000000 -4226.000000 -4357.000000 -4490.000000 -4625.000000 -4762.000000 -4901.000000 -5042.000000 -5185.000000 -5330.000000 -5477.000000 -5626.000000 -5777.000000 -5930.000000 -6085.000000 -6242.000000 -6401.000000 -6562.000000 -6725.000000 -6890.000000 -7057.000000 -7226.000000 -7397.000000 -7570.000000 -7745.000000 -7922.000000 -8101.000000 -8282.000000 -8465.000000 -8650.000000 -8837.000000 -9026.000000 -9217.000000 -9410.000000 -9605.000000 -9802.000000 -10001.000000 diff --git a/tests/arr/test.sh b/tests/arr/test.sh deleted file mode 100755 index d50fb1a..0000000 --- a/tests/arr/test.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -./arr.bin > got || exit 1 -diff got expected || exit 1 diff --git a/tests/arr2.toc b/tests/arr2.toc new file mode 100644 index 0000000..e016cf2 --- /dev/null +++ b/tests/arr2.toc @@ -0,0 +1,71 @@ +puti ::= fn(x: int) { +#C("#ifndef __TINYC__ +extern int printf(const char *fmt, ...); +#endif +"); + #C("printf(\"%ld\\n\", (long)x); +"); +}; +putf ::= fn(x: float) { +#C("#ifndef __TINYC__ +extern int printf(const char *fmt, ...); +#endif +"); + #C("printf(\"%f\\n\", (double)x); +"); +}; + +// it would be nice if Arr.data.len == Arr.len (: but this will require some C code... +Arr ::= fn (t :: Type) Type { + struct { + data : []t; + len, cap : int; + } +}; + +arr_add ::= fn(t ::=, a : &Arr(t), x : t) { + if a.len >= a.cap { + a.cap = a.cap * 2 + 2; + new_data := new(t, a.cap); + for i := 0..a.len-1 { + new_data[i] = a.data[i]; + } + a.data = new_data; + } + a.data[a.len] = x; + a.len += 1; +}; + +square ::= fn(t ::=, x : t) t { + a : Arr(t); + for i := 1,2..2*x-1 { + arr_add(&a, i); + }; + sum := 0 as t; + for i := 0..a.len-1 { + sum += a.data[i]; + }; + sum +}; + + +// ArrInt ::= Arr(int); + +inc ::= fn(t ::=, x : t) t { + x + 1 +}; + +main ::= fn() { + arr : Arr(int); + farr : Arr(float); + for i := 1..100 { + arr_add(&arr, inc(square(i))); + arr_add(&farr, inc(square(i as float))); + } + for i := 0..arr.len - 1 { + puti(arr.data[i]); + } + for i := 0..farr.len - 1 { + putf(farr.data[i]); + } +}; diff --git a/tests/arr2/arr2.toc b/tests/arr2/arr2.toc deleted file mode 100644 index e016cf2..0000000 --- a/tests/arr2/arr2.toc +++ /dev/null @@ -1,71 +0,0 @@ -puti ::= fn(x: int) { -#C("#ifndef __TINYC__ -extern int printf(const char *fmt, ...); -#endif -"); - #C("printf(\"%ld\\n\", (long)x); -"); -}; -putf ::= fn(x: float) { -#C("#ifndef __TINYC__ -extern int printf(const char *fmt, ...); -#endif -"); - #C("printf(\"%f\\n\", (double)x); -"); -}; - -// it would be nice if Arr.data.len == Arr.len (: but this will require some C code... -Arr ::= fn (t :: Type) Type { - struct { - data : []t; - len, cap : int; - } -}; - -arr_add ::= fn(t ::=, a : &Arr(t), x : t) { - if a.len >= a.cap { - a.cap = a.cap * 2 + 2; - new_data := new(t, a.cap); - for i := 0..a.len-1 { - new_data[i] = a.data[i]; - } - a.data = new_data; - } - a.data[a.len] = x; - a.len += 1; -}; - -square ::= fn(t ::=, x : t) t { - a : Arr(t); - for i := 1,2..2*x-1 { - arr_add(&a, i); - }; - sum := 0 as t; - for i := 0..a.len-1 { - sum += a.data[i]; - }; - sum -}; - - -// ArrInt ::= Arr(int); - -inc ::= fn(t ::=, x : t) t { - x + 1 -}; - -main ::= fn() { - arr : Arr(int); - farr : Arr(float); - for i := 1..100 { - arr_add(&arr, inc(square(i))); - arr_add(&farr, inc(square(i as float))); - } - for i := 0..arr.len - 1 { - puti(arr.data[i]); - } - for i := 0..farr.len - 1 { - putf(farr.data[i]); - } -}; diff --git a/tests/arr2/expected b/tests/arr2/expected deleted file mode 100644 index c0a3e45..0000000 --- a/tests/arr2/expected +++ /dev/null @@ -1,200 +0,0 @@ -2 -5 -10 -17 -26 -37 -50 -65 -82 -101 -122 -145 -170 -197 -226 -257 -290 -325 -362 -401 -442 -485 -530 -577 -626 -677 -730 -785 -842 -901 -962 -1025 -1090 -1157 -1226 -1297 -1370 -1445 -1522 -1601 -1682 -1765 -1850 -1937 -2026 -2117 -2210 -2305 -2402 -2501 -2602 -2705 -2810 -2917 -3026 -3137 -3250 -3365 -3482 -3601 -3722 -3845 -3970 -4097 -4226 -4357 -4490 -4625 -4762 -4901 -5042 -5185 -5330 -5477 -5626 -5777 -5930 -6085 -6242 -6401 -6562 -6725 -6890 -7057 -7226 -7397 -7570 -7745 -7922 -8101 -8282 -8465 -8650 -8837 -9026 -9217 -9410 -9605 -9802 -10001 -2.000000 -5.000000 -10.000000 -17.000000 -26.000000 -37.000000 -50.000000 -65.000000 -82.000000 -101.000000 -122.000000 -145.000000 -170.000000 -197.000000 -226.000000 -257.000000 -290.000000 -325.000000 -362.000000 -401.000000 -442.000000 -485.000000 -530.000000 -577.000000 -626.000000 -677.000000 -730.000000 -785.000000 -842.000000 -901.000000 -962.000000 -1025.000000 -1090.000000 -1157.000000 -1226.000000 -1297.000000 -1370.000000 -1445.000000 -1522.000000 -1601.000000 -1682.000000 -1765.000000 -1850.000000 -1937.000000 -2026.000000 -2117.000000 -2210.000000 -2305.000000 -2402.000000 -2501.000000 -2602.000000 -2705.000000 -2810.000000 -2917.000000 -3026.000000 -3137.000000 -3250.000000 -3365.000000 -3482.000000 -3601.000000 -3722.000000 -3845.000000 -3970.000000 -4097.000000 -4226.000000 -4357.000000 -4490.000000 -4625.000000 -4762.000000 -4901.000000 -5042.000000 -5185.000000 -5330.000000 -5477.000000 -5626.000000 -5777.000000 -5930.000000 -6085.000000 -6242.000000 -6401.000000 -6562.000000 -6725.000000 -6890.000000 -7057.000000 -7226.000000 -7397.000000 -7570.000000 -7745.000000 -7922.000000 -8101.000000 -8282.000000 -8465.000000 -8650.000000 -8837.000000 -9026.000000 -9217.000000 -9410.000000 -9605.000000 -9802.000000 -10001.000000 diff --git a/tests/arr2/test.sh b/tests/arr2/test.sh deleted file mode 100755 index 0c1a5b7..0000000 --- a/tests/arr2/test.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -./arr2.bin > got || exit 1 -diff got expected || exit 1 diff --git a/tests/arr2_expected b/tests/arr2_expected new file mode 100644 index 0000000..c0a3e45 --- /dev/null +++ b/tests/arr2_expected @@ -0,0 +1,200 @@ +2 +5 +10 +17 +26 +37 +50 +65 +82 +101 +122 +145 +170 +197 +226 +257 +290 +325 +362 +401 +442 +485 +530 +577 +626 +677 +730 +785 +842 +901 +962 +1025 +1090 +1157 +1226 +1297 +1370 +1445 +1522 +1601 +1682 +1765 +1850 +1937 +2026 +2117 +2210 +2305 +2402 +2501 +2602 +2705 +2810 +2917 +3026 +3137 +3250 +3365 +3482 +3601 +3722 +3845 +3970 +4097 +4226 +4357 +4490 +4625 +4762 +4901 +5042 +5185 +5330 +5477 +5626 +5777 +5930 +6085 +6242 +6401 +6562 +6725 +6890 +7057 +7226 +7397 +7570 +7745 +7922 +8101 +8282 +8465 +8650 +8837 +9026 +9217 +9410 +9605 +9802 +10001 +2.000000 +5.000000 +10.000000 +17.000000 +26.000000 +37.000000 +50.000000 +65.000000 +82.000000 +101.000000 +122.000000 +145.000000 +170.000000 +197.000000 +226.000000 +257.000000 +290.000000 +325.000000 +362.000000 +401.000000 +442.000000 +485.000000 +530.000000 +577.000000 +626.000000 +677.000000 +730.000000 +785.000000 +842.000000 +901.000000 +962.000000 +1025.000000 +1090.000000 +1157.000000 +1226.000000 +1297.000000 +1370.000000 +1445.000000 +1522.000000 +1601.000000 +1682.000000 +1765.000000 +1850.000000 +1937.000000 +2026.000000 +2117.000000 +2210.000000 +2305.000000 +2402.000000 +2501.000000 +2602.000000 +2705.000000 +2810.000000 +2917.000000 +3026.000000 +3137.000000 +3250.000000 +3365.000000 +3482.000000 +3601.000000 +3722.000000 +3845.000000 +3970.000000 +4097.000000 +4226.000000 +4357.000000 +4490.000000 +4625.000000 +4762.000000 +4901.000000 +5042.000000 +5185.000000 +5330.000000 +5477.000000 +5626.000000 +5777.000000 +5930.000000 +6085.000000 +6242.000000 +6401.000000 +6562.000000 +6725.000000 +6890.000000 +7057.000000 +7226.000000 +7397.000000 +7570.000000 +7745.000000 +7922.000000 +8101.000000 +8282.000000 +8465.000000 +8650.000000 +8837.000000 +9026.000000 +9217.000000 +9410.000000 +9605.000000 +9802.000000 +10001.000000 diff --git a/tests/arr3.toc b/tests/arr3.toc new file mode 100644 index 0000000..a6d1b14 --- /dev/null +++ b/tests/arr3.toc @@ -0,0 +1,54 @@ +#include "io.toc"; + +Arr ::= struct (t :: Type) { + data: []t; + len, cap: int; +}; + + +arr_add ::= fn(t ::=, a : &Arr(t), x : t) { + if a.len >= a.cap { + a.cap = a.cap * 2 + 2; + new_data := new(t, a.cap); + for i := 0..a.len-1 { + new_data[i] = a.data[i]; + } + a.data = new_data; + } + a.data[a.len] = x; + a.len += 1; +}; + +square ::= fn(t ::=, x : t) t { + a : Arr(t); + for i := 1,2..2*x-1 { + arr_add(&a, i); + }; + sum := 0 as t; + for i := 0..a.len-1 { + sum += a.data[i]; + }; + sum +}; + + +// ArrInt ::= Arr(int); + +inc ::= fn(t ::=, x : t) t { + x + 1 +}; + +main ::= fn() { + arr : Arr(int); + farr : Arr(float); + for i := 1..100 { + arr_add(&arr, inc(square(i))); + arr_add(&farr, inc(square(i as float))); + } + for i := 0..arr.len - 1 { + puti(arr.data[i]); + } + for i := 0..farr.len - 1 { + puti(farr.data[i] as int); + } +}; diff --git a/tests/arr3/arr3.toc b/tests/arr3/arr3.toc deleted file mode 100644 index a6d1b14..0000000 --- a/tests/arr3/arr3.toc +++ /dev/null @@ -1,54 +0,0 @@ -#include "io.toc"; - -Arr ::= struct (t :: Type) { - data: []t; - len, cap: int; -}; - - -arr_add ::= fn(t ::=, a : &Arr(t), x : t) { - if a.len >= a.cap { - a.cap = a.cap * 2 + 2; - new_data := new(t, a.cap); - for i := 0..a.len-1 { - new_data[i] = a.data[i]; - } - a.data = new_data; - } - a.data[a.len] = x; - a.len += 1; -}; - -square ::= fn(t ::=, x : t) t { - a : Arr(t); - for i := 1,2..2*x-1 { - arr_add(&a, i); - }; - sum := 0 as t; - for i := 0..a.len-1 { - sum += a.data[i]; - }; - sum -}; - - -// ArrInt ::= Arr(int); - -inc ::= fn(t ::=, x : t) t { - x + 1 -}; - -main ::= fn() { - arr : Arr(int); - farr : Arr(float); - for i := 1..100 { - arr_add(&arr, inc(square(i))); - arr_add(&farr, inc(square(i as float))); - } - for i := 0..arr.len - 1 { - puti(arr.data[i]); - } - for i := 0..farr.len - 1 { - puti(farr.data[i] as int); - } -}; diff --git a/tests/arr3/expected b/tests/arr3/expected deleted file mode 100644 index 101ae98..0000000 --- a/tests/arr3/expected +++ /dev/null @@ -1,200 +0,0 @@ -2 -5 -10 -17 -26 -37 -50 -65 -82 -101 -122 -145 -170 -197 -226 -257 -290 -325 -362 -401 -442 -485 -530 -577 -626 -677 -730 -785 -842 -901 -962 -1025 -1090 -1157 -1226 -1297 -1370 -1445 -1522 -1601 -1682 -1765 -1850 -1937 -2026 -2117 -2210 -2305 -2402 -2501 -2602 -2705 -2810 -2917 -3026 -3137 -3250 -3365 -3482 -3601 -3722 -3845 -3970 -4097 -4226 -4357 -4490 -4625 -4762 -4901 -5042 -5185 -5330 -5477 -5626 -5777 -5930 -6085 -6242 -6401 -6562 -6725 -6890 -7057 -7226 -7397 -7570 -7745 -7922 -8101 -8282 -8465 -8650 -8837 -9026 -9217 -9410 -9605 -9802 -10001 -2 -5 -10 -17 -26 -37 -50 -65 -82 -101 -122 -145 -170 -197 -226 -257 -290 -325 -362 -401 -442 -485 -530 -577 -626 -677 -730 -785 -842 -901 -962 -1025 -1090 -1157 -1226 -1297 -1370 -1445 -1522 -1601 -1682 -1765 -1850 -1937 -2026 -2117 -2210 -2305 -2402 -2501 -2602 -2705 -2810 -2917 -3026 -3137 -3250 -3365 -3482 -3601 -3722 -3845 -3970 -4097 -4226 -4357 -4490 -4625 -4762 -4901 -5042 -5185 -5330 -5477 -5626 -5777 -5930 -6085 -6242 -6401 -6562 -6725 -6890 -7057 -7226 -7397 -7570 -7745 -7922 -8101 -8282 -8465 -8650 -8837 -9026 -9217 -9410 -9605 -9802 -10001 diff --git a/tests/arr3/io.toc b/tests/arr3/io.toc deleted file mode 100644 index 5a69269..0000000 --- a/tests/arr3/io.toc +++ /dev/null @@ -1,57 +0,0 @@ -get_type_with_size ::= fn(size :: i64) Type { - if size == 1 { i8 } - elif size == 2 { i16 } - elif size == 4 { i32 } - elif size == 8 { i64 } - else { f32 } -}; - -get_utype_with_size ::= fn(size :: i64) Type { - if size == 1 { u8 } - elif size == 2 { u16 } - elif size == 4 { u32 } - elif size == 8 { u64 } - else { f32 } -}; - -c_int ::= get_type_with_size(#builtin("sizeof int")); -c_size_t ::= get_utype_with_size(#builtin("sizeof size_t")); - -c_putchar ::= #foreign("putchar", "libc.so.6") fn(#C int) #C int; -toc_putchar ::= fn(x: char) { - c_putchar(x as c_int); -}; - -c_fwrite ::= #foreign("fwrite", "libc.so.6") fn(&u8, #C size_t, #C size_t, &u8) #C size_t; - -stdout_fwrite ::= fn(data: &u8, size: u64, nmemb: u64) { - c_fwrite(data, size as c_size_t, nmemb as c_size_t, #builtin("stdout")); -}; - -puts ::= fn(x: []char) { - stdout_fwrite(&x[0] as &u8, 1, x.len as u64); - toc_putchar('\n'); -}; - -puti ::= fn(x: int) { - if x < 0 { - toc_putchar('-'); - // NOTE: don't do x = -x; here to make sure I64_MIN works - } - if x == 0 { - toc_putchar('0'); - } else { - abs ::= fn(x: int) int { if x < 0 { -x } else { x } }; - scan_digit := 1000000000000000000; - started := false; - while scan_digit > 0 { - digit := abs((x / scan_digit) % 10); - if digit > 0 { started = true; } - if started { - toc_putchar((('0' as int) + digit) as char); - } - scan_digit /= 10; - } - } - toc_putchar('\n'); -}; diff --git a/tests/arr3/test.sh b/tests/arr3/test.sh deleted file mode 100755 index 135a6e0..0000000 --- a/tests/arr3/test.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -./arr3.bin > got || exit 1 -diff got expected || exit 1 diff --git a/tests/arr3_expected b/tests/arr3_expected new file mode 100644 index 0000000..101ae98 --- /dev/null +++ b/tests/arr3_expected @@ -0,0 +1,200 @@ +2 +5 +10 +17 +26 +37 +50 +65 +82 +101 +122 +145 +170 +197 +226 +257 +290 +325 +362 +401 +442 +485 +530 +577 +626 +677 +730 +785 +842 +901 +962 +1025 +1090 +1157 +1226 +1297 +1370 +1445 +1522 +1601 +1682 +1765 +1850 +1937 +2026 +2117 +2210 +2305 +2402 +2501 +2602 +2705 +2810 +2917 +3026 +3137 +3250 +3365 +3482 +3601 +3722 +3845 +3970 +4097 +4226 +4357 +4490 +4625 +4762 +4901 +5042 +5185 +5330 +5477 +5626 +5777 +5930 +6085 +6242 +6401 +6562 +6725 +6890 +7057 +7226 +7397 +7570 +7745 +7922 +8101 +8282 +8465 +8650 +8837 +9026 +9217 +9410 +9605 +9802 +10001 +2 +5 +10 +17 +26 +37 +50 +65 +82 +101 +122 +145 +170 +197 +226 +257 +290 +325 +362 +401 +442 +485 +530 +577 +626 +677 +730 +785 +842 +901 +962 +1025 +1090 +1157 +1226 +1297 +1370 +1445 +1522 +1601 +1682 +1765 +1850 +1937 +2026 +2117 +2210 +2305 +2402 +2501 +2602 +2705 +2810 +2917 +3026 +3137 +3250 +3365 +3482 +3601 +3722 +3845 +3970 +4097 +4226 +4357 +4490 +4625 +4762 +4901 +5042 +5185 +5330 +5477 +5626 +5777 +5930 +6085 +6242 +6401 +6562 +6725 +6890 +7057 +7226 +7397 +7570 +7745 +7922 +8101 +8282 +8465 +8650 +8837 +9026 +9217 +9410 +9605 +9802 +10001 diff --git a/tests/arr_expected b/tests/arr_expected new file mode 100644 index 0000000..c0a3e45 --- /dev/null +++ b/tests/arr_expected @@ -0,0 +1,200 @@ +2 +5 +10 +17 +26 +37 +50 +65 +82 +101 +122 +145 +170 +197 +226 +257 +290 +325 +362 +401 +442 +485 +530 +577 +626 +677 +730 +785 +842 +901 +962 +1025 +1090 +1157 +1226 +1297 +1370 +1445 +1522 +1601 +1682 +1765 +1850 +1937 +2026 +2117 +2210 +2305 +2402 +2501 +2602 +2705 +2810 +2917 +3026 +3137 +3250 +3365 +3482 +3601 +3722 +3845 +3970 +4097 +4226 +4357 +4490 +4625 +4762 +4901 +5042 +5185 +5330 +5477 +5626 +5777 +5930 +6085 +6242 +6401 +6562 +6725 +6890 +7057 +7226 +7397 +7570 +7745 +7922 +8101 +8282 +8465 +8650 +8837 +9026 +9217 +9410 +9605 +9802 +10001 +2.000000 +5.000000 +10.000000 +17.000000 +26.000000 +37.000000 +50.000000 +65.000000 +82.000000 +101.000000 +122.000000 +145.000000 +170.000000 +197.000000 +226.000000 +257.000000 +290.000000 +325.000000 +362.000000 +401.000000 +442.000000 +485.000000 +530.000000 +577.000000 +626.000000 +677.000000 +730.000000 +785.000000 +842.000000 +901.000000 +962.000000 +1025.000000 +1090.000000 +1157.000000 +1226.000000 +1297.000000 +1370.000000 +1445.000000 +1522.000000 +1601.000000 +1682.000000 +1765.000000 +1850.000000 +1937.000000 +2026.000000 +2117.000000 +2210.000000 +2305.000000 +2402.000000 +2501.000000 +2602.000000 +2705.000000 +2810.000000 +2917.000000 +3026.000000 +3137.000000 +3250.000000 +3365.000000 +3482.000000 +3601.000000 +3722.000000 +3845.000000 +3970.000000 +4097.000000 +4226.000000 +4357.000000 +4490.000000 +4625.000000 +4762.000000 +4901.000000 +5042.000000 +5185.000000 +5330.000000 +5477.000000 +5626.000000 +5777.000000 +5930.000000 +6085.000000 +6242.000000 +6401.000000 +6562.000000 +6725.000000 +6890.000000 +7057.000000 +7226.000000 +7397.000000 +7570.000000 +7745.000000 +7922.000000 +8101.000000 +8282.000000 +8465.000000 +8650.000000 +8837.000000 +9026.000000 +9217.000000 +9410.000000 +9605.000000 +9802.000000 +10001.000000 diff --git a/tests/bf.toc b/tests/bf.toc new file mode 100644 index 0000000..e1f8781 --- /dev/null +++ b/tests/bf.toc @@ -0,0 +1,120 @@ +readfile ::= fn(filename: []char) []char { +#C("extern void *fopen(char *name, char const *mode); extern char *fgets(char *buf, size_t sz, void *f);"); + fp : &u8 = #C("fopen(&(((char *)filename.data)[0]), \"r\")"); + contents : []char; + contents_sz : int; + contents_len : int; + buffer : [1024]char; + while #C("fgets(buffer, 1024, fp)") { + buffer_len : int; + while buffer[buffer_len] { + buffer_len = buffer_len + 1; + } + if contents_sz < contents_len + buffer_len { + old_contents := contents; + contents_sz = 2*contents_sz + 1024; + contents = new(char, contents_sz); + i := 0; + while i < contents_len { + contents[i] = old_contents[i]; + i = i + 1; + } + del(old_contents); + } + i := 0; + while i < buffer_len { + contents[contents_len] = buffer[i]; + contents_len = contents_len + 1; + i = i + 1; + } + } + contents[contents_len] = 0 as char; + contents +}; + +puti ::= fn(x: int) { + #C("#ifndef __TINYC__ +extern int printf(const char *fmt, ...); +#endif +"); + #C("printf(\"%ld\\n\", x);"); +}; + +runfile ::= fn(filename: []char) { + #C("extern int putchar(int c);"); + code := readfile(filename); + tape_sz := 3; + tape := new(int, tape_sz); + ptr := tape_sz / 2; + i := 0; + while code[i] { + // puti(ptr); + // puti(tape_sz); + if code[i] == '+' { + tape[ptr] = tape[ptr]+1; + } elif code[i] == '-' { + tape[ptr] = tape[ptr]-1; + } elif code[i] == '>' { + ptr = ptr + 1; + if ptr >= tape_sz { + // extend to the right + newtape := new(int, 2*tape_sz); + j := 0; + while j < tape_sz { + newtape[j] = tape[j]; + j = j + 1; + } + tape_sz = tape_sz * 2; + del(tape); + tape = newtape; + } + } elif code[i] == '<' { + ptr = ptr - 1; + if ptr < 0 { + // extend to the left + newtape := new(int, 2*tape_sz); + j := 0; + while j < tape_sz { + newtape[j+tape_sz] = tape[j]; + j = j + 1; + } + tape_sz = tape_sz * 2; + del(tape); + tape = newtape; + ptr = ptr + tape_sz; + } + } elif code[i] == '[' { + if !tape[ptr] { + // jump to matching ] + level := 0; + while level >= 0 { + i = i + 1; + level = level + (if code[i] == '[' { 1 } elif code[i] == ']' { -1 } else {0}); + } + } + } elif code[i] == ']' { + if tape[ptr] { + // jump to matching [ + level := 0; + while level <= 0 { + i = i - 1; + level = level + (if code[i] == '[' { 1 } elif code[i] == ']' { -1 } else {0}); + } + } + } elif code[i] == '.' { + c := tape[ptr] as char; + #C("putchar(c);"); + } elif code[i] == ',' { + // Input doesn't really work, because you + // need to send an EOF to end the program. + } + i = i + 1; + } + del(tape); + del(code); +}; + +main ::= fn() { + runfile("bf_hw0"); + runfile("bf_hw1"); +}; diff --git a/tests/bf/bf.toc b/tests/bf/bf.toc deleted file mode 100644 index 2331467..0000000 --- a/tests/bf/bf.toc +++ /dev/null @@ -1,114 +0,0 @@ -getstdin ::= fn() []char { -#C("extern void *stdin; extern char *fgets(char *buf, size_t sz, void *f);"); - contents : []char; - contents_sz : int; - contents_len : int; - buffer : [1024]char; - while #C("fgets(buffer, 1024, stdin)") { - buffer_len : int; - while buffer[buffer_len] { - buffer_len = buffer_len + 1; - } - if contents_sz < contents_len + buffer_len { - old_contents := contents; - contents_sz = 2*contents_sz + 1024; - contents = new(char, contents_sz); - i := 0; - while i < contents_len { - contents[i] = old_contents[i]; - i = i + 1; - } - del(old_contents); - } - i := 0; - while i < buffer_len { - contents[contents_len] = buffer[i]; - contents_len = contents_len + 1; - i = i + 1; - } - } - contents[contents_len] = 0 as char; - contents -}; - -puti ::= fn(x: int) { - #C("#ifndef __TINYC__ -extern int printf(const char *fmt, ...); -#endif -"); - #C("printf(\"%ld\\n\", x);"); -}; - -main ::= fn() { - #C("extern int putchar(int c);"); - code := getstdin(); - tape_sz := 3; - tape := new(int, tape_sz); - ptr := tape_sz / 2; - i := 0; - while code[i] { - // puti(ptr); - // puti(tape_sz); - if code[i] == '+' { - tape[ptr] = tape[ptr]+1; - } elif code[i] == '-' { - tape[ptr] = tape[ptr]-1; - } elif code[i] == '>' { - ptr = ptr + 1; - if ptr >= tape_sz { - // extend to the right - newtape := new(int, 2*tape_sz); - j := 0; - while j < tape_sz { - newtape[j] = tape[j]; - j = j + 1; - } - tape_sz = tape_sz * 2; - del(tape); - tape = newtape; - } - } elif code[i] == '<' { - ptr = ptr - 1; - if ptr < 0 { - // extend to the left - newtape := new(int, 2*tape_sz); - j := 0; - while j < tape_sz { - newtape[j+tape_sz] = tape[j]; - j = j + 1; - } - tape_sz = tape_sz * 2; - del(tape); - tape = newtape; - ptr = ptr + tape_sz; - } - } elif code[i] == '[' { - if !tape[ptr] { - // jump to matching ] - level := 0; - while level >= 0 { - i = i + 1; - level = level + (if code[i] == '[' { 1 } elif code[i] == ']' { -1 } else {0}); - } - } - } elif code[i] == ']' { - if tape[ptr] { - // jump to matching [ - level := 0; - while level <= 0 { - i = i - 1; - level = level + (if code[i] == '[' { 1 } elif code[i] == ']' { -1 } else {0}); - } - } - } elif code[i] == '.' { - c := tape[ptr] as char; - #C("putchar(c);"); - } elif code[i] == ',' { - // Input doesn't really work, because you - // need to send an EOF to end the program. - } - i = i + 1; - } - del(tape); - del(code); -}; diff --git a/tests/bf/hw0.bf b/tests/bf/hw0.bf deleted file mode 100644 index ea2b641..0000000 --- a/tests/bf/hw0.bf +++ /dev/null @@ -1 +0,0 @@ -++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++. \ No newline at end of file diff --git a/tests/bf/hw1.bf b/tests/bf/hw1.bf deleted file mode 100644 index db5525f..0000000 --- a/tests/bf/hw1.bf +++ /dev/null @@ -1,2 +0,0 @@ ->++++++++[-<+++++++++>]<.>>+>-[+]++>++>+++[>[->+++<<+++>]<<]>-----.>-> -+++..+++.>-.<<+[>[+>+]>>]<--------------.>>.+++.------.--------.>+.>+. \ No newline at end of file diff --git a/tests/bf/test.sh b/tests/bf/test.sh deleted file mode 100755 index 8b76794..0000000 --- a/tests/bf/test.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh -if [ "$(cat hw0.bf | ./bf.bin)" != "Hello World!" ]; then - echo "hello world 0 failed." - exit 1 -fi -if [ "$(cat hw1.bf | ./bf.bin)" != "Hello World!" ]; then - echo "hello world 1 failed." - exit 1 -fi diff --git a/tests/bf_expected b/tests/bf_expected new file mode 100644 index 0000000..f28b391 --- /dev/null +++ b/tests/bf_expected @@ -0,0 +1,2 @@ +Hello World! +Hello World! diff --git a/tests/bf_hw0 b/tests/bf_hw0 new file mode 100644 index 0000000..ea2b641 --- /dev/null +++ b/tests/bf_hw0 @@ -0,0 +1 @@ +++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++. \ No newline at end of file diff --git a/tests/bf_hw1 b/tests/bf_hw1 new file mode 100644 index 0000000..db5525f --- /dev/null +++ b/tests/bf_hw1 @@ -0,0 +1,2 @@ +>++++++++[-<+++++++++>]<.>>+>-[+]++>++>+++[>[->+++<<+++>]<<]>-----.>-> ++++..+++.>-.<<+[>[+>+]>>]<--------------.>>.+++.------.--------.>+.>+. \ No newline at end of file diff --git a/tests/foreign.toc b/tests/foreign.toc new file mode 100644 index 0000000..d88a223 --- /dev/null +++ b/tests/foreign.toc @@ -0,0 +1,25 @@ +fwrite ::= #foreign("fwrite", "libc.so.6") fn (#C &"void const", #C size_t, #C size_t, &u8) #C size_t; +fputc ::= #foreign("fputc", "libc.so.6") fn (#C int, &u8) #C int; + +writes ::= fn(x : []char) { + fwrite(&x[0], 1, x.len as u64, #builtin("stdout")); +}; + +puts ::= fn(x : []char) { + writes(x); + fputc('\n' as i32, #builtin("stdout")); +}; + +hw ::= fn() int { + writes("Hello,"); + if #builtin("compiling") { + writes(" compiling"); + } + puts(" world!"); + 3 +}; + +main ::= fn() { + hw(); + x ::= hw(); +}; \ No newline at end of file diff --git a/tests/foreign/expected b/tests/foreign/expected deleted file mode 100644 index af5626b..0000000 --- a/tests/foreign/expected +++ /dev/null @@ -1 +0,0 @@ -Hello, world! diff --git a/tests/foreign/foreign.toc b/tests/foreign/foreign.toc deleted file mode 100644 index d88a223..0000000 --- a/tests/foreign/foreign.toc +++ /dev/null @@ -1,25 +0,0 @@ -fwrite ::= #foreign("fwrite", "libc.so.6") fn (#C &"void const", #C size_t, #C size_t, &u8) #C size_t; -fputc ::= #foreign("fputc", "libc.so.6") fn (#C int, &u8) #C int; - -writes ::= fn(x : []char) { - fwrite(&x[0], 1, x.len as u64, #builtin("stdout")); -}; - -puts ::= fn(x : []char) { - writes(x); - fputc('\n' as i32, #builtin("stdout")); -}; - -hw ::= fn() int { - writes("Hello,"); - if #builtin("compiling") { - writes(" compiling"); - } - puts(" world!"); - 3 -}; - -main ::= fn() { - hw(); - x ::= hw(); -}; \ No newline at end of file diff --git a/tests/foreign/test.sh b/tests/foreign/test.sh deleted file mode 100755 index 1d6eb8f..0000000 --- a/tests/foreign/test.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -./foreign.bin > got || exit 1 -diff got expected || exit 1 diff --git a/tests/foreign_expected b/tests/foreign_expected new file mode 100644 index 0000000..af5626b --- /dev/null +++ b/tests/foreign_expected @@ -0,0 +1 @@ +Hello, world! diff --git a/tests/io.toc b/tests/io.toc new file mode 100644 index 0000000..9e94147 --- /dev/null +++ b/tests/io.toc @@ -0,0 +1,39 @@ + +putchar ::= #foreign("putchar", "libc.so.6") fn(#C int) #C int; +toc_putchar ::= fn(x: char) { + putchar(x as #C int); +}; + +fwrite ::= #foreign("fwrite", "libc.so.6") fn(#C &"void", #C size_t, #C size_t, #C &"void") #C size_t; + +stdout_fwrite ::= fn(data: &u8, size: u64, nmemb: u64) { + fwrite(data, size as #C size_t, nmemb as #C size_t, #builtin("stdout")); +}; + +puts ::= fn(x: []char) { + stdout_fwrite(&x[0] as &u8, 1, x.len as u64); + toc_putchar('\n'); +}; + +puti ::= fn(x: int) { + if x < 0 { + toc_putchar('-'); + // NOTE: don't do x = -x; here to make sure I64_MIN works + } + if x == 0 { + toc_putchar('0'); + } else { + abs ::= fn(x: int) int { if x < 0 { -x } else { x } }; + scan_digit := 1000000000000000000; + started := false; + while scan_digit > 0 { + digit := abs((x / scan_digit) % 10); + if digit > 0 { started = true; } + if started { + toc_putchar((('0' as int) + digit) as char); + } + scan_digit /= 10; + } + } + toc_putchar('\n'); +}; diff --git a/tests/nms.toc b/tests/nms.toc new file mode 100644 index 0000000..413da8d --- /dev/null +++ b/tests/nms.toc @@ -0,0 +1,20 @@ +io ::= nms { + #include "io.toc"; +}; + +n ::= nms { + x := 1; + counter ::= fn() int { x += 1; x }; +}; + + +main ::= fn() { + a := n.counter(); + b := n.counter(); + n.counter(); + c := n.counter(); + io.puts("Hello!"); + io.puti(a); + io.puti(b); + io.puti(c); +}; diff --git a/tests/nms/expected b/tests/nms/expected deleted file mode 100644 index d26c123..0000000 --- a/tests/nms/expected +++ /dev/null @@ -1,4 +0,0 @@ -Hello! -2 -3 -5 diff --git a/tests/nms/io.toc b/tests/nms/io.toc deleted file mode 100644 index 5a69269..0000000 --- a/tests/nms/io.toc +++ /dev/null @@ -1,57 +0,0 @@ -get_type_with_size ::= fn(size :: i64) Type { - if size == 1 { i8 } - elif size == 2 { i16 } - elif size == 4 { i32 } - elif size == 8 { i64 } - else { f32 } -}; - -get_utype_with_size ::= fn(size :: i64) Type { - if size == 1 { u8 } - elif size == 2 { u16 } - elif size == 4 { u32 } - elif size == 8 { u64 } - else { f32 } -}; - -c_int ::= get_type_with_size(#builtin("sizeof int")); -c_size_t ::= get_utype_with_size(#builtin("sizeof size_t")); - -c_putchar ::= #foreign("putchar", "libc.so.6") fn(#C int) #C int; -toc_putchar ::= fn(x: char) { - c_putchar(x as c_int); -}; - -c_fwrite ::= #foreign("fwrite", "libc.so.6") fn(&u8, #C size_t, #C size_t, &u8) #C size_t; - -stdout_fwrite ::= fn(data: &u8, size: u64, nmemb: u64) { - c_fwrite(data, size as c_size_t, nmemb as c_size_t, #builtin("stdout")); -}; - -puts ::= fn(x: []char) { - stdout_fwrite(&x[0] as &u8, 1, x.len as u64); - toc_putchar('\n'); -}; - -puti ::= fn(x: int) { - if x < 0 { - toc_putchar('-'); - // NOTE: don't do x = -x; here to make sure I64_MIN works - } - if x == 0 { - toc_putchar('0'); - } else { - abs ::= fn(x: int) int { if x < 0 { -x } else { x } }; - scan_digit := 1000000000000000000; - started := false; - while scan_digit > 0 { - digit := abs((x / scan_digit) % 10); - if digit > 0 { started = true; } - if started { - toc_putchar((('0' as int) + digit) as char); - } - scan_digit /= 10; - } - } - toc_putchar('\n'); -}; diff --git a/tests/nms/nms.toc b/tests/nms/nms.toc deleted file mode 100644 index 413da8d..0000000 --- a/tests/nms/nms.toc +++ /dev/null @@ -1,20 +0,0 @@ -io ::= nms { - #include "io.toc"; -}; - -n ::= nms { - x := 1; - counter ::= fn() int { x += 1; x }; -}; - - -main ::= fn() { - a := n.counter(); - b := n.counter(); - n.counter(); - c := n.counter(); - io.puts("Hello!"); - io.puti(a); - io.puti(b); - io.puti(c); -}; diff --git a/tests/nms/test.sh b/tests/nms/test.sh deleted file mode 100755 index 8f1a481..0000000 --- a/tests/nms/test.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -./nms.bin > got || exit 1 -diff got expected || exit 1 diff --git a/tests/nms_expected b/tests/nms_expected new file mode 100644 index 0000000..d26c123 --- /dev/null +++ b/tests/nms_expected @@ -0,0 +1,4 @@ +Hello! +2 +3 +5 diff --git a/tests/params.toc b/tests/params.toc new file mode 100644 index 0000000..4d37cf1 --- /dev/null +++ b/tests/params.toc @@ -0,0 +1,40 @@ +addmul ::= fn (x:=0, y:=0) add := x+y, mul := x*y { +}; + +do_foo ::= fn (x := 3) y := x { + y *= 12; + y += x; +}; + +puti ::= fn(x: int) { + #C("#ifndef __TINYC__ +extern int printf(const char *fmt, ...); +#endif +"); + #C("printf(\"%ld\\n\", x);"); +}; + + +main ::= fn() { + a, m := addmul(); + puti(a); puti(m); + a, m = addmul(7,3); + puti(a); puti(m); + a, m = addmul(5); + puti(a); puti(m); + a, m = addmul(y = 17); + puti(a); puti(m); + + c, d ::= addmul(); + puti(c); puti(d); + e, f ::= addmul(y = 3, x = 7); + puti(e); puti(f); + + + z := do_foo(); + puti(z); + z = do_foo(-1); + puti(z); + z = do_foo(x = -1); + puti(z); +}; \ No newline at end of file diff --git a/tests/params/expected b/tests/params/expected deleted file mode 100644 index 082b847..0000000 --- a/tests/params/expected +++ /dev/null @@ -1,15 +0,0 @@ -0 -0 -10 -21 -5 -0 -17 -0 -0 -0 -10 -21 -39 --13 --13 diff --git a/tests/params/params.toc b/tests/params/params.toc deleted file mode 100644 index 4d37cf1..0000000 --- a/tests/params/params.toc +++ /dev/null @@ -1,40 +0,0 @@ -addmul ::= fn (x:=0, y:=0) add := x+y, mul := x*y { -}; - -do_foo ::= fn (x := 3) y := x { - y *= 12; - y += x; -}; - -puti ::= fn(x: int) { - #C("#ifndef __TINYC__ -extern int printf(const char *fmt, ...); -#endif -"); - #C("printf(\"%ld\\n\", x);"); -}; - - -main ::= fn() { - a, m := addmul(); - puti(a); puti(m); - a, m = addmul(7,3); - puti(a); puti(m); - a, m = addmul(5); - puti(a); puti(m); - a, m = addmul(y = 17); - puti(a); puti(m); - - c, d ::= addmul(); - puti(c); puti(d); - e, f ::= addmul(y = 3, x = 7); - puti(e); puti(f); - - - z := do_foo(); - puti(z); - z = do_foo(-1); - puti(z); - z = do_foo(x = -1); - puti(z); -}; \ No newline at end of file diff --git a/tests/params/test.sh b/tests/params/test.sh deleted file mode 100755 index 582bdec..0000000 --- a/tests/params/test.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -./params.bin > got || exit 1 -diff got expected || exit 1 diff --git a/tests/params_expected b/tests/params_expected new file mode 100644 index 0000000..082b847 --- /dev/null +++ b/tests/params_expected @@ -0,0 +1,15 @@ +0 +0 +10 +21 +5 +0 +17 +0 +0 +0 +10 +21 +39 +-13 +-13 diff --git a/tests/test.sh b/tests/test.sh index 6d534d3..1d47dff 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -1,10 +1,11 @@ #!/bin/bash -DIR=$(pwd)/$(dirname $0) -TOC=$DIR/../toc +STARTPWD=$(pwd) +cd $(pwd)/$(dirname $0) +TOC=../toc CFLAGS="-g -Wno-parentheses-equality" echo $$ -compile() { +compile_c() { EXTRA_FLAGS="" if [ "$CC" = "gcc -O0 -g" ]; then EXTRA_FLAGS="-Wno-builtin-declaration-mismatch" @@ -13,24 +14,24 @@ compile() { elif [ "$CC" = "tcc" ]; then EXTRA_FLAGS="-w" fi - $CC $CFLAGS $EXTRA_FLAGS -o $DIR/$1/$1.bin $DIR/$1/$1.c || exit 1 + $CC $CFLAGS $EXTRA_FLAGS -o a.out out.c || exit 1 } do_tests() { - cd "$DIR/$1" - valgrind -q --exit-on-first-error=yes --error-exitcode=1 $TOC "$DIR/$1/$1.toc" -o "$DIR/$1/$1.c" >/dev/null || exit 1 + valgrind -q --exit-on-first-error=yes --error-exitcode=1 $TOC "$1.toc" -o out.c || exit 1 for CC in "gcc -O0 -g" "tcc" "clang -O3 -s"; do printf "Running test $1 with C compiler $CC... " - compile "$1" - ./test.sh || { printf "\x1b[91mfailed!\x1b[0m\n"; exit 1; } - printf '\x1b[92mpassed!\x1b[0m\n' + compile_c "$1" + ./a.out > got + if diff "$1"_expected got; then + printf '\x1b[92mpassed!\x1b[0m\n' + else + printf '\x1b[91mfailed!\x1b[0m\n' + exit 1 + fi done - cd $STARTPWD - } -STARTPWD="$(pwd)" - do_tests bf do_tests arr do_tests arr2 @@ -38,3 +39,4 @@ do_tests arr3 do_tests foreign do_tests params do_tests nms +rm got a.out out.c -- cgit v1.2.3